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 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 74 | static constexpr uint32_t kMaxIntShiftValue = 0x1f; |
| 75 | static constexpr uint64_t kMaxLongShiftValue = 0x3f; |
| 76 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 77 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 78 | static constexpr uint16_t kUnknownClassDefIndex = static_cast<uint16_t>(-1); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 79 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 80 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 81 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 82 | static constexpr uint32_t kNoDexPc = -1; |
| 83 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 84 | enum IfCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 85 | // All types. |
| 86 | kCondEQ, // == |
| 87 | kCondNE, // != |
| 88 | // Signed integers and floating-point numbers. |
| 89 | kCondLT, // < |
| 90 | kCondLE, // <= |
| 91 | kCondGT, // > |
| 92 | kCondGE, // >= |
| 93 | // Unsigned integers. |
| 94 | kCondB, // < |
| 95 | kCondBE, // <= |
| 96 | kCondA, // > |
| 97 | kCondAE, // >= |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 98 | }; |
| 99 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 100 | enum GraphAnalysisResult { |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 101 | kAnalysisInvalidBytecode, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 102 | kAnalysisFailThrowCatchLoop, |
| 103 | kAnalysisFailAmbiguousArrayOp, |
| 104 | kAnalysisSuccess, |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 105 | }; |
| 106 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 107 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 108 | public: |
| 109 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 110 | |
| 111 | void AddInstruction(HInstruction* instruction); |
| 112 | void RemoveInstruction(HInstruction* instruction); |
| 113 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 114 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 115 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 116 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 117 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 118 | // Return true if this list contains `instruction`. |
| 119 | bool Contains(HInstruction* instruction) const; |
| 120 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 121 | // Return true if `instruction1` is found before `instruction2` in |
| 122 | // this instruction list and false otherwise. Abort if none |
| 123 | // of these instructions is found. |
| 124 | bool FoundBefore(const HInstruction* instruction1, |
| 125 | const HInstruction* instruction2) const; |
| 126 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 127 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 128 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 129 | |
| 130 | // Update the block of all instructions to be `block`. |
| 131 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 132 | |
| 133 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
| 134 | void Add(const HInstructionList& instruction_list); |
| 135 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 136 | // Return the number of instructions in the list. This is an expensive operation. |
| 137 | size_t CountSize() const; |
| 138 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 139 | private: |
| 140 | HInstruction* first_instruction_; |
| 141 | HInstruction* last_instruction_; |
| 142 | |
| 143 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 144 | friend class HGraph; |
| 145 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 146 | friend class HInstructionIterator; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 147 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 148 | |
| 149 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 150 | }; |
| 151 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 152 | class ReferenceTypeInfo : ValueObject { |
| 153 | public: |
| 154 | typedef Handle<mirror::Class> TypeHandle; |
| 155 | |
| 156 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact) { |
| 157 | // The constructor will check that the type_handle is valid. |
| 158 | return ReferenceTypeInfo(type_handle, is_exact); |
| 159 | } |
| 160 | |
| 161 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 162 | |
Vladimir Marko | f39745e | 2016-01-26 12:16:55 +0000 | [diff] [blame] | 163 | static bool IsValidHandle(TypeHandle handle) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 164 | return handle.GetReference() != nullptr; |
| 165 | } |
| 166 | |
| 167 | bool IsValid() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 168 | return IsValidHandle(type_handle_); |
| 169 | } |
| 170 | |
| 171 | bool IsExact() const { return is_exact_; } |
| 172 | |
| 173 | bool IsObjectClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 174 | DCHECK(IsValid()); |
| 175 | return GetTypeHandle()->IsObjectClass(); |
| 176 | } |
| 177 | |
| 178 | bool IsStringClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 179 | DCHECK(IsValid()); |
| 180 | return GetTypeHandle()->IsStringClass(); |
| 181 | } |
| 182 | |
| 183 | bool IsObjectArray() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 184 | DCHECK(IsValid()); |
| 185 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 186 | } |
| 187 | |
| 188 | bool IsInterface() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 189 | DCHECK(IsValid()); |
| 190 | return GetTypeHandle()->IsInterface(); |
| 191 | } |
| 192 | |
| 193 | bool IsArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 194 | DCHECK(IsValid()); |
| 195 | return GetTypeHandle()->IsArrayClass(); |
| 196 | } |
| 197 | |
| 198 | bool IsPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 199 | DCHECK(IsValid()); |
| 200 | return GetTypeHandle()->IsPrimitiveArray(); |
| 201 | } |
| 202 | |
| 203 | bool IsNonPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 204 | DCHECK(IsValid()); |
| 205 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 206 | } |
| 207 | |
| 208 | bool CanArrayHold(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 209 | DCHECK(IsValid()); |
| 210 | if (!IsExact()) return false; |
| 211 | if (!IsArrayClass()) return false; |
| 212 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 213 | } |
| 214 | |
| 215 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 216 | DCHECK(IsValid()); |
| 217 | if (!IsExact()) return false; |
| 218 | if (!IsArrayClass()) return false; |
| 219 | if (!rti.IsArrayClass()) return false; |
| 220 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 221 | rti.GetTypeHandle()->GetComponentType()); |
| 222 | } |
| 223 | |
| 224 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 225 | |
| 226 | bool IsSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 227 | DCHECK(IsValid()); |
| 228 | DCHECK(rti.IsValid()); |
| 229 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 230 | } |
| 231 | |
| 232 | bool IsStrictSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 233 | DCHECK(IsValid()); |
| 234 | DCHECK(rti.IsValid()); |
| 235 | return GetTypeHandle().Get() != rti.GetTypeHandle().Get() && |
| 236 | GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 237 | } |
| 238 | |
| 239 | // Returns true if the type information provide the same amount of details. |
| 240 | // Note that it does not mean that the instructions have the same actual type |
| 241 | // (because the type can be the result of a merge). |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 242 | bool IsEqual(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 243 | if (!IsValid() && !rti.IsValid()) { |
| 244 | // Invalid types are equal. |
| 245 | return true; |
| 246 | } |
| 247 | if (!IsValid() || !rti.IsValid()) { |
| 248 | // One is valid, the other not. |
| 249 | return false; |
| 250 | } |
| 251 | return IsExact() == rti.IsExact() |
| 252 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
| 253 | } |
| 254 | |
| 255 | private: |
| 256 | ReferenceTypeInfo(); |
| 257 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact); |
| 258 | |
| 259 | // The class of the object. |
| 260 | TypeHandle type_handle_; |
| 261 | // Whether or not the type is exact or a superclass of the actual type. |
| 262 | // Whether or not we have any information about this type. |
| 263 | bool is_exact_; |
| 264 | }; |
| 265 | |
| 266 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 267 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 268 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 269 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 270 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 271 | HGraph(ArenaAllocator* arena, |
| 272 | const DexFile& dex_file, |
| 273 | uint32_t method_idx, |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 274 | bool should_generate_constructor_barrier, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 275 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 276 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 277 | bool debuggable = false, |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 278 | bool osr = false, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 279 | int start_instruction_id = 0) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 280 | : arena_(arena), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 281 | blocks_(arena->Adapter(kArenaAllocBlockList)), |
| 282 | reverse_post_order_(arena->Adapter(kArenaAllocReversePostOrder)), |
| 283 | linear_order_(arena->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 284 | entry_block_(nullptr), |
| 285 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 286 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 287 | number_of_vregs_(0), |
| 288 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 289 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 290 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 291 | has_try_catch_(false), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 292 | has_irreducible_loops_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 293 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 294 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 295 | dex_file_(dex_file), |
| 296 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 297 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 298 | in_ssa_form_(false), |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 299 | should_generate_constructor_barrier_(should_generate_constructor_barrier), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 300 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 301 | cached_null_constant_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 302 | cached_int_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 303 | cached_float_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 304 | cached_long_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 305 | cached_double_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 306 | cached_current_method_(nullptr), |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 307 | inexact_object_rti_(ReferenceTypeInfo::CreateInvalid()), |
| 308 | osr_(osr) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 309 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 310 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 311 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 312 | // Acquires and stores RTI of inexact Object to be used when creating HNullConstant. |
| 313 | void InitializeInexactObjectRTI(StackHandleScopeCollection* handles); |
| 314 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 315 | ArenaAllocator* GetArena() const { return arena_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 316 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 317 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 318 | bool IsInSsaForm() const { return in_ssa_form_; } |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 319 | void SetInSsaForm() { in_ssa_form_ = true; } |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 320 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 321 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 322 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 323 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 324 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 325 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 326 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 327 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 328 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 329 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 330 | void ComputeDominanceInformation(); |
| 331 | void ClearDominanceInformation(); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 332 | void ClearLoopInformation(); |
| 333 | void FindBackEdges(ArenaBitVector* visited); |
| 334 | GraphAnalysisResult BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 335 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 336 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 337 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 338 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 339 | // 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] | 340 | // 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] | 341 | GraphAnalysisResult AnalyzeLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 342 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 343 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 344 | // order and loop information. |
| 345 | void ComputeTryBlockInformation(); |
| 346 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 347 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 348 | // Returns the instruction to replace the invoke expression or null if the |
| 349 | // invoke is for a void method. Note that the caller is responsible for replacing |
| 350 | // and removing the invoke instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 351 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 352 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 353 | // Need to add a couple of blocks to test if the loop body is entered and |
| 354 | // put deoptimization instructions, etc. |
| 355 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 356 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 357 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 358 | // other blocks and has no instructions or phis. |
| 359 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 360 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 361 | // Splits the edge between `block` and `successor` while preserving the |
| 362 | // indices in the predecessor/successor lists. If there are multiple edges |
| 363 | // between the blocks, the lowest indices are used. |
| 364 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 365 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 366 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 367 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 368 | void SimplifyLoop(HBasicBlock* header); |
| 369 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 370 | int32_t GetNextInstructionId() { |
| 371 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 372 | return current_instruction_id_++; |
| 373 | } |
| 374 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 375 | int32_t GetCurrentInstructionId() const { |
| 376 | return current_instruction_id_; |
| 377 | } |
| 378 | |
| 379 | void SetCurrentInstructionId(int32_t id) { |
| 380 | current_instruction_id_ = id; |
| 381 | } |
| 382 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 383 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 384 | return maximum_number_of_out_vregs_; |
| 385 | } |
| 386 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 387 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 388 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 389 | } |
| 390 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 391 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 392 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 393 | } |
| 394 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 395 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 396 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 397 | } |
| 398 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 399 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 400 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 401 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 402 | } |
| 403 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 404 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 405 | number_of_vregs_ = number_of_vregs; |
| 406 | } |
| 407 | |
| 408 | uint16_t GetNumberOfVRegs() const { |
| 409 | return number_of_vregs_; |
| 410 | } |
| 411 | |
| 412 | void SetNumberOfInVRegs(uint16_t value) { |
| 413 | number_of_in_vregs_ = value; |
| 414 | } |
| 415 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 416 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 417 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 418 | return number_of_vregs_ - number_of_in_vregs_; |
| 419 | } |
| 420 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 421 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 422 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 423 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 424 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 425 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 426 | return linear_order_; |
| 427 | } |
| 428 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 429 | bool HasBoundsChecks() const { |
| 430 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 431 | } |
| 432 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 433 | void SetHasBoundsChecks(bool value) { |
| 434 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 435 | } |
| 436 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 437 | bool ShouldGenerateConstructorBarrier() const { |
| 438 | return should_generate_constructor_barrier_; |
| 439 | } |
| 440 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 441 | bool IsDebuggable() const { return debuggable_; } |
| 442 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 443 | // 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] | 444 | // already, it is created and inserted into the graph. This method is only for |
| 445 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 446 | 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] | 447 | |
| 448 | // TODO: This is problematic for the consistency of reference type propagation |
| 449 | // because it can be created anytime after the pass and thus it will be left |
| 450 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 451 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 452 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 453 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 454 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 455 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 456 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 457 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 458 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 459 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 460 | 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] | 461 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 462 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 463 | 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] | 464 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 465 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 466 | HCurrentMethod* GetCurrentMethod(); |
| 467 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 468 | const DexFile& GetDexFile() const { |
| 469 | return dex_file_; |
| 470 | } |
| 471 | |
| 472 | uint32_t GetMethodIdx() const { |
| 473 | return method_idx_; |
| 474 | } |
| 475 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 476 | InvokeType GetInvokeType() const { |
| 477 | return invoke_type_; |
| 478 | } |
| 479 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 480 | InstructionSet GetInstructionSet() const { |
| 481 | return instruction_set_; |
| 482 | } |
| 483 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 484 | bool IsCompilingOsr() const { return osr_; } |
| 485 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 486 | bool HasTryCatch() const { return has_try_catch_; } |
| 487 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 488 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 489 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 490 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 491 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 492 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 493 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 494 | |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 495 | // Returns an instruction with the opposite boolean value from 'cond'. |
| 496 | // The instruction has been inserted into the graph, either as a constant, or |
| 497 | // before cursor. |
| 498 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 499 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 500 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 501 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 502 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 503 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 504 | template <class InstructionType, typename ValueType> |
| 505 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 506 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 507 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 508 | // Try to find an existing constant of the given value. |
| 509 | InstructionType* constant = nullptr; |
| 510 | auto cached_constant = cache->find(value); |
| 511 | if (cached_constant != cache->end()) { |
| 512 | constant = cached_constant->second; |
| 513 | } |
| 514 | |
| 515 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 516 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 517 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 518 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 519 | cache->Overwrite(value, constant); |
| 520 | InsertConstant(constant); |
| 521 | } |
| 522 | return constant; |
| 523 | } |
| 524 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 525 | void InsertConstant(HConstant* instruction); |
| 526 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 527 | // Cache a float constant into the graph. This method should only be |
| 528 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 529 | void CacheFloatConstant(HFloatConstant* constant); |
| 530 | |
| 531 | // See CacheFloatConstant comment. |
| 532 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 533 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 534 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 535 | |
| 536 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 537 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 538 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 539 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 540 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 541 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 542 | // List of blocks to perform a linear order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 543 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 544 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 545 | HBasicBlock* entry_block_; |
| 546 | HBasicBlock* exit_block_; |
| 547 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 548 | // 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] | 549 | uint16_t maximum_number_of_out_vregs_; |
| 550 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 551 | // The number of virtual registers in this method. Contains the parameters. |
| 552 | uint16_t number_of_vregs_; |
| 553 | |
| 554 | // The number of virtual registers used by parameters of this method. |
| 555 | uint16_t number_of_in_vregs_; |
| 556 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 557 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 558 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 559 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 560 | // Has bounds checks. We can totally skip BCE if it's false. |
| 561 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 562 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 563 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 564 | // try/catch-related passes if false. |
| 565 | bool has_try_catch_; |
| 566 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 567 | // Flag whether there are any irreducible loops in the graph. |
| 568 | bool has_irreducible_loops_; |
| 569 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 570 | // Indicates whether the graph should be compiled in a way that |
| 571 | // ensures full debuggability. If false, we can apply more |
| 572 | // aggressive optimizations that may limit the level of debugging. |
| 573 | const bool debuggable_; |
| 574 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 575 | // 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] | 576 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 577 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 578 | // The dex file from which the method is from. |
| 579 | const DexFile& dex_file_; |
| 580 | |
| 581 | // The method index in the dex file. |
| 582 | const uint32_t method_idx_; |
| 583 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 584 | // If inlined, this encodes how the callee is being invoked. |
| 585 | const InvokeType invoke_type_; |
| 586 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 587 | // Whether the graph has been transformed to SSA form. Only used |
| 588 | // in debug mode to ensure we are not using properties only valid |
| 589 | // for non-SSA form (like the number of temporaries). |
| 590 | bool in_ssa_form_; |
| 591 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 592 | const bool should_generate_constructor_barrier_; |
| 593 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 594 | const InstructionSet instruction_set_; |
| 595 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 596 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 597 | HNullConstant* cached_null_constant_; |
| 598 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 599 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 600 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 601 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 602 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 603 | HCurrentMethod* cached_current_method_; |
| 604 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 605 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 606 | // for example for methods whose declaring class could not be resolved |
| 607 | // (such as when the superclass could not be found). |
| 608 | ArtMethod* art_method_; |
| 609 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 610 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 611 | // collection pointer to passes which may create NullConstant. |
| 612 | ReferenceTypeInfo inexact_object_rti_; |
| 613 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 614 | // Whether we are compiling this graph for on stack replacement: this will |
| 615 | // make all loops seen as irreducible and emit special stack maps to mark |
| 616 | // compiled code entries which the interpreter can directly jump to. |
| 617 | const bool osr_; |
| 618 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 619 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 620 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 621 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 622 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 623 | }; |
| 624 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 625 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 626 | public: |
| 627 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 628 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 629 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 630 | irreducible_(false), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 631 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 632 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 633 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true) { |
| 634 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 635 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 636 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 637 | bool IsIrreducible() const { return irreducible_; } |
| 638 | |
| 639 | void Dump(std::ostream& os); |
| 640 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 641 | HBasicBlock* GetHeader() const { |
| 642 | return header_; |
| 643 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 644 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 645 | void SetHeader(HBasicBlock* block) { |
| 646 | header_ = block; |
| 647 | } |
| 648 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 649 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 650 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 651 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 652 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 653 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 654 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 655 | } |
| 656 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 657 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 658 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 659 | } |
| 660 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 661 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 662 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 663 | } |
| 664 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 665 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 666 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 667 | } |
| 668 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 669 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 670 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 671 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 672 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 673 | } |
| 674 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 675 | // Returns the lifetime position of the back edge that has the |
| 676 | // greatest lifetime position. |
| 677 | size_t GetLifetimeEnd() const; |
| 678 | |
| 679 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 680 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 681 | } |
| 682 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 683 | // Finds blocks that are part of this loop. |
| 684 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 685 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 686 | // Returns whether this loop information contains `block`. |
| 687 | // Note that this loop information *must* be populated before entering this function. |
| 688 | bool Contains(const HBasicBlock& block) const; |
| 689 | |
| 690 | // Returns whether this loop information is an inner loop of `other`. |
| 691 | // Note that `other` *must* be populated before entering this function. |
| 692 | bool IsIn(const HLoopInformation& other) const; |
| 693 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 694 | // Returns true if instruction is not defined within this loop. |
| 695 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 696 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 697 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 698 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 699 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 700 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 701 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 702 | void ClearAllBlocks() { |
| 703 | blocks_.ClearAllBits(); |
| 704 | } |
| 705 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 706 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 707 | // Internal recursive implementation of `Populate`. |
| 708 | void PopulateRecursive(HBasicBlock* block); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 709 | void PopulateIrreducibleRecursive(HBasicBlock* block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 710 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 711 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 712 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 713 | bool irreducible_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 714 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 715 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 716 | |
| 717 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 718 | }; |
| 719 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 720 | // Stores try/catch information for basic blocks. |
| 721 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 722 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 723 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 724 | public: |
| 725 | // Try block information constructor. |
| 726 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 727 | : try_entry_(&try_entry), |
| 728 | catch_dex_file_(nullptr), |
| 729 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 730 | DCHECK(try_entry_ != nullptr); |
| 731 | } |
| 732 | |
| 733 | // Catch block information constructor. |
| 734 | TryCatchInformation(uint16_t catch_type_index, const DexFile& dex_file) |
| 735 | : try_entry_(nullptr), |
| 736 | catch_dex_file_(&dex_file), |
| 737 | catch_type_index_(catch_type_index) {} |
| 738 | |
| 739 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 740 | |
| 741 | const HTryBoundary& GetTryEntry() const { |
| 742 | DCHECK(IsTryBlock()); |
| 743 | return *try_entry_; |
| 744 | } |
| 745 | |
| 746 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 747 | |
| 748 | bool IsCatchAllTypeIndex() const { |
| 749 | DCHECK(IsCatchBlock()); |
| 750 | return catch_type_index_ == DexFile::kDexNoIndex16; |
| 751 | } |
| 752 | |
| 753 | uint16_t GetCatchTypeIndex() const { |
| 754 | DCHECK(IsCatchBlock()); |
| 755 | return catch_type_index_; |
| 756 | } |
| 757 | |
| 758 | const DexFile& GetCatchDexFile() const { |
| 759 | DCHECK(IsCatchBlock()); |
| 760 | return *catch_dex_file_; |
| 761 | } |
| 762 | |
| 763 | private: |
| 764 | // One of possibly several TryBoundary instructions entering the block's try. |
| 765 | // Only set for try blocks. |
| 766 | const HTryBoundary* try_entry_; |
| 767 | |
| 768 | // Exception type information. Only set for catch blocks. |
| 769 | const DexFile* catch_dex_file_; |
| 770 | const uint16_t catch_type_index_; |
| 771 | }; |
| 772 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 773 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 774 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 775 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 776 | // A block in a method. Contains the list of instructions represented |
| 777 | // as a double linked list. Each block knows its predecessors and |
| 778 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 779 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 780 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 781 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 782 | HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 783 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 784 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 785 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 786 | loop_information_(nullptr), |
| 787 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 788 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 789 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 790 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 791 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 792 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 793 | try_catch_information_(nullptr) { |
| 794 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 795 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 796 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 797 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 798 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 799 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 800 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 801 | } |
| 802 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 803 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 804 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 805 | } |
| 806 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 807 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 808 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 809 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 810 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 811 | return ContainsElement(successors_, block, start_from); |
| 812 | } |
| 813 | |
| 814 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 815 | return dominated_blocks_; |
| 816 | } |
| 817 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 818 | bool IsEntryBlock() const { |
| 819 | return graph_->GetEntryBlock() == this; |
| 820 | } |
| 821 | |
| 822 | bool IsExitBlock() const { |
| 823 | return graph_->GetExitBlock() == this; |
| 824 | } |
| 825 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 826 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 827 | bool IsSingleTryBoundary() const; |
| 828 | |
| 829 | // Returns true if this block emits nothing but a jump. |
| 830 | bool IsSingleJump() const { |
| 831 | HLoopInformation* loop_info = GetLoopInformation(); |
| 832 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 833 | // Back edges generate a suspend check. |
| 834 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 835 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 836 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 837 | void AddBackEdge(HBasicBlock* back_edge) { |
| 838 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 839 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 840 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 841 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 842 | loop_information_->AddBackEdge(back_edge); |
| 843 | } |
| 844 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 845 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 846 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 847 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 848 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 849 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 850 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 851 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 852 | HBasicBlock* GetDominator() const { return dominator_; } |
| 853 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 854 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 855 | |
| 856 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 857 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 858 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 859 | |
| 860 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 861 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 862 | } |
| 863 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 864 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 865 | |
| 866 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 867 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 868 | } |
| 869 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 870 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 871 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 872 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 873 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 874 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 875 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 876 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 877 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 878 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 879 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 880 | successors_.push_back(block); |
| 881 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 882 | } |
| 883 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 884 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 885 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 886 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 887 | new_block->predecessors_.push_back(this); |
| 888 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 889 | } |
| 890 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 891 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 892 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 893 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 894 | new_block->successors_.push_back(this); |
| 895 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 896 | } |
| 897 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 898 | // Insert `this` between `predecessor` and `successor. This method |
| 899 | // preserves the indicies, and will update the first edge found between |
| 900 | // `predecessor` and `successor`. |
| 901 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 902 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 903 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 904 | successor->predecessors_[predecessor_index] = this; |
| 905 | predecessor->successors_[successor_index] = this; |
| 906 | successors_.push_back(successor); |
| 907 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 908 | } |
| 909 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 910 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 911 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 912 | } |
| 913 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 914 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 915 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 916 | } |
| 917 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 918 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 919 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 923 | predecessors_.push_back(block); |
| 924 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 925 | } |
| 926 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 927 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 928 | DCHECK_EQ(predecessors_.size(), 2u); |
| 929 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 930 | } |
| 931 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 932 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 933 | DCHECK_EQ(successors_.size(), 2u); |
| 934 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 935 | } |
| 936 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 937 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 938 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 939 | } |
| 940 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 941 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 942 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 943 | } |
| 944 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 945 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 946 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 947 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 951 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 952 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | // Returns whether the first occurrence of `predecessor` in the list of |
| 956 | // predecessors is at index `idx`. |
| 957 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 958 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 959 | return GetPredecessorIndexOf(predecessor) == idx; |
| 960 | } |
| 961 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 962 | // Create a new block between this block and its predecessors. The new block |
| 963 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 964 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 965 | // loop and try/catch information are not updated. |
| 966 | HBasicBlock* CreateImmediateDominator(); |
| 967 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 968 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 969 | // created, latter block. Note that this method will add the block to the |
| 970 | // graph, create a Goto at the end of the former block and will create an edge |
| 971 | // 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] | 972 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 973 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 974 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 975 | // Split the block into two blocks just after `cursor`. Returns the newly |
| 976 | // created block. Note that this method just updates raw block information, |
| 977 | // like predecessors, successors, dominators, and instruction list. It does not |
| 978 | // update the graph, reverse post order, loop information, nor make sure the |
| 979 | // blocks are consistent (for example ending with a control flow instruction). |
| 980 | HBasicBlock* SplitAfter(HInstruction* cursor); |
| 981 | |
David Brazdil | 9bc4361 | 2015-11-05 21:25:24 +0000 | [diff] [blame] | 982 | // Split catch block into two blocks after the original move-exception bytecode |
| 983 | // instruction, or at the beginning if not present. Returns the newly created, |
| 984 | // latter block, or nullptr if such block could not be created (must be dead |
| 985 | // in that case). Note that this method just updates raw block information, |
| 986 | // like predecessors, successors, dominators, and instruction list. It does not |
| 987 | // update the graph, reverse post order, loop information, nor make sure the |
| 988 | // blocks are consistent (for example ending with a control flow instruction). |
| 989 | HBasicBlock* SplitCatchBlockAfterMoveException(); |
| 990 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 991 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 992 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 993 | // that this method does not update the graph, reverse post order, loop |
| 994 | // information, nor make sure the blocks are consistent (for example ending |
| 995 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 996 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 997 | |
| 998 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 999 | // of `this` are moved to `other`. |
| 1000 | // Note that this method does not update the graph, reverse post order, loop |
| 1001 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1002 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1003 | void ReplaceWith(HBasicBlock* other); |
| 1004 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1005 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1006 | // order, links to predecessors, successors, dominators and deletes the block |
| 1007 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1008 | // predecessor of `other` and vice versa. |
| 1009 | void MergeWith(HBasicBlock* other); |
| 1010 | |
| 1011 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1012 | // removes it from all loops it is included in and eventually from the graph. |
| 1013 | // The block must not dominate any other block. Predecessors and successors |
| 1014 | // are safely updated. |
| 1015 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1016 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1017 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1018 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1019 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1020 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1021 | // Replace instruction `initial` with `replacement` within this block. |
| 1022 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1023 | HInstruction* replacement); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1024 | void MoveInstructionBefore(HInstruction* insn, HInstruction* cursor); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1025 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1026 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1027 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1028 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1029 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1030 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1031 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1032 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1033 | |
| 1034 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1035 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1036 | } |
| 1037 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1038 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1039 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1040 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1041 | } |
| 1042 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1043 | bool IsFirstPredecessorBackEdge() const { |
| 1044 | DCHECK(IsLoopHeader()); |
| 1045 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1046 | } |
| 1047 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1048 | HLoopInformation* GetLoopInformation() const { |
| 1049 | return loop_information_; |
| 1050 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1051 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1052 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1053 | // 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] | 1054 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1055 | void SetInLoop(HLoopInformation* info) { |
| 1056 | if (IsLoopHeader()) { |
| 1057 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1058 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1059 | loop_information_ = info; |
| 1060 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1061 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1062 | // Note that a non loop header having a loop information means this loop information |
| 1063 | // has already been populated |
| 1064 | loop_information_ = info; |
| 1065 | } else { |
| 1066 | // Block is part of an inner loop. Do not update the loop information. |
| 1067 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1068 | // at this point, because this method is being called while populating `info`. |
| 1069 | } |
| 1070 | } |
| 1071 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1072 | // Raw update of the loop information. |
| 1073 | void SetLoopInformation(HLoopInformation* info) { |
| 1074 | loop_information_ = info; |
| 1075 | } |
| 1076 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1077 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1078 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1079 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1080 | |
| 1081 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1082 | try_catch_information_ = try_catch_information; |
| 1083 | } |
| 1084 | |
| 1085 | bool IsTryBlock() const { |
| 1086 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1087 | } |
| 1088 | |
| 1089 | bool IsCatchBlock() const { |
| 1090 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1091 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1092 | |
| 1093 | // Returns the try entry that this block's successors should have. They will |
| 1094 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1095 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1096 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1097 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1098 | bool HasThrowingInstructions() const; |
| 1099 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1100 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1101 | bool Dominates(HBasicBlock* block) const; |
| 1102 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1103 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1104 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1105 | |
| 1106 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1107 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1108 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1109 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1110 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1111 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1112 | bool HasSinglePhi() const; |
| 1113 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1114 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1115 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1116 | ArenaVector<HBasicBlock*> predecessors_; |
| 1117 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1118 | HInstructionList instructions_; |
| 1119 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1120 | HLoopInformation* loop_information_; |
| 1121 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1122 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1123 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1124 | // The dex program counter of the first instruction of this block. |
| 1125 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1126 | size_t lifetime_start_; |
| 1127 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1128 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1129 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1130 | friend class HGraph; |
| 1131 | friend class HInstruction; |
| 1132 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1133 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1134 | }; |
| 1135 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1136 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1137 | // from the innermost to the outermost. |
| 1138 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1139 | public: |
| 1140 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1141 | : current_(block.GetLoopInformation()) {} |
| 1142 | |
| 1143 | bool Done() const { return current_ == nullptr; } |
| 1144 | |
| 1145 | void Advance() { |
| 1146 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1147 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | HLoopInformation* Current() const { |
| 1151 | DCHECK(!Done()); |
| 1152 | return current_; |
| 1153 | } |
| 1154 | |
| 1155 | private: |
| 1156 | HLoopInformation* current_; |
| 1157 | |
| 1158 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1159 | }; |
| 1160 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1161 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1162 | M(Above, Condition) \ |
| 1163 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1164 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1165 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1166 | M(ArrayGet, Instruction) \ |
| 1167 | M(ArrayLength, Instruction) \ |
| 1168 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1169 | M(Below, Condition) \ |
| 1170 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1171 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1172 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1173 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1174 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1175 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1176 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1177 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1178 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1179 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1180 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1181 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1182 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1183 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1184 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1185 | M(Exit, Instruction) \ |
| 1186 | M(FloatConstant, Constant) \ |
| 1187 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1188 | M(GreaterThan, Condition) \ |
| 1189 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1190 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1191 | M(InstanceFieldGet, Instruction) \ |
| 1192 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1193 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1194 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1195 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1196 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1197 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1198 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1199 | M(LessThan, Condition) \ |
| 1200 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1201 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1202 | M(LoadException, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1203 | M(LoadLocal, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1204 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1205 | M(Local, Instruction) \ |
| 1206 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1207 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1208 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1209 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1210 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1211 | M(Neg, UnaryOperation) \ |
| 1212 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1213 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1214 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1215 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1216 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1217 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1218 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1219 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1220 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1221 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1222 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1223 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1224 | M(Return, Instruction) \ |
| 1225 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1226 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1227 | M(Shl, BinaryOperation) \ |
| 1228 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1229 | M(StaticFieldGet, Instruction) \ |
| 1230 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1231 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1232 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1233 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1234 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1235 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1236 | M(StoreLocal, Instruction) \ |
| 1237 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1238 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1239 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1240 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1241 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1242 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1243 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1244 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1245 | #ifndef ART_ENABLE_CODEGEN_arm |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1246 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1247 | #else |
| 1248 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1249 | M(ArmDexCacheArraysBase, Instruction) |
| 1250 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1251 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1252 | #ifndef ART_ENABLE_CODEGEN_arm64 |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1253 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1254 | #else |
| 1255 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1256 | M(Arm64DataProcWithShifterOp, Instruction) \ |
Nicolas Geoffray | 6b5afdd | 2016-01-22 09:31:52 +0000 | [diff] [blame] | 1257 | M(Arm64IntermediateAddress, Instruction) \ |
| 1258 | M(Arm64MultiplyAccumulate, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1259 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1260 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1261 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
| 1262 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1263 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1264 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1265 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1266 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1267 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1268 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1269 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1270 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1271 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1272 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1273 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1274 | |
| 1275 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1276 | |
| 1277 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1278 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
| 1279 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1280 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1281 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1282 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1283 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1284 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1285 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1286 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1287 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1288 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1289 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1290 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1291 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1292 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1293 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1294 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1295 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1296 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1297 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1298 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1299 | #undef FORWARD_DECLARATION |
| 1300 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1301 | #define DECLARE_INSTRUCTION(type) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1302 | InstructionKind GetKindInternal() const OVERRIDE { return k##type; } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1303 | const char* DebugName() const OVERRIDE { return #type; } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1304 | bool InstructionTypeEquals(HInstruction* other) const OVERRIDE { \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1305 | return other->Is##type(); \ |
| 1306 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1307 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1308 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1309 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
| 1310 | bool Is##type() const { return As##type() != nullptr; } \ |
| 1311 | const H##type* As##type() const { return this; } \ |
| 1312 | H##type* As##type() { return this; } |
| 1313 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1314 | template <typename T> class HUseList; |
| 1315 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1316 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1317 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1318 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1319 | HUseListNode* GetPrevious() const { return prev_; } |
| 1320 | HUseListNode* GetNext() const { return next_; } |
| 1321 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1322 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1323 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1324 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1325 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1326 | HUseListNode(T user, size_t index) |
| 1327 | : user_(user), index_(index), prev_(nullptr), next_(nullptr) {} |
| 1328 | |
| 1329 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1330 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1331 | HUseListNode<T>* prev_; |
| 1332 | HUseListNode<T>* next_; |
| 1333 | |
| 1334 | friend class HUseList<T>; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1335 | |
| 1336 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1337 | }; |
| 1338 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1339 | template <typename T> |
| 1340 | class HUseList : public ValueObject { |
| 1341 | public: |
| 1342 | HUseList() : first_(nullptr) {} |
| 1343 | |
| 1344 | void Clear() { |
| 1345 | first_ = nullptr; |
| 1346 | } |
| 1347 | |
| 1348 | // Adds a new entry at the beginning of the use list and returns |
| 1349 | // the newly created node. |
| 1350 | HUseListNode<T>* AddUse(T user, size_t index, ArenaAllocator* arena) { |
David Brazdil | ea55b93 | 2015-01-27 17:12:29 +0000 | [diff] [blame] | 1351 | HUseListNode<T>* new_node = new (arena) HUseListNode<T>(user, index); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1352 | if (IsEmpty()) { |
| 1353 | first_ = new_node; |
| 1354 | } else { |
| 1355 | first_->prev_ = new_node; |
| 1356 | new_node->next_ = first_; |
| 1357 | first_ = new_node; |
| 1358 | } |
| 1359 | return new_node; |
| 1360 | } |
| 1361 | |
| 1362 | HUseListNode<T>* GetFirst() const { |
| 1363 | return first_; |
| 1364 | } |
| 1365 | |
| 1366 | void Remove(HUseListNode<T>* node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1367 | DCHECK(node != nullptr); |
| 1368 | DCHECK(Contains(node)); |
| 1369 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1370 | if (node->prev_ != nullptr) { |
| 1371 | node->prev_->next_ = node->next_; |
| 1372 | } |
| 1373 | if (node->next_ != nullptr) { |
| 1374 | node->next_->prev_ = node->prev_; |
| 1375 | } |
| 1376 | if (node == first_) { |
| 1377 | first_ = node->next_; |
| 1378 | } |
| 1379 | } |
| 1380 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1381 | bool Contains(const HUseListNode<T>* node) const { |
| 1382 | if (node == nullptr) { |
| 1383 | return false; |
| 1384 | } |
| 1385 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1386 | if (current == node) { |
| 1387 | return true; |
| 1388 | } |
| 1389 | } |
| 1390 | return false; |
| 1391 | } |
| 1392 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1393 | bool IsEmpty() const { |
| 1394 | return first_ == nullptr; |
| 1395 | } |
| 1396 | |
| 1397 | bool HasOnlyOneUse() const { |
| 1398 | return first_ != nullptr && first_->next_ == nullptr; |
| 1399 | } |
| 1400 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1401 | size_t SizeSlow() const { |
| 1402 | size_t count = 0; |
| 1403 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1404 | ++count; |
| 1405 | } |
| 1406 | return count; |
| 1407 | } |
| 1408 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1409 | private: |
| 1410 | HUseListNode<T>* first_; |
| 1411 | }; |
| 1412 | |
| 1413 | template<typename T> |
| 1414 | class HUseIterator : public ValueObject { |
| 1415 | public: |
| 1416 | explicit HUseIterator(const HUseList<T>& uses) : current_(uses.GetFirst()) {} |
| 1417 | |
| 1418 | bool Done() const { return current_ == nullptr; } |
| 1419 | |
| 1420 | void Advance() { |
| 1421 | DCHECK(!Done()); |
| 1422 | current_ = current_->GetNext(); |
| 1423 | } |
| 1424 | |
| 1425 | HUseListNode<T>* Current() const { |
| 1426 | DCHECK(!Done()); |
| 1427 | return current_; |
| 1428 | } |
| 1429 | |
| 1430 | private: |
| 1431 | HUseListNode<T>* current_; |
| 1432 | |
| 1433 | friend class HValue; |
| 1434 | }; |
| 1435 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1436 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1437 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1438 | // by the used instructions. |
| 1439 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1440 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1441 | public: |
| 1442 | HUserRecord() : instruction_(nullptr), use_node_(nullptr) {} |
| 1443 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), use_node_(nullptr) {} |
| 1444 | |
| 1445 | HUserRecord(const HUserRecord<T>& old_record, HUseListNode<T>* use_node) |
| 1446 | : instruction_(old_record.instruction_), use_node_(use_node) { |
| 1447 | DCHECK(instruction_ != nullptr); |
| 1448 | DCHECK(use_node_ != nullptr); |
| 1449 | DCHECK(old_record.use_node_ == nullptr); |
| 1450 | } |
| 1451 | |
| 1452 | HInstruction* GetInstruction() const { return instruction_; } |
| 1453 | HUseListNode<T>* GetUseNode() const { return use_node_; } |
| 1454 | |
| 1455 | private: |
| 1456 | // Instruction used by the user. |
| 1457 | HInstruction* instruction_; |
| 1458 | |
| 1459 | // Corresponding entry in the use list kept by 'instruction_'. |
| 1460 | HUseListNode<T>* use_node_; |
| 1461 | }; |
| 1462 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1463 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1464 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1465 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1466 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1467 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1468 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1469 | * modify the value of a reference field read [although it may modify the |
| 1470 | * reference fetch prior to reading the field, which is represented by its own |
| 1471 | * write/read dependence]). The analysis makes conservative points-to |
| 1472 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1473 | * the same, and any reference read depends on any reference read without |
| 1474 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1475 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1476 | * The internal representation uses 38-bit and is described in the table below. |
| 1477 | * The first line indicates the side effect, and for field/array accesses the |
| 1478 | * second line indicates the type of the access (in the order of the |
| 1479 | * Primitive::Type enum). |
| 1480 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1481 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1482 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1483 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1484 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1485 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1486 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1487 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1488 | * |
| 1489 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1490 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1491 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1492 | class SideEffects : public ValueObject { |
| 1493 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1494 | SideEffects() : flags_(0) {} |
| 1495 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1496 | static SideEffects None() { |
| 1497 | return SideEffects(0); |
| 1498 | } |
| 1499 | |
| 1500 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1501 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1502 | } |
| 1503 | |
| 1504 | static SideEffects AllChanges() { |
| 1505 | return SideEffects(kAllChangeBits); |
| 1506 | } |
| 1507 | |
| 1508 | static SideEffects AllDependencies() { |
| 1509 | return SideEffects(kAllDependOnBits); |
| 1510 | } |
| 1511 | |
| 1512 | static SideEffects AllExceptGCDependency() { |
| 1513 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1514 | } |
| 1515 | |
| 1516 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1517 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1518 | } |
| 1519 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1520 | static SideEffects AllWrites() { |
| 1521 | return SideEffects(kAllWrites); |
| 1522 | } |
| 1523 | |
| 1524 | static SideEffects AllReads() { |
| 1525 | return SideEffects(kAllReads); |
| 1526 | } |
| 1527 | |
| 1528 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1529 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1530 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1531 | : SideEffects(TypeFlagWithAlias(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1532 | } |
| 1533 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1534 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
| 1535 | return SideEffects(TypeFlagWithAlias(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1536 | } |
| 1537 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1538 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1539 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1540 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1541 | : SideEffects(TypeFlagWithAlias(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
| 1545 | return SideEffects(TypeFlagWithAlias(type, kArrayReadOffset)); |
| 1546 | } |
| 1547 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1548 | static SideEffects CanTriggerGC() { |
| 1549 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1550 | } |
| 1551 | |
| 1552 | static SideEffects DependsOnGC() { |
| 1553 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1554 | } |
| 1555 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1556 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1557 | SideEffects Union(SideEffects other) const { |
| 1558 | return SideEffects(flags_ | other.flags_); |
| 1559 | } |
| 1560 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1561 | SideEffects Exclusion(SideEffects other) const { |
| 1562 | return SideEffects(flags_ & ~other.flags_); |
| 1563 | } |
| 1564 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1565 | void Add(SideEffects other) { |
| 1566 | flags_ |= other.flags_; |
| 1567 | } |
| 1568 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1569 | bool Includes(SideEffects other) const { |
| 1570 | return (other.flags_ & flags_) == other.flags_; |
| 1571 | } |
| 1572 | |
| 1573 | bool HasSideEffects() const { |
| 1574 | return (flags_ & kAllChangeBits); |
| 1575 | } |
| 1576 | |
| 1577 | bool HasDependencies() const { |
| 1578 | return (flags_ & kAllDependOnBits); |
| 1579 | } |
| 1580 | |
| 1581 | // Returns true if there are no side effects or dependencies. |
| 1582 | bool DoesNothing() const { |
| 1583 | return flags_ == 0; |
| 1584 | } |
| 1585 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1586 | // Returns true if something is written. |
| 1587 | bool DoesAnyWrite() const { |
| 1588 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1589 | } |
| 1590 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1591 | // Returns true if something is read. |
| 1592 | bool DoesAnyRead() const { |
| 1593 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1594 | } |
| 1595 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1596 | // Returns true if potentially everything is written and read |
| 1597 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1598 | bool DoesAllReadWrite() const { |
| 1599 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1600 | } |
| 1601 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1602 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1603 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1604 | } |
| 1605 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1606 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1607 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1608 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1609 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1610 | } |
| 1611 | |
| 1612 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1613 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1614 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1615 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1616 | for (int s = kLastBit; s >= 0; s--) { |
| 1617 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1618 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1619 | // This is a bit for the GC side effect. |
| 1620 | if (current_bit_is_set) { |
| 1621 | flags += "GC"; |
| 1622 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1623 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1624 | } else { |
| 1625 | // This is a bit for the array/field analysis. |
| 1626 | // The underscore character stands for the 'can trigger GC' bit. |
| 1627 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1628 | if (current_bit_is_set) { |
| 1629 | flags += kDebug[s]; |
| 1630 | } |
| 1631 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1632 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1633 | flags += "|"; |
| 1634 | } |
| 1635 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1636 | } |
| 1637 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1638 | } |
| 1639 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1640 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1641 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1642 | private: |
| 1643 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1644 | |
| 1645 | static constexpr int kFieldWriteOffset = 0; |
| 1646 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1647 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1648 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1649 | |
| 1650 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1651 | |
| 1652 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1653 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1654 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1655 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1656 | |
| 1657 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1658 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1659 | |
| 1660 | // Aliases. |
| 1661 | |
| 1662 | static_assert(kChangeBits == kDependOnBits, |
| 1663 | "the 'change' bits should match the 'depend on' bits."); |
| 1664 | |
| 1665 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1666 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1667 | static constexpr uint64_t kAllWrites = |
| 1668 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1669 | static constexpr uint64_t kAllReads = |
| 1670 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1671 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1672 | // Work around the fact that HIR aliases I/F and J/D. |
| 1673 | // TODO: remove this interceptor once HIR types are clean |
| 1674 | static uint64_t TypeFlagWithAlias(Primitive::Type type, int offset) { |
| 1675 | switch (type) { |
| 1676 | case Primitive::kPrimInt: |
| 1677 | case Primitive::kPrimFloat: |
| 1678 | return TypeFlag(Primitive::kPrimInt, offset) | |
| 1679 | TypeFlag(Primitive::kPrimFloat, offset); |
| 1680 | case Primitive::kPrimLong: |
| 1681 | case Primitive::kPrimDouble: |
| 1682 | return TypeFlag(Primitive::kPrimLong, offset) | |
| 1683 | TypeFlag(Primitive::kPrimDouble, offset); |
| 1684 | default: |
| 1685 | return TypeFlag(type, offset); |
| 1686 | } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1687 | } |
| 1688 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1689 | // Translates type to bit flag. |
| 1690 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1691 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1692 | const uint64_t one = 1; |
| 1693 | const int shift = type; // 0-based consecutive enum |
| 1694 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1695 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1696 | return one << (type + offset); |
| 1697 | } |
| 1698 | |
| 1699 | // Private constructor on direct flags value. |
| 1700 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1701 | |
| 1702 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1703 | }; |
| 1704 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1705 | // 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] | 1706 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1707 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1708 | HEnvironment(ArenaAllocator* arena, |
| 1709 | size_t number_of_vregs, |
| 1710 | const DexFile& dex_file, |
| 1711 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1712 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1713 | InvokeType invoke_type, |
| 1714 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1715 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1716 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1717 | parent_(nullptr), |
| 1718 | dex_file_(dex_file), |
| 1719 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1720 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1721 | invoke_type_(invoke_type), |
| 1722 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1723 | } |
| 1724 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1725 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1726 | : HEnvironment(arena, |
| 1727 | to_copy.Size(), |
| 1728 | to_copy.GetDexFile(), |
| 1729 | to_copy.GetMethodIdx(), |
| 1730 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1731 | to_copy.GetInvokeType(), |
| 1732 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1733 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1734 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1735 | if (parent_ != nullptr) { |
| 1736 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1737 | } else { |
| 1738 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1739 | parent_->CopyFrom(parent); |
| 1740 | if (parent->GetParent() != nullptr) { |
| 1741 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1742 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1743 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1744 | } |
| 1745 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1746 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1747 | void CopyFrom(HEnvironment* environment); |
| 1748 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1749 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1750 | // input to the loop phi instead. This is for inserting instructions that |
| 1751 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1752 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1753 | |
| 1754 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1755 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1759 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1760 | } |
| 1761 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1762 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1763 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1764 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1765 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1766 | HEnvironment* GetParent() const { return parent_; } |
| 1767 | |
| 1768 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1769 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1773 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | uint32_t GetDexPc() const { |
| 1777 | return dex_pc_; |
| 1778 | } |
| 1779 | |
| 1780 | uint32_t GetMethodIdx() const { |
| 1781 | return method_idx_; |
| 1782 | } |
| 1783 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1784 | InvokeType GetInvokeType() const { |
| 1785 | return invoke_type_; |
| 1786 | } |
| 1787 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1788 | const DexFile& GetDexFile() const { |
| 1789 | return dex_file_; |
| 1790 | } |
| 1791 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1792 | HInstruction* GetHolder() const { |
| 1793 | return holder_; |
| 1794 | } |
| 1795 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1796 | |
| 1797 | bool IsFromInlinedInvoke() const { |
| 1798 | return GetParent() != nullptr; |
| 1799 | } |
| 1800 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1801 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1802 | // Record instructions' use entries of this environment for constant-time removal. |
| 1803 | // It should only be called by HInstruction when a new environment use is added. |
| 1804 | void RecordEnvUse(HUseListNode<HEnvironment*>* env_use) { |
| 1805 | DCHECK(env_use->GetUser() == this); |
| 1806 | size_t index = env_use->GetIndex(); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1807 | vregs_[index] = HUserRecord<HEnvironment*>(vregs_[index], env_use); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1808 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1809 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1810 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1811 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1812 | HEnvironment* parent_; |
| 1813 | const DexFile& dex_file_; |
| 1814 | const uint32_t method_idx_; |
| 1815 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1816 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1817 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1818 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1819 | HInstruction* const holder_; |
| 1820 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1821 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1822 | |
| 1823 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1824 | }; |
| 1825 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1826 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1827 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1828 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1829 | : previous_(nullptr), |
| 1830 | next_(nullptr), |
| 1831 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1832 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1833 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1834 | ssa_index_(-1), |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1835 | emitted_at_use_site_(false), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1836 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1837 | locations_(nullptr), |
| 1838 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1839 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1840 | side_effects_(side_effects), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1841 | reference_type_info_(ReferenceTypeInfo::CreateInvalid()) {} |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1842 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1843 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1844 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1845 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1846 | enum InstructionKind { |
| 1847 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1848 | }; |
| 1849 | #undef DECLARE_KIND |
| 1850 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1851 | HInstruction* GetNext() const { return next_; } |
| 1852 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1853 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1854 | HInstruction* GetNextDisregardingMoves() const; |
| 1855 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1856 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1857 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1858 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1859 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1860 | bool IsInBlock() const { return block_ != nullptr; } |
| 1861 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1862 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 1863 | bool IsIrreducibleLoopHeaderPhi() const { |
| 1864 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 1865 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1866 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1867 | virtual size_t InputCount() const = 0; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1868 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1869 | |
| 1870 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1871 | virtual const char* DebugName() const = 0; |
| 1872 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1873 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1874 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1875 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1876 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1877 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1878 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1879 | |
| 1880 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1881 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1882 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1883 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1884 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1885 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1886 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1887 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1888 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1889 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1890 | // Does not apply for all instructions, but having this at top level greatly |
| 1891 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1892 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1893 | virtual bool CanBeNull() const { |
| 1894 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1895 | return true; |
| 1896 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1897 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1898 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1899 | return false; |
| 1900 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1901 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 1902 | virtual bool IsActualObject() const { |
| 1903 | return GetType() == Primitive::kPrimNot; |
| 1904 | } |
| 1905 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1906 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1907 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1908 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1909 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
| 1910 | return reference_type_info_; |
| 1911 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1912 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1913 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1914 | DCHECK(user != nullptr); |
| 1915 | HUseListNode<HInstruction*>* use = |
| 1916 | uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1917 | user->SetRawInputRecordAt(index, HUserRecord<HInstruction*>(user->InputRecordAt(index), use)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1918 | } |
| 1919 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1920 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1921 | DCHECK(user != nullptr); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1922 | HUseListNode<HEnvironment*>* env_use = |
| 1923 | env_uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1924 | user->RecordEnvUse(env_use); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1925 | } |
| 1926 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1927 | void RemoveAsUserOfInput(size_t input) { |
| 1928 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
| 1929 | input_use.GetInstruction()->uses_.Remove(input_use.GetUseNode()); |
| 1930 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1931 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1932 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1933 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1934 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1935 | bool HasUses() const { return !uses_.IsEmpty() || !env_uses_.IsEmpty(); } |
| 1936 | bool HasEnvironmentUses() const { return !env_uses_.IsEmpty(); } |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 1937 | bool HasNonEnvironmentUses() const { return !uses_.IsEmpty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1938 | bool HasOnlyOneNonEnvironmentUse() const { |
| 1939 | return !HasEnvironmentUses() && GetUses().HasOnlyOneUse(); |
| 1940 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1941 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1942 | // Does this instruction strictly dominate `other_instruction`? |
| 1943 | // Returns false if this instruction and `other_instruction` are the same. |
| 1944 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1945 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1946 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1947 | int GetId() const { return id_; } |
| 1948 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1949 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1950 | int GetSsaIndex() const { return ssa_index_; } |
| 1951 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 1952 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 1953 | |
| 1954 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 1955 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1956 | // Set the `environment_` field. Raw because this method does not |
| 1957 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1958 | void SetRawEnvironment(HEnvironment* environment) { |
| 1959 | DCHECK(environment_ == nullptr); |
| 1960 | DCHECK_EQ(environment->GetHolder(), this); |
| 1961 | environment_ = environment; |
| 1962 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1963 | |
| 1964 | // Set the environment of this instruction, copying it from `environment`. While |
| 1965 | // copying, the uses lists are being updated. |
| 1966 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1967 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1968 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1969 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1970 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1971 | if (environment->GetParent() != nullptr) { |
| 1972 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1973 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1974 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1975 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1976 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 1977 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1978 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1979 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1980 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1981 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1982 | if (environment->GetParent() != nullptr) { |
| 1983 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1984 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1985 | } |
| 1986 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1987 | // Returns the number of entries in the environment. Typically, that is the |
| 1988 | // number of dex registers in a method. It could be more in case of inlining. |
| 1989 | size_t EnvironmentSize() const; |
| 1990 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1991 | LocationSummary* GetLocations() const { return locations_; } |
| 1992 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1993 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1994 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1995 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1996 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1997 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 1998 | // uses of this instruction by `other` are *not* updated. |
| 1999 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 2000 | ReplaceWith(other); |
| 2001 | other->ReplaceInput(this, use_index); |
| 2002 | } |
| 2003 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 2004 | // Move `this` instruction before `cursor`. |
| 2005 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2006 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2007 | // Move `this` before its first user and out of any loops. If there is no |
| 2008 | // out-of-loop user that dominates all other users, move the instruction |
| 2009 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2010 | // |
| 2011 | // This can be used only on non-throwing instructions with no side effects that |
| 2012 | // have at least one use but no environment uses. |
| 2013 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2014 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2015 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2016 | bool Is##type() const; \ |
| 2017 | const H##type* As##type() const; \ |
| 2018 | H##type* As##type(); |
| 2019 | |
| 2020 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2021 | #undef INSTRUCTION_TYPE_CHECK |
| 2022 | |
| 2023 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2024 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 2025 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2026 | virtual H##type* As##type() { return nullptr; } |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2027 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2028 | #undef INSTRUCTION_TYPE_CHECK |
| 2029 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2030 | // Returns whether the instruction can be moved within the graph. |
| 2031 | virtual bool CanBeMoved() const { return false; } |
| 2032 | |
| 2033 | // Returns whether the two instructions are of the same kind. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2034 | virtual bool InstructionTypeEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2035 | return false; |
| 2036 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2037 | |
| 2038 | // Returns whether any data encoded in the two instructions is equal. |
| 2039 | // This method does not look at the inputs. Both instructions must be |
| 2040 | // of the same type, otherwise the method has undefined behavior. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2041 | virtual bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2042 | return false; |
| 2043 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2044 | |
| 2045 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2046 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2047 | // 2) Their inputs are identical. |
| 2048 | bool Equals(HInstruction* other) const; |
| 2049 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2050 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2051 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2052 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2053 | // apply the strong requirement for virtual functions, preventing optimizations. |
| 2054 | InstructionKind GetKind() const PURE; |
| 2055 | virtual InstructionKind GetKindInternal() const = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2056 | |
| 2057 | virtual size_t ComputeHashCode() const { |
| 2058 | size_t result = GetKind(); |
| 2059 | for (size_t i = 0, e = InputCount(); i < e; ++i) { |
| 2060 | result = (result * 31) + InputAt(i)->GetId(); |
| 2061 | } |
| 2062 | return result; |
| 2063 | } |
| 2064 | |
| 2065 | SideEffects GetSideEffects() const { return side_effects_; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2066 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2067 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2068 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2069 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2070 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2071 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2072 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2073 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2074 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2075 | |
| 2076 | // Returns whether the code generation of the instruction will require to have access |
| 2077 | // to the current method. Such instructions are: |
| 2078 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2079 | // to walk the stack and have the current method stored at a specific stack address. |
| 2080 | // (2): Object literals like classes and strings, that are loaded from the dex cache |
| 2081 | // fields of the current method. |
| 2082 | bool NeedsCurrentMethod() const { |
| 2083 | return NeedsEnvironment() || IsLoadClass() || IsLoadString(); |
| 2084 | } |
| 2085 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2086 | // Returns whether the code generation of the instruction will require to have access |
| 2087 | // to the dex cache of the current method's declaring class via the current method. |
| 2088 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2089 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2090 | // Does this instruction have any use in an environment before |
| 2091 | // control flow hits 'other'? |
| 2092 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2093 | |
| 2094 | // Remove all references to environment uses of this instruction. |
| 2095 | // The caller must ensure that this is safe to do. |
| 2096 | void RemoveEnvironmentUsers(); |
| 2097 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2098 | bool IsEmittedAtUseSite() const { return emitted_at_use_site_; } |
| 2099 | void MarkEmittedAtUseSite() { emitted_at_use_site_ = true; } |
| 2100 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2101 | protected: |
| 2102 | virtual const HUserRecord<HInstruction*> InputRecordAt(size_t i) const = 0; |
| 2103 | virtual void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) = 0; |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 2104 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2105 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2106 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2107 | void RemoveEnvironmentUser(HUseListNode<HEnvironment*>* use_node) { env_uses_.Remove(use_node); } |
| 2108 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2109 | HInstruction* previous_; |
| 2110 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2111 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2112 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2113 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2114 | // An instruction gets an id when it is added to the graph. |
| 2115 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2116 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2117 | int id_; |
| 2118 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2119 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2120 | int ssa_index_; |
| 2121 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2122 | // If set, the machine code for this instruction is assumed to be generated by |
| 2123 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2124 | bool emitted_at_use_site_; |
| 2125 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2126 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2127 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2128 | |
| 2129 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2130 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2131 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2132 | // The environment associated with this instruction. Not null if the instruction |
| 2133 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2134 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2135 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2136 | // Set by the code generator. |
| 2137 | LocationSummary* locations_; |
| 2138 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2139 | // Set by the liveness analysis. |
| 2140 | LiveInterval* live_interval_; |
| 2141 | |
| 2142 | // Set by the liveness analysis, this is the position in a linear |
| 2143 | // order of blocks where this instruction's live interval start. |
| 2144 | size_t lifetime_position_; |
| 2145 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2146 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2147 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2148 | // TODO: for primitive types this should be marked as invalid. |
| 2149 | ReferenceTypeInfo reference_type_info_; |
| 2150 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2151 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2152 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2153 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2154 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2155 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2156 | |
| 2157 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2158 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2159 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2160 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2161 | class HInputIterator : public ValueObject { |
| 2162 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2163 | explicit HInputIterator(HInstruction* instruction) : instruction_(instruction), index_(0) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2164 | |
| 2165 | bool Done() const { return index_ == instruction_->InputCount(); } |
| 2166 | HInstruction* Current() const { return instruction_->InputAt(index_); } |
| 2167 | void Advance() { index_++; } |
| 2168 | |
| 2169 | private: |
| 2170 | HInstruction* instruction_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2171 | size_t index_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2172 | |
| 2173 | DISALLOW_COPY_AND_ASSIGN(HInputIterator); |
| 2174 | }; |
| 2175 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2176 | class HInstructionIterator : public ValueObject { |
| 2177 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2178 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2179 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2180 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2181 | } |
| 2182 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2183 | bool Done() const { return instruction_ == nullptr; } |
| 2184 | HInstruction* Current() const { return instruction_; } |
| 2185 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2186 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2187 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2188 | } |
| 2189 | |
| 2190 | private: |
| 2191 | HInstruction* instruction_; |
| 2192 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2193 | |
| 2194 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2195 | }; |
| 2196 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2197 | class HBackwardInstructionIterator : public ValueObject { |
| 2198 | public: |
| 2199 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2200 | : instruction_(instructions.last_instruction_) { |
| 2201 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2202 | } |
| 2203 | |
| 2204 | bool Done() const { return instruction_ == nullptr; } |
| 2205 | HInstruction* Current() const { return instruction_; } |
| 2206 | void Advance() { |
| 2207 | instruction_ = next_; |
| 2208 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2209 | } |
| 2210 | |
| 2211 | private: |
| 2212 | HInstruction* instruction_; |
| 2213 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2214 | |
| 2215 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2216 | }; |
| 2217 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2218 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2219 | class HTemplateInstruction: public HInstruction { |
| 2220 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2221 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2222 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2223 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2224 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2225 | size_t InputCount() const OVERRIDE { return N; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2226 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2227 | protected: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2228 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 2229 | DCHECK_LT(i, N); |
| 2230 | return inputs_[i]; |
| 2231 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2232 | |
| 2233 | void SetRawInputRecordAt(size_t i, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2234 | DCHECK_LT(i, N); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2235 | inputs_[i] = input; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2236 | } |
| 2237 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2238 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2239 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2240 | |
| 2241 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2242 | }; |
| 2243 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2244 | // HTemplateInstruction specialization for N=0. |
| 2245 | template<> |
| 2246 | class HTemplateInstruction<0>: public HInstruction { |
| 2247 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2248 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2249 | : HInstruction(side_effects, dex_pc) {} |
| 2250 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2251 | virtual ~HTemplateInstruction() {} |
| 2252 | |
| 2253 | size_t InputCount() const OVERRIDE { return 0; } |
| 2254 | |
| 2255 | protected: |
| 2256 | const HUserRecord<HInstruction*> InputRecordAt(size_t i ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2257 | LOG(FATAL) << "Unreachable"; |
| 2258 | UNREACHABLE(); |
| 2259 | } |
| 2260 | |
| 2261 | void SetRawInputRecordAt(size_t i ATTRIBUTE_UNUSED, |
| 2262 | const HUserRecord<HInstruction*>& input ATTRIBUTE_UNUSED) OVERRIDE { |
| 2263 | LOG(FATAL) << "Unreachable"; |
| 2264 | UNREACHABLE(); |
| 2265 | } |
| 2266 | |
| 2267 | private: |
| 2268 | friend class SsaBuilder; |
| 2269 | }; |
| 2270 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2271 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2272 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2273 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2274 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2275 | : HTemplateInstruction<N>(side_effects, dex_pc), type_(type) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2276 | virtual ~HExpression() {} |
| 2277 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2278 | Primitive::Type GetType() const OVERRIDE { return type_; } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2279 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2280 | protected: |
| 2281 | Primitive::Type type_; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2282 | }; |
| 2283 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2284 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2285 | // instruction that branches to the exit block. |
| 2286 | class HReturnVoid : public HTemplateInstruction<0> { |
| 2287 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2288 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2289 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2290 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2291 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2292 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2293 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2294 | |
| 2295 | private: |
| 2296 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2297 | }; |
| 2298 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2299 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2300 | // instruction that branches to the exit block. |
| 2301 | class HReturn : public HTemplateInstruction<1> { |
| 2302 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2303 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2304 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2305 | SetRawInputAt(0, value); |
| 2306 | } |
| 2307 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2308 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2309 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2310 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2311 | |
| 2312 | private: |
| 2313 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2314 | }; |
| 2315 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2316 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2317 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2318 | // exit block. |
| 2319 | class HExit : public HTemplateInstruction<0> { |
| 2320 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2321 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2322 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2323 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2324 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2325 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2326 | |
| 2327 | private: |
| 2328 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2329 | }; |
| 2330 | |
| 2331 | // Jumps from one block to another. |
| 2332 | class HGoto : public HTemplateInstruction<0> { |
| 2333 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2334 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2335 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2336 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2337 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2338 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2339 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2340 | } |
| 2341 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2342 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2343 | |
| 2344 | private: |
| 2345 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2346 | }; |
| 2347 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2348 | class HConstant : public HExpression<0> { |
| 2349 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2350 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2351 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2352 | |
| 2353 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2354 | |
| 2355 | virtual bool IsMinusOne() const { return false; } |
| 2356 | virtual bool IsZero() const { return false; } |
| 2357 | virtual bool IsOne() const { return false; } |
| 2358 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2359 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2360 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2361 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2362 | |
| 2363 | private: |
| 2364 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2365 | }; |
| 2366 | |
| 2367 | class HNullConstant : public HConstant { |
| 2368 | public: |
| 2369 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2370 | return true; |
| 2371 | } |
| 2372 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2373 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2374 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2375 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2376 | |
| 2377 | DECLARE_INSTRUCTION(NullConstant); |
| 2378 | |
| 2379 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2380 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2381 | |
| 2382 | friend class HGraph; |
| 2383 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2384 | }; |
| 2385 | |
| 2386 | // Constants of the type int. Those can be from Dex instructions, or |
| 2387 | // synthesized (for example with the if-eqz instruction). |
| 2388 | class HIntConstant : public HConstant { |
| 2389 | public: |
| 2390 | int32_t GetValue() const { return value_; } |
| 2391 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2392 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2393 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2394 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2395 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2396 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2397 | DCHECK(other->IsIntConstant()); |
| 2398 | return other->AsIntConstant()->value_ == value_; |
| 2399 | } |
| 2400 | |
| 2401 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2402 | |
| 2403 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2404 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2405 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2406 | |
| 2407 | DECLARE_INSTRUCTION(IntConstant); |
| 2408 | |
| 2409 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2410 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2411 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2412 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2413 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2414 | |
| 2415 | const int32_t value_; |
| 2416 | |
| 2417 | friend class HGraph; |
| 2418 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2419 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2420 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2421 | }; |
| 2422 | |
| 2423 | class HLongConstant : public HConstant { |
| 2424 | public: |
| 2425 | int64_t GetValue() const { return value_; } |
| 2426 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2427 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2428 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2429 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2430 | DCHECK(other->IsLongConstant()); |
| 2431 | return other->AsLongConstant()->value_ == value_; |
| 2432 | } |
| 2433 | |
| 2434 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2435 | |
| 2436 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2437 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2438 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2439 | |
| 2440 | DECLARE_INSTRUCTION(LongConstant); |
| 2441 | |
| 2442 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2443 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2444 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2445 | |
| 2446 | const int64_t value_; |
| 2447 | |
| 2448 | friend class HGraph; |
| 2449 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2450 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2451 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2452 | // Conditional branch. A block ending with an HIf instruction must have |
| 2453 | // two successors. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2454 | class HIf : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2455 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2456 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2457 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2458 | SetRawInputAt(0, input); |
| 2459 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2460 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2461 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2462 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2463 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2464 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2465 | } |
| 2466 | |
| 2467 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2468 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2469 | } |
| 2470 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2471 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2472 | |
| 2473 | private: |
| 2474 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2475 | }; |
| 2476 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2477 | |
| 2478 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2479 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2480 | // non-exceptional control flow. |
| 2481 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2482 | // higher indices in no particular order. |
| 2483 | class HTryBoundary : public HTemplateInstruction<0> { |
| 2484 | public: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2485 | enum BoundaryKind { |
| 2486 | kEntry, |
| 2487 | kExit, |
| 2488 | }; |
| 2489 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2490 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
| 2491 | : HTemplateInstruction(SideEffects::None(), dex_pc), kind_(kind) {} |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2492 | |
| 2493 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2494 | |
| 2495 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2496 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2497 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 2498 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 2499 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 2500 | } |
| 2501 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2502 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2503 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2504 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2505 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2506 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2507 | } |
| 2508 | |
| 2509 | // If not present already, adds `handler` to its block's list of exception |
| 2510 | // handlers. |
| 2511 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2512 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2513 | GetBlock()->AddSuccessor(handler); |
| 2514 | } |
| 2515 | } |
| 2516 | |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2517 | bool IsEntry() const { return kind_ == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2518 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2519 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2520 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2521 | DECLARE_INSTRUCTION(TryBoundary); |
| 2522 | |
| 2523 | private: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2524 | const BoundaryKind kind_; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2525 | |
| 2526 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2527 | }; |
| 2528 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2529 | // Deoptimize to interpreter, upon checking a condition. |
| 2530 | class HDeoptimize : public HTemplateInstruction<1> { |
| 2531 | public: |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2532 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 2533 | // at the point of the `HDeoptimize`. |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2534 | HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2535 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2536 | SetRawInputAt(0, cond); |
| 2537 | } |
| 2538 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2539 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2540 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2541 | return true; |
| 2542 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2543 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2544 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2545 | |
| 2546 | DECLARE_INSTRUCTION(Deoptimize); |
| 2547 | |
| 2548 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2549 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2550 | }; |
| 2551 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2552 | // Represents the ArtMethod that was passed as a first argument to |
| 2553 | // the method. It is used by instructions that depend on it, like |
| 2554 | // instructions that work with the dex cache. |
| 2555 | class HCurrentMethod : public HExpression<0> { |
| 2556 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2557 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2558 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2559 | |
| 2560 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2561 | |
| 2562 | private: |
| 2563 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2564 | }; |
| 2565 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2566 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 2567 | // of a class. |
| 2568 | class HClassTableGet : public HExpression<1> { |
| 2569 | public: |
| 2570 | enum TableKind { |
| 2571 | kVTable, |
| 2572 | kIMTable, |
| 2573 | }; |
| 2574 | HClassTableGet(HInstruction* cls, |
| 2575 | Primitive::Type type, |
| 2576 | TableKind kind, |
| 2577 | size_t index, |
| 2578 | uint32_t dex_pc) |
| 2579 | : HExpression(type, SideEffects::None(), dex_pc), |
| 2580 | index_(index), |
| 2581 | table_kind_(kind) { |
| 2582 | SetRawInputAt(0, cls); |
| 2583 | } |
| 2584 | |
| 2585 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2586 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2587 | return other->AsClassTableGet()->GetIndex() == index_ && |
| 2588 | other->AsClassTableGet()->GetTableKind() == table_kind_; |
| 2589 | } |
| 2590 | |
| 2591 | TableKind GetTableKind() const { return table_kind_; } |
| 2592 | size_t GetIndex() const { return index_; } |
| 2593 | |
| 2594 | DECLARE_INSTRUCTION(ClassTableGet); |
| 2595 | |
| 2596 | private: |
| 2597 | // The index of the ArtMethod in the table. |
| 2598 | const size_t index_; |
| 2599 | const TableKind table_kind_; |
| 2600 | |
| 2601 | DISALLOW_COPY_AND_ASSIGN(HClassTableGet); |
| 2602 | }; |
| 2603 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2604 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 2605 | // have one successor for each entry in the switch table, and the final successor |
| 2606 | // will be the block containing the next Dex opcode. |
| 2607 | class HPackedSwitch : public HTemplateInstruction<1> { |
| 2608 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2609 | HPackedSwitch(int32_t start_value, |
| 2610 | uint32_t num_entries, |
| 2611 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2612 | uint32_t dex_pc = kNoDexPc) |
| 2613 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 2614 | start_value_(start_value), |
| 2615 | num_entries_(num_entries) { |
| 2616 | SetRawInputAt(0, input); |
| 2617 | } |
| 2618 | |
| 2619 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2620 | |
| 2621 | int32_t GetStartValue() const { return start_value_; } |
| 2622 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 2623 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2624 | |
| 2625 | HBasicBlock* GetDefaultBlock() const { |
| 2626 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2627 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2628 | } |
| 2629 | DECLARE_INSTRUCTION(PackedSwitch); |
| 2630 | |
| 2631 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2632 | const int32_t start_value_; |
| 2633 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2634 | |
| 2635 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 2636 | }; |
| 2637 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2638 | class HUnaryOperation : public HExpression<1> { |
| 2639 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2640 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2641 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2642 | SetRawInputAt(0, input); |
| 2643 | } |
| 2644 | |
| 2645 | HInstruction* GetInput() const { return InputAt(0); } |
| 2646 | Primitive::Type GetResultType() const { return GetType(); } |
| 2647 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2648 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2649 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2650 | return true; |
| 2651 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2652 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2653 | // Try to statically evaluate `operation` and return a HConstant |
| 2654 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2655 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2656 | HConstant* TryStaticEvaluation() const; |
| 2657 | |
| 2658 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2659 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 2660 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2661 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2662 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2663 | |
| 2664 | private: |
| 2665 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 2666 | }; |
| 2667 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2668 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2669 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2670 | HBinaryOperation(Primitive::Type result_type, |
| 2671 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2672 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2673 | SideEffects side_effects = SideEffects::None(), |
| 2674 | uint32_t dex_pc = kNoDexPc) |
| 2675 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2676 | SetRawInputAt(0, left); |
| 2677 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2678 | } |
| 2679 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2680 | HInstruction* GetLeft() const { return InputAt(0); } |
| 2681 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2682 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2683 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2684 | virtual bool IsCommutative() const { return false; } |
| 2685 | |
| 2686 | // Put constant on the right. |
| 2687 | // Returns whether order is changed. |
| 2688 | bool OrderInputsWithConstantOnTheRight() { |
| 2689 | HInstruction* left = InputAt(0); |
| 2690 | HInstruction* right = InputAt(1); |
| 2691 | if (left->IsConstant() && !right->IsConstant()) { |
| 2692 | ReplaceInput(right, 0); |
| 2693 | ReplaceInput(left, 1); |
| 2694 | return true; |
| 2695 | } |
| 2696 | return false; |
| 2697 | } |
| 2698 | |
| 2699 | // Order inputs by instruction id, but favor constant on the right side. |
| 2700 | // This helps GVN for commutative ops. |
| 2701 | void OrderInputs() { |
| 2702 | DCHECK(IsCommutative()); |
| 2703 | HInstruction* left = InputAt(0); |
| 2704 | HInstruction* right = InputAt(1); |
| 2705 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 2706 | return; |
| 2707 | } |
| 2708 | if (OrderInputsWithConstantOnTheRight()) { |
| 2709 | return; |
| 2710 | } |
| 2711 | // Order according to instruction id. |
| 2712 | if (left->GetId() > right->GetId()) { |
| 2713 | ReplaceInput(right, 0); |
| 2714 | ReplaceInput(left, 1); |
| 2715 | } |
| 2716 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2717 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2718 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2719 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2720 | return true; |
| 2721 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2722 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2723 | // Try to statically evaluate `operation` and return a HConstant |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2724 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2725 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2726 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2727 | |
| 2728 | // Apply this operation to `x` and `y`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2729 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 2730 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
| 2731 | virtual HConstant* Evaluate(HIntConstant* x ATTRIBUTE_UNUSED, |
| 2732 | HLongConstant* y ATTRIBUTE_UNUSED) const { |
| 2733 | VLOG(compiler) << DebugName() << " is not defined for the (int, long) case."; |
| 2734 | return nullptr; |
| 2735 | } |
| 2736 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 2737 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
| 2738 | VLOG(compiler) << DebugName() << " is not defined for the (long, int) case."; |
| 2739 | return nullptr; |
| 2740 | } |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2741 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2742 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
| 2743 | VLOG(compiler) << DebugName() << " is not defined for the (null, null) case."; |
| 2744 | return nullptr; |
| 2745 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2746 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2747 | // 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] | 2748 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2749 | HConstant* GetConstantRight() const; |
| 2750 | |
| 2751 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2752 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2753 | HInstruction* GetLeastConstantLeft() const; |
| 2754 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2755 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2756 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2757 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2758 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 2759 | }; |
| 2760 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2761 | // The comparison bias applies for floating point operations and indicates how NaN |
| 2762 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2763 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2764 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 2765 | kGtBias, // return 1 for NaN comparisons |
| 2766 | kLtBias, // return -1 for NaN comparisons |
| 2767 | }; |
| 2768 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2769 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2770 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2771 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2772 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc), |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2773 | bias_(ComparisonBias::kNoBias) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2774 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2775 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2776 | // `instruction`, and disregard moves in between. |
| 2777 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2778 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2779 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2780 | |
| 2781 | virtual IfCondition GetCondition() const = 0; |
| 2782 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2783 | virtual IfCondition GetOppositeCondition() const = 0; |
| 2784 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2785 | bool IsGtBias() const { return bias_ == ComparisonBias::kGtBias; } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2786 | |
| 2787 | void SetBias(ComparisonBias bias) { bias_ = bias; } |
| 2788 | |
| 2789 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2790 | return bias_ == other->AsCondition()->bias_; |
| 2791 | } |
| 2792 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2793 | bool IsFPConditionTrueIfNaN() const { |
| 2794 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2795 | IfCondition if_cond = GetCondition(); |
Nicolas Geoffray | d4aee94 | 2016-01-22 12:35:26 +0000 | [diff] [blame] | 2796 | return IsGtBias() ? ((if_cond == kCondGT) || (if_cond == kCondGE)) : (if_cond == kCondNE); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2797 | } |
| 2798 | |
| 2799 | bool IsFPConditionFalseIfNaN() const { |
| 2800 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2801 | IfCondition if_cond = GetCondition(); |
Nicolas Geoffray | d4aee94 | 2016-01-22 12:35:26 +0000 | [diff] [blame] | 2802 | return IsGtBias() ? ((if_cond == kCondLT) || (if_cond == kCondLE)) : (if_cond == kCondEQ); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2803 | } |
| 2804 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2805 | private: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2806 | // Needed if we merge a HCompare into a HCondition. |
| 2807 | ComparisonBias bias_; |
| 2808 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2809 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 2810 | }; |
| 2811 | |
| 2812 | // Instruction to check if two inputs are equal to each other. |
| 2813 | class HEqual : public HCondition { |
| 2814 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2815 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2816 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2817 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2818 | bool IsCommutative() const OVERRIDE { return true; } |
| 2819 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2820 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2821 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2822 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2823 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2824 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2825 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2826 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2827 | } |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2828 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2829 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Vladimir Marko | 040db34 | 2015-11-10 19:53:01 +0000 | [diff] [blame] | 2830 | return GetBlock()->GetGraph()->GetIntConstant(1); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2831 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2832 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2833 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2834 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2835 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2836 | return kCondEQ; |
| 2837 | } |
| 2838 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2839 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2840 | return kCondNE; |
| 2841 | } |
| 2842 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2843 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2844 | template <typename T> bool Compute(T x, T y) const { return x == y; } |
| 2845 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2846 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 2847 | }; |
| 2848 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2849 | class HNotEqual : public HCondition { |
| 2850 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2851 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2852 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2853 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2854 | bool IsCommutative() const OVERRIDE { return true; } |
| 2855 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2856 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2857 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2858 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2859 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2860 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2861 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2862 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2863 | } |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2864 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2865 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Vladimir Marko | 040db34 | 2015-11-10 19:53:01 +0000 | [diff] [blame] | 2866 | return GetBlock()->GetGraph()->GetIntConstant(0); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2867 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2868 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2869 | DECLARE_INSTRUCTION(NotEqual); |
| 2870 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2871 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2872 | return kCondNE; |
| 2873 | } |
| 2874 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2875 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2876 | return kCondEQ; |
| 2877 | } |
| 2878 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2879 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2880 | template <typename T> bool Compute(T x, T y) const { return x != y; } |
| 2881 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2882 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 2883 | }; |
| 2884 | |
| 2885 | class HLessThan : public HCondition { |
| 2886 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2887 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2888 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2889 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2890 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2891 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2892 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2893 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2894 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2895 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2896 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2897 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2898 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2899 | DECLARE_INSTRUCTION(LessThan); |
| 2900 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2901 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2902 | return kCondLT; |
| 2903 | } |
| 2904 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2905 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2906 | return kCondGE; |
| 2907 | } |
| 2908 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2909 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2910 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 2911 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2912 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 2913 | }; |
| 2914 | |
| 2915 | class HLessThanOrEqual : public HCondition { |
| 2916 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2917 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2918 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2919 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2920 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2921 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2922 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2923 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2924 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2925 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2926 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2927 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2928 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2929 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 2930 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2931 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2932 | return kCondLE; |
| 2933 | } |
| 2934 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2935 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2936 | return kCondGT; |
| 2937 | } |
| 2938 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2939 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2940 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 2941 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2942 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 2943 | }; |
| 2944 | |
| 2945 | class HGreaterThan : public HCondition { |
| 2946 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2947 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2948 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2949 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2950 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2951 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2952 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2953 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2954 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2955 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2956 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2957 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2958 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2959 | DECLARE_INSTRUCTION(GreaterThan); |
| 2960 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2961 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2962 | return kCondGT; |
| 2963 | } |
| 2964 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2965 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2966 | return kCondLE; |
| 2967 | } |
| 2968 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2969 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2970 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 2971 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2972 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 2973 | }; |
| 2974 | |
| 2975 | class HGreaterThanOrEqual : public HCondition { |
| 2976 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2977 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2978 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2979 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2980 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2981 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2982 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2983 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2984 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2985 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2986 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2987 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2988 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2989 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 2990 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2991 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2992 | return kCondGE; |
| 2993 | } |
| 2994 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2995 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2996 | return kCondLT; |
| 2997 | } |
| 2998 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2999 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3000 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 3001 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3002 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 3003 | }; |
| 3004 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3005 | class HBelow : public HCondition { |
| 3006 | public: |
| 3007 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3008 | : HCondition(first, second, dex_pc) {} |
| 3009 | |
| 3010 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3011 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3012 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 3013 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 3014 | } |
| 3015 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3016 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3017 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 3018 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 3019 | } |
| 3020 | |
| 3021 | DECLARE_INSTRUCTION(Below); |
| 3022 | |
| 3023 | IfCondition GetCondition() const OVERRIDE { |
| 3024 | return kCondB; |
| 3025 | } |
| 3026 | |
| 3027 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3028 | return kCondAE; |
| 3029 | } |
| 3030 | |
| 3031 | private: |
| 3032 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 3033 | |
| 3034 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 3035 | }; |
| 3036 | |
| 3037 | class HBelowOrEqual : public HCondition { |
| 3038 | public: |
| 3039 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3040 | : HCondition(first, second, dex_pc) {} |
| 3041 | |
| 3042 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3043 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3044 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 3045 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 3046 | } |
| 3047 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3048 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3049 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 3050 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 3051 | } |
| 3052 | |
| 3053 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 3054 | |
| 3055 | IfCondition GetCondition() const OVERRIDE { |
| 3056 | return kCondBE; |
| 3057 | } |
| 3058 | |
| 3059 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3060 | return kCondA; |
| 3061 | } |
| 3062 | |
| 3063 | private: |
| 3064 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 3065 | |
| 3066 | DISALLOW_COPY_AND_ASSIGN(HBelowOrEqual); |
| 3067 | }; |
| 3068 | |
| 3069 | class HAbove : public HCondition { |
| 3070 | public: |
| 3071 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3072 | : HCondition(first, second, dex_pc) {} |
| 3073 | |
| 3074 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3075 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3076 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 3077 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 3078 | } |
| 3079 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3080 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3081 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 3082 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 3083 | } |
| 3084 | |
| 3085 | DECLARE_INSTRUCTION(Above); |
| 3086 | |
| 3087 | IfCondition GetCondition() const OVERRIDE { |
| 3088 | return kCondA; |
| 3089 | } |
| 3090 | |
| 3091 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3092 | return kCondBE; |
| 3093 | } |
| 3094 | |
| 3095 | private: |
| 3096 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 3097 | |
| 3098 | DISALLOW_COPY_AND_ASSIGN(HAbove); |
| 3099 | }; |
| 3100 | |
| 3101 | class HAboveOrEqual : public HCondition { |
| 3102 | public: |
| 3103 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3104 | : HCondition(first, second, dex_pc) {} |
| 3105 | |
| 3106 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3107 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3108 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 3109 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 3110 | } |
| 3111 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3112 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3113 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 3114 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 3115 | } |
| 3116 | |
| 3117 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 3118 | |
| 3119 | IfCondition GetCondition() const OVERRIDE { |
| 3120 | return kCondAE; |
| 3121 | } |
| 3122 | |
| 3123 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3124 | return kCondB; |
| 3125 | } |
| 3126 | |
| 3127 | private: |
| 3128 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 3129 | |
| 3130 | DISALLOW_COPY_AND_ASSIGN(HAboveOrEqual); |
| 3131 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3132 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3133 | // Instruction to check how two inputs compare to each other. |
| 3134 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
| 3135 | class HCompare : public HBinaryOperation { |
| 3136 | public: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3137 | HCompare(Primitive::Type type, |
| 3138 | HInstruction* first, |
| 3139 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3140 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3141 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3142 | : HBinaryOperation(Primitive::kPrimInt, |
| 3143 | first, |
| 3144 | second, |
| 3145 | SideEffectsForArchRuntimeCalls(type), |
| 3146 | dex_pc), |
| 3147 | bias_(bias) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3148 | DCHECK_EQ(type, first->GetType()); |
| 3149 | DCHECK_EQ(type, second->GetType()); |
| 3150 | } |
| 3151 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3152 | template <typename T> |
| 3153 | int32_t Compute(T x, T y) const { return x == y ? 0 : x > y ? 1 : -1; } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3154 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3155 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3156 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3157 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3158 | } |
| 3159 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3160 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3161 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3162 | } |
| 3163 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3164 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3165 | return bias_ == other->AsCompare()->bias_; |
| 3166 | } |
| 3167 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3168 | ComparisonBias GetBias() const { return bias_; } |
| 3169 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3170 | bool IsGtBias() { return bias_ == ComparisonBias::kGtBias; } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3171 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3172 | |
| 3173 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type) { |
| 3174 | // MIPS64 uses a runtime call for FP comparisons. |
| 3175 | return Primitive::IsFloatingPointType(type) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 3176 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3177 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3178 | DECLARE_INSTRUCTION(Compare); |
| 3179 | |
| 3180 | private: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3181 | const ComparisonBias bias_; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3182 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3183 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3184 | }; |
| 3185 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3186 | // A local in the graph. Corresponds to a Dex register. |
| 3187 | class HLocal : public HTemplateInstruction<0> { |
| 3188 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3189 | explicit HLocal(uint16_t reg_number) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3190 | : HTemplateInstruction(SideEffects::None(), kNoDexPc), reg_number_(reg_number) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3191 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3192 | DECLARE_INSTRUCTION(Local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3193 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3194 | uint16_t GetRegNumber() const { return reg_number_; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3195 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3196 | private: |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3197 | // The Dex register number. |
| 3198 | const uint16_t reg_number_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3199 | |
| 3200 | DISALLOW_COPY_AND_ASSIGN(HLocal); |
| 3201 | }; |
| 3202 | |
| 3203 | // Load a given local. The local is an input of this instruction. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3204 | class HLoadLocal : public HExpression<1> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3205 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3206 | HLoadLocal(HLocal* local, Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 3207 | : HExpression(type, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3208 | SetRawInputAt(0, local); |
| 3209 | } |
| 3210 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3211 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 3212 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3213 | DECLARE_INSTRUCTION(LoadLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3214 | |
| 3215 | private: |
| 3216 | DISALLOW_COPY_AND_ASSIGN(HLoadLocal); |
| 3217 | }; |
| 3218 | |
| 3219 | // Store a value in a given local. This instruction has two inputs: the value |
| 3220 | // and the local. |
| 3221 | class HStoreLocal : public HTemplateInstruction<2> { |
| 3222 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3223 | HStoreLocal(HLocal* local, HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 3224 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3225 | SetRawInputAt(0, local); |
| 3226 | SetRawInputAt(1, value); |
| 3227 | } |
| 3228 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3229 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 3230 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3231 | DECLARE_INSTRUCTION(StoreLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3232 | |
| 3233 | private: |
| 3234 | DISALLOW_COPY_AND_ASSIGN(HStoreLocal); |
| 3235 | }; |
| 3236 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3237 | class HFloatConstant : public HConstant { |
| 3238 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3239 | float GetValue() const { return value_; } |
| 3240 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3241 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 3242 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 3243 | } |
| 3244 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3245 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3246 | DCHECK(other->IsFloatConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3247 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3248 | } |
| 3249 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3250 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3251 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3252 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3253 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3254 | } |
| 3255 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3256 | return value_ == 0.0f; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3257 | } |
| 3258 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3259 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 3260 | } |
| 3261 | bool IsNaN() const { |
| 3262 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3263 | } |
| 3264 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3265 | DECLARE_INSTRUCTION(FloatConstant); |
| 3266 | |
| 3267 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3268 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 3269 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 3270 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 3271 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3272 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3273 | const float value_; |
| 3274 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3275 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3276 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3277 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3278 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 3279 | }; |
| 3280 | |
| 3281 | class HDoubleConstant : public HConstant { |
| 3282 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3283 | double GetValue() const { return value_; } |
| 3284 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3285 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 3286 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3287 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3288 | DCHECK(other->IsDoubleConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3289 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3290 | } |
| 3291 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3292 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3293 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3294 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3295 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3296 | } |
| 3297 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3298 | return value_ == 0.0; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3299 | } |
| 3300 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3301 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 3302 | } |
| 3303 | bool IsNaN() const { |
| 3304 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3305 | } |
| 3306 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3307 | DECLARE_INSTRUCTION(DoubleConstant); |
| 3308 | |
| 3309 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3310 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 3311 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 3312 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 3313 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3314 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3315 | const double value_; |
| 3316 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3317 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3318 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3319 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3320 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 3321 | }; |
| 3322 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3323 | class HNewInstance : public HExpression<2> { |
| 3324 | public: |
| 3325 | HNewInstance(HInstruction* cls, |
| 3326 | HCurrentMethod* current_method, |
| 3327 | uint32_t dex_pc, |
| 3328 | uint16_t type_index, |
| 3329 | const DexFile& dex_file, |
| 3330 | bool can_throw, |
| 3331 | bool finalizable, |
| 3332 | QuickEntrypointEnum entrypoint) |
| 3333 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
| 3334 | type_index_(type_index), |
| 3335 | dex_file_(dex_file), |
| 3336 | can_throw_(can_throw), |
| 3337 | finalizable_(finalizable), |
| 3338 | entrypoint_(entrypoint) { |
| 3339 | SetRawInputAt(0, cls); |
| 3340 | SetRawInputAt(1, current_method); |
| 3341 | } |
| 3342 | |
| 3343 | uint16_t GetTypeIndex() const { return type_index_; } |
| 3344 | const DexFile& GetDexFile() const { return dex_file_; } |
| 3345 | |
| 3346 | // Calls runtime so needs an environment. |
| 3347 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3348 | |
| 3349 | // It may throw when called on type that's not instantiable/accessible. |
| 3350 | // It can throw OOME. |
| 3351 | // TODO: distinguish between the two cases so we can for example allow allocation elimination. |
| 3352 | bool CanThrow() const OVERRIDE { return can_throw_ || true; } |
| 3353 | |
| 3354 | bool IsFinalizable() const { return finalizable_; } |
| 3355 | |
| 3356 | bool CanBeNull() const OVERRIDE { return false; } |
| 3357 | |
| 3358 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3359 | |
| 3360 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 3361 | entrypoint_ = entrypoint; |
| 3362 | } |
| 3363 | |
| 3364 | bool IsStringAlloc() const; |
| 3365 | |
| 3366 | DECLARE_INSTRUCTION(NewInstance); |
| 3367 | |
| 3368 | private: |
| 3369 | const uint16_t type_index_; |
| 3370 | const DexFile& dex_file_; |
| 3371 | const bool can_throw_; |
| 3372 | const bool finalizable_; |
| 3373 | QuickEntrypointEnum entrypoint_; |
| 3374 | |
| 3375 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3376 | }; |
| 3377 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3378 | enum class Intrinsics { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3379 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache, SideEffects, Exceptions) \ |
| 3380 | k ## Name, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3381 | #include "intrinsics_list.h" |
| 3382 | kNone, |
| 3383 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
| 3384 | #undef INTRINSICS_LIST |
| 3385 | #undef OPTIMIZING_INTRINSICS |
| 3386 | }; |
| 3387 | std::ostream& operator<<(std::ostream& os, const Intrinsics& intrinsic); |
| 3388 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3389 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3390 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3391 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3392 | }; |
| 3393 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3394 | enum IntrinsicSideEffects { |
| 3395 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 3396 | kReadSideEffects, // Intrinsic may read heap memory. |
| 3397 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 3398 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 3399 | }; |
| 3400 | |
| 3401 | enum IntrinsicExceptions { |
| 3402 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 3403 | kCanThrow // Intrinsic may throw exceptions. |
| 3404 | }; |
| 3405 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3406 | class HInvoke : public HInstruction { |
| 3407 | public: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3408 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3409 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3410 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3411 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3412 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3413 | SetRawInputAt(index, argument); |
| 3414 | } |
| 3415 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3416 | // Return the number of arguments. This number can be lower than |
| 3417 | // the number of inputs returned by InputCount(), as some invoke |
| 3418 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3419 | // inputs at the end of their list of inputs. |
| 3420 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3421 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3422 | Primitive::Type GetType() const OVERRIDE { return return_type_; } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3423 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3424 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3425 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3426 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3427 | InvokeType GetOriginalInvokeType() const { return original_invoke_type_; } |
| 3428 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3429 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3430 | return intrinsic_; |
| 3431 | } |
| 3432 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3433 | void SetIntrinsic(Intrinsics intrinsic, |
| 3434 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 3435 | IntrinsicSideEffects side_effects, |
| 3436 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3437 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3438 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 3439 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3440 | } |
| 3441 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3442 | bool CanThrow() const OVERRIDE { return can_throw_; } |
| 3443 | |
| 3444 | bool CanBeMoved() const OVERRIDE { return IsIntrinsic(); } |
| 3445 | |
| 3446 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3447 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 3448 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3449 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3450 | uint32_t* GetIntrinsicOptimizations() { |
| 3451 | return &intrinsic_optimizations_; |
| 3452 | } |
| 3453 | |
| 3454 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3455 | return &intrinsic_optimizations_; |
| 3456 | } |
| 3457 | |
| 3458 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3459 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3460 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3461 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3462 | protected: |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3463 | HInvoke(ArenaAllocator* arena, |
| 3464 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3465 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3466 | Primitive::Type return_type, |
| 3467 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3468 | uint32_t dex_method_index, |
| 3469 | InvokeType original_invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3470 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3471 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3472 | number_of_arguments_(number_of_arguments), |
Vladimir Marko | b7d8e8c | 2015-09-17 15:47:05 +0100 | [diff] [blame] | 3473 | inputs_(number_of_arguments + number_of_other_inputs, |
| 3474 | arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3475 | return_type_(return_type), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3476 | dex_method_index_(dex_method_index), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3477 | original_invoke_type_(original_invoke_type), |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3478 | can_throw_(true), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3479 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3480 | intrinsic_optimizations_(0) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3481 | } |
| 3482 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3483 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3484 | return inputs_[index]; |
| 3485 | } |
| 3486 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3487 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3488 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3489 | } |
| 3490 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3491 | void SetCanThrow(bool can_throw) { can_throw_ = can_throw; } |
| 3492 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3493 | uint32_t number_of_arguments_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3494 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3495 | const Primitive::Type return_type_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3496 | const uint32_t dex_method_index_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3497 | const InvokeType original_invoke_type_; |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3498 | bool can_throw_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3499 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3500 | |
| 3501 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3502 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3503 | |
| 3504 | private: |
| 3505 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3506 | }; |
| 3507 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3508 | class HInvokeUnresolved : public HInvoke { |
| 3509 | public: |
| 3510 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3511 | uint32_t number_of_arguments, |
| 3512 | Primitive::Type return_type, |
| 3513 | uint32_t dex_pc, |
| 3514 | uint32_t dex_method_index, |
| 3515 | InvokeType invoke_type) |
| 3516 | : HInvoke(arena, |
| 3517 | number_of_arguments, |
| 3518 | 0u /* number_of_other_inputs */, |
| 3519 | return_type, |
| 3520 | dex_pc, |
| 3521 | dex_method_index, |
| 3522 | invoke_type) { |
| 3523 | } |
| 3524 | |
| 3525 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3526 | |
| 3527 | private: |
| 3528 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3529 | }; |
| 3530 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3531 | class HInvokeStaticOrDirect : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3532 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3533 | // Requirements of this method call regarding the class |
| 3534 | // initialization (clinit) check of its declaring class. |
| 3535 | enum class ClinitCheckRequirement { |
| 3536 | kNone, // Class already initialized. |
| 3537 | kExplicit, // Static call having explicit clinit check as last input. |
| 3538 | kImplicit, // Static call implicitly requiring a clinit check. |
| 3539 | }; |
| 3540 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3541 | // Determines how to load the target ArtMethod*. |
| 3542 | enum class MethodLoadKind { |
| 3543 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3544 | kStringInit, |
| 3545 | |
| 3546 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3547 | kRecursive, |
| 3548 | |
| 3549 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3550 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3551 | kDirectAddress, |
| 3552 | |
| 3553 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3554 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3555 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3556 | // the image relocatable or not. |
| 3557 | kDirectAddressWithFixup, |
| 3558 | |
| 3559 | // Load from resoved methods array in the dex cache using a PC-relative load. |
| 3560 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3561 | // may cause class initialization (the entry may point to a resolution method), |
| 3562 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3563 | kDexCachePcRelative, |
| 3564 | |
| 3565 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3566 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3567 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3568 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3569 | kDexCacheViaMethod, |
| 3570 | }; |
| 3571 | |
| 3572 | // Determines the location of the code pointer. |
| 3573 | enum class CodePtrLocation { |
| 3574 | // Recursive call, use local PC-relative call instruction. |
| 3575 | kCallSelf, |
| 3576 | |
| 3577 | // Use PC-relative call instruction patched at link time. |
| 3578 | // Used for calls within an oat file, boot->boot or app->app. |
| 3579 | kCallPCRelative, |
| 3580 | |
| 3581 | // Call to a known target address, embed the direct address in code. |
| 3582 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3583 | kCallDirect, |
| 3584 | |
| 3585 | // Call to a target address that will be known at link time, embed the direct |
| 3586 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3587 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3588 | // the image relocatable or not. |
| 3589 | kCallDirectWithFixup, |
| 3590 | |
| 3591 | // Use code pointer from the ArtMethod*. |
| 3592 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3593 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3594 | kCallArtMethod, |
| 3595 | }; |
| 3596 | |
| 3597 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3598 | MethodLoadKind method_load_kind; |
| 3599 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3600 | // The method load data holds |
| 3601 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3602 | // Note that there are multiple string init methods, each having its own offset. |
| 3603 | // - the method address for kDirectAddress |
| 3604 | // - the dex cache arrays offset for kDexCachePcRel. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3605 | uint64_t method_load_data; |
| 3606 | uint64_t direct_code_ptr; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3607 | }; |
| 3608 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3609 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 3610 | uint32_t number_of_arguments, |
| 3611 | Primitive::Type return_type, |
| 3612 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3613 | uint32_t method_index, |
| 3614 | MethodReference target_method, |
| 3615 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 7904129 | 2015-03-26 10:05:54 +0000 | [diff] [blame] | 3616 | InvokeType original_invoke_type, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3617 | InvokeType optimized_invoke_type, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3618 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3619 | : HInvoke(arena, |
| 3620 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3621 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 3622 | // potentially one other if the clinit check is explicit, and potentially |
| 3623 | // one other if the method is a string factory. |
| 3624 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
| 3625 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u) + |
| 3626 | (dispatch_info.method_load_kind == MethodLoadKind::kStringInit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3627 | return_type, |
| 3628 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3629 | method_index, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3630 | original_invoke_type), |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3631 | optimized_invoke_type_(optimized_invoke_type), |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 3632 | clinit_check_requirement_(clinit_check_requirement), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3633 | target_method_(target_method), |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3634 | dispatch_info_(dispatch_info) { } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3635 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3636 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3637 | bool had_current_method_input = HasCurrentMethodInput(); |
| 3638 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 3639 | |
| 3640 | // Using the current method is the default and once we find a better |
| 3641 | // method load kind, we should not go back to using the current method. |
| 3642 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 3643 | |
| 3644 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3645 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 3646 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3647 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3648 | dispatch_info_ = dispatch_info; |
| 3649 | } |
| 3650 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3651 | void AddSpecialInput(HInstruction* input) { |
| 3652 | // We allow only one special input. |
| 3653 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 3654 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3655 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 3656 | InsertInputAt(GetSpecialInputIndex(), input); |
| 3657 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3658 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3659 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3660 | // We access the method via the dex cache so we can't do an implicit null check. |
| 3661 | // TODO: for intrinsics we can generate implicit null checks. |
| 3662 | return false; |
| 3663 | } |
| 3664 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3665 | bool CanBeNull() const OVERRIDE { |
| 3666 | return return_type_ == Primitive::kPrimNot && !IsStringInit(); |
| 3667 | } |
| 3668 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3669 | // Get the index of the special input, if any. |
| 3670 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3671 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 3672 | // method pointer; otherwise there may be one platform-specific special input, |
| 3673 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3674 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
Nicolas Geoffray | 9779307 | 2016-02-16 15:33:54 +0000 | [diff] [blame] | 3675 | bool HasSpecialInput() const { return GetNumberOfArguments() != InputCount(); } |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3676 | |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3677 | InvokeType GetOptimizedInvokeType() const { return optimized_invoke_type_; } |
| 3678 | void SetOptimizedInvokeType(InvokeType invoke_type) { |
| 3679 | optimized_invoke_type_ = invoke_type; |
| 3680 | } |
| 3681 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3682 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 3683 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 3684 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3685 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3686 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3687 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3688 | bool HasPcRelativeDexCache() const { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3689 | return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; |
| 3690 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3691 | bool HasCurrentMethodInput() const { |
| 3692 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 3693 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3694 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3695 | return true; |
| 3696 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3697 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3698 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3699 | return false; |
| 3700 | } |
| 3701 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3702 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
| 3703 | MethodReference GetTargetMethod() const { return target_method_; } |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3704 | void SetTargetMethod(MethodReference method) { target_method_ = method; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3705 | |
| 3706 | int32_t GetStringInitOffset() const { |
| 3707 | DCHECK(IsStringInit()); |
| 3708 | return dispatch_info_.method_load_data; |
| 3709 | } |
| 3710 | |
| 3711 | uint64_t GetMethodAddress() const { |
| 3712 | DCHECK(HasMethodAddress()); |
| 3713 | return dispatch_info_.method_load_data; |
| 3714 | } |
| 3715 | |
| 3716 | uint32_t GetDexCacheArrayOffset() const { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3717 | DCHECK(HasPcRelativeDexCache()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3718 | return dispatch_info_.method_load_data; |
| 3719 | } |
| 3720 | |
| 3721 | uint64_t GetDirectCodePtr() const { |
| 3722 | DCHECK(HasDirectCodePtr()); |
| 3723 | return dispatch_info_.direct_code_ptr; |
| 3724 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3725 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 3726 | ClinitCheckRequirement GetClinitCheckRequirement() const { return clinit_check_requirement_; } |
| 3727 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3728 | // Is this instruction a call to a static method? |
| 3729 | bool IsStatic() const { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3730 | return GetOriginalInvokeType() == kStatic; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3731 | } |
| 3732 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3733 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 3734 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 3735 | // instruction; only relevant for static calls with explicit clinit check. |
| 3736 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3737 | DCHECK(IsStaticWithExplicitClinitCheck()); |
| 3738 | size_t last_input_index = InputCount() - 1; |
| 3739 | HInstruction* last_input = InputAt(last_input_index); |
| 3740 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3741 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3742 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3743 | inputs_.pop_back(); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3744 | clinit_check_requirement_ = new_requirement; |
| 3745 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3746 | } |
| 3747 | |
David Brazdil | bc9ab16 | 2016-01-20 14:50:19 +0000 | [diff] [blame] | 3748 | HInstruction* GetAndRemoveThisArgumentOfStringInit() { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3749 | DCHECK(IsStringInit()); |
| 3750 | size_t index = InputCount() - 1; |
David Brazdil | bc9ab16 | 2016-01-20 14:50:19 +0000 | [diff] [blame] | 3751 | HInstruction* input = InputAt(index); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3752 | RemoveAsUserOfInput(index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3753 | inputs_.pop_back(); |
David Brazdil | bc9ab16 | 2016-01-20 14:50:19 +0000 | [diff] [blame] | 3754 | return input; |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3755 | } |
| 3756 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3757 | // 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] | 3758 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3759 | bool IsStaticWithExplicitClinitCheck() const { |
| 3760 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kExplicit); |
| 3761 | } |
| 3762 | |
| 3763 | // Is this a call to a static method whose declaring class has an |
| 3764 | // implicit intialization check requirement? |
| 3765 | bool IsStaticWithImplicitClinitCheck() const { |
| 3766 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kImplicit); |
| 3767 | } |
| 3768 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3769 | // Does this method load kind need the current method as an input? |
| 3770 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
| 3771 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kDexCacheViaMethod; |
| 3772 | } |
| 3773 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3774 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3775 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3776 | protected: |
| 3777 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 3778 | const HUserRecord<HInstruction*> input_record = HInvoke::InputRecordAt(i); |
| 3779 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck() && (i == InputCount() - 1)) { |
| 3780 | HInstruction* input = input_record.GetInstruction(); |
| 3781 | // `input` is the last input of a static invoke marked as having |
| 3782 | // an explicit clinit check. It must either be: |
| 3783 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 3784 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 3785 | DCHECK(input != nullptr); |
| 3786 | DCHECK(input->IsClinitCheck() || input->IsLoadClass()) << input->DebugName(); |
| 3787 | } |
| 3788 | return input_record; |
| 3789 | } |
| 3790 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3791 | void InsertInputAt(size_t index, HInstruction* input); |
| 3792 | void RemoveInputAt(size_t index); |
| 3793 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3794 | private: |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3795 | InvokeType optimized_invoke_type_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3796 | ClinitCheckRequirement clinit_check_requirement_; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3797 | // The target method may refer to different dex file or method index than the original |
| 3798 | // invoke. This happens for sharpened calls and for calls where a method was redeclared |
| 3799 | // in derived class to increase visibility. |
| 3800 | MethodReference target_method_; |
| 3801 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3802 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3803 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3804 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 3805 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3806 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3807 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3808 | class HInvokeVirtual : public HInvoke { |
| 3809 | public: |
| 3810 | HInvokeVirtual(ArenaAllocator* arena, |
| 3811 | uint32_t number_of_arguments, |
| 3812 | Primitive::Type return_type, |
| 3813 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3814 | uint32_t dex_method_index, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3815 | uint32_t vtable_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3816 | : 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] | 3817 | vtable_index_(vtable_index) {} |
| 3818 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3819 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3820 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3821 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3822 | } |
| 3823 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3824 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 3825 | |
| 3826 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 3827 | |
| 3828 | private: |
| 3829 | const uint32_t vtable_index_; |
| 3830 | |
| 3831 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 3832 | }; |
| 3833 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3834 | class HInvokeInterface : public HInvoke { |
| 3835 | public: |
| 3836 | HInvokeInterface(ArenaAllocator* arena, |
| 3837 | uint32_t number_of_arguments, |
| 3838 | Primitive::Type return_type, |
| 3839 | uint32_t dex_pc, |
| 3840 | uint32_t dex_method_index, |
| 3841 | uint32_t imt_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3842 | : 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] | 3843 | imt_index_(imt_index) {} |
| 3844 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3845 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3846 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3847 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3848 | } |
| 3849 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3850 | uint32_t GetImtIndex() const { return imt_index_; } |
| 3851 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 3852 | |
| 3853 | DECLARE_INSTRUCTION(InvokeInterface); |
| 3854 | |
| 3855 | private: |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3856 | const uint32_t imt_index_; |
| 3857 | |
| 3858 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 3859 | }; |
| 3860 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3861 | class HNeg : public HUnaryOperation { |
| 3862 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3863 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3864 | : HUnaryOperation(result_type, input, dex_pc) {} |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3865 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3866 | template <typename T> T Compute(T x) const { return -x; } |
| 3867 | |
| 3868 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3869 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3870 | } |
| 3871 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3872 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3873 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3874 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3875 | DECLARE_INSTRUCTION(Neg); |
| 3876 | |
| 3877 | private: |
| 3878 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 3879 | }; |
| 3880 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3881 | class HNewArray : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3882 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3883 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3884 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3885 | uint32_t dex_pc, |
| 3886 | uint16_t type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3887 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3888 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3889 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3890 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3891 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3892 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3893 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3894 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3895 | } |
| 3896 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3897 | uint16_t GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3898 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3899 | |
| 3900 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3901 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3902 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 3903 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 3904 | bool CanThrow() const OVERRIDE { return true; } |
| 3905 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3906 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3907 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3908 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3909 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3910 | DECLARE_INSTRUCTION(NewArray); |
| 3911 | |
| 3912 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3913 | const uint16_t type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3914 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3915 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3916 | |
| 3917 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 3918 | }; |
| 3919 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3920 | class HAdd : public HBinaryOperation { |
| 3921 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3922 | HAdd(Primitive::Type result_type, |
| 3923 | HInstruction* left, |
| 3924 | HInstruction* right, |
| 3925 | uint32_t dex_pc = kNoDexPc) |
| 3926 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3927 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3928 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3929 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3930 | template <typename T> T Compute(T x, T y) const { return x + y; } |
| 3931 | |
| 3932 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3933 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3934 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3935 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3936 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3937 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3938 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3939 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3940 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3941 | DECLARE_INSTRUCTION(Add); |
| 3942 | |
| 3943 | private: |
| 3944 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 3945 | }; |
| 3946 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3947 | class HSub : public HBinaryOperation { |
| 3948 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3949 | HSub(Primitive::Type result_type, |
| 3950 | HInstruction* left, |
| 3951 | HInstruction* right, |
| 3952 | uint32_t dex_pc = kNoDexPc) |
| 3953 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3954 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3955 | template <typename T> T Compute(T x, T y) const { return x - y; } |
| 3956 | |
| 3957 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3958 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3959 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3960 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3961 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3962 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3963 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3964 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3965 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3966 | DECLARE_INSTRUCTION(Sub); |
| 3967 | |
| 3968 | private: |
| 3969 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 3970 | }; |
| 3971 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3972 | class HMul : public HBinaryOperation { |
| 3973 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3974 | HMul(Primitive::Type result_type, |
| 3975 | HInstruction* left, |
| 3976 | HInstruction* right, |
| 3977 | uint32_t dex_pc = kNoDexPc) |
| 3978 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3979 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3980 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3981 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3982 | template <typename T> T Compute(T x, T y) const { return x * y; } |
| 3983 | |
| 3984 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3985 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3986 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3987 | } |
| 3988 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3989 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3990 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3991 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3992 | |
| 3993 | DECLARE_INSTRUCTION(Mul); |
| 3994 | |
| 3995 | private: |
| 3996 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 3997 | }; |
| 3998 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3999 | class HDiv : public HBinaryOperation { |
| 4000 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4001 | HDiv(Primitive::Type result_type, |
| 4002 | HInstruction* left, |
| 4003 | HInstruction* right, |
| 4004 | uint32_t dex_pc) |
| 4005 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4006 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4007 | template <typename T> |
| 4008 | T Compute(T x, T y) const { |
| 4009 | // Our graph structure ensures we never have 0 for `y` during |
| 4010 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4011 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4012 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4013 | return (y == -1) ? -x : x / y; |
| 4014 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4015 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4016 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4017 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4018 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4019 | } |
| 4020 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4021 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4022 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4023 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4024 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4025 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4026 | // The generated code can use a runtime call. |
| 4027 | return SideEffects::CanTriggerGC(); |
| 4028 | } |
| 4029 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4030 | DECLARE_INSTRUCTION(Div); |
| 4031 | |
| 4032 | private: |
| 4033 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 4034 | }; |
| 4035 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4036 | class HRem : public HBinaryOperation { |
| 4037 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4038 | HRem(Primitive::Type result_type, |
| 4039 | HInstruction* left, |
| 4040 | HInstruction* right, |
| 4041 | uint32_t dex_pc) |
| 4042 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4043 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4044 | template <typename T> |
| 4045 | T Compute(T x, T y) const { |
| 4046 | // Our graph structure ensures we never have 0 for `y` during |
| 4047 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4048 | DCHECK_NE(y, 0); |
| 4049 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 4050 | return (y == -1) ? 0 : x % y; |
| 4051 | } |
| 4052 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4053 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4054 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4055 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4056 | } |
| 4057 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4058 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4059 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4060 | } |
| 4061 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4062 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4063 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4064 | return SideEffects::CanTriggerGC(); |
| 4065 | } |
| 4066 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4067 | DECLARE_INSTRUCTION(Rem); |
| 4068 | |
| 4069 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4070 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 4071 | }; |
| 4072 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4073 | class HDivZeroCheck : public HExpression<1> { |
| 4074 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4075 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
| 4076 | // constructor. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4077 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4078 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4079 | SetRawInputAt(0, value); |
| 4080 | } |
| 4081 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4082 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 4083 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4084 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4085 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4086 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4087 | return true; |
| 4088 | } |
| 4089 | |
| 4090 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4091 | bool CanThrow() const OVERRIDE { return true; } |
| 4092 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4093 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 4094 | |
| 4095 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4096 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 4097 | }; |
| 4098 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4099 | class HShl : public HBinaryOperation { |
| 4100 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4101 | HShl(Primitive::Type result_type, |
| 4102 | HInstruction* left, |
| 4103 | HInstruction* right, |
| 4104 | uint32_t dex_pc = kNoDexPc) |
| 4105 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4106 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4107 | template <typename T, typename U, typename V> |
| 4108 | T Compute(T x, U y, V max_shift_value) const { |
| 4109 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4110 | "V is not the unsigned integer type corresponding to T"); |
| 4111 | return x << (y & max_shift_value); |
| 4112 | } |
| 4113 | |
| 4114 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4115 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4116 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4117 | } |
| 4118 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 4119 | // case is handled as `x << static_cast<int>(y)`. |
| 4120 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4121 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4122 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4123 | } |
| 4124 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4125 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4126 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4127 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4128 | |
| 4129 | DECLARE_INSTRUCTION(Shl); |
| 4130 | |
| 4131 | private: |
| 4132 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 4133 | }; |
| 4134 | |
| 4135 | class HShr : public HBinaryOperation { |
| 4136 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4137 | HShr(Primitive::Type result_type, |
| 4138 | HInstruction* left, |
| 4139 | HInstruction* right, |
| 4140 | uint32_t dex_pc = kNoDexPc) |
| 4141 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4142 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4143 | template <typename T, typename U, typename V> |
| 4144 | T Compute(T x, U y, V max_shift_value) const { |
| 4145 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4146 | "V is not the unsigned integer type corresponding to T"); |
| 4147 | return x >> (y & max_shift_value); |
| 4148 | } |
| 4149 | |
| 4150 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4151 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4152 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4153 | } |
| 4154 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 4155 | // case is handled as `x >> static_cast<int>(y)`. |
| 4156 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4157 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4158 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4159 | } |
| 4160 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4161 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4162 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4163 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4164 | |
| 4165 | DECLARE_INSTRUCTION(Shr); |
| 4166 | |
| 4167 | private: |
| 4168 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 4169 | }; |
| 4170 | |
| 4171 | class HUShr : public HBinaryOperation { |
| 4172 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4173 | HUShr(Primitive::Type result_type, |
| 4174 | HInstruction* left, |
| 4175 | HInstruction* right, |
| 4176 | uint32_t dex_pc = kNoDexPc) |
| 4177 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4178 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4179 | template <typename T, typename U, typename V> |
| 4180 | T Compute(T x, U y, V max_shift_value) const { |
| 4181 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4182 | "V is not the unsigned integer type corresponding to T"); |
| 4183 | V ux = static_cast<V>(x); |
| 4184 | return static_cast<T>(ux >> (y & max_shift_value)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4185 | } |
| 4186 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4187 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4188 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4189 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4190 | } |
| 4191 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 4192 | // case is handled as `x >>> static_cast<int>(y)`. |
| 4193 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4194 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4195 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4196 | } |
| 4197 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4198 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4199 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4200 | } |
| 4201 | |
| 4202 | DECLARE_INSTRUCTION(UShr); |
| 4203 | |
| 4204 | private: |
| 4205 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 4206 | }; |
| 4207 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4208 | class HAnd : public HBinaryOperation { |
| 4209 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4210 | HAnd(Primitive::Type result_type, |
| 4211 | HInstruction* left, |
| 4212 | HInstruction* right, |
| 4213 | uint32_t dex_pc = kNoDexPc) |
| 4214 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4215 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4216 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4217 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4218 | template <typename T, typename U> |
| 4219 | auto Compute(T x, U y) const -> decltype(x & y) { return x & y; } |
| 4220 | |
| 4221 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4222 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4223 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4224 | } |
| 4225 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4226 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4227 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4228 | } |
| 4229 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4230 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4231 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4232 | } |
| 4233 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4234 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4235 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4236 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4237 | |
| 4238 | DECLARE_INSTRUCTION(And); |
| 4239 | |
| 4240 | private: |
| 4241 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4242 | }; |
| 4243 | |
| 4244 | class HOr : public HBinaryOperation { |
| 4245 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4246 | HOr(Primitive::Type result_type, |
| 4247 | HInstruction* left, |
| 4248 | HInstruction* right, |
| 4249 | uint32_t dex_pc = kNoDexPc) |
| 4250 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4251 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4252 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4253 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4254 | template <typename T, typename U> |
| 4255 | auto Compute(T x, U y) const -> decltype(x | y) { return x | y; } |
| 4256 | |
| 4257 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4258 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4259 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4260 | } |
| 4261 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4262 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4263 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4264 | } |
| 4265 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4266 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4267 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4268 | } |
| 4269 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4270 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4271 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4272 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4273 | |
| 4274 | DECLARE_INSTRUCTION(Or); |
| 4275 | |
| 4276 | private: |
| 4277 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4278 | }; |
| 4279 | |
| 4280 | class HXor : public HBinaryOperation { |
| 4281 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4282 | HXor(Primitive::Type result_type, |
| 4283 | HInstruction* left, |
| 4284 | HInstruction* right, |
| 4285 | uint32_t dex_pc = kNoDexPc) |
| 4286 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4287 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4288 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4289 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4290 | template <typename T, typename U> |
| 4291 | auto Compute(T x, U y) const -> decltype(x ^ y) { return x ^ y; } |
| 4292 | |
| 4293 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4294 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4295 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4296 | } |
| 4297 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4298 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4299 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4300 | } |
| 4301 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4302 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4303 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4304 | } |
| 4305 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4306 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4307 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4308 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4309 | |
| 4310 | DECLARE_INSTRUCTION(Xor); |
| 4311 | |
| 4312 | private: |
| 4313 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 4314 | }; |
| 4315 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4316 | class HRor : public HBinaryOperation { |
| 4317 | public: |
| 4318 | HRor(Primitive::Type result_type, HInstruction* value, HInstruction* distance) |
| 4319 | : HBinaryOperation(result_type, value, distance) {} |
| 4320 | |
| 4321 | template <typename T, typename U, typename V> |
| 4322 | T Compute(T x, U y, V max_shift_value) const { |
| 4323 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4324 | "V is not the unsigned integer type corresponding to T"); |
| 4325 | V ux = static_cast<V>(x); |
| 4326 | if ((y & max_shift_value) == 0) { |
| 4327 | return static_cast<T>(ux); |
| 4328 | } else { |
| 4329 | const V reg_bits = sizeof(T) * 8; |
| 4330 | return static_cast<T>(ux >> (y & max_shift_value)) | |
| 4331 | (x << (reg_bits - (y & max_shift_value))); |
| 4332 | } |
| 4333 | } |
| 4334 | |
| 4335 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4336 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4337 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
| 4338 | } |
| 4339 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4340 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4341 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
| 4342 | } |
| 4343 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4344 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4345 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
| 4346 | } |
| 4347 | |
| 4348 | DECLARE_INSTRUCTION(Ror); |
| 4349 | |
| 4350 | private: |
| 4351 | DISALLOW_COPY_AND_ASSIGN(HRor); |
| 4352 | }; |
| 4353 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4354 | // The value of a parameter in this method. Its location depends on |
| 4355 | // the calling convention. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4356 | class HParameterValue : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4357 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4358 | HParameterValue(const DexFile& dex_file, |
| 4359 | uint16_t type_index, |
| 4360 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4361 | Primitive::Type parameter_type, |
| 4362 | bool is_this = false) |
| 4363 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4364 | dex_file_(dex_file), |
| 4365 | type_index_(type_index), |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4366 | index_(index), |
| 4367 | is_this_(is_this), |
| 4368 | can_be_null_(!is_this) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4369 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4370 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4371 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4372 | uint8_t GetIndex() const { return index_; } |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4373 | bool IsThis() const { return is_this_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4374 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4375 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4376 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4377 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4378 | DECLARE_INSTRUCTION(ParameterValue); |
| 4379 | |
| 4380 | private: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4381 | const DexFile& dex_file_; |
| 4382 | const uint16_t type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4383 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4384 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4385 | const uint8_t index_; |
| 4386 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4387 | // Whether or not the parameter value corresponds to 'this' argument. |
| 4388 | const bool is_this_; |
| 4389 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4390 | bool can_be_null_; |
| 4391 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4392 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 4393 | }; |
| 4394 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4395 | class HNot : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4396 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4397 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4398 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4399 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4400 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4401 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4402 | return true; |
| 4403 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4404 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4405 | template <typename T> T Compute(T x) const { return ~x; } |
| 4406 | |
| 4407 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4408 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4409 | } |
| 4410 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4411 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4412 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4413 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4414 | DECLARE_INSTRUCTION(Not); |
| 4415 | |
| 4416 | private: |
| 4417 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 4418 | }; |
| 4419 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4420 | class HBooleanNot : public HUnaryOperation { |
| 4421 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4422 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4423 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4424 | |
| 4425 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4426 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4427 | return true; |
| 4428 | } |
| 4429 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4430 | template <typename T> bool Compute(T x) const { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4431 | DCHECK(IsUint<1>(x)); |
| 4432 | return !x; |
| 4433 | } |
| 4434 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4435 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4436 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4437 | } |
| 4438 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4439 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4440 | UNREACHABLE(); |
| 4441 | } |
| 4442 | |
| 4443 | DECLARE_INSTRUCTION(BooleanNot); |
| 4444 | |
| 4445 | private: |
| 4446 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 4447 | }; |
| 4448 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4449 | class HTypeConversion : public HExpression<1> { |
| 4450 | public: |
| 4451 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4452 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4453 | : HExpression(result_type, |
| 4454 | SideEffectsForArchRuntimeCalls(input->GetType(), result_type), |
| 4455 | dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4456 | SetRawInputAt(0, input); |
| 4457 | DCHECK_NE(input->GetType(), result_type); |
| 4458 | } |
| 4459 | |
| 4460 | HInstruction* GetInput() const { return InputAt(0); } |
| 4461 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 4462 | Primitive::Type GetResultType() const { return GetType(); } |
| 4463 | |
| 4464 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | ed9b195 | 2014-11-06 11:10:17 +0000 | [diff] [blame] | 4465 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4466 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 4467 | // Try to statically evaluate the conversion and return a HConstant |
| 4468 | // containing the result. If the input cannot be converted, return nullptr. |
| 4469 | HConstant* TryStaticEvaluation() const; |
| 4470 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4471 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type input_type, |
| 4472 | Primitive::Type result_type) { |
| 4473 | // Some architectures may not require the 'GC' side effects, but at this point |
| 4474 | // in the compilation process we do not know what architecture we will |
| 4475 | // generate code for, so we must be conservative. |
Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 4476 | if ((Primitive::IsFloatingPointType(input_type) && Primitive::IsIntegralType(result_type)) |
| 4477 | || (input_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(result_type))) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4478 | return SideEffects::CanTriggerGC(); |
| 4479 | } |
| 4480 | return SideEffects::None(); |
| 4481 | } |
| 4482 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4483 | DECLARE_INSTRUCTION(TypeConversion); |
| 4484 | |
| 4485 | private: |
| 4486 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 4487 | }; |
| 4488 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 4489 | static constexpr uint32_t kNoRegNumber = -1; |
| 4490 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4491 | class HPhi : public HInstruction { |
| 4492 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4493 | HPhi(ArenaAllocator* arena, |
| 4494 | uint32_t reg_number, |
| 4495 | size_t number_of_inputs, |
| 4496 | Primitive::Type type, |
| 4497 | uint32_t dex_pc = kNoDexPc) |
| 4498 | : HInstruction(SideEffects::None(), dex_pc), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4499 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4500 | reg_number_(reg_number), |
David Brazdil | 809d70f | 2015-11-19 10:29:39 +0000 | [diff] [blame] | 4501 | type_(ToPhiType(type)), |
| 4502 | // Phis are constructed live and marked dead if conflicting or unused. |
| 4503 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 4504 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 4505 | is_live_(true), |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4506 | can_be_null_(true) { |
David Brazdil | 809d70f | 2015-11-19 10:29:39 +0000 | [diff] [blame] | 4507 | DCHECK_NE(type_, Primitive::kPrimVoid); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4508 | } |
| 4509 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 4510 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 4511 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 4512 | switch (type) { |
| 4513 | case Primitive::kPrimBoolean: |
| 4514 | case Primitive::kPrimByte: |
| 4515 | case Primitive::kPrimShort: |
| 4516 | case Primitive::kPrimChar: |
| 4517 | return Primitive::kPrimInt; |
| 4518 | default: |
| 4519 | return type; |
| 4520 | } |
| 4521 | } |
| 4522 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 4523 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 4524 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4525 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4526 | |
| 4527 | void AddInput(HInstruction* input); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 4528 | void RemoveInputAt(size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4529 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4530 | Primitive::Type GetType() const OVERRIDE { return type_; } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 4531 | void SetType(Primitive::Type new_type) { |
| 4532 | // Make sure that only valid type changes occur. The following are allowed: |
| 4533 | // (1) int -> float/ref (primitive type propagation), |
| 4534 | // (2) long -> double (primitive type propagation). |
| 4535 | DCHECK(type_ == new_type || |
| 4536 | (type_ == Primitive::kPrimInt && new_type == Primitive::kPrimFloat) || |
| 4537 | (type_ == Primitive::kPrimInt && new_type == Primitive::kPrimNot) || |
| 4538 | (type_ == Primitive::kPrimLong && new_type == Primitive::kPrimDouble)); |
| 4539 | type_ = new_type; |
| 4540 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4541 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4542 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4543 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
| 4544 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4545 | uint32_t GetRegNumber() const { return reg_number_; } |
| 4546 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4547 | void SetDead() { is_live_ = false; } |
| 4548 | void SetLive() { is_live_ = true; } |
| 4549 | bool IsDead() const { return !is_live_; } |
| 4550 | bool IsLive() const { return is_live_; } |
| 4551 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4552 | bool IsVRegEquivalentOf(HInstruction* other) const { |
| 4553 | return other != nullptr |
| 4554 | && other->IsPhi() |
| 4555 | && other->AsPhi()->GetBlock() == GetBlock() |
| 4556 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 4557 | } |
| 4558 | |
Calin Juravle | a4f8831 | 2015-04-16 12:57:19 +0100 | [diff] [blame] | 4559 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 4560 | // An equivalent phi is a phi having the same dex register and type. |
| 4561 | // It assumes that phis with the same dex register are adjacent. |
| 4562 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 4563 | HInstruction* next = GetNext(); |
| 4564 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 4565 | if (next->GetType() == GetType()) { |
| 4566 | return next->AsPhi(); |
| 4567 | } |
| 4568 | next = next->GetNext(); |
| 4569 | } |
| 4570 | return nullptr; |
| 4571 | } |
| 4572 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4573 | DECLARE_INSTRUCTION(Phi); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4574 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4575 | protected: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4576 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4577 | return inputs_[index]; |
| 4578 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4579 | |
| 4580 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4581 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4582 | } |
| 4583 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4584 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4585 | ArenaVector<HUserRecord<HInstruction*> > inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4586 | const uint32_t reg_number_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4587 | Primitive::Type type_; |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4588 | bool is_live_; |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4589 | bool can_be_null_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4590 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4591 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 4592 | }; |
| 4593 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4594 | class HNullCheck : public HExpression<1> { |
| 4595 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4596 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
| 4597 | // constructor. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4598 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4599 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4600 | SetRawInputAt(0, value); |
| 4601 | } |
| 4602 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4603 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4604 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4605 | return true; |
| 4606 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4607 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4608 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4609 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4610 | bool CanThrow() const OVERRIDE { return true; } |
| 4611 | |
| 4612 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4613 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4614 | |
| 4615 | DECLARE_INSTRUCTION(NullCheck); |
| 4616 | |
| 4617 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4618 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 4619 | }; |
| 4620 | |
| 4621 | class FieldInfo : public ValueObject { |
| 4622 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4623 | FieldInfo(MemberOffset field_offset, |
| 4624 | Primitive::Type field_type, |
| 4625 | bool is_volatile, |
| 4626 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4627 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4628 | const DexFile& dex_file, |
| 4629 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4630 | : field_offset_(field_offset), |
| 4631 | field_type_(field_type), |
| 4632 | is_volatile_(is_volatile), |
| 4633 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4634 | declaring_class_def_index_(declaring_class_def_index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4635 | dex_file_(dex_file), |
| 4636 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4637 | |
| 4638 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4639 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4640 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4641 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4642 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4643 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4644 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4645 | |
| 4646 | private: |
| 4647 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4648 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4649 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4650 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4651 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4652 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4653 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4654 | }; |
| 4655 | |
| 4656 | class HInstanceFieldGet : public HExpression<1> { |
| 4657 | public: |
| 4658 | HInstanceFieldGet(HInstruction* value, |
| 4659 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4660 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4661 | bool is_volatile, |
| 4662 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4663 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4664 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4665 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4666 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4667 | : HExpression(field_type, |
| 4668 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 4669 | dex_pc), |
| 4670 | field_info_(field_offset, |
| 4671 | field_type, |
| 4672 | is_volatile, |
| 4673 | field_idx, |
| 4674 | declaring_class_def_index, |
| 4675 | dex_file, |
| 4676 | dex_cache) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4677 | SetRawInputAt(0, value); |
| 4678 | } |
| 4679 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 4680 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4681 | |
| 4682 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4683 | HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
| 4684 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4685 | } |
| 4686 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4687 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4688 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4689 | } |
| 4690 | |
| 4691 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 4692 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 4693 | } |
| 4694 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4695 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4696 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4697 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4698 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4699 | |
| 4700 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 4701 | |
| 4702 | private: |
| 4703 | const FieldInfo field_info_; |
| 4704 | |
| 4705 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 4706 | }; |
| 4707 | |
| 4708 | class HInstanceFieldSet : public HTemplateInstruction<2> { |
| 4709 | public: |
| 4710 | HInstanceFieldSet(HInstruction* object, |
| 4711 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4712 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4713 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4714 | bool is_volatile, |
| 4715 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4716 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4717 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4718 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4719 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4720 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 4721 | dex_pc), |
| 4722 | field_info_(field_offset, |
| 4723 | field_type, |
| 4724 | is_volatile, |
| 4725 | field_idx, |
| 4726 | declaring_class_def_index, |
| 4727 | dex_file, |
| 4728 | dex_cache), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4729 | value_can_be_null_(true) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4730 | SetRawInputAt(0, object); |
| 4731 | SetRawInputAt(1, value); |
| 4732 | } |
| 4733 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4734 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4735 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4736 | } |
| 4737 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4738 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4739 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4740 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4741 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4742 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4743 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 4744 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4745 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4746 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 4747 | |
| 4748 | private: |
| 4749 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4750 | bool value_can_be_null_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4751 | |
| 4752 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 4753 | }; |
| 4754 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4755 | class HArrayGet : public HExpression<2> { |
| 4756 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4757 | HArrayGet(HInstruction* array, |
| 4758 | HInstruction* index, |
| 4759 | Primitive::Type type, |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4760 | uint32_t dex_pc, |
| 4761 | SideEffects additional_side_effects = SideEffects::None()) |
| 4762 | : HExpression(type, |
| 4763 | SideEffects::ArrayReadOfType(type).Union(additional_side_effects), |
David Brazdil | 2bd4c5c | 2015-11-04 22:48:45 +0000 | [diff] [blame] | 4764 | dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4765 | SetRawInputAt(0, array); |
| 4766 | SetRawInputAt(1, index); |
| 4767 | } |
| 4768 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4769 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4770 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4771 | return true; |
| 4772 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4773 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4774 | // TODO: We can be smarter here. |
| 4775 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 4776 | // which generates the implicit null check. There are cases when these can be removed |
| 4777 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 4778 | // implicit check here (as long as the address falls in the first page). |
| 4779 | return false; |
| 4780 | } |
| 4781 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 4782 | bool IsEquivalentOf(HArrayGet* other) const { |
| 4783 | bool result = (GetDexPc() == other->GetDexPc()); |
| 4784 | if (kIsDebugBuild && result) { |
| 4785 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 4786 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 4787 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
| 4788 | if (Primitive::IsIntOrLongType(GetType())) { |
| 4789 | DCHECK(Primitive::IsFloatingPointType(other->GetType())); |
| 4790 | } else { |
| 4791 | DCHECK(Primitive::IsFloatingPointType(GetType())); |
| 4792 | DCHECK(Primitive::IsIntOrLongType(other->GetType())); |
| 4793 | } |
| 4794 | } |
| 4795 | return result; |
| 4796 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4797 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4798 | HInstruction* GetArray() const { return InputAt(0); } |
| 4799 | HInstruction* GetIndex() const { return InputAt(1); } |
| 4800 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4801 | DECLARE_INSTRUCTION(ArrayGet); |
| 4802 | |
| 4803 | private: |
| 4804 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 4805 | }; |
| 4806 | |
| 4807 | class HArraySet : public HTemplateInstruction<3> { |
| 4808 | public: |
| 4809 | HArraySet(HInstruction* array, |
| 4810 | HInstruction* index, |
| 4811 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4812 | Primitive::Type expected_component_type, |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4813 | uint32_t dex_pc, |
| 4814 | SideEffects additional_side_effects = SideEffects::None()) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4815 | : HTemplateInstruction( |
| 4816 | SideEffects::ArrayWriteOfType(expected_component_type).Union( |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4817 | SideEffectsForArchRuntimeCalls(value->GetType())).Union( |
| 4818 | additional_side_effects), |
| 4819 | dex_pc), |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4820 | expected_component_type_(expected_component_type), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4821 | needs_type_check_(value->GetType() == Primitive::kPrimNot), |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4822 | value_can_be_null_(true), |
| 4823 | static_type_of_array_is_object_array_(false) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4824 | SetRawInputAt(0, array); |
| 4825 | SetRawInputAt(1, index); |
| 4826 | SetRawInputAt(2, value); |
| 4827 | } |
| 4828 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4829 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 4830 | // We call a runtime method to throw ArrayStoreException. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4831 | return needs_type_check_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4832 | } |
| 4833 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 4834 | // Can throw ArrayStoreException. |
| 4835 | bool CanThrow() const OVERRIDE { return needs_type_check_; } |
| 4836 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4837 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4838 | // TODO: Same as for ArrayGet. |
| 4839 | return false; |
| 4840 | } |
| 4841 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4842 | void ClearNeedsTypeCheck() { |
| 4843 | needs_type_check_ = false; |
| 4844 | } |
| 4845 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4846 | void ClearValueCanBeNull() { |
| 4847 | value_can_be_null_ = false; |
| 4848 | } |
| 4849 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4850 | void SetStaticTypeOfArrayIsObjectArray() { |
| 4851 | static_type_of_array_is_object_array_ = true; |
| 4852 | } |
| 4853 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4854 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4855 | bool NeedsTypeCheck() const { return needs_type_check_; } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4856 | bool StaticTypeOfArrayIsObjectArray() const { return static_type_of_array_is_object_array_; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4857 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4858 | HInstruction* GetArray() const { return InputAt(0); } |
| 4859 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4860 | HInstruction* GetValue() const { return InputAt(2); } |
| 4861 | |
| 4862 | Primitive::Type GetComponentType() const { |
| 4863 | // The Dex format does not type floating point index operations. Since the |
| 4864 | // `expected_component_type_` is set during building and can therefore not |
| 4865 | // be correct, we also check what is the value type. If it is a floating |
| 4866 | // point type, we must use that type. |
| 4867 | Primitive::Type value_type = GetValue()->GetType(); |
| 4868 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 4869 | ? value_type |
| 4870 | : expected_component_type_; |
| 4871 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4872 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4873 | Primitive::Type GetRawExpectedComponentType() const { |
| 4874 | return expected_component_type_; |
| 4875 | } |
| 4876 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4877 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 4878 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 4879 | } |
| 4880 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4881 | DECLARE_INSTRUCTION(ArraySet); |
| 4882 | |
| 4883 | private: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4884 | const Primitive::Type expected_component_type_; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4885 | bool needs_type_check_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4886 | bool value_can_be_null_; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4887 | // Cached information for the reference_type_info_ so that codegen |
| 4888 | // does not need to inspect the static type. |
| 4889 | bool static_type_of_array_is_object_array_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4890 | |
| 4891 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 4892 | }; |
| 4893 | |
| 4894 | class HArrayLength : public HExpression<1> { |
| 4895 | public: |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 4896 | HArrayLength(HInstruction* array, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4897 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4898 | // Note that arrays do not change length, so the instruction does not |
| 4899 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4900 | SetRawInputAt(0, array); |
| 4901 | } |
| 4902 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4903 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4904 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4905 | return true; |
| 4906 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4907 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4908 | return obj == InputAt(0); |
| 4909 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4910 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4911 | DECLARE_INSTRUCTION(ArrayLength); |
| 4912 | |
| 4913 | private: |
| 4914 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 4915 | }; |
| 4916 | |
| 4917 | class HBoundsCheck : public HExpression<2> { |
| 4918 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4919 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
| 4920 | // constructor. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4921 | HBoundsCheck(HInstruction* index, HInstruction* length, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4922 | : HExpression(index->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4923 | DCHECK(index->GetType() == Primitive::kPrimInt); |
| 4924 | SetRawInputAt(0, index); |
| 4925 | SetRawInputAt(1, length); |
| 4926 | } |
| 4927 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4928 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4929 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4930 | return true; |
| 4931 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4932 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4933 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4934 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4935 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4936 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4937 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4938 | |
| 4939 | DECLARE_INSTRUCTION(BoundsCheck); |
| 4940 | |
| 4941 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4942 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 4943 | }; |
| 4944 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4945 | class HSuspendCheck : public HTemplateInstruction<0> { |
| 4946 | public: |
| 4947 | explicit HSuspendCheck(uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4948 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4949 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4950 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4951 | return true; |
| 4952 | } |
| 4953 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4954 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 4955 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4956 | |
| 4957 | DECLARE_INSTRUCTION(SuspendCheck); |
| 4958 | |
| 4959 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4960 | // Only used for code generation, in order to share the same slow path between back edges |
| 4961 | // of a same loop. |
| 4962 | SlowPathCode* slow_path_; |
| 4963 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4964 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 4965 | }; |
| 4966 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4967 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 4968 | // It ensures that we can generate line number and local variables at this point. |
| 4969 | class HNativeDebugInfo : public HTemplateInstruction<0> { |
| 4970 | public: |
| 4971 | explicit HNativeDebugInfo(uint32_t dex_pc) |
| 4972 | : HTemplateInstruction<0>(SideEffects::None(), dex_pc) {} |
| 4973 | |
| 4974 | bool NeedsEnvironment() const OVERRIDE { |
| 4975 | return true; |
| 4976 | } |
| 4977 | |
| 4978 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 4979 | |
| 4980 | private: |
| 4981 | DISALLOW_COPY_AND_ASSIGN(HNativeDebugInfo); |
| 4982 | }; |
| 4983 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4984 | /** |
| 4985 | * Instruction to load a Class object. |
| 4986 | */ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4987 | class HLoadClass : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4988 | public: |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4989 | HLoadClass(HCurrentMethod* current_method, |
| 4990 | uint16_t type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4991 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4992 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4993 | uint32_t dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4994 | bool needs_access_check, |
| 4995 | bool is_in_dex_cache) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4996 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4997 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4998 | dex_file_(dex_file), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4999 | is_referrers_class_(is_referrers_class), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5000 | generate_clinit_check_(false), |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5001 | needs_access_check_(needs_access_check), |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5002 | is_in_dex_cache_(is_in_dex_cache), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5003 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5004 | // Referrers class should not need access check. We never inline unverified |
| 5005 | // methods so we can't possibly end up in this situation. |
| 5006 | DCHECK(!is_referrers_class_ || !needs_access_check_); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5007 | SetRawInputAt(0, current_method); |
| 5008 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5009 | |
| 5010 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5011 | |
| 5012 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | a9a306d | 2015-10-08 16:48:31 +0100 | [diff] [blame] | 5013 | // Note that we don't need to test for generate_clinit_check_. |
| 5014 | // Whether or not we need to generate the clinit check is processed in |
| 5015 | // prepare_for_register_allocator based on existing HInvokes and HClinitChecks. |
Calin Juravle | 386062d | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5016 | return other->AsLoadClass()->type_index_ == type_index_ && |
| 5017 | other->AsLoadClass()->needs_access_check_ == needs_access_check_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5018 | } |
| 5019 | |
| 5020 | size_t ComputeHashCode() const OVERRIDE { return type_index_; } |
| 5021 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5022 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5023 | bool IsReferrersClass() const { return is_referrers_class_; } |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 5024 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5025 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5026 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5027 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5028 | } |
| 5029 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5030 | bool MustGenerateClinitCheck() const { |
| 5031 | return generate_clinit_check_; |
| 5032 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5033 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 5034 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 5035 | // The entrypoint the code generator is going to call does not do |
| 5036 | // clinit of the class. |
| 5037 | DCHECK(!NeedsAccessCheck()); |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 5038 | generate_clinit_check_ = generate_clinit_check; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5039 | } |
| 5040 | |
| 5041 | bool CanCallRuntime() const { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5042 | return MustGenerateClinitCheck() || |
| 5043 | (!is_referrers_class_ && !is_in_dex_cache_) || |
| 5044 | needs_access_check_; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5045 | } |
| 5046 | |
| 5047 | bool NeedsAccessCheck() const { |
| 5048 | return needs_access_check_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5049 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5050 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5051 | bool CanThrow() const OVERRIDE { |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 5052 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5053 | } |
| 5054 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5055 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 5056 | return loaded_class_rti_; |
| 5057 | } |
| 5058 | |
| 5059 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 5060 | // Make sure we only set exact types (the loaded class should never be merged). |
| 5061 | DCHECK(rti.IsExact()); |
| 5062 | loaded_class_rti_ = rti; |
| 5063 | } |
| 5064 | |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5065 | const DexFile& GetDexFile() { return dex_file_; } |
| 5066 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5067 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return !is_referrers_class_; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 5068 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5069 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5070 | return SideEffects::CanTriggerGC(); |
| 5071 | } |
| 5072 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5073 | bool IsInDexCache() const { return is_in_dex_cache_; } |
| 5074 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5075 | DECLARE_INSTRUCTION(LoadClass); |
| 5076 | |
| 5077 | private: |
| 5078 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5079 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5080 | const bool is_referrers_class_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5081 | // Whether this instruction must generate the initialization check. |
| 5082 | // Used for code generation. |
| 5083 | bool generate_clinit_check_; |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5084 | const bool needs_access_check_; |
| 5085 | const bool is_in_dex_cache_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5086 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5087 | ReferenceTypeInfo loaded_class_rti_; |
| 5088 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5089 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 5090 | }; |
| 5091 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5092 | class HLoadString : public HExpression<1> { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5093 | public: |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5094 | HLoadString(HCurrentMethod* current_method, |
| 5095 | uint32_t string_index, |
| 5096 | uint32_t dex_pc, |
| 5097 | bool is_in_dex_cache) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5098 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5099 | string_index_(string_index), |
| 5100 | is_in_dex_cache_(is_in_dex_cache) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5101 | SetRawInputAt(0, current_method); |
| 5102 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5103 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5104 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5105 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5106 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 5107 | return other->AsLoadString()->string_index_ == string_index_; |
| 5108 | } |
| 5109 | |
| 5110 | size_t ComputeHashCode() const OVERRIDE { return string_index_; } |
| 5111 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5112 | uint32_t GetStringIndex() const { return string_index_; } |
| 5113 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5114 | // Will call the runtime if the string is not already in the dex cache. |
| 5115 | bool NeedsEnvironment() const OVERRIDE { return !IsInDexCache(); } |
| 5116 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5117 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return true; } |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 5118 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5119 | bool IsInDexCache() const { return is_in_dex_cache_; } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5120 | bool CanThrow() const OVERRIDE { return !IsInDexCache(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5121 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5122 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5123 | return SideEffects::CanTriggerGC(); |
| 5124 | } |
| 5125 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5126 | DECLARE_INSTRUCTION(LoadString); |
| 5127 | |
| 5128 | private: |
| 5129 | const uint32_t string_index_; |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5130 | const bool is_in_dex_cache_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5131 | |
| 5132 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 5133 | }; |
| 5134 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5135 | /** |
| 5136 | * Performs an initialization check on its Class object input. |
| 5137 | */ |
| 5138 | class HClinitCheck : public HExpression<1> { |
| 5139 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 5140 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 5141 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5142 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5143 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 5144 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5145 | SetRawInputAt(0, constant); |
| 5146 | } |
| 5147 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5148 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5149 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5150 | return true; |
| 5151 | } |
| 5152 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5153 | bool NeedsEnvironment() const OVERRIDE { |
| 5154 | // May call runtime to initialize the class. |
| 5155 | return true; |
| 5156 | } |
| 5157 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 5158 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5159 | |
| 5160 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 5161 | |
| 5162 | DECLARE_INSTRUCTION(ClinitCheck); |
| 5163 | |
| 5164 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5165 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 5166 | }; |
| 5167 | |
| 5168 | class HStaticFieldGet : public HExpression<1> { |
| 5169 | public: |
| 5170 | HStaticFieldGet(HInstruction* cls, |
| 5171 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5172 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5173 | bool is_volatile, |
| 5174 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5175 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5176 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5177 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5178 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5179 | : HExpression(field_type, |
| 5180 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5181 | dex_pc), |
| 5182 | field_info_(field_offset, |
| 5183 | field_type, |
| 5184 | is_volatile, |
| 5185 | field_idx, |
| 5186 | declaring_class_def_index, |
| 5187 | dex_file, |
| 5188 | dex_cache) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5189 | SetRawInputAt(0, cls); |
| 5190 | } |
| 5191 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5192 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5193 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5194 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5195 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5196 | HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
| 5197 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5198 | } |
| 5199 | |
| 5200 | size_t ComputeHashCode() const OVERRIDE { |
| 5201 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5202 | } |
| 5203 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5204 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5205 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5206 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5207 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5208 | |
| 5209 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 5210 | |
| 5211 | private: |
| 5212 | const FieldInfo field_info_; |
| 5213 | |
| 5214 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 5215 | }; |
| 5216 | |
| 5217 | class HStaticFieldSet : public HTemplateInstruction<2> { |
| 5218 | public: |
| 5219 | HStaticFieldSet(HInstruction* cls, |
| 5220 | HInstruction* value, |
| 5221 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5222 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5223 | bool is_volatile, |
| 5224 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5225 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5226 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5227 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5228 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5229 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5230 | dex_pc), |
| 5231 | field_info_(field_offset, |
| 5232 | field_type, |
| 5233 | is_volatile, |
| 5234 | field_idx, |
| 5235 | declaring_class_def_index, |
| 5236 | dex_file, |
| 5237 | dex_cache), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5238 | value_can_be_null_(true) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5239 | SetRawInputAt(0, cls); |
| 5240 | SetRawInputAt(1, value); |
| 5241 | } |
| 5242 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5243 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5244 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5245 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5246 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5247 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5248 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5249 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 5250 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5251 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5252 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 5253 | |
| 5254 | private: |
| 5255 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5256 | bool value_can_be_null_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5257 | |
| 5258 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 5259 | }; |
| 5260 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5261 | class HUnresolvedInstanceFieldGet : public HExpression<1> { |
| 5262 | public: |
| 5263 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 5264 | Primitive::Type field_type, |
| 5265 | uint32_t field_index, |
| 5266 | uint32_t dex_pc) |
| 5267 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5268 | field_index_(field_index) { |
| 5269 | SetRawInputAt(0, obj); |
| 5270 | } |
| 5271 | |
| 5272 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5273 | bool CanThrow() const OVERRIDE { return true; } |
| 5274 | |
| 5275 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5276 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5277 | |
| 5278 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 5279 | |
| 5280 | private: |
| 5281 | const uint32_t field_index_; |
| 5282 | |
| 5283 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 5284 | }; |
| 5285 | |
| 5286 | class HUnresolvedInstanceFieldSet : public HTemplateInstruction<2> { |
| 5287 | public: |
| 5288 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 5289 | HInstruction* value, |
| 5290 | Primitive::Type field_type, |
| 5291 | uint32_t field_index, |
| 5292 | uint32_t dex_pc) |
| 5293 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
| 5294 | field_type_(field_type), |
| 5295 | field_index_(field_index) { |
| 5296 | DCHECK_EQ(field_type, value->GetType()); |
| 5297 | SetRawInputAt(0, obj); |
| 5298 | SetRawInputAt(1, value); |
| 5299 | } |
| 5300 | |
| 5301 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5302 | bool CanThrow() const OVERRIDE { return true; } |
| 5303 | |
| 5304 | Primitive::Type GetFieldType() const { return field_type_; } |
| 5305 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5306 | |
| 5307 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 5308 | |
| 5309 | private: |
| 5310 | const Primitive::Type field_type_; |
| 5311 | const uint32_t field_index_; |
| 5312 | |
| 5313 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 5314 | }; |
| 5315 | |
| 5316 | class HUnresolvedStaticFieldGet : public HExpression<0> { |
| 5317 | public: |
| 5318 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 5319 | uint32_t field_index, |
| 5320 | uint32_t dex_pc) |
| 5321 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5322 | field_index_(field_index) { |
| 5323 | } |
| 5324 | |
| 5325 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5326 | bool CanThrow() const OVERRIDE { return true; } |
| 5327 | |
| 5328 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5329 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5330 | |
| 5331 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 5332 | |
| 5333 | private: |
| 5334 | const uint32_t field_index_; |
| 5335 | |
| 5336 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 5337 | }; |
| 5338 | |
| 5339 | class HUnresolvedStaticFieldSet : public HTemplateInstruction<1> { |
| 5340 | public: |
| 5341 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 5342 | Primitive::Type field_type, |
| 5343 | uint32_t field_index, |
| 5344 | uint32_t dex_pc) |
| 5345 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
| 5346 | field_type_(field_type), |
| 5347 | field_index_(field_index) { |
| 5348 | DCHECK_EQ(field_type, value->GetType()); |
| 5349 | SetRawInputAt(0, value); |
| 5350 | } |
| 5351 | |
| 5352 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5353 | bool CanThrow() const OVERRIDE { return true; } |
| 5354 | |
| 5355 | Primitive::Type GetFieldType() const { return field_type_; } |
| 5356 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5357 | |
| 5358 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 5359 | |
| 5360 | private: |
| 5361 | const Primitive::Type field_type_; |
| 5362 | const uint32_t field_index_; |
| 5363 | |
| 5364 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 5365 | }; |
| 5366 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5367 | // Implement the move-exception DEX instruction. |
| 5368 | class HLoadException : public HExpression<0> { |
| 5369 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5370 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 5371 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5372 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 5373 | bool CanBeNull() const OVERRIDE { return false; } |
| 5374 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5375 | DECLARE_INSTRUCTION(LoadException); |
| 5376 | |
| 5377 | private: |
| 5378 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 5379 | }; |
| 5380 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5381 | // Implicit part of move-exception which clears thread-local exception storage. |
| 5382 | // Must not be removed because the runtime expects the TLS to get cleared. |
| 5383 | class HClearException : public HTemplateInstruction<0> { |
| 5384 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5385 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 5386 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5387 | |
| 5388 | DECLARE_INSTRUCTION(ClearException); |
| 5389 | |
| 5390 | private: |
| 5391 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 5392 | }; |
| 5393 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5394 | class HThrow : public HTemplateInstruction<1> { |
| 5395 | public: |
| 5396 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5397 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5398 | SetRawInputAt(0, exception); |
| 5399 | } |
| 5400 | |
| 5401 | bool IsControlFlow() const OVERRIDE { return true; } |
| 5402 | |
| 5403 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5404 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5405 | bool CanThrow() const OVERRIDE { return true; } |
| 5406 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5407 | |
| 5408 | DECLARE_INSTRUCTION(Throw); |
| 5409 | |
| 5410 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5411 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 5412 | }; |
| 5413 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5414 | /** |
| 5415 | * Implementation strategies for the code generator of a HInstanceOf |
| 5416 | * or `HCheckCast`. |
| 5417 | */ |
| 5418 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5419 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5420 | kExactCheck, // Can do a single class compare. |
| 5421 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 5422 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 5423 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 5424 | kArrayObjectCheck, // Can just check if the array is not primitive. |
| 5425 | kArrayCheck // No optimization yet when checking against a generic array. |
| 5426 | }; |
| 5427 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5428 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 5429 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5430 | class HInstanceOf : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5431 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5432 | HInstanceOf(HInstruction* object, |
| 5433 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5434 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5435 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5436 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5437 | SideEffectsForArchRuntimeCalls(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5438 | dex_pc), |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5439 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5440 | must_do_null_check_(true) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5441 | SetRawInputAt(0, object); |
| 5442 | SetRawInputAt(1, constant); |
| 5443 | } |
| 5444 | |
| 5445 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5446 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5447 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5448 | return true; |
| 5449 | } |
| 5450 | |
| 5451 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5452 | return CanCallRuntime(check_kind_); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5453 | } |
| 5454 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5455 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
| 5456 | |
| 5457 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5458 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5459 | // Used only in code generation. |
| 5460 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 5461 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
| 5462 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5463 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 5464 | // Mips currently does runtime calls for any other checks. |
| 5465 | return check_kind != TypeCheckKind::kExactCheck; |
| 5466 | } |
| 5467 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5468 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5469 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5470 | } |
| 5471 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5472 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5473 | |
| 5474 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5475 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5476 | bool must_do_null_check_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5477 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5478 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 5479 | }; |
| 5480 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5481 | class HBoundType : public HExpression<1> { |
| 5482 | public: |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5483 | HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5484 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5485 | upper_bound_(ReferenceTypeInfo::CreateInvalid()), |
| 5486 | upper_can_be_null_(true), |
| 5487 | can_be_null_(true) { |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 5488 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5489 | SetRawInputAt(0, input); |
| 5490 | } |
| 5491 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5492 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5493 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
| 5494 | bool GetUpperCanBeNull() const { return upper_can_be_null_; } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5495 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5496 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5497 | void SetCanBeNull(bool can_be_null) { |
| 5498 | DCHECK(upper_can_be_null_ || !can_be_null); |
| 5499 | can_be_null_ = can_be_null; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5500 | } |
| 5501 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5502 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 5503 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5504 | DECLARE_INSTRUCTION(BoundType); |
| 5505 | |
| 5506 | private: |
| 5507 | // 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] | 5508 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 5509 | // It is used to bound the type in cases like: |
| 5510 | // if (x instanceof ClassX) { |
| 5511 | // // uper_bound_ will be ClassX |
| 5512 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5513 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5514 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 5515 | // is false then can_be_null_ cannot be true). |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5516 | bool upper_can_be_null_; |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5517 | bool can_be_null_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5518 | |
| 5519 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 5520 | }; |
| 5521 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5522 | class HCheckCast : public HTemplateInstruction<2> { |
| 5523 | public: |
| 5524 | HCheckCast(HInstruction* object, |
| 5525 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5526 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5527 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5528 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5529 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5530 | must_do_null_check_(true) { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5531 | SetRawInputAt(0, object); |
| 5532 | SetRawInputAt(1, constant); |
| 5533 | } |
| 5534 | |
| 5535 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5536 | |
| 5537 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5538 | return true; |
| 5539 | } |
| 5540 | |
| 5541 | bool NeedsEnvironment() const OVERRIDE { |
| 5542 | // Instruction may throw a CheckCastError. |
| 5543 | return true; |
| 5544 | } |
| 5545 | |
| 5546 | bool CanThrow() const OVERRIDE { return true; } |
| 5547 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5548 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 5549 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5550 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5551 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5552 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5553 | |
| 5554 | DECLARE_INSTRUCTION(CheckCast); |
| 5555 | |
| 5556 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5557 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5558 | bool must_do_null_check_; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5559 | |
| 5560 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5561 | }; |
| 5562 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5563 | class HMemoryBarrier : public HTemplateInstruction<0> { |
| 5564 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5565 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 5566 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5567 | SideEffects::AllWritesAndReads(), dex_pc), // Assume write/read on all fields/arrays. |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5568 | barrier_kind_(barrier_kind) {} |
| 5569 | |
| 5570 | MemBarrierKind GetBarrierKind() { return barrier_kind_; } |
| 5571 | |
| 5572 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 5573 | |
| 5574 | private: |
| 5575 | const MemBarrierKind barrier_kind_; |
| 5576 | |
| 5577 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 5578 | }; |
| 5579 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5580 | class HMonitorOperation : public HTemplateInstruction<1> { |
| 5581 | public: |
| 5582 | enum OperationKind { |
| 5583 | kEnter, |
| 5584 | kExit, |
| 5585 | }; |
| 5586 | |
| 5587 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5588 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5589 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
| 5590 | kind_(kind) { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5591 | SetRawInputAt(0, object); |
| 5592 | } |
| 5593 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5594 | // Instruction may go into runtime, so we need an environment. |
| 5595 | bool NeedsEnvironment() const OVERRIDE { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 5596 | |
| 5597 | bool CanThrow() const OVERRIDE { |
| 5598 | // Verifier guarantees that monitor-exit cannot throw. |
| 5599 | // This is important because it allows the HGraphBuilder to remove |
| 5600 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 5601 | return IsEnter(); |
| 5602 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5603 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5604 | |
| 5605 | bool IsEnter() const { return kind_ == kEnter; } |
| 5606 | |
| 5607 | DECLARE_INSTRUCTION(MonitorOperation); |
| 5608 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5609 | private: |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5610 | const OperationKind kind_; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5611 | |
| 5612 | private: |
| 5613 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 5614 | }; |
| 5615 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5616 | class HSelect : public HExpression<3> { |
| 5617 | public: |
| 5618 | HSelect(HInstruction* condition, |
| 5619 | HInstruction* true_value, |
| 5620 | HInstruction* false_value, |
| 5621 | uint32_t dex_pc) |
| 5622 | : HExpression(HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
| 5623 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 5624 | |
| 5625 | // First input must be `true_value` or `false_value` to allow codegens to |
| 5626 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 5627 | // that architectures which implement HSelect as a conditional move also |
| 5628 | // will not need to invert the condition. |
| 5629 | SetRawInputAt(0, false_value); |
| 5630 | SetRawInputAt(1, true_value); |
| 5631 | SetRawInputAt(2, condition); |
| 5632 | } |
| 5633 | |
| 5634 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 5635 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 5636 | HInstruction* GetCondition() const { return InputAt(2); } |
| 5637 | |
| 5638 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5639 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
| 5640 | |
| 5641 | bool CanBeNull() const OVERRIDE { |
| 5642 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 5643 | } |
| 5644 | |
| 5645 | DECLARE_INSTRUCTION(Select); |
| 5646 | |
| 5647 | private: |
| 5648 | DISALLOW_COPY_AND_ASSIGN(HSelect); |
| 5649 | }; |
| 5650 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 5651 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5652 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5653 | MoveOperands(Location source, |
| 5654 | Location destination, |
| 5655 | Primitive::Type type, |
| 5656 | HInstruction* instruction) |
| 5657 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5658 | |
| 5659 | Location GetSource() const { return source_; } |
| 5660 | Location GetDestination() const { return destination_; } |
| 5661 | |
| 5662 | void SetSource(Location value) { source_ = value; } |
| 5663 | void SetDestination(Location value) { destination_ = value; } |
| 5664 | |
| 5665 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 5666 | // destination (but not the source). |
| 5667 | Location MarkPending() { |
| 5668 | DCHECK(!IsPending()); |
| 5669 | Location dest = destination_; |
| 5670 | destination_ = Location::NoLocation(); |
| 5671 | return dest; |
| 5672 | } |
| 5673 | |
| 5674 | void ClearPending(Location dest) { |
| 5675 | DCHECK(IsPending()); |
| 5676 | destination_ = dest; |
| 5677 | } |
| 5678 | |
| 5679 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5680 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 5681 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5682 | } |
| 5683 | |
| 5684 | // True if this blocks a move from the given location. |
| 5685 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 5686 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5687 | } |
| 5688 | |
| 5689 | // A move is redundant if it's been eliminated, if its source and |
| 5690 | // destination are the same, or if its destination is unneeded. |
| 5691 | bool IsRedundant() const { |
| 5692 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 5693 | } |
| 5694 | |
| 5695 | // We clear both operands to indicate move that's been eliminated. |
| 5696 | void Eliminate() { |
| 5697 | source_ = destination_ = Location::NoLocation(); |
| 5698 | } |
| 5699 | |
| 5700 | bool IsEliminated() const { |
| 5701 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 5702 | return source_.IsInvalid(); |
| 5703 | } |
| 5704 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5705 | Primitive::Type GetType() const { return type_; } |
| 5706 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5707 | bool Is64BitMove() const { |
| 5708 | return Primitive::Is64BitType(type_); |
| 5709 | } |
| 5710 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5711 | HInstruction* GetInstruction() const { return instruction_; } |
| 5712 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5713 | private: |
| 5714 | Location source_; |
| 5715 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5716 | // The type this move is for. |
| 5717 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5718 | // The instruction this move is assocatied with. Null when this move is |
| 5719 | // for moving an input in the expected locations of user (including a phi user). |
| 5720 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 5721 | // in the same parallel move. |
| 5722 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5723 | }; |
| 5724 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5725 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 5726 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5727 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 5728 | |
| 5729 | class HParallelMove : public HTemplateInstruction<0> { |
| 5730 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5731 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5732 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 5733 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 5734 | moves_.reserve(kDefaultNumberOfMoves); |
| 5735 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5736 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5737 | void AddMove(Location source, |
| 5738 | Location destination, |
| 5739 | Primitive::Type type, |
| 5740 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5741 | DCHECK(source.IsValid()); |
| 5742 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5743 | if (kIsDebugBuild) { |
| 5744 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5745 | for (const MoveOperands& move : moves_) { |
| 5746 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5747 | // Special case the situation where the move is for the spill slot |
| 5748 | // of the instruction. |
| 5749 | if ((GetPrevious() == instruction) |
| 5750 | || ((GetPrevious() == nullptr) |
| 5751 | && instruction->IsPhi() |
| 5752 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5753 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5754 | << "Doing parallel moves for the same instruction."; |
| 5755 | } else { |
| 5756 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 5757 | } |
| 5758 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 5759 | } |
| 5760 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5761 | for (const MoveOperands& move : moves_) { |
| 5762 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5763 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5764 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5765 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5766 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5767 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5768 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5769 | } |
| 5770 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5771 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5772 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5773 | } |
| 5774 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5775 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5776 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 5777 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5778 | |
| 5779 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5780 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5781 | |
| 5782 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 5783 | }; |
| 5784 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5785 | } // namespace art |
| 5786 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 5787 | #ifdef ART_ENABLE_CODEGEN_arm |
| 5788 | #include "nodes_arm.h" |
| 5789 | #endif |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5790 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| 5791 | #include "nodes_arm64.h" |
| 5792 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5793 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 5794 | #include "nodes_x86.h" |
| 5795 | #endif |
| 5796 | |
| 5797 | namespace art { |
| 5798 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5799 | class HGraphVisitor : public ValueObject { |
| 5800 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 5801 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 5802 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5803 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5804 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5805 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 5806 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5807 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5808 | void VisitInsertionOrder(); |
| 5809 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5810 | // Visit the graph following dominator tree reverse post-order. |
| 5811 | void VisitReversePostOrder(); |
| 5812 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 5813 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 5814 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5815 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5816 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5817 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 5818 | |
| 5819 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5820 | |
| 5821 | #undef DECLARE_VISIT_INSTRUCTION |
| 5822 | |
| 5823 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 5824 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5825 | |
| 5826 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 5827 | }; |
| 5828 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5829 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 5830 | public: |
| 5831 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 5832 | virtual ~HGraphDelegateVisitor() {} |
| 5833 | |
| 5834 | // Visit functions that delegate to to super class. |
| 5835 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5836 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5837 | |
| 5838 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5839 | |
| 5840 | #undef DECLARE_VISIT_INSTRUCTION |
| 5841 | |
| 5842 | private: |
| 5843 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 5844 | }; |
| 5845 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5846 | class HInsertionOrderIterator : public ValueObject { |
| 5847 | public: |
| 5848 | explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {} |
| 5849 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5850 | bool Done() const { return index_ == graph_.GetBlocks().size(); } |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 5851 | HBasicBlock* Current() const { return graph_.GetBlocks()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5852 | void Advance() { ++index_; } |
| 5853 | |
| 5854 | private: |
| 5855 | const HGraph& graph_; |
| 5856 | size_t index_; |
| 5857 | |
| 5858 | DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator); |
| 5859 | }; |
| 5860 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5861 | class HReversePostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5862 | public: |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5863 | explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) { |
| 5864 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5865 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5866 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5867 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5868 | bool Done() const { return index_ == graph_.GetReversePostOrder().size(); } |
| 5869 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5870 | void Advance() { ++index_; } |
| 5871 | |
| 5872 | private: |
| 5873 | const HGraph& graph_; |
| 5874 | size_t index_; |
| 5875 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5876 | DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5877 | }; |
| 5878 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5879 | class HPostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5880 | public: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5881 | explicit HPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5882 | : graph_(graph), index_(graph_.GetReversePostOrder().size()) { |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5883 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5884 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5885 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5886 | |
| 5887 | bool Done() const { return index_ == 0; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5888 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_ - 1u]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5889 | void Advance() { --index_; } |
| 5890 | |
| 5891 | private: |
| 5892 | const HGraph& graph_; |
| 5893 | size_t index_; |
| 5894 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5895 | DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5896 | }; |
| 5897 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5898 | class HLinearPostOrderIterator : public ValueObject { |
| 5899 | public: |
| 5900 | explicit HLinearPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5901 | : order_(graph.GetLinearOrder()), index_(graph.GetLinearOrder().size()) {} |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5902 | |
| 5903 | bool Done() const { return index_ == 0; } |
| 5904 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5905 | HBasicBlock* Current() const { return order_[index_ - 1u]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5906 | |
| 5907 | void Advance() { |
| 5908 | --index_; |
| 5909 | DCHECK_GE(index_, 0U); |
| 5910 | } |
| 5911 | |
| 5912 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5913 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5914 | size_t index_; |
| 5915 | |
| 5916 | DISALLOW_COPY_AND_ASSIGN(HLinearPostOrderIterator); |
| 5917 | }; |
| 5918 | |
| 5919 | class HLinearOrderIterator : public ValueObject { |
| 5920 | public: |
| 5921 | explicit HLinearOrderIterator(const HGraph& graph) |
| 5922 | : order_(graph.GetLinearOrder()), index_(0) {} |
| 5923 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5924 | bool Done() const { return index_ == order_.size(); } |
| 5925 | HBasicBlock* Current() const { return order_[index_]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5926 | void Advance() { ++index_; } |
| 5927 | |
| 5928 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5929 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5930 | size_t index_; |
| 5931 | |
| 5932 | DISALLOW_COPY_AND_ASSIGN(HLinearOrderIterator); |
| 5933 | }; |
| 5934 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5935 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5936 | // of an inner loop. The order in which the blocks are iterated is on their |
| 5937 | // block id. |
| 5938 | class HBlocksInLoopIterator : public ValueObject { |
| 5939 | public: |
| 5940 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 5941 | : blocks_in_loop_(info.GetBlocks()), |
| 5942 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 5943 | index_(0) { |
| 5944 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 5945 | Advance(); |
| 5946 | } |
| 5947 | } |
| 5948 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5949 | bool Done() const { return index_ == blocks_.size(); } |
| 5950 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5951 | void Advance() { |
| 5952 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5953 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5954 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 5955 | break; |
| 5956 | } |
| 5957 | } |
| 5958 | } |
| 5959 | |
| 5960 | private: |
| 5961 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5962 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5963 | size_t index_; |
| 5964 | |
| 5965 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 5966 | }; |
| 5967 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5968 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5969 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 5970 | // post order. |
| 5971 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 5972 | public: |
| 5973 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 5974 | : blocks_in_loop_(info.GetBlocks()), |
| 5975 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 5976 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5977 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5978 | Advance(); |
| 5979 | } |
| 5980 | } |
| 5981 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5982 | bool Done() const { return index_ == blocks_.size(); } |
| 5983 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5984 | void Advance() { |
| 5985 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5986 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 5987 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5988 | break; |
| 5989 | } |
| 5990 | } |
| 5991 | } |
| 5992 | |
| 5993 | private: |
| 5994 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5995 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5996 | size_t index_; |
| 5997 | |
| 5998 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 5999 | }; |
| 6000 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6001 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6002 | if (constant->IsIntConstant()) { |
| 6003 | return constant->AsIntConstant()->GetValue(); |
| 6004 | } else if (constant->IsLongConstant()) { |
| 6005 | return constant->AsLongConstant()->GetValue(); |
| 6006 | } else { |
| 6007 | DCHECK(constant->IsNullConstant()); |
| 6008 | return 0; |
| 6009 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6010 | } |
| 6011 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6012 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 6013 | // For the purposes of the compiler, the dex files must actually be the same object |
| 6014 | // if we want to safely treat them as the same. This is especially important for JIT |
| 6015 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 6016 | // times and provide different class resolution but no two class loaders should ever |
| 6017 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 6018 | // all sorts of weird failures. |
| 6019 | return &lhs == &rhs; |
| 6020 | } |
| 6021 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6022 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 6023 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } \ |
| 6024 | inline const H##type* HInstruction::As##type() const { \ |
| 6025 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 6026 | } \ |
| 6027 | inline H##type* HInstruction::As##type() { \ |
| 6028 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 6029 | } |
| 6030 | |
| 6031 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 6032 | #undef INSTRUCTION_TYPE_CHECK |
| 6033 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 6034 | class SwitchTable : public ValueObject { |
| 6035 | public: |
| 6036 | SwitchTable(const Instruction& instruction, uint32_t dex_pc, bool sparse) |
| 6037 | : instruction_(instruction), dex_pc_(dex_pc), sparse_(sparse) { |
| 6038 | int32_t table_offset = instruction.VRegB_31t(); |
| 6039 | const uint16_t* table = reinterpret_cast<const uint16_t*>(&instruction) + table_offset; |
| 6040 | if (sparse) { |
| 6041 | CHECK_EQ(table[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature)); |
| 6042 | } else { |
| 6043 | CHECK_EQ(table[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature)); |
| 6044 | } |
| 6045 | num_entries_ = table[1]; |
| 6046 | values_ = reinterpret_cast<const int32_t*>(&table[2]); |
| 6047 | } |
| 6048 | |
| 6049 | uint16_t GetNumEntries() const { |
| 6050 | return num_entries_; |
| 6051 | } |
| 6052 | |
| 6053 | void CheckIndex(size_t index) const { |
| 6054 | if (sparse_) { |
| 6055 | // In a sparse table, we have num_entries_ keys and num_entries_ values, in that order. |
| 6056 | DCHECK_LT(index, 2 * static_cast<size_t>(num_entries_)); |
| 6057 | } else { |
| 6058 | // In a packed table, we have the starting key and num_entries_ values. |
| 6059 | DCHECK_LT(index, 1 + static_cast<size_t>(num_entries_)); |
| 6060 | } |
| 6061 | } |
| 6062 | |
| 6063 | int32_t GetEntryAt(size_t index) const { |
| 6064 | CheckIndex(index); |
| 6065 | return values_[index]; |
| 6066 | } |
| 6067 | |
| 6068 | uint32_t GetDexPcForIndex(size_t index) const { |
| 6069 | CheckIndex(index); |
| 6070 | return dex_pc_ + |
| 6071 | (reinterpret_cast<const int16_t*>(values_ + index) - |
| 6072 | reinterpret_cast<const int16_t*>(&instruction_)); |
| 6073 | } |
| 6074 | |
| 6075 | // Index of the first value in the table. |
| 6076 | size_t GetFirstValueIndex() const { |
| 6077 | if (sparse_) { |
| 6078 | // In a sparse table, we have num_entries_ keys and num_entries_ values, in that order. |
| 6079 | return num_entries_; |
| 6080 | } else { |
| 6081 | // In a packed table, we have the starting key and num_entries_ values. |
| 6082 | return 1; |
| 6083 | } |
| 6084 | } |
| 6085 | |
| 6086 | private: |
| 6087 | const Instruction& instruction_; |
| 6088 | const uint32_t dex_pc_; |
| 6089 | |
| 6090 | // Whether this is a sparse-switch table (or a packed-switch one). |
| 6091 | const bool sparse_; |
| 6092 | |
| 6093 | // This can't be const as it needs to be computed off of the given instruction, and complicated |
| 6094 | // expressions in the initializer list seemed very ugly. |
| 6095 | uint16_t num_entries_; |
| 6096 | |
| 6097 | const int32_t* values_; |
| 6098 | |
| 6099 | DISALLOW_COPY_AND_ASSIGN(SwitchTable); |
| 6100 | }; |
| 6101 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6102 | } // namespace art |
| 6103 | |
| 6104 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |