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. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 348 | // Returns the instruction used to replace the invoke expression or null if the |
| 349 | // invoke is for a void method. |
| 350 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 351 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 352 | // Need to add a couple of blocks to test if the loop body is entered and |
| 353 | // put deoptimization instructions, etc. |
| 354 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 355 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 356 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 357 | // other blocks and has no instructions or phis. |
| 358 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 359 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 360 | // Splits the edge between `block` and `successor` while preserving the |
| 361 | // indices in the predecessor/successor lists. If there are multiple edges |
| 362 | // between the blocks, the lowest indices are used. |
| 363 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 364 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 365 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 366 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 367 | void SimplifyLoop(HBasicBlock* header); |
| 368 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 369 | int32_t GetNextInstructionId() { |
| 370 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 371 | return current_instruction_id_++; |
| 372 | } |
| 373 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 374 | int32_t GetCurrentInstructionId() const { |
| 375 | return current_instruction_id_; |
| 376 | } |
| 377 | |
| 378 | void SetCurrentInstructionId(int32_t id) { |
| 379 | current_instruction_id_ = id; |
| 380 | } |
| 381 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 382 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 383 | return maximum_number_of_out_vregs_; |
| 384 | } |
| 385 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 386 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 387 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 388 | } |
| 389 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 390 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 391 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 392 | } |
| 393 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 394 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 395 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 396 | } |
| 397 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 398 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 399 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 400 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 401 | } |
| 402 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 403 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 404 | number_of_vregs_ = number_of_vregs; |
| 405 | } |
| 406 | |
| 407 | uint16_t GetNumberOfVRegs() const { |
| 408 | return number_of_vregs_; |
| 409 | } |
| 410 | |
| 411 | void SetNumberOfInVRegs(uint16_t value) { |
| 412 | number_of_in_vregs_ = value; |
| 413 | } |
| 414 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 415 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 416 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 417 | return number_of_vregs_ - number_of_in_vregs_; |
| 418 | } |
| 419 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 420 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 421 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 422 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 423 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 424 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 425 | return linear_order_; |
| 426 | } |
| 427 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 428 | bool HasBoundsChecks() const { |
| 429 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 430 | } |
| 431 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 432 | void SetHasBoundsChecks(bool value) { |
| 433 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 434 | } |
| 435 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 436 | bool ShouldGenerateConstructorBarrier() const { |
| 437 | return should_generate_constructor_barrier_; |
| 438 | } |
| 439 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 440 | bool IsDebuggable() const { return debuggable_; } |
| 441 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 442 | // 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] | 443 | // already, it is created and inserted into the graph. This method is only for |
| 444 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 445 | 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] | 446 | |
| 447 | // TODO: This is problematic for the consistency of reference type propagation |
| 448 | // because it can be created anytime after the pass and thus it will be left |
| 449 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 450 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 451 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 452 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 453 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 454 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 455 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 456 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 457 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 458 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 459 | 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] | 460 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 461 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 462 | 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] | 463 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 464 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 465 | HCurrentMethod* GetCurrentMethod(); |
| 466 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 467 | const DexFile& GetDexFile() const { |
| 468 | return dex_file_; |
| 469 | } |
| 470 | |
| 471 | uint32_t GetMethodIdx() const { |
| 472 | return method_idx_; |
| 473 | } |
| 474 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 475 | InvokeType GetInvokeType() const { |
| 476 | return invoke_type_; |
| 477 | } |
| 478 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 479 | InstructionSet GetInstructionSet() const { |
| 480 | return instruction_set_; |
| 481 | } |
| 482 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 483 | bool IsCompilingOsr() const { return osr_; } |
| 484 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 485 | bool HasTryCatch() const { return has_try_catch_; } |
| 486 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 487 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 488 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 489 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 490 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 491 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 492 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 493 | |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 494 | // Returns an instruction with the opposite boolean value from 'cond'. |
| 495 | // The instruction has been inserted into the graph, either as a constant, or |
| 496 | // before cursor. |
| 497 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 498 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 499 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 500 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 501 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 502 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 503 | template <class InstructionType, typename ValueType> |
| 504 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 505 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 506 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 507 | // Try to find an existing constant of the given value. |
| 508 | InstructionType* constant = nullptr; |
| 509 | auto cached_constant = cache->find(value); |
| 510 | if (cached_constant != cache->end()) { |
| 511 | constant = cached_constant->second; |
| 512 | } |
| 513 | |
| 514 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 515 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 516 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 517 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 518 | cache->Overwrite(value, constant); |
| 519 | InsertConstant(constant); |
| 520 | } |
| 521 | return constant; |
| 522 | } |
| 523 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 524 | void InsertConstant(HConstant* instruction); |
| 525 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 526 | // Cache a float constant into the graph. This method should only be |
| 527 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 528 | void CacheFloatConstant(HFloatConstant* constant); |
| 529 | |
| 530 | // See CacheFloatConstant comment. |
| 531 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 532 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 533 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 534 | |
| 535 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 536 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 537 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 538 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 539 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 540 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 541 | // List of blocks to perform a linear order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 542 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 543 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 544 | HBasicBlock* entry_block_; |
| 545 | HBasicBlock* exit_block_; |
| 546 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 547 | // 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] | 548 | uint16_t maximum_number_of_out_vregs_; |
| 549 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 550 | // The number of virtual registers in this method. Contains the parameters. |
| 551 | uint16_t number_of_vregs_; |
| 552 | |
| 553 | // The number of virtual registers used by parameters of this method. |
| 554 | uint16_t number_of_in_vregs_; |
| 555 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 556 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 557 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 558 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 559 | // Has bounds checks. We can totally skip BCE if it's false. |
| 560 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 561 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 562 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 563 | // try/catch-related passes if false. |
| 564 | bool has_try_catch_; |
| 565 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 566 | // Flag whether there are any irreducible loops in the graph. |
| 567 | bool has_irreducible_loops_; |
| 568 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 569 | // Indicates whether the graph should be compiled in a way that |
| 570 | // ensures full debuggability. If false, we can apply more |
| 571 | // aggressive optimizations that may limit the level of debugging. |
| 572 | const bool debuggable_; |
| 573 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 574 | // 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] | 575 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 576 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 577 | // The dex file from which the method is from. |
| 578 | const DexFile& dex_file_; |
| 579 | |
| 580 | // The method index in the dex file. |
| 581 | const uint32_t method_idx_; |
| 582 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 583 | // If inlined, this encodes how the callee is being invoked. |
| 584 | const InvokeType invoke_type_; |
| 585 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 586 | // Whether the graph has been transformed to SSA form. Only used |
| 587 | // in debug mode to ensure we are not using properties only valid |
| 588 | // for non-SSA form (like the number of temporaries). |
| 589 | bool in_ssa_form_; |
| 590 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 591 | const bool should_generate_constructor_barrier_; |
| 592 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 593 | const InstructionSet instruction_set_; |
| 594 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 595 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 596 | HNullConstant* cached_null_constant_; |
| 597 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 598 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 599 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 600 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 601 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 602 | HCurrentMethod* cached_current_method_; |
| 603 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 604 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 605 | // for example for methods whose declaring class could not be resolved |
| 606 | // (such as when the superclass could not be found). |
| 607 | ArtMethod* art_method_; |
| 608 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 609 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 610 | // collection pointer to passes which may create NullConstant. |
| 611 | ReferenceTypeInfo inexact_object_rti_; |
| 612 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 613 | // Whether we are compiling this graph for on stack replacement: this will |
| 614 | // make all loops seen as irreducible and emit special stack maps to mark |
| 615 | // compiled code entries which the interpreter can directly jump to. |
| 616 | const bool osr_; |
| 617 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 618 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 619 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 620 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 621 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 622 | }; |
| 623 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 624 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 625 | public: |
| 626 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 627 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 628 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 629 | irreducible_(false), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 630 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 631 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 632 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true) { |
| 633 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 634 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 635 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 636 | bool IsIrreducible() const { return irreducible_; } |
| 637 | |
| 638 | void Dump(std::ostream& os); |
| 639 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 640 | HBasicBlock* GetHeader() const { |
| 641 | return header_; |
| 642 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 643 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 644 | void SetHeader(HBasicBlock* block) { |
| 645 | header_ = block; |
| 646 | } |
| 647 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 648 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 649 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 650 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 651 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 652 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 653 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 654 | } |
| 655 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 656 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 657 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 658 | } |
| 659 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 660 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 661 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 662 | } |
| 663 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 664 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 665 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 666 | } |
| 667 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 668 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 669 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 670 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 671 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 672 | } |
| 673 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 674 | // Returns the lifetime position of the back edge that has the |
| 675 | // greatest lifetime position. |
| 676 | size_t GetLifetimeEnd() const; |
| 677 | |
| 678 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 679 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 680 | } |
| 681 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 682 | // Finds blocks that are part of this loop. |
| 683 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 684 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 685 | // Returns whether this loop information contains `block`. |
| 686 | // Note that this loop information *must* be populated before entering this function. |
| 687 | bool Contains(const HBasicBlock& block) const; |
| 688 | |
| 689 | // Returns whether this loop information is an inner loop of `other`. |
| 690 | // Note that `other` *must* be populated before entering this function. |
| 691 | bool IsIn(const HLoopInformation& other) const; |
| 692 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 693 | // Returns true if instruction is not defined within this loop. |
| 694 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 695 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 696 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 697 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 698 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 699 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 700 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 701 | void ClearAllBlocks() { |
| 702 | blocks_.ClearAllBits(); |
| 703 | } |
| 704 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 705 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 706 | // Internal recursive implementation of `Populate`. |
| 707 | void PopulateRecursive(HBasicBlock* block); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 708 | void PopulateIrreducibleRecursive(HBasicBlock* block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 709 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 710 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 711 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 712 | bool irreducible_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 713 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 714 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 715 | |
| 716 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 717 | }; |
| 718 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 719 | // Stores try/catch information for basic blocks. |
| 720 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 721 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 722 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 723 | public: |
| 724 | // Try block information constructor. |
| 725 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 726 | : try_entry_(&try_entry), |
| 727 | catch_dex_file_(nullptr), |
| 728 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 729 | DCHECK(try_entry_ != nullptr); |
| 730 | } |
| 731 | |
| 732 | // Catch block information constructor. |
| 733 | TryCatchInformation(uint16_t catch_type_index, const DexFile& dex_file) |
| 734 | : try_entry_(nullptr), |
| 735 | catch_dex_file_(&dex_file), |
| 736 | catch_type_index_(catch_type_index) {} |
| 737 | |
| 738 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 739 | |
| 740 | const HTryBoundary& GetTryEntry() const { |
| 741 | DCHECK(IsTryBlock()); |
| 742 | return *try_entry_; |
| 743 | } |
| 744 | |
| 745 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 746 | |
| 747 | bool IsCatchAllTypeIndex() const { |
| 748 | DCHECK(IsCatchBlock()); |
| 749 | return catch_type_index_ == DexFile::kDexNoIndex16; |
| 750 | } |
| 751 | |
| 752 | uint16_t GetCatchTypeIndex() const { |
| 753 | DCHECK(IsCatchBlock()); |
| 754 | return catch_type_index_; |
| 755 | } |
| 756 | |
| 757 | const DexFile& GetCatchDexFile() const { |
| 758 | DCHECK(IsCatchBlock()); |
| 759 | return *catch_dex_file_; |
| 760 | } |
| 761 | |
| 762 | private: |
| 763 | // One of possibly several TryBoundary instructions entering the block's try. |
| 764 | // Only set for try blocks. |
| 765 | const HTryBoundary* try_entry_; |
| 766 | |
| 767 | // Exception type information. Only set for catch blocks. |
| 768 | const DexFile* catch_dex_file_; |
| 769 | const uint16_t catch_type_index_; |
| 770 | }; |
| 771 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 772 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 773 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 774 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 775 | // A block in a method. Contains the list of instructions represented |
| 776 | // as a double linked list. Each block knows its predecessors and |
| 777 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 778 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 779 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 780 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 781 | HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 782 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 783 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 784 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 785 | loop_information_(nullptr), |
| 786 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 787 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 788 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 789 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 790 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 791 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 792 | try_catch_information_(nullptr) { |
| 793 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 794 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 795 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 796 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 797 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 798 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 799 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 800 | } |
| 801 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 802 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 803 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 804 | } |
| 805 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 806 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 807 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 808 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 809 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 810 | return ContainsElement(successors_, block, start_from); |
| 811 | } |
| 812 | |
| 813 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 814 | return dominated_blocks_; |
| 815 | } |
| 816 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 817 | bool IsEntryBlock() const { |
| 818 | return graph_->GetEntryBlock() == this; |
| 819 | } |
| 820 | |
| 821 | bool IsExitBlock() const { |
| 822 | return graph_->GetExitBlock() == this; |
| 823 | } |
| 824 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 825 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 826 | bool IsSingleTryBoundary() const; |
| 827 | |
| 828 | // Returns true if this block emits nothing but a jump. |
| 829 | bool IsSingleJump() const { |
| 830 | HLoopInformation* loop_info = GetLoopInformation(); |
| 831 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 832 | // Back edges generate a suspend check. |
| 833 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 834 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 835 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 836 | void AddBackEdge(HBasicBlock* back_edge) { |
| 837 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 838 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 839 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 840 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 841 | loop_information_->AddBackEdge(back_edge); |
| 842 | } |
| 843 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 844 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 845 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 846 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 847 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 848 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 849 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 850 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 851 | HBasicBlock* GetDominator() const { return dominator_; } |
| 852 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 853 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 854 | |
| 855 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 856 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 857 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 858 | |
| 859 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 860 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 861 | } |
| 862 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 863 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 864 | |
| 865 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 866 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 867 | } |
| 868 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 869 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 870 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 871 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 872 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 873 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 874 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 875 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 876 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 877 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 878 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 879 | successors_.push_back(block); |
| 880 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 881 | } |
| 882 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 883 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 884 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 885 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 886 | new_block->predecessors_.push_back(this); |
| 887 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 888 | } |
| 889 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 890 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 891 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 892 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 893 | new_block->successors_.push_back(this); |
| 894 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 895 | } |
| 896 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 897 | // Insert `this` between `predecessor` and `successor. This method |
| 898 | // preserves the indicies, and will update the first edge found between |
| 899 | // `predecessor` and `successor`. |
| 900 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 901 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 902 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 903 | successor->predecessors_[predecessor_index] = this; |
| 904 | predecessor->successors_[successor_index] = this; |
| 905 | successors_.push_back(successor); |
| 906 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 907 | } |
| 908 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 909 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 910 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 911 | } |
| 912 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 913 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 914 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 915 | } |
| 916 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 917 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 918 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 922 | predecessors_.push_back(block); |
| 923 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 924 | } |
| 925 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 926 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 927 | DCHECK_EQ(predecessors_.size(), 2u); |
| 928 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 929 | } |
| 930 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 931 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 932 | DCHECK_EQ(successors_.size(), 2u); |
| 933 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 934 | } |
| 935 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 936 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 937 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 938 | } |
| 939 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 940 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 941 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 942 | } |
| 943 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 944 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 945 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 946 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 950 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 951 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | // Returns whether the first occurrence of `predecessor` in the list of |
| 955 | // predecessors is at index `idx`. |
| 956 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 957 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 958 | return GetPredecessorIndexOf(predecessor) == idx; |
| 959 | } |
| 960 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 961 | // Create a new block between this block and its predecessors. The new block |
| 962 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 963 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 964 | // loop and try/catch information are not updated. |
| 965 | HBasicBlock* CreateImmediateDominator(); |
| 966 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 967 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 968 | // created, latter block. Note that this method will add the block to the |
| 969 | // graph, create a Goto at the end of the former block and will create an edge |
| 970 | // 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] | 971 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 972 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 973 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 974 | // Split the block into two blocks just after `cursor`. Returns the newly |
| 975 | // created block. Note that this method just updates raw block information, |
| 976 | // like predecessors, successors, dominators, and instruction list. It does not |
| 977 | // update the graph, reverse post order, loop information, nor make sure the |
| 978 | // blocks are consistent (for example ending with a control flow instruction). |
| 979 | HBasicBlock* SplitAfter(HInstruction* cursor); |
| 980 | |
David Brazdil | 9bc4361 | 2015-11-05 21:25:24 +0000 | [diff] [blame] | 981 | // Split catch block into two blocks after the original move-exception bytecode |
| 982 | // instruction, or at the beginning if not present. Returns the newly created, |
| 983 | // latter block, or nullptr if such block could not be created (must be dead |
| 984 | // in that case). Note that this method just updates raw block information, |
| 985 | // like predecessors, successors, dominators, and instruction list. It does not |
| 986 | // update the graph, reverse post order, loop information, nor make sure the |
| 987 | // blocks are consistent (for example ending with a control flow instruction). |
| 988 | HBasicBlock* SplitCatchBlockAfterMoveException(); |
| 989 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 990 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 991 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 992 | // that this method does not update the graph, reverse post order, loop |
| 993 | // information, nor make sure the blocks are consistent (for example ending |
| 994 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 995 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 996 | |
| 997 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 998 | // of `this` are moved to `other`. |
| 999 | // Note that this method does not update the graph, reverse post order, loop |
| 1000 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1001 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1002 | void ReplaceWith(HBasicBlock* other); |
| 1003 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1004 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1005 | // order, links to predecessors, successors, dominators and deletes the block |
| 1006 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1007 | // predecessor of `other` and vice versa. |
| 1008 | void MergeWith(HBasicBlock* other); |
| 1009 | |
| 1010 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1011 | // removes it from all loops it is included in and eventually from the graph. |
| 1012 | // The block must not dominate any other block. Predecessors and successors |
| 1013 | // are safely updated. |
| 1014 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1015 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1016 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1017 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1018 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1019 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1020 | // Replace instruction `initial` with `replacement` within this block. |
| 1021 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1022 | HInstruction* replacement); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1023 | void MoveInstructionBefore(HInstruction* insn, HInstruction* cursor); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1024 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1025 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1026 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1027 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1028 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1029 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1030 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1031 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1032 | |
| 1033 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1034 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1035 | } |
| 1036 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1037 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1038 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1039 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1040 | } |
| 1041 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1042 | bool IsFirstPredecessorBackEdge() const { |
| 1043 | DCHECK(IsLoopHeader()); |
| 1044 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1045 | } |
| 1046 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1047 | HLoopInformation* GetLoopInformation() const { |
| 1048 | return loop_information_; |
| 1049 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1050 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1051 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1052 | // 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] | 1053 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1054 | void SetInLoop(HLoopInformation* info) { |
| 1055 | if (IsLoopHeader()) { |
| 1056 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1057 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1058 | loop_information_ = info; |
| 1059 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1060 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1061 | // Note that a non loop header having a loop information means this loop information |
| 1062 | // has already been populated |
| 1063 | loop_information_ = info; |
| 1064 | } else { |
| 1065 | // Block is part of an inner loop. Do not update the loop information. |
| 1066 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1067 | // at this point, because this method is being called while populating `info`. |
| 1068 | } |
| 1069 | } |
| 1070 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1071 | // Raw update of the loop information. |
| 1072 | void SetLoopInformation(HLoopInformation* info) { |
| 1073 | loop_information_ = info; |
| 1074 | } |
| 1075 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1076 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1077 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1078 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1079 | |
| 1080 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1081 | try_catch_information_ = try_catch_information; |
| 1082 | } |
| 1083 | |
| 1084 | bool IsTryBlock() const { |
| 1085 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1086 | } |
| 1087 | |
| 1088 | bool IsCatchBlock() const { |
| 1089 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1090 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1091 | |
| 1092 | // Returns the try entry that this block's successors should have. They will |
| 1093 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1094 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1095 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1096 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1097 | bool HasThrowingInstructions() const; |
| 1098 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1099 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1100 | bool Dominates(HBasicBlock* block) const; |
| 1101 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1102 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1103 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1104 | |
| 1105 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1106 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1107 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1108 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1109 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1110 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1111 | bool HasSinglePhi() const; |
| 1112 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1113 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1114 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1115 | ArenaVector<HBasicBlock*> predecessors_; |
| 1116 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1117 | HInstructionList instructions_; |
| 1118 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1119 | HLoopInformation* loop_information_; |
| 1120 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1121 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1122 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1123 | // The dex program counter of the first instruction of this block. |
| 1124 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1125 | size_t lifetime_start_; |
| 1126 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1127 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1128 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1129 | friend class HGraph; |
| 1130 | friend class HInstruction; |
| 1131 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1132 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1133 | }; |
| 1134 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1135 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1136 | // from the innermost to the outermost. |
| 1137 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1138 | public: |
| 1139 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1140 | : current_(block.GetLoopInformation()) {} |
| 1141 | |
| 1142 | bool Done() const { return current_ == nullptr; } |
| 1143 | |
| 1144 | void Advance() { |
| 1145 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1146 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | HLoopInformation* Current() const { |
| 1150 | DCHECK(!Done()); |
| 1151 | return current_; |
| 1152 | } |
| 1153 | |
| 1154 | private: |
| 1155 | HLoopInformation* current_; |
| 1156 | |
| 1157 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1158 | }; |
| 1159 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1160 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1161 | M(Above, Condition) \ |
| 1162 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1163 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1164 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1165 | M(ArrayGet, Instruction) \ |
| 1166 | M(ArrayLength, Instruction) \ |
| 1167 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1168 | M(Below, Condition) \ |
| 1169 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1170 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1171 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1172 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1173 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1174 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1175 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1176 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1177 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1178 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1179 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1180 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1181 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1182 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1183 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1184 | M(Exit, Instruction) \ |
| 1185 | M(FloatConstant, Constant) \ |
| 1186 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1187 | M(GreaterThan, Condition) \ |
| 1188 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1189 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1190 | M(InstanceFieldGet, Instruction) \ |
| 1191 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1192 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1193 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1194 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1195 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1196 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1197 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1198 | M(LessThan, Condition) \ |
| 1199 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1200 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1201 | M(LoadException, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1202 | M(LoadLocal, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1203 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1204 | M(Local, Instruction) \ |
| 1205 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1206 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1207 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1208 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1209 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1210 | M(Neg, UnaryOperation) \ |
| 1211 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1212 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1213 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1214 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1215 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1216 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1217 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1218 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1219 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1220 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1221 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1222 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1223 | M(Return, Instruction) \ |
| 1224 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1225 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1226 | M(Shl, BinaryOperation) \ |
| 1227 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1228 | M(StaticFieldGet, Instruction) \ |
| 1229 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1230 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1231 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1232 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1233 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1234 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1235 | M(StoreLocal, Instruction) \ |
| 1236 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1237 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1238 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1239 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1240 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1241 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1242 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1243 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1244 | #ifndef ART_ENABLE_CODEGEN_arm |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1245 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1246 | #else |
| 1247 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1248 | M(ArmDexCacheArraysBase, Instruction) |
| 1249 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1250 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1251 | #ifndef ART_ENABLE_CODEGEN_arm64 |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1252 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1253 | #else |
| 1254 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1255 | M(Arm64DataProcWithShifterOp, Instruction) \ |
Nicolas Geoffray | 6b5afdd | 2016-01-22 09:31:52 +0000 | [diff] [blame] | 1256 | M(Arm64IntermediateAddress, Instruction) \ |
| 1257 | M(Arm64MultiplyAccumulate, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1258 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1259 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1260 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
| 1261 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1262 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1263 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1264 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1265 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1266 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1267 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1268 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1269 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1270 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1271 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1272 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1273 | |
| 1274 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1275 | |
| 1276 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1277 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
| 1278 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1279 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1280 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1281 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1282 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1283 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1284 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1285 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1286 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1287 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1288 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1289 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1290 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1291 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1292 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1293 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1294 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1295 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1296 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1297 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1298 | #undef FORWARD_DECLARATION |
| 1299 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1300 | #define DECLARE_INSTRUCTION(type) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1301 | InstructionKind GetKindInternal() const OVERRIDE { return k##type; } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1302 | const char* DebugName() const OVERRIDE { return #type; } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1303 | bool InstructionTypeEquals(HInstruction* other) const OVERRIDE { \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1304 | return other->Is##type(); \ |
| 1305 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1306 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1307 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1308 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
| 1309 | bool Is##type() const { return As##type() != nullptr; } \ |
| 1310 | const H##type* As##type() const { return this; } \ |
| 1311 | H##type* As##type() { return this; } |
| 1312 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1313 | template <typename T> class HUseList; |
| 1314 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1315 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1316 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1317 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1318 | HUseListNode* GetPrevious() const { return prev_; } |
| 1319 | HUseListNode* GetNext() const { return next_; } |
| 1320 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1321 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1322 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1323 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1324 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1325 | HUseListNode(T user, size_t index) |
| 1326 | : user_(user), index_(index), prev_(nullptr), next_(nullptr) {} |
| 1327 | |
| 1328 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1329 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1330 | HUseListNode<T>* prev_; |
| 1331 | HUseListNode<T>* next_; |
| 1332 | |
| 1333 | friend class HUseList<T>; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1334 | |
| 1335 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1336 | }; |
| 1337 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1338 | template <typename T> |
| 1339 | class HUseList : public ValueObject { |
| 1340 | public: |
| 1341 | HUseList() : first_(nullptr) {} |
| 1342 | |
| 1343 | void Clear() { |
| 1344 | first_ = nullptr; |
| 1345 | } |
| 1346 | |
| 1347 | // Adds a new entry at the beginning of the use list and returns |
| 1348 | // the newly created node. |
| 1349 | HUseListNode<T>* AddUse(T user, size_t index, ArenaAllocator* arena) { |
David Brazdil | ea55b93 | 2015-01-27 17:12:29 +0000 | [diff] [blame] | 1350 | HUseListNode<T>* new_node = new (arena) HUseListNode<T>(user, index); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1351 | if (IsEmpty()) { |
| 1352 | first_ = new_node; |
| 1353 | } else { |
| 1354 | first_->prev_ = new_node; |
| 1355 | new_node->next_ = first_; |
| 1356 | first_ = new_node; |
| 1357 | } |
| 1358 | return new_node; |
| 1359 | } |
| 1360 | |
| 1361 | HUseListNode<T>* GetFirst() const { |
| 1362 | return first_; |
| 1363 | } |
| 1364 | |
| 1365 | void Remove(HUseListNode<T>* node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1366 | DCHECK(node != nullptr); |
| 1367 | DCHECK(Contains(node)); |
| 1368 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1369 | if (node->prev_ != nullptr) { |
| 1370 | node->prev_->next_ = node->next_; |
| 1371 | } |
| 1372 | if (node->next_ != nullptr) { |
| 1373 | node->next_->prev_ = node->prev_; |
| 1374 | } |
| 1375 | if (node == first_) { |
| 1376 | first_ = node->next_; |
| 1377 | } |
| 1378 | } |
| 1379 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1380 | bool Contains(const HUseListNode<T>* node) const { |
| 1381 | if (node == nullptr) { |
| 1382 | return false; |
| 1383 | } |
| 1384 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1385 | if (current == node) { |
| 1386 | return true; |
| 1387 | } |
| 1388 | } |
| 1389 | return false; |
| 1390 | } |
| 1391 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1392 | bool IsEmpty() const { |
| 1393 | return first_ == nullptr; |
| 1394 | } |
| 1395 | |
| 1396 | bool HasOnlyOneUse() const { |
| 1397 | return first_ != nullptr && first_->next_ == nullptr; |
| 1398 | } |
| 1399 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1400 | size_t SizeSlow() const { |
| 1401 | size_t count = 0; |
| 1402 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1403 | ++count; |
| 1404 | } |
| 1405 | return count; |
| 1406 | } |
| 1407 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1408 | private: |
| 1409 | HUseListNode<T>* first_; |
| 1410 | }; |
| 1411 | |
| 1412 | template<typename T> |
| 1413 | class HUseIterator : public ValueObject { |
| 1414 | public: |
| 1415 | explicit HUseIterator(const HUseList<T>& uses) : current_(uses.GetFirst()) {} |
| 1416 | |
| 1417 | bool Done() const { return current_ == nullptr; } |
| 1418 | |
| 1419 | void Advance() { |
| 1420 | DCHECK(!Done()); |
| 1421 | current_ = current_->GetNext(); |
| 1422 | } |
| 1423 | |
| 1424 | HUseListNode<T>* Current() const { |
| 1425 | DCHECK(!Done()); |
| 1426 | return current_; |
| 1427 | } |
| 1428 | |
| 1429 | private: |
| 1430 | HUseListNode<T>* current_; |
| 1431 | |
| 1432 | friend class HValue; |
| 1433 | }; |
| 1434 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1435 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1436 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1437 | // by the used instructions. |
| 1438 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1439 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1440 | public: |
| 1441 | HUserRecord() : instruction_(nullptr), use_node_(nullptr) {} |
| 1442 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), use_node_(nullptr) {} |
| 1443 | |
| 1444 | HUserRecord(const HUserRecord<T>& old_record, HUseListNode<T>* use_node) |
| 1445 | : instruction_(old_record.instruction_), use_node_(use_node) { |
| 1446 | DCHECK(instruction_ != nullptr); |
| 1447 | DCHECK(use_node_ != nullptr); |
| 1448 | DCHECK(old_record.use_node_ == nullptr); |
| 1449 | } |
| 1450 | |
| 1451 | HInstruction* GetInstruction() const { return instruction_; } |
| 1452 | HUseListNode<T>* GetUseNode() const { return use_node_; } |
| 1453 | |
| 1454 | private: |
| 1455 | // Instruction used by the user. |
| 1456 | HInstruction* instruction_; |
| 1457 | |
| 1458 | // Corresponding entry in the use list kept by 'instruction_'. |
| 1459 | HUseListNode<T>* use_node_; |
| 1460 | }; |
| 1461 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1462 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1463 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1464 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1465 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1466 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1467 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1468 | * modify the value of a reference field read [although it may modify the |
| 1469 | * reference fetch prior to reading the field, which is represented by its own |
| 1470 | * write/read dependence]). The analysis makes conservative points-to |
| 1471 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1472 | * the same, and any reference read depends on any reference read without |
| 1473 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1474 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1475 | * The internal representation uses 38-bit and is described in the table below. |
| 1476 | * The first line indicates the side effect, and for field/array accesses the |
| 1477 | * second line indicates the type of the access (in the order of the |
| 1478 | * Primitive::Type enum). |
| 1479 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1480 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1481 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1482 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1483 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1484 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1485 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1486 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1487 | * |
| 1488 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1489 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1490 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1491 | class SideEffects : public ValueObject { |
| 1492 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1493 | SideEffects() : flags_(0) {} |
| 1494 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1495 | static SideEffects None() { |
| 1496 | return SideEffects(0); |
| 1497 | } |
| 1498 | |
| 1499 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1500 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1501 | } |
| 1502 | |
| 1503 | static SideEffects AllChanges() { |
| 1504 | return SideEffects(kAllChangeBits); |
| 1505 | } |
| 1506 | |
| 1507 | static SideEffects AllDependencies() { |
| 1508 | return SideEffects(kAllDependOnBits); |
| 1509 | } |
| 1510 | |
| 1511 | static SideEffects AllExceptGCDependency() { |
| 1512 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1513 | } |
| 1514 | |
| 1515 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1516 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1517 | } |
| 1518 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1519 | static SideEffects AllWrites() { |
| 1520 | return SideEffects(kAllWrites); |
| 1521 | } |
| 1522 | |
| 1523 | static SideEffects AllReads() { |
| 1524 | return SideEffects(kAllReads); |
| 1525 | } |
| 1526 | |
| 1527 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1528 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1529 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1530 | : SideEffects(TypeFlagWithAlias(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1531 | } |
| 1532 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1533 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
| 1534 | return SideEffects(TypeFlagWithAlias(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1535 | } |
| 1536 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1537 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1538 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1539 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1540 | : SideEffects(TypeFlagWithAlias(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1541 | } |
| 1542 | |
| 1543 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
| 1544 | return SideEffects(TypeFlagWithAlias(type, kArrayReadOffset)); |
| 1545 | } |
| 1546 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1547 | static SideEffects CanTriggerGC() { |
| 1548 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1549 | } |
| 1550 | |
| 1551 | static SideEffects DependsOnGC() { |
| 1552 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1553 | } |
| 1554 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1555 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1556 | SideEffects Union(SideEffects other) const { |
| 1557 | return SideEffects(flags_ | other.flags_); |
| 1558 | } |
| 1559 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1560 | SideEffects Exclusion(SideEffects other) const { |
| 1561 | return SideEffects(flags_ & ~other.flags_); |
| 1562 | } |
| 1563 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1564 | void Add(SideEffects other) { |
| 1565 | flags_ |= other.flags_; |
| 1566 | } |
| 1567 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1568 | bool Includes(SideEffects other) const { |
| 1569 | return (other.flags_ & flags_) == other.flags_; |
| 1570 | } |
| 1571 | |
| 1572 | bool HasSideEffects() const { |
| 1573 | return (flags_ & kAllChangeBits); |
| 1574 | } |
| 1575 | |
| 1576 | bool HasDependencies() const { |
| 1577 | return (flags_ & kAllDependOnBits); |
| 1578 | } |
| 1579 | |
| 1580 | // Returns true if there are no side effects or dependencies. |
| 1581 | bool DoesNothing() const { |
| 1582 | return flags_ == 0; |
| 1583 | } |
| 1584 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1585 | // Returns true if something is written. |
| 1586 | bool DoesAnyWrite() const { |
| 1587 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1588 | } |
| 1589 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1590 | // Returns true if something is read. |
| 1591 | bool DoesAnyRead() const { |
| 1592 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1593 | } |
| 1594 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1595 | // Returns true if potentially everything is written and read |
| 1596 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1597 | bool DoesAllReadWrite() const { |
| 1598 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1599 | } |
| 1600 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1601 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1602 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1603 | } |
| 1604 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1605 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1606 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1607 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1608 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1609 | } |
| 1610 | |
| 1611 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1612 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1613 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1614 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1615 | for (int s = kLastBit; s >= 0; s--) { |
| 1616 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1617 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1618 | // This is a bit for the GC side effect. |
| 1619 | if (current_bit_is_set) { |
| 1620 | flags += "GC"; |
| 1621 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1622 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1623 | } else { |
| 1624 | // This is a bit for the array/field analysis. |
| 1625 | // The underscore character stands for the 'can trigger GC' bit. |
| 1626 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1627 | if (current_bit_is_set) { |
| 1628 | flags += kDebug[s]; |
| 1629 | } |
| 1630 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1631 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1632 | flags += "|"; |
| 1633 | } |
| 1634 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1635 | } |
| 1636 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1637 | } |
| 1638 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1639 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1640 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1641 | private: |
| 1642 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1643 | |
| 1644 | static constexpr int kFieldWriteOffset = 0; |
| 1645 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1646 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1647 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1648 | |
| 1649 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1650 | |
| 1651 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1652 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1653 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1654 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1655 | |
| 1656 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1657 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1658 | |
| 1659 | // Aliases. |
| 1660 | |
| 1661 | static_assert(kChangeBits == kDependOnBits, |
| 1662 | "the 'change' bits should match the 'depend on' bits."); |
| 1663 | |
| 1664 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1665 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1666 | static constexpr uint64_t kAllWrites = |
| 1667 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1668 | static constexpr uint64_t kAllReads = |
| 1669 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1670 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1671 | // Work around the fact that HIR aliases I/F and J/D. |
| 1672 | // TODO: remove this interceptor once HIR types are clean |
| 1673 | static uint64_t TypeFlagWithAlias(Primitive::Type type, int offset) { |
| 1674 | switch (type) { |
| 1675 | case Primitive::kPrimInt: |
| 1676 | case Primitive::kPrimFloat: |
| 1677 | return TypeFlag(Primitive::kPrimInt, offset) | |
| 1678 | TypeFlag(Primitive::kPrimFloat, offset); |
| 1679 | case Primitive::kPrimLong: |
| 1680 | case Primitive::kPrimDouble: |
| 1681 | return TypeFlag(Primitive::kPrimLong, offset) | |
| 1682 | TypeFlag(Primitive::kPrimDouble, offset); |
| 1683 | default: |
| 1684 | return TypeFlag(type, offset); |
| 1685 | } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1686 | } |
| 1687 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1688 | // Translates type to bit flag. |
| 1689 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1690 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1691 | const uint64_t one = 1; |
| 1692 | const int shift = type; // 0-based consecutive enum |
| 1693 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1694 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1695 | return one << (type + offset); |
| 1696 | } |
| 1697 | |
| 1698 | // Private constructor on direct flags value. |
| 1699 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1700 | |
| 1701 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1702 | }; |
| 1703 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1704 | // 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] | 1705 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1706 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1707 | HEnvironment(ArenaAllocator* arena, |
| 1708 | size_t number_of_vregs, |
| 1709 | const DexFile& dex_file, |
| 1710 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1711 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1712 | InvokeType invoke_type, |
| 1713 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1714 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1715 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1716 | parent_(nullptr), |
| 1717 | dex_file_(dex_file), |
| 1718 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1719 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1720 | invoke_type_(invoke_type), |
| 1721 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1722 | } |
| 1723 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1724 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1725 | : HEnvironment(arena, |
| 1726 | to_copy.Size(), |
| 1727 | to_copy.GetDexFile(), |
| 1728 | to_copy.GetMethodIdx(), |
| 1729 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1730 | to_copy.GetInvokeType(), |
| 1731 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1732 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1733 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1734 | if (parent_ != nullptr) { |
| 1735 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1736 | } else { |
| 1737 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1738 | parent_->CopyFrom(parent); |
| 1739 | if (parent->GetParent() != nullptr) { |
| 1740 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1741 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1742 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1743 | } |
| 1744 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1745 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1746 | void CopyFrom(HEnvironment* environment); |
| 1747 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1748 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1749 | // input to the loop phi instead. This is for inserting instructions that |
| 1750 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1751 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1752 | |
| 1753 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1754 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1758 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1759 | } |
| 1760 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1761 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1762 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1763 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1764 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1765 | HEnvironment* GetParent() const { return parent_; } |
| 1766 | |
| 1767 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1768 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1772 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | uint32_t GetDexPc() const { |
| 1776 | return dex_pc_; |
| 1777 | } |
| 1778 | |
| 1779 | uint32_t GetMethodIdx() const { |
| 1780 | return method_idx_; |
| 1781 | } |
| 1782 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1783 | InvokeType GetInvokeType() const { |
| 1784 | return invoke_type_; |
| 1785 | } |
| 1786 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1787 | const DexFile& GetDexFile() const { |
| 1788 | return dex_file_; |
| 1789 | } |
| 1790 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1791 | HInstruction* GetHolder() const { |
| 1792 | return holder_; |
| 1793 | } |
| 1794 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1795 | |
| 1796 | bool IsFromInlinedInvoke() const { |
| 1797 | return GetParent() != nullptr; |
| 1798 | } |
| 1799 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1800 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1801 | // Record instructions' use entries of this environment for constant-time removal. |
| 1802 | // It should only be called by HInstruction when a new environment use is added. |
| 1803 | void RecordEnvUse(HUseListNode<HEnvironment*>* env_use) { |
| 1804 | DCHECK(env_use->GetUser() == this); |
| 1805 | size_t index = env_use->GetIndex(); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1806 | vregs_[index] = HUserRecord<HEnvironment*>(vregs_[index], env_use); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1807 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1808 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1809 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1810 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1811 | HEnvironment* parent_; |
| 1812 | const DexFile& dex_file_; |
| 1813 | const uint32_t method_idx_; |
| 1814 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1815 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1816 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1817 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1818 | HInstruction* const holder_; |
| 1819 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1820 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1821 | |
| 1822 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1823 | }; |
| 1824 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1825 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1826 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1827 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1828 | : previous_(nullptr), |
| 1829 | next_(nullptr), |
| 1830 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1831 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1832 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1833 | ssa_index_(-1), |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1834 | emitted_at_use_site_(false), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1835 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1836 | locations_(nullptr), |
| 1837 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1838 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1839 | side_effects_(side_effects), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1840 | reference_type_info_(ReferenceTypeInfo::CreateInvalid()) {} |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1841 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1842 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1843 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1844 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1845 | enum InstructionKind { |
| 1846 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1847 | }; |
| 1848 | #undef DECLARE_KIND |
| 1849 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1850 | HInstruction* GetNext() const { return next_; } |
| 1851 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1852 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1853 | HInstruction* GetNextDisregardingMoves() const; |
| 1854 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1855 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1856 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1857 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1858 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1859 | bool IsInBlock() const { return block_ != nullptr; } |
| 1860 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1861 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 1862 | bool IsIrreducibleLoopHeaderPhi() const { |
| 1863 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 1864 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1865 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1866 | virtual size_t InputCount() const = 0; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1867 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1868 | |
| 1869 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1870 | virtual const char* DebugName() const = 0; |
| 1871 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1872 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1873 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1874 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1875 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1876 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1877 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1878 | |
| 1879 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1880 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1881 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1882 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1883 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1884 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1885 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1886 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1887 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1888 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1889 | // Does not apply for all instructions, but having this at top level greatly |
| 1890 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1891 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1892 | virtual bool CanBeNull() const { |
| 1893 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1894 | return true; |
| 1895 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1896 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1897 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1898 | return false; |
| 1899 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1900 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 1901 | virtual bool IsActualObject() const { |
| 1902 | return GetType() == Primitive::kPrimNot; |
| 1903 | } |
| 1904 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1905 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1906 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1907 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1908 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
| 1909 | return reference_type_info_; |
| 1910 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1911 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1912 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1913 | DCHECK(user != nullptr); |
| 1914 | HUseListNode<HInstruction*>* use = |
| 1915 | uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1916 | user->SetRawInputRecordAt(index, HUserRecord<HInstruction*>(user->InputRecordAt(index), use)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1917 | } |
| 1918 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1919 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1920 | DCHECK(user != nullptr); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1921 | HUseListNode<HEnvironment*>* env_use = |
| 1922 | env_uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1923 | user->RecordEnvUse(env_use); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1924 | } |
| 1925 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1926 | void RemoveAsUserOfInput(size_t input) { |
| 1927 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
| 1928 | input_use.GetInstruction()->uses_.Remove(input_use.GetUseNode()); |
| 1929 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1930 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1931 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1932 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1933 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1934 | bool HasUses() const { return !uses_.IsEmpty() || !env_uses_.IsEmpty(); } |
| 1935 | bool HasEnvironmentUses() const { return !env_uses_.IsEmpty(); } |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 1936 | bool HasNonEnvironmentUses() const { return !uses_.IsEmpty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1937 | bool HasOnlyOneNonEnvironmentUse() const { |
| 1938 | return !HasEnvironmentUses() && GetUses().HasOnlyOneUse(); |
| 1939 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1940 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1941 | // Does this instruction strictly dominate `other_instruction`? |
| 1942 | // Returns false if this instruction and `other_instruction` are the same. |
| 1943 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1944 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1945 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1946 | int GetId() const { return id_; } |
| 1947 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1948 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1949 | int GetSsaIndex() const { return ssa_index_; } |
| 1950 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 1951 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 1952 | |
| 1953 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 1954 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1955 | // Set the `environment_` field. Raw because this method does not |
| 1956 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1957 | void SetRawEnvironment(HEnvironment* environment) { |
| 1958 | DCHECK(environment_ == nullptr); |
| 1959 | DCHECK_EQ(environment->GetHolder(), this); |
| 1960 | environment_ = environment; |
| 1961 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1962 | |
| 1963 | // Set the environment of this instruction, copying it from `environment`. While |
| 1964 | // copying, the uses lists are being updated. |
| 1965 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1966 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1967 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1968 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1969 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1970 | if (environment->GetParent() != nullptr) { |
| 1971 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1972 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1973 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1974 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1975 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 1976 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1977 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1978 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1979 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1980 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1981 | if (environment->GetParent() != nullptr) { |
| 1982 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1983 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1984 | } |
| 1985 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1986 | // Returns the number of entries in the environment. Typically, that is the |
| 1987 | // number of dex registers in a method. It could be more in case of inlining. |
| 1988 | size_t EnvironmentSize() const; |
| 1989 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1990 | LocationSummary* GetLocations() const { return locations_; } |
| 1991 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1992 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1993 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1994 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1995 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1996 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 1997 | // uses of this instruction by `other` are *not* updated. |
| 1998 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 1999 | ReplaceWith(other); |
| 2000 | other->ReplaceInput(this, use_index); |
| 2001 | } |
| 2002 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 2003 | // Move `this` instruction before `cursor`. |
| 2004 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2005 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2006 | // Move `this` before its first user and out of any loops. If there is no |
| 2007 | // out-of-loop user that dominates all other users, move the instruction |
| 2008 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2009 | // |
| 2010 | // This can be used only on non-throwing instructions with no side effects that |
| 2011 | // have at least one use but no environment uses. |
| 2012 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2013 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2014 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2015 | bool Is##type() const; \ |
| 2016 | const H##type* As##type() const; \ |
| 2017 | H##type* As##type(); |
| 2018 | |
| 2019 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2020 | #undef INSTRUCTION_TYPE_CHECK |
| 2021 | |
| 2022 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2023 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 2024 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2025 | virtual H##type* As##type() { return nullptr; } |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2026 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2027 | #undef INSTRUCTION_TYPE_CHECK |
| 2028 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2029 | // Returns whether the instruction can be moved within the graph. |
| 2030 | virtual bool CanBeMoved() const { return false; } |
| 2031 | |
| 2032 | // Returns whether the two instructions are of the same kind. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2033 | virtual bool InstructionTypeEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2034 | return false; |
| 2035 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2036 | |
| 2037 | // Returns whether any data encoded in the two instructions is equal. |
| 2038 | // This method does not look at the inputs. Both instructions must be |
| 2039 | // of the same type, otherwise the method has undefined behavior. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2040 | virtual bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2041 | return false; |
| 2042 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2043 | |
| 2044 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2045 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2046 | // 2) Their inputs are identical. |
| 2047 | bool Equals(HInstruction* other) const; |
| 2048 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2049 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2050 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2051 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2052 | // apply the strong requirement for virtual functions, preventing optimizations. |
| 2053 | InstructionKind GetKind() const PURE; |
| 2054 | virtual InstructionKind GetKindInternal() const = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2055 | |
| 2056 | virtual size_t ComputeHashCode() const { |
| 2057 | size_t result = GetKind(); |
| 2058 | for (size_t i = 0, e = InputCount(); i < e; ++i) { |
| 2059 | result = (result * 31) + InputAt(i)->GetId(); |
| 2060 | } |
| 2061 | return result; |
| 2062 | } |
| 2063 | |
| 2064 | SideEffects GetSideEffects() const { return side_effects_; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2065 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2066 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2067 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2068 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2069 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2070 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2071 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2072 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2073 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2074 | |
| 2075 | // Returns whether the code generation of the instruction will require to have access |
| 2076 | // to the current method. Such instructions are: |
| 2077 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2078 | // to walk the stack and have the current method stored at a specific stack address. |
| 2079 | // (2): Object literals like classes and strings, that are loaded from the dex cache |
| 2080 | // fields of the current method. |
| 2081 | bool NeedsCurrentMethod() const { |
| 2082 | return NeedsEnvironment() || IsLoadClass() || IsLoadString(); |
| 2083 | } |
| 2084 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2085 | // Returns whether the code generation of the instruction will require to have access |
| 2086 | // to the dex cache of the current method's declaring class via the current method. |
| 2087 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2088 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2089 | // Does this instruction have any use in an environment before |
| 2090 | // control flow hits 'other'? |
| 2091 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2092 | |
| 2093 | // Remove all references to environment uses of this instruction. |
| 2094 | // The caller must ensure that this is safe to do. |
| 2095 | void RemoveEnvironmentUsers(); |
| 2096 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2097 | bool IsEmittedAtUseSite() const { return emitted_at_use_site_; } |
| 2098 | void MarkEmittedAtUseSite() { emitted_at_use_site_ = true; } |
| 2099 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2100 | protected: |
| 2101 | virtual const HUserRecord<HInstruction*> InputRecordAt(size_t i) const = 0; |
| 2102 | virtual void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) = 0; |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 2103 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2104 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2105 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2106 | void RemoveEnvironmentUser(HUseListNode<HEnvironment*>* use_node) { env_uses_.Remove(use_node); } |
| 2107 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2108 | HInstruction* previous_; |
| 2109 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2110 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2111 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2112 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2113 | // An instruction gets an id when it is added to the graph. |
| 2114 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2115 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2116 | int id_; |
| 2117 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2118 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2119 | int ssa_index_; |
| 2120 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2121 | // If set, the machine code for this instruction is assumed to be generated by |
| 2122 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2123 | bool emitted_at_use_site_; |
| 2124 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2125 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2126 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2127 | |
| 2128 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2129 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2130 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2131 | // The environment associated with this instruction. Not null if the instruction |
| 2132 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2133 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2134 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2135 | // Set by the code generator. |
| 2136 | LocationSummary* locations_; |
| 2137 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2138 | // Set by the liveness analysis. |
| 2139 | LiveInterval* live_interval_; |
| 2140 | |
| 2141 | // Set by the liveness analysis, this is the position in a linear |
| 2142 | // order of blocks where this instruction's live interval start. |
| 2143 | size_t lifetime_position_; |
| 2144 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2145 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2146 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2147 | // TODO: for primitive types this should be marked as invalid. |
| 2148 | ReferenceTypeInfo reference_type_info_; |
| 2149 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2150 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2151 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2152 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2153 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2154 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2155 | |
| 2156 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2157 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2158 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2159 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2160 | class HInputIterator : public ValueObject { |
| 2161 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2162 | explicit HInputIterator(HInstruction* instruction) : instruction_(instruction), index_(0) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2163 | |
| 2164 | bool Done() const { return index_ == instruction_->InputCount(); } |
| 2165 | HInstruction* Current() const { return instruction_->InputAt(index_); } |
| 2166 | void Advance() { index_++; } |
| 2167 | |
| 2168 | private: |
| 2169 | HInstruction* instruction_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2170 | size_t index_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2171 | |
| 2172 | DISALLOW_COPY_AND_ASSIGN(HInputIterator); |
| 2173 | }; |
| 2174 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2175 | class HInstructionIterator : public ValueObject { |
| 2176 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2177 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2178 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2179 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2180 | } |
| 2181 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2182 | bool Done() const { return instruction_ == nullptr; } |
| 2183 | HInstruction* Current() const { return instruction_; } |
| 2184 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2185 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2186 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2187 | } |
| 2188 | |
| 2189 | private: |
| 2190 | HInstruction* instruction_; |
| 2191 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2192 | |
| 2193 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2194 | }; |
| 2195 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2196 | class HBackwardInstructionIterator : public ValueObject { |
| 2197 | public: |
| 2198 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2199 | : instruction_(instructions.last_instruction_) { |
| 2200 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2201 | } |
| 2202 | |
| 2203 | bool Done() const { return instruction_ == nullptr; } |
| 2204 | HInstruction* Current() const { return instruction_; } |
| 2205 | void Advance() { |
| 2206 | instruction_ = next_; |
| 2207 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2208 | } |
| 2209 | |
| 2210 | private: |
| 2211 | HInstruction* instruction_; |
| 2212 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2213 | |
| 2214 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2215 | }; |
| 2216 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2217 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2218 | class HTemplateInstruction: public HInstruction { |
| 2219 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2220 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2221 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2222 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2223 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2224 | size_t InputCount() const OVERRIDE { return N; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2225 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2226 | protected: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2227 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 2228 | DCHECK_LT(i, N); |
| 2229 | return inputs_[i]; |
| 2230 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2231 | |
| 2232 | void SetRawInputRecordAt(size_t i, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2233 | DCHECK_LT(i, N); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2234 | inputs_[i] = input; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2235 | } |
| 2236 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2237 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2238 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2239 | |
| 2240 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2241 | }; |
| 2242 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2243 | // HTemplateInstruction specialization for N=0. |
| 2244 | template<> |
| 2245 | class HTemplateInstruction<0>: public HInstruction { |
| 2246 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2247 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2248 | : HInstruction(side_effects, dex_pc) {} |
| 2249 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2250 | virtual ~HTemplateInstruction() {} |
| 2251 | |
| 2252 | size_t InputCount() const OVERRIDE { return 0; } |
| 2253 | |
| 2254 | protected: |
| 2255 | const HUserRecord<HInstruction*> InputRecordAt(size_t i ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2256 | LOG(FATAL) << "Unreachable"; |
| 2257 | UNREACHABLE(); |
| 2258 | } |
| 2259 | |
| 2260 | void SetRawInputRecordAt(size_t i ATTRIBUTE_UNUSED, |
| 2261 | const HUserRecord<HInstruction*>& input ATTRIBUTE_UNUSED) OVERRIDE { |
| 2262 | LOG(FATAL) << "Unreachable"; |
| 2263 | UNREACHABLE(); |
| 2264 | } |
| 2265 | |
| 2266 | private: |
| 2267 | friend class SsaBuilder; |
| 2268 | }; |
| 2269 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2270 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2271 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2272 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2273 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2274 | : HTemplateInstruction<N>(side_effects, dex_pc), type_(type) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2275 | virtual ~HExpression() {} |
| 2276 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2277 | Primitive::Type GetType() const OVERRIDE { return type_; } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2278 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2279 | protected: |
| 2280 | Primitive::Type type_; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2281 | }; |
| 2282 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2283 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2284 | // instruction that branches to the exit block. |
| 2285 | class HReturnVoid : public HTemplateInstruction<0> { |
| 2286 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2287 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2288 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2289 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2290 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2291 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2292 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2293 | |
| 2294 | private: |
| 2295 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2296 | }; |
| 2297 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2298 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2299 | // instruction that branches to the exit block. |
| 2300 | class HReturn : public HTemplateInstruction<1> { |
| 2301 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2302 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2303 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2304 | SetRawInputAt(0, value); |
| 2305 | } |
| 2306 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2307 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2308 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2309 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2310 | |
| 2311 | private: |
| 2312 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2313 | }; |
| 2314 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2315 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2316 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2317 | // exit block. |
| 2318 | class HExit : public HTemplateInstruction<0> { |
| 2319 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2320 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2321 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2322 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2323 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2324 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2325 | |
| 2326 | private: |
| 2327 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2328 | }; |
| 2329 | |
| 2330 | // Jumps from one block to another. |
| 2331 | class HGoto : public HTemplateInstruction<0> { |
| 2332 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2333 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2334 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2335 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2336 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2337 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2338 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2339 | } |
| 2340 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2341 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2342 | |
| 2343 | private: |
| 2344 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2345 | }; |
| 2346 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2347 | class HConstant : public HExpression<0> { |
| 2348 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2349 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2350 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2351 | |
| 2352 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2353 | |
| 2354 | virtual bool IsMinusOne() const { return false; } |
| 2355 | virtual bool IsZero() const { return false; } |
| 2356 | virtual bool IsOne() const { return false; } |
| 2357 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2358 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2359 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2360 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2361 | |
| 2362 | private: |
| 2363 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2364 | }; |
| 2365 | |
| 2366 | class HNullConstant : public HConstant { |
| 2367 | public: |
| 2368 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2369 | return true; |
| 2370 | } |
| 2371 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2372 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2373 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2374 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2375 | |
| 2376 | DECLARE_INSTRUCTION(NullConstant); |
| 2377 | |
| 2378 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2379 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2380 | |
| 2381 | friend class HGraph; |
| 2382 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2383 | }; |
| 2384 | |
| 2385 | // Constants of the type int. Those can be from Dex instructions, or |
| 2386 | // synthesized (for example with the if-eqz instruction). |
| 2387 | class HIntConstant : public HConstant { |
| 2388 | public: |
| 2389 | int32_t GetValue() const { return value_; } |
| 2390 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2391 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2392 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2393 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2394 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2395 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2396 | DCHECK(other->IsIntConstant()); |
| 2397 | return other->AsIntConstant()->value_ == value_; |
| 2398 | } |
| 2399 | |
| 2400 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2401 | |
| 2402 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2403 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2404 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2405 | |
| 2406 | DECLARE_INSTRUCTION(IntConstant); |
| 2407 | |
| 2408 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2409 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2410 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2411 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2412 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2413 | |
| 2414 | const int32_t value_; |
| 2415 | |
| 2416 | friend class HGraph; |
| 2417 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2418 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2419 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2420 | }; |
| 2421 | |
| 2422 | class HLongConstant : public HConstant { |
| 2423 | public: |
| 2424 | int64_t GetValue() const { return value_; } |
| 2425 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2426 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2427 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2428 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2429 | DCHECK(other->IsLongConstant()); |
| 2430 | return other->AsLongConstant()->value_ == value_; |
| 2431 | } |
| 2432 | |
| 2433 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2434 | |
| 2435 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2436 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2437 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2438 | |
| 2439 | DECLARE_INSTRUCTION(LongConstant); |
| 2440 | |
| 2441 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2442 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2443 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2444 | |
| 2445 | const int64_t value_; |
| 2446 | |
| 2447 | friend class HGraph; |
| 2448 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2449 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2450 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2451 | // Conditional branch. A block ending with an HIf instruction must have |
| 2452 | // two successors. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2453 | class HIf : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2454 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2455 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2456 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2457 | SetRawInputAt(0, input); |
| 2458 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2459 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2460 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2461 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2462 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2463 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2464 | } |
| 2465 | |
| 2466 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2467 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2468 | } |
| 2469 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2470 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2471 | |
| 2472 | private: |
| 2473 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2474 | }; |
| 2475 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2476 | |
| 2477 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2478 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2479 | // non-exceptional control flow. |
| 2480 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2481 | // higher indices in no particular order. |
| 2482 | class HTryBoundary : public HTemplateInstruction<0> { |
| 2483 | public: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2484 | enum BoundaryKind { |
| 2485 | kEntry, |
| 2486 | kExit, |
| 2487 | }; |
| 2488 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2489 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
| 2490 | : HTemplateInstruction(SideEffects::None(), dex_pc), kind_(kind) {} |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2491 | |
| 2492 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2493 | |
| 2494 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2495 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2496 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 2497 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 2498 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 2499 | } |
| 2500 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2501 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2502 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2503 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2504 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2505 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2506 | } |
| 2507 | |
| 2508 | // If not present already, adds `handler` to its block's list of exception |
| 2509 | // handlers. |
| 2510 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2511 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2512 | GetBlock()->AddSuccessor(handler); |
| 2513 | } |
| 2514 | } |
| 2515 | |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2516 | bool IsEntry() const { return kind_ == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2517 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2518 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2519 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2520 | DECLARE_INSTRUCTION(TryBoundary); |
| 2521 | |
| 2522 | private: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2523 | const BoundaryKind kind_; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2524 | |
| 2525 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2526 | }; |
| 2527 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2528 | // Deoptimize to interpreter, upon checking a condition. |
| 2529 | class HDeoptimize : public HTemplateInstruction<1> { |
| 2530 | public: |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2531 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 2532 | // at the point of the `HDeoptimize`. |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2533 | HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2534 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2535 | SetRawInputAt(0, cond); |
| 2536 | } |
| 2537 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2538 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2539 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2540 | return true; |
| 2541 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2542 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2543 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2544 | |
| 2545 | DECLARE_INSTRUCTION(Deoptimize); |
| 2546 | |
| 2547 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2548 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2549 | }; |
| 2550 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2551 | // Represents the ArtMethod that was passed as a first argument to |
| 2552 | // the method. It is used by instructions that depend on it, like |
| 2553 | // instructions that work with the dex cache. |
| 2554 | class HCurrentMethod : public HExpression<0> { |
| 2555 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2556 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2557 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2558 | |
| 2559 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2560 | |
| 2561 | private: |
| 2562 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2563 | }; |
| 2564 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2565 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 2566 | // of a class. |
| 2567 | class HClassTableGet : public HExpression<1> { |
| 2568 | public: |
| 2569 | enum TableKind { |
| 2570 | kVTable, |
| 2571 | kIMTable, |
| 2572 | }; |
| 2573 | HClassTableGet(HInstruction* cls, |
| 2574 | Primitive::Type type, |
| 2575 | TableKind kind, |
| 2576 | size_t index, |
| 2577 | uint32_t dex_pc) |
| 2578 | : HExpression(type, SideEffects::None(), dex_pc), |
| 2579 | index_(index), |
| 2580 | table_kind_(kind) { |
| 2581 | SetRawInputAt(0, cls); |
| 2582 | } |
| 2583 | |
| 2584 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2585 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2586 | return other->AsClassTableGet()->GetIndex() == index_ && |
| 2587 | other->AsClassTableGet()->GetTableKind() == table_kind_; |
| 2588 | } |
| 2589 | |
| 2590 | TableKind GetTableKind() const { return table_kind_; } |
| 2591 | size_t GetIndex() const { return index_; } |
| 2592 | |
| 2593 | DECLARE_INSTRUCTION(ClassTableGet); |
| 2594 | |
| 2595 | private: |
| 2596 | // The index of the ArtMethod in the table. |
| 2597 | const size_t index_; |
| 2598 | const TableKind table_kind_; |
| 2599 | |
| 2600 | DISALLOW_COPY_AND_ASSIGN(HClassTableGet); |
| 2601 | }; |
| 2602 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2603 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 2604 | // have one successor for each entry in the switch table, and the final successor |
| 2605 | // will be the block containing the next Dex opcode. |
| 2606 | class HPackedSwitch : public HTemplateInstruction<1> { |
| 2607 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2608 | HPackedSwitch(int32_t start_value, |
| 2609 | uint32_t num_entries, |
| 2610 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2611 | uint32_t dex_pc = kNoDexPc) |
| 2612 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 2613 | start_value_(start_value), |
| 2614 | num_entries_(num_entries) { |
| 2615 | SetRawInputAt(0, input); |
| 2616 | } |
| 2617 | |
| 2618 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2619 | |
| 2620 | int32_t GetStartValue() const { return start_value_; } |
| 2621 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 2622 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2623 | |
| 2624 | HBasicBlock* GetDefaultBlock() const { |
| 2625 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2626 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2627 | } |
| 2628 | DECLARE_INSTRUCTION(PackedSwitch); |
| 2629 | |
| 2630 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2631 | const int32_t start_value_; |
| 2632 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2633 | |
| 2634 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 2635 | }; |
| 2636 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2637 | class HUnaryOperation : public HExpression<1> { |
| 2638 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2639 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2640 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2641 | SetRawInputAt(0, input); |
| 2642 | } |
| 2643 | |
| 2644 | HInstruction* GetInput() const { return InputAt(0); } |
| 2645 | Primitive::Type GetResultType() const { return GetType(); } |
| 2646 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2647 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2648 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2649 | return true; |
| 2650 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2651 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2652 | // Try to statically evaluate `operation` and return a HConstant |
| 2653 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2654 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2655 | HConstant* TryStaticEvaluation() const; |
| 2656 | |
| 2657 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2658 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 2659 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2660 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2661 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2662 | |
| 2663 | private: |
| 2664 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 2665 | }; |
| 2666 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2667 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2668 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2669 | HBinaryOperation(Primitive::Type result_type, |
| 2670 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2671 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2672 | SideEffects side_effects = SideEffects::None(), |
| 2673 | uint32_t dex_pc = kNoDexPc) |
| 2674 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2675 | SetRawInputAt(0, left); |
| 2676 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2677 | } |
| 2678 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2679 | HInstruction* GetLeft() const { return InputAt(0); } |
| 2680 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2681 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2682 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2683 | virtual bool IsCommutative() const { return false; } |
| 2684 | |
| 2685 | // Put constant on the right. |
| 2686 | // Returns whether order is changed. |
| 2687 | bool OrderInputsWithConstantOnTheRight() { |
| 2688 | HInstruction* left = InputAt(0); |
| 2689 | HInstruction* right = InputAt(1); |
| 2690 | if (left->IsConstant() && !right->IsConstant()) { |
| 2691 | ReplaceInput(right, 0); |
| 2692 | ReplaceInput(left, 1); |
| 2693 | return true; |
| 2694 | } |
| 2695 | return false; |
| 2696 | } |
| 2697 | |
| 2698 | // Order inputs by instruction id, but favor constant on the right side. |
| 2699 | // This helps GVN for commutative ops. |
| 2700 | void OrderInputs() { |
| 2701 | DCHECK(IsCommutative()); |
| 2702 | HInstruction* left = InputAt(0); |
| 2703 | HInstruction* right = InputAt(1); |
| 2704 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 2705 | return; |
| 2706 | } |
| 2707 | if (OrderInputsWithConstantOnTheRight()) { |
| 2708 | return; |
| 2709 | } |
| 2710 | // Order according to instruction id. |
| 2711 | if (left->GetId() > right->GetId()) { |
| 2712 | ReplaceInput(right, 0); |
| 2713 | ReplaceInput(left, 1); |
| 2714 | } |
| 2715 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2716 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2717 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2718 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2719 | return true; |
| 2720 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2721 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2722 | // Try to statically evaluate `operation` and return a HConstant |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2723 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2724 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2725 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2726 | |
| 2727 | // Apply this operation to `x` and `y`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2728 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 2729 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
| 2730 | virtual HConstant* Evaluate(HIntConstant* x ATTRIBUTE_UNUSED, |
| 2731 | HLongConstant* y ATTRIBUTE_UNUSED) const { |
| 2732 | VLOG(compiler) << DebugName() << " is not defined for the (int, long) case."; |
| 2733 | return nullptr; |
| 2734 | } |
| 2735 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 2736 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
| 2737 | VLOG(compiler) << DebugName() << " is not defined for the (long, int) case."; |
| 2738 | return nullptr; |
| 2739 | } |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2740 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2741 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
| 2742 | VLOG(compiler) << DebugName() << " is not defined for the (null, null) case."; |
| 2743 | return nullptr; |
| 2744 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2745 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2746 | // 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] | 2747 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2748 | HConstant* GetConstantRight() const; |
| 2749 | |
| 2750 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2751 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2752 | HInstruction* GetLeastConstantLeft() const; |
| 2753 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2754 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2755 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2756 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2757 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 2758 | }; |
| 2759 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2760 | // The comparison bias applies for floating point operations and indicates how NaN |
| 2761 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2762 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2763 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 2764 | kGtBias, // return 1 for NaN comparisons |
| 2765 | kLtBias, // return -1 for NaN comparisons |
| 2766 | }; |
| 2767 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2768 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2769 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2770 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2771 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc), |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2772 | bias_(ComparisonBias::kNoBias) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2773 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2774 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2775 | // `instruction`, and disregard moves in between. |
| 2776 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2777 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2778 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2779 | |
| 2780 | virtual IfCondition GetCondition() const = 0; |
| 2781 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2782 | virtual IfCondition GetOppositeCondition() const = 0; |
| 2783 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2784 | bool IsGtBias() const { return bias_ == ComparisonBias::kGtBias; } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2785 | |
| 2786 | void SetBias(ComparisonBias bias) { bias_ = bias; } |
| 2787 | |
| 2788 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2789 | return bias_ == other->AsCondition()->bias_; |
| 2790 | } |
| 2791 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2792 | bool IsFPConditionTrueIfNaN() const { |
| 2793 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2794 | IfCondition if_cond = GetCondition(); |
Nicolas Geoffray | d4aee94 | 2016-01-22 12:35:26 +0000 | [diff] [blame] | 2795 | return IsGtBias() ? ((if_cond == kCondGT) || (if_cond == kCondGE)) : (if_cond == kCondNE); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2796 | } |
| 2797 | |
| 2798 | bool IsFPConditionFalseIfNaN() const { |
| 2799 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2800 | IfCondition if_cond = GetCondition(); |
Nicolas Geoffray | d4aee94 | 2016-01-22 12:35:26 +0000 | [diff] [blame] | 2801 | return IsGtBias() ? ((if_cond == kCondLT) || (if_cond == kCondLE)) : (if_cond == kCondEQ); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2802 | } |
| 2803 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2804 | private: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2805 | // Needed if we merge a HCompare into a HCondition. |
| 2806 | ComparisonBias bias_; |
| 2807 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2808 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 2809 | }; |
| 2810 | |
| 2811 | // Instruction to check if two inputs are equal to each other. |
| 2812 | class HEqual : public HCondition { |
| 2813 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2814 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2815 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2816 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2817 | bool IsCommutative() const OVERRIDE { return true; } |
| 2818 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2819 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2820 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2821 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2822 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2823 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2824 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2825 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2826 | } |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2827 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2828 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Vladimir Marko | 040db34 | 2015-11-10 19:53:01 +0000 | [diff] [blame] | 2829 | return GetBlock()->GetGraph()->GetIntConstant(1); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2830 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2831 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2832 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2833 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2834 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2835 | return kCondEQ; |
| 2836 | } |
| 2837 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2838 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2839 | return kCondNE; |
| 2840 | } |
| 2841 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2842 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2843 | template <typename T> bool Compute(T x, T y) const { return x == y; } |
| 2844 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2845 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 2846 | }; |
| 2847 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2848 | class HNotEqual : public HCondition { |
| 2849 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2850 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2851 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2852 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2853 | bool IsCommutative() const OVERRIDE { return true; } |
| 2854 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2855 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2856 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2857 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2858 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2859 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2860 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2861 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2862 | } |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2863 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2864 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Vladimir Marko | 040db34 | 2015-11-10 19:53:01 +0000 | [diff] [blame] | 2865 | return GetBlock()->GetGraph()->GetIntConstant(0); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2866 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2867 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2868 | DECLARE_INSTRUCTION(NotEqual); |
| 2869 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2870 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2871 | return kCondNE; |
| 2872 | } |
| 2873 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2874 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2875 | return kCondEQ; |
| 2876 | } |
| 2877 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2878 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2879 | template <typename T> bool Compute(T x, T y) const { return x != y; } |
| 2880 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2881 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 2882 | }; |
| 2883 | |
| 2884 | class HLessThan : public HCondition { |
| 2885 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2886 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2887 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2888 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2889 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2890 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2891 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2892 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2893 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2894 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2895 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2896 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2897 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2898 | DECLARE_INSTRUCTION(LessThan); |
| 2899 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2900 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2901 | return kCondLT; |
| 2902 | } |
| 2903 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2904 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2905 | return kCondGE; |
| 2906 | } |
| 2907 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2908 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2909 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 2910 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2911 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 2912 | }; |
| 2913 | |
| 2914 | class HLessThanOrEqual : public HCondition { |
| 2915 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2916 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2917 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2918 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2919 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2920 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2921 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2922 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2923 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2924 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2925 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2926 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2927 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2928 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 2929 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2930 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2931 | return kCondLE; |
| 2932 | } |
| 2933 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2934 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2935 | return kCondGT; |
| 2936 | } |
| 2937 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2938 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2939 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 2940 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2941 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 2942 | }; |
| 2943 | |
| 2944 | class HGreaterThan : public HCondition { |
| 2945 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2946 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2947 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2948 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2949 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2950 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2951 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2952 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2953 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2954 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2955 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2956 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2957 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2958 | DECLARE_INSTRUCTION(GreaterThan); |
| 2959 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2960 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2961 | return kCondGT; |
| 2962 | } |
| 2963 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2964 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2965 | return kCondLE; |
| 2966 | } |
| 2967 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2968 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2969 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 2970 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2971 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 2972 | }; |
| 2973 | |
| 2974 | class HGreaterThanOrEqual : public HCondition { |
| 2975 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2976 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2977 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2978 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2979 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2980 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2981 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2982 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2983 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2984 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2985 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2986 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2987 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2988 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 2989 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2990 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2991 | return kCondGE; |
| 2992 | } |
| 2993 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2994 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2995 | return kCondLT; |
| 2996 | } |
| 2997 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2998 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2999 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 3000 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3001 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 3002 | }; |
| 3003 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3004 | class HBelow : public HCondition { |
| 3005 | public: |
| 3006 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3007 | : HCondition(first, second, dex_pc) {} |
| 3008 | |
| 3009 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3010 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3011 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 3012 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 3013 | } |
| 3014 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3015 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3016 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 3017 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 3018 | } |
| 3019 | |
| 3020 | DECLARE_INSTRUCTION(Below); |
| 3021 | |
| 3022 | IfCondition GetCondition() const OVERRIDE { |
| 3023 | return kCondB; |
| 3024 | } |
| 3025 | |
| 3026 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3027 | return kCondAE; |
| 3028 | } |
| 3029 | |
| 3030 | private: |
| 3031 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 3032 | |
| 3033 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 3034 | }; |
| 3035 | |
| 3036 | class HBelowOrEqual : public HCondition { |
| 3037 | public: |
| 3038 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3039 | : HCondition(first, second, dex_pc) {} |
| 3040 | |
| 3041 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3042 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3043 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 3044 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 3045 | } |
| 3046 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3047 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3048 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 3049 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 3050 | } |
| 3051 | |
| 3052 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 3053 | |
| 3054 | IfCondition GetCondition() const OVERRIDE { |
| 3055 | return kCondBE; |
| 3056 | } |
| 3057 | |
| 3058 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3059 | return kCondA; |
| 3060 | } |
| 3061 | |
| 3062 | private: |
| 3063 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 3064 | |
| 3065 | DISALLOW_COPY_AND_ASSIGN(HBelowOrEqual); |
| 3066 | }; |
| 3067 | |
| 3068 | class HAbove : public HCondition { |
| 3069 | public: |
| 3070 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3071 | : HCondition(first, second, dex_pc) {} |
| 3072 | |
| 3073 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3074 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3075 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 3076 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 3077 | } |
| 3078 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3079 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3080 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 3081 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 3082 | } |
| 3083 | |
| 3084 | DECLARE_INSTRUCTION(Above); |
| 3085 | |
| 3086 | IfCondition GetCondition() const OVERRIDE { |
| 3087 | return kCondA; |
| 3088 | } |
| 3089 | |
| 3090 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3091 | return kCondBE; |
| 3092 | } |
| 3093 | |
| 3094 | private: |
| 3095 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 3096 | |
| 3097 | DISALLOW_COPY_AND_ASSIGN(HAbove); |
| 3098 | }; |
| 3099 | |
| 3100 | class HAboveOrEqual : public HCondition { |
| 3101 | public: |
| 3102 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3103 | : HCondition(first, second, dex_pc) {} |
| 3104 | |
| 3105 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3106 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3107 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 3108 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 3109 | } |
| 3110 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3111 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3112 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 3113 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 3114 | } |
| 3115 | |
| 3116 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 3117 | |
| 3118 | IfCondition GetCondition() const OVERRIDE { |
| 3119 | return kCondAE; |
| 3120 | } |
| 3121 | |
| 3122 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3123 | return kCondB; |
| 3124 | } |
| 3125 | |
| 3126 | private: |
| 3127 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 3128 | |
| 3129 | DISALLOW_COPY_AND_ASSIGN(HAboveOrEqual); |
| 3130 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3131 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3132 | // Instruction to check how two inputs compare to each other. |
| 3133 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
| 3134 | class HCompare : public HBinaryOperation { |
| 3135 | public: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3136 | HCompare(Primitive::Type type, |
| 3137 | HInstruction* first, |
| 3138 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3139 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3140 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3141 | : HBinaryOperation(Primitive::kPrimInt, |
| 3142 | first, |
| 3143 | second, |
| 3144 | SideEffectsForArchRuntimeCalls(type), |
| 3145 | dex_pc), |
| 3146 | bias_(bias) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3147 | DCHECK_EQ(type, first->GetType()); |
| 3148 | DCHECK_EQ(type, second->GetType()); |
| 3149 | } |
| 3150 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3151 | template <typename T> |
| 3152 | 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] | 3153 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3154 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3155 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3156 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3157 | } |
| 3158 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3159 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3160 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3161 | } |
| 3162 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3163 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3164 | return bias_ == other->AsCompare()->bias_; |
| 3165 | } |
| 3166 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3167 | ComparisonBias GetBias() const { return bias_; } |
| 3168 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3169 | bool IsGtBias() { return bias_ == ComparisonBias::kGtBias; } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3170 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3171 | |
| 3172 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type) { |
| 3173 | // MIPS64 uses a runtime call for FP comparisons. |
| 3174 | return Primitive::IsFloatingPointType(type) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 3175 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3176 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3177 | DECLARE_INSTRUCTION(Compare); |
| 3178 | |
| 3179 | private: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3180 | const ComparisonBias bias_; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3181 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3182 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3183 | }; |
| 3184 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3185 | // A local in the graph. Corresponds to a Dex register. |
| 3186 | class HLocal : public HTemplateInstruction<0> { |
| 3187 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3188 | explicit HLocal(uint16_t reg_number) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3189 | : HTemplateInstruction(SideEffects::None(), kNoDexPc), reg_number_(reg_number) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3190 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3191 | DECLARE_INSTRUCTION(Local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3192 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3193 | uint16_t GetRegNumber() const { return reg_number_; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3194 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3195 | private: |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3196 | // The Dex register number. |
| 3197 | const uint16_t reg_number_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3198 | |
| 3199 | DISALLOW_COPY_AND_ASSIGN(HLocal); |
| 3200 | }; |
| 3201 | |
| 3202 | // Load a given local. The local is an input of this instruction. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3203 | class HLoadLocal : public HExpression<1> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3204 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3205 | HLoadLocal(HLocal* local, Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 3206 | : HExpression(type, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3207 | SetRawInputAt(0, local); |
| 3208 | } |
| 3209 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3210 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 3211 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3212 | DECLARE_INSTRUCTION(LoadLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3213 | |
| 3214 | private: |
| 3215 | DISALLOW_COPY_AND_ASSIGN(HLoadLocal); |
| 3216 | }; |
| 3217 | |
| 3218 | // Store a value in a given local. This instruction has two inputs: the value |
| 3219 | // and the local. |
| 3220 | class HStoreLocal : public HTemplateInstruction<2> { |
| 3221 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3222 | HStoreLocal(HLocal* local, HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 3223 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3224 | SetRawInputAt(0, local); |
| 3225 | SetRawInputAt(1, value); |
| 3226 | } |
| 3227 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3228 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 3229 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3230 | DECLARE_INSTRUCTION(StoreLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3231 | |
| 3232 | private: |
| 3233 | DISALLOW_COPY_AND_ASSIGN(HStoreLocal); |
| 3234 | }; |
| 3235 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3236 | class HFloatConstant : public HConstant { |
| 3237 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3238 | float GetValue() const { return value_; } |
| 3239 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3240 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 3241 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 3242 | } |
| 3243 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3244 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3245 | DCHECK(other->IsFloatConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3246 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3247 | } |
| 3248 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3249 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3250 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3251 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3252 | 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] | 3253 | } |
| 3254 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3255 | return value_ == 0.0f; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3256 | } |
| 3257 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3258 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 3259 | } |
| 3260 | bool IsNaN() const { |
| 3261 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3262 | } |
| 3263 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3264 | DECLARE_INSTRUCTION(FloatConstant); |
| 3265 | |
| 3266 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3267 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 3268 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 3269 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 3270 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3271 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3272 | const float value_; |
| 3273 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3274 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3275 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3276 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3277 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 3278 | }; |
| 3279 | |
| 3280 | class HDoubleConstant : public HConstant { |
| 3281 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3282 | double GetValue() const { return value_; } |
| 3283 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3284 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 3285 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3286 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3287 | DCHECK(other->IsDoubleConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3288 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3289 | } |
| 3290 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3291 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3292 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3293 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3294 | 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] | 3295 | } |
| 3296 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3297 | return value_ == 0.0; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3298 | } |
| 3299 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3300 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 3301 | } |
| 3302 | bool IsNaN() const { |
| 3303 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3304 | } |
| 3305 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3306 | DECLARE_INSTRUCTION(DoubleConstant); |
| 3307 | |
| 3308 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3309 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 3310 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 3311 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 3312 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3313 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3314 | const double value_; |
| 3315 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3316 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3317 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3318 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3319 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 3320 | }; |
| 3321 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3322 | class HNewInstance : public HExpression<2> { |
| 3323 | public: |
| 3324 | HNewInstance(HInstruction* cls, |
| 3325 | HCurrentMethod* current_method, |
| 3326 | uint32_t dex_pc, |
| 3327 | uint16_t type_index, |
| 3328 | const DexFile& dex_file, |
| 3329 | bool can_throw, |
| 3330 | bool finalizable, |
| 3331 | QuickEntrypointEnum entrypoint) |
| 3332 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
| 3333 | type_index_(type_index), |
| 3334 | dex_file_(dex_file), |
| 3335 | can_throw_(can_throw), |
| 3336 | finalizable_(finalizable), |
| 3337 | entrypoint_(entrypoint) { |
| 3338 | SetRawInputAt(0, cls); |
| 3339 | SetRawInputAt(1, current_method); |
| 3340 | } |
| 3341 | |
| 3342 | uint16_t GetTypeIndex() const { return type_index_; } |
| 3343 | const DexFile& GetDexFile() const { return dex_file_; } |
| 3344 | |
| 3345 | // Calls runtime so needs an environment. |
| 3346 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3347 | |
| 3348 | // It may throw when called on type that's not instantiable/accessible. |
| 3349 | // It can throw OOME. |
| 3350 | // TODO: distinguish between the two cases so we can for example allow allocation elimination. |
| 3351 | bool CanThrow() const OVERRIDE { return can_throw_ || true; } |
| 3352 | |
| 3353 | bool IsFinalizable() const { return finalizable_; } |
| 3354 | |
| 3355 | bool CanBeNull() const OVERRIDE { return false; } |
| 3356 | |
| 3357 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3358 | |
| 3359 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 3360 | entrypoint_ = entrypoint; |
| 3361 | } |
| 3362 | |
| 3363 | bool IsStringAlloc() const; |
| 3364 | |
| 3365 | DECLARE_INSTRUCTION(NewInstance); |
| 3366 | |
| 3367 | private: |
| 3368 | const uint16_t type_index_; |
| 3369 | const DexFile& dex_file_; |
| 3370 | const bool can_throw_; |
| 3371 | const bool finalizable_; |
| 3372 | QuickEntrypointEnum entrypoint_; |
| 3373 | |
| 3374 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3375 | }; |
| 3376 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3377 | enum class Intrinsics { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3378 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache, SideEffects, Exceptions) \ |
| 3379 | k ## Name, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3380 | #include "intrinsics_list.h" |
| 3381 | kNone, |
| 3382 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
| 3383 | #undef INTRINSICS_LIST |
| 3384 | #undef OPTIMIZING_INTRINSICS |
| 3385 | }; |
| 3386 | std::ostream& operator<<(std::ostream& os, const Intrinsics& intrinsic); |
| 3387 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3388 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3389 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3390 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3391 | }; |
| 3392 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3393 | enum IntrinsicSideEffects { |
| 3394 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 3395 | kReadSideEffects, // Intrinsic may read heap memory. |
| 3396 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 3397 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 3398 | }; |
| 3399 | |
| 3400 | enum IntrinsicExceptions { |
| 3401 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 3402 | kCanThrow // Intrinsic may throw exceptions. |
| 3403 | }; |
| 3404 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3405 | class HInvoke : public HInstruction { |
| 3406 | public: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3407 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3408 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3409 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3410 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3411 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3412 | SetRawInputAt(index, argument); |
| 3413 | } |
| 3414 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3415 | // Return the number of arguments. This number can be lower than |
| 3416 | // the number of inputs returned by InputCount(), as some invoke |
| 3417 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3418 | // inputs at the end of their list of inputs. |
| 3419 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3420 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3421 | Primitive::Type GetType() const OVERRIDE { return return_type_; } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3422 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3423 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3424 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3425 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3426 | InvokeType GetOriginalInvokeType() const { return original_invoke_type_; } |
| 3427 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3428 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3429 | return intrinsic_; |
| 3430 | } |
| 3431 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3432 | void SetIntrinsic(Intrinsics intrinsic, |
| 3433 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 3434 | IntrinsicSideEffects side_effects, |
| 3435 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3436 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3437 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 3438 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3439 | } |
| 3440 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3441 | bool CanThrow() const OVERRIDE { return can_throw_; } |
| 3442 | |
| 3443 | bool CanBeMoved() const OVERRIDE { return IsIntrinsic(); } |
| 3444 | |
| 3445 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3446 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 3447 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3448 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3449 | uint32_t* GetIntrinsicOptimizations() { |
| 3450 | return &intrinsic_optimizations_; |
| 3451 | } |
| 3452 | |
| 3453 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3454 | return &intrinsic_optimizations_; |
| 3455 | } |
| 3456 | |
| 3457 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3458 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3459 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3460 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3461 | protected: |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3462 | HInvoke(ArenaAllocator* arena, |
| 3463 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3464 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3465 | Primitive::Type return_type, |
| 3466 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3467 | uint32_t dex_method_index, |
| 3468 | InvokeType original_invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3469 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3470 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3471 | number_of_arguments_(number_of_arguments), |
Vladimir Marko | b7d8e8c | 2015-09-17 15:47:05 +0100 | [diff] [blame] | 3472 | inputs_(number_of_arguments + number_of_other_inputs, |
| 3473 | arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3474 | return_type_(return_type), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3475 | dex_method_index_(dex_method_index), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3476 | original_invoke_type_(original_invoke_type), |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3477 | can_throw_(true), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3478 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3479 | intrinsic_optimizations_(0) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3480 | } |
| 3481 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3482 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3483 | return inputs_[index]; |
| 3484 | } |
| 3485 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3486 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3487 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3488 | } |
| 3489 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3490 | void SetCanThrow(bool can_throw) { can_throw_ = can_throw; } |
| 3491 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3492 | uint32_t number_of_arguments_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3493 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3494 | const Primitive::Type return_type_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3495 | const uint32_t dex_method_index_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3496 | const InvokeType original_invoke_type_; |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3497 | bool can_throw_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3498 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3499 | |
| 3500 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3501 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3502 | |
| 3503 | private: |
| 3504 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3505 | }; |
| 3506 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3507 | class HInvokeUnresolved : public HInvoke { |
| 3508 | public: |
| 3509 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3510 | uint32_t number_of_arguments, |
| 3511 | Primitive::Type return_type, |
| 3512 | uint32_t dex_pc, |
| 3513 | uint32_t dex_method_index, |
| 3514 | InvokeType invoke_type) |
| 3515 | : HInvoke(arena, |
| 3516 | number_of_arguments, |
| 3517 | 0u /* number_of_other_inputs */, |
| 3518 | return_type, |
| 3519 | dex_pc, |
| 3520 | dex_method_index, |
| 3521 | invoke_type) { |
| 3522 | } |
| 3523 | |
| 3524 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3525 | |
| 3526 | private: |
| 3527 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3528 | }; |
| 3529 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3530 | class HInvokeStaticOrDirect : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3531 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3532 | // Requirements of this method call regarding the class |
| 3533 | // initialization (clinit) check of its declaring class. |
| 3534 | enum class ClinitCheckRequirement { |
| 3535 | kNone, // Class already initialized. |
| 3536 | kExplicit, // Static call having explicit clinit check as last input. |
| 3537 | kImplicit, // Static call implicitly requiring a clinit check. |
| 3538 | }; |
| 3539 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3540 | // Determines how to load the target ArtMethod*. |
| 3541 | enum class MethodLoadKind { |
| 3542 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3543 | kStringInit, |
| 3544 | |
| 3545 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3546 | kRecursive, |
| 3547 | |
| 3548 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3549 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3550 | kDirectAddress, |
| 3551 | |
| 3552 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3553 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3554 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3555 | // the image relocatable or not. |
| 3556 | kDirectAddressWithFixup, |
| 3557 | |
| 3558 | // Load from resoved methods array in the dex cache using a PC-relative load. |
| 3559 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3560 | // may cause class initialization (the entry may point to a resolution method), |
| 3561 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3562 | kDexCachePcRelative, |
| 3563 | |
| 3564 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3565 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3566 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3567 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3568 | kDexCacheViaMethod, |
| 3569 | }; |
| 3570 | |
| 3571 | // Determines the location of the code pointer. |
| 3572 | enum class CodePtrLocation { |
| 3573 | // Recursive call, use local PC-relative call instruction. |
| 3574 | kCallSelf, |
| 3575 | |
| 3576 | // Use PC-relative call instruction patched at link time. |
| 3577 | // Used for calls within an oat file, boot->boot or app->app. |
| 3578 | kCallPCRelative, |
| 3579 | |
| 3580 | // Call to a known target address, embed the direct address in code. |
| 3581 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3582 | kCallDirect, |
| 3583 | |
| 3584 | // Call to a target address that will be known at link time, embed the direct |
| 3585 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3586 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3587 | // the image relocatable or not. |
| 3588 | kCallDirectWithFixup, |
| 3589 | |
| 3590 | // Use code pointer from the ArtMethod*. |
| 3591 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3592 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3593 | kCallArtMethod, |
| 3594 | }; |
| 3595 | |
| 3596 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3597 | MethodLoadKind method_load_kind; |
| 3598 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3599 | // The method load data holds |
| 3600 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3601 | // Note that there are multiple string init methods, each having its own offset. |
| 3602 | // - the method address for kDirectAddress |
| 3603 | // - the dex cache arrays offset for kDexCachePcRel. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3604 | uint64_t method_load_data; |
| 3605 | uint64_t direct_code_ptr; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3606 | }; |
| 3607 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3608 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 3609 | uint32_t number_of_arguments, |
| 3610 | Primitive::Type return_type, |
| 3611 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3612 | uint32_t method_index, |
| 3613 | MethodReference target_method, |
| 3614 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 7904129 | 2015-03-26 10:05:54 +0000 | [diff] [blame] | 3615 | InvokeType original_invoke_type, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3616 | InvokeType optimized_invoke_type, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3617 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3618 | : HInvoke(arena, |
| 3619 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3620 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 3621 | // potentially one other if the clinit check is explicit, and potentially |
| 3622 | // one other if the method is a string factory. |
| 3623 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
| 3624 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u) + |
| 3625 | (dispatch_info.method_load_kind == MethodLoadKind::kStringInit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3626 | return_type, |
| 3627 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3628 | method_index, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3629 | original_invoke_type), |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3630 | optimized_invoke_type_(optimized_invoke_type), |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 3631 | clinit_check_requirement_(clinit_check_requirement), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3632 | target_method_(target_method), |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3633 | dispatch_info_(dispatch_info) { } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3634 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3635 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3636 | bool had_current_method_input = HasCurrentMethodInput(); |
| 3637 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 3638 | |
| 3639 | // Using the current method is the default and once we find a better |
| 3640 | // method load kind, we should not go back to using the current method. |
| 3641 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 3642 | |
| 3643 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3644 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 3645 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3646 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3647 | dispatch_info_ = dispatch_info; |
| 3648 | } |
| 3649 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3650 | void AddSpecialInput(HInstruction* input) { |
| 3651 | // We allow only one special input. |
| 3652 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 3653 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3654 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 3655 | InsertInputAt(GetSpecialInputIndex(), input); |
| 3656 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3657 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3658 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3659 | // We access the method via the dex cache so we can't do an implicit null check. |
| 3660 | // TODO: for intrinsics we can generate implicit null checks. |
| 3661 | return false; |
| 3662 | } |
| 3663 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3664 | bool CanBeNull() const OVERRIDE { |
| 3665 | return return_type_ == Primitive::kPrimNot && !IsStringInit(); |
| 3666 | } |
| 3667 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3668 | // Get the index of the special input, if any. |
| 3669 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3670 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 3671 | // method pointer; otherwise there may be one platform-specific special input, |
| 3672 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3673 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
| 3674 | |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3675 | InvokeType GetOptimizedInvokeType() const { return optimized_invoke_type_; } |
| 3676 | void SetOptimizedInvokeType(InvokeType invoke_type) { |
| 3677 | optimized_invoke_type_ = invoke_type; |
| 3678 | } |
| 3679 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3680 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 3681 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 3682 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3683 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3684 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3685 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3686 | bool HasPcRelativeDexCache() const { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3687 | return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; |
| 3688 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3689 | bool HasCurrentMethodInput() const { |
| 3690 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 3691 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3692 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3693 | return true; |
| 3694 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3695 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3696 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3697 | return false; |
| 3698 | } |
| 3699 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3700 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
| 3701 | MethodReference GetTargetMethod() const { return target_method_; } |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3702 | void SetTargetMethod(MethodReference method) { target_method_ = method; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3703 | |
| 3704 | int32_t GetStringInitOffset() const { |
| 3705 | DCHECK(IsStringInit()); |
| 3706 | return dispatch_info_.method_load_data; |
| 3707 | } |
| 3708 | |
| 3709 | uint64_t GetMethodAddress() const { |
| 3710 | DCHECK(HasMethodAddress()); |
| 3711 | return dispatch_info_.method_load_data; |
| 3712 | } |
| 3713 | |
| 3714 | uint32_t GetDexCacheArrayOffset() const { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3715 | DCHECK(HasPcRelativeDexCache()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3716 | return dispatch_info_.method_load_data; |
| 3717 | } |
| 3718 | |
| 3719 | uint64_t GetDirectCodePtr() const { |
| 3720 | DCHECK(HasDirectCodePtr()); |
| 3721 | return dispatch_info_.direct_code_ptr; |
| 3722 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3723 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 3724 | ClinitCheckRequirement GetClinitCheckRequirement() const { return clinit_check_requirement_; } |
| 3725 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3726 | // Is this instruction a call to a static method? |
| 3727 | bool IsStatic() const { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3728 | return GetOriginalInvokeType() == kStatic; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3729 | } |
| 3730 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3731 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 3732 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 3733 | // instruction; only relevant for static calls with explicit clinit check. |
| 3734 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3735 | DCHECK(IsStaticWithExplicitClinitCheck()); |
| 3736 | size_t last_input_index = InputCount() - 1; |
| 3737 | HInstruction* last_input = InputAt(last_input_index); |
| 3738 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3739 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3740 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3741 | inputs_.pop_back(); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3742 | clinit_check_requirement_ = new_requirement; |
| 3743 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3744 | } |
| 3745 | |
David Brazdil | bc9ab16 | 2016-01-20 14:50:19 +0000 | [diff] [blame] | 3746 | HInstruction* GetAndRemoveThisArgumentOfStringInit() { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3747 | DCHECK(IsStringInit()); |
| 3748 | size_t index = InputCount() - 1; |
David Brazdil | bc9ab16 | 2016-01-20 14:50:19 +0000 | [diff] [blame] | 3749 | HInstruction* input = InputAt(index); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3750 | RemoveAsUserOfInput(index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3751 | inputs_.pop_back(); |
David Brazdil | bc9ab16 | 2016-01-20 14:50:19 +0000 | [diff] [blame] | 3752 | return input; |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3753 | } |
| 3754 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3755 | // 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] | 3756 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3757 | bool IsStaticWithExplicitClinitCheck() const { |
| 3758 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kExplicit); |
| 3759 | } |
| 3760 | |
| 3761 | // Is this a call to a static method whose declaring class has an |
| 3762 | // implicit intialization check requirement? |
| 3763 | bool IsStaticWithImplicitClinitCheck() const { |
| 3764 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kImplicit); |
| 3765 | } |
| 3766 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3767 | // Does this method load kind need the current method as an input? |
| 3768 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
| 3769 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kDexCacheViaMethod; |
| 3770 | } |
| 3771 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3772 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3773 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3774 | protected: |
| 3775 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 3776 | const HUserRecord<HInstruction*> input_record = HInvoke::InputRecordAt(i); |
| 3777 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck() && (i == InputCount() - 1)) { |
| 3778 | HInstruction* input = input_record.GetInstruction(); |
| 3779 | // `input` is the last input of a static invoke marked as having |
| 3780 | // an explicit clinit check. It must either be: |
| 3781 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 3782 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 3783 | DCHECK(input != nullptr); |
| 3784 | DCHECK(input->IsClinitCheck() || input->IsLoadClass()) << input->DebugName(); |
| 3785 | } |
| 3786 | return input_record; |
| 3787 | } |
| 3788 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3789 | void InsertInputAt(size_t index, HInstruction* input); |
| 3790 | void RemoveInputAt(size_t index); |
| 3791 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3792 | private: |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3793 | InvokeType optimized_invoke_type_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3794 | ClinitCheckRequirement clinit_check_requirement_; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3795 | // The target method may refer to different dex file or method index than the original |
| 3796 | // invoke. This happens for sharpened calls and for calls where a method was redeclared |
| 3797 | // in derived class to increase visibility. |
| 3798 | MethodReference target_method_; |
| 3799 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3800 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3801 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3802 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 3803 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3804 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3805 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3806 | class HInvokeVirtual : public HInvoke { |
| 3807 | public: |
| 3808 | HInvokeVirtual(ArenaAllocator* arena, |
| 3809 | uint32_t number_of_arguments, |
| 3810 | Primitive::Type return_type, |
| 3811 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3812 | uint32_t dex_method_index, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3813 | uint32_t vtable_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3814 | : 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] | 3815 | vtable_index_(vtable_index) {} |
| 3816 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3817 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3818 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3819 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3820 | } |
| 3821 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3822 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 3823 | |
| 3824 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 3825 | |
| 3826 | private: |
| 3827 | const uint32_t vtable_index_; |
| 3828 | |
| 3829 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 3830 | }; |
| 3831 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3832 | class HInvokeInterface : public HInvoke { |
| 3833 | public: |
| 3834 | HInvokeInterface(ArenaAllocator* arena, |
| 3835 | uint32_t number_of_arguments, |
| 3836 | Primitive::Type return_type, |
| 3837 | uint32_t dex_pc, |
| 3838 | uint32_t dex_method_index, |
| 3839 | uint32_t imt_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3840 | : 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] | 3841 | imt_index_(imt_index) {} |
| 3842 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3843 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3844 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3845 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3846 | } |
| 3847 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3848 | uint32_t GetImtIndex() const { return imt_index_; } |
| 3849 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 3850 | |
| 3851 | DECLARE_INSTRUCTION(InvokeInterface); |
| 3852 | |
| 3853 | private: |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3854 | const uint32_t imt_index_; |
| 3855 | |
| 3856 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 3857 | }; |
| 3858 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3859 | class HNeg : public HUnaryOperation { |
| 3860 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3861 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3862 | : HUnaryOperation(result_type, input, dex_pc) {} |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3863 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3864 | template <typename T> T Compute(T x) const { return -x; } |
| 3865 | |
| 3866 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3867 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3868 | } |
| 3869 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3870 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3871 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3872 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3873 | DECLARE_INSTRUCTION(Neg); |
| 3874 | |
| 3875 | private: |
| 3876 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 3877 | }; |
| 3878 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3879 | class HNewArray : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3880 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3881 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3882 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3883 | uint32_t dex_pc, |
| 3884 | uint16_t type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3885 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3886 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3887 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3888 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3889 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3890 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3891 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3892 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3893 | } |
| 3894 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3895 | uint16_t GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3896 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3897 | |
| 3898 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3899 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3900 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 3901 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 3902 | bool CanThrow() const OVERRIDE { return true; } |
| 3903 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3904 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3905 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3906 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3907 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3908 | DECLARE_INSTRUCTION(NewArray); |
| 3909 | |
| 3910 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3911 | const uint16_t type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3912 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3913 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3914 | |
| 3915 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 3916 | }; |
| 3917 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3918 | class HAdd : public HBinaryOperation { |
| 3919 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3920 | HAdd(Primitive::Type result_type, |
| 3921 | HInstruction* left, |
| 3922 | HInstruction* right, |
| 3923 | uint32_t dex_pc = kNoDexPc) |
| 3924 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3925 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3926 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3927 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3928 | template <typename T> T Compute(T x, T y) const { return x + y; } |
| 3929 | |
| 3930 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3931 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3932 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3933 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3934 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3935 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3936 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3937 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3938 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3939 | DECLARE_INSTRUCTION(Add); |
| 3940 | |
| 3941 | private: |
| 3942 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 3943 | }; |
| 3944 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3945 | class HSub : public HBinaryOperation { |
| 3946 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3947 | HSub(Primitive::Type result_type, |
| 3948 | HInstruction* left, |
| 3949 | HInstruction* right, |
| 3950 | uint32_t dex_pc = kNoDexPc) |
| 3951 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3952 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3953 | template <typename T> T Compute(T x, T y) const { return x - y; } |
| 3954 | |
| 3955 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3956 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3957 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3958 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3959 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3960 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3961 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3962 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3963 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3964 | DECLARE_INSTRUCTION(Sub); |
| 3965 | |
| 3966 | private: |
| 3967 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 3968 | }; |
| 3969 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3970 | class HMul : public HBinaryOperation { |
| 3971 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3972 | HMul(Primitive::Type result_type, |
| 3973 | HInstruction* left, |
| 3974 | HInstruction* right, |
| 3975 | uint32_t dex_pc = kNoDexPc) |
| 3976 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3977 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3978 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3979 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3980 | template <typename T> T Compute(T x, T y) const { return x * y; } |
| 3981 | |
| 3982 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3983 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3984 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3985 | } |
| 3986 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3987 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3988 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3989 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3990 | |
| 3991 | DECLARE_INSTRUCTION(Mul); |
| 3992 | |
| 3993 | private: |
| 3994 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 3995 | }; |
| 3996 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3997 | class HDiv : public HBinaryOperation { |
| 3998 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3999 | HDiv(Primitive::Type result_type, |
| 4000 | HInstruction* left, |
| 4001 | HInstruction* right, |
| 4002 | uint32_t dex_pc) |
| 4003 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4004 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4005 | template <typename T> |
| 4006 | T Compute(T x, T y) const { |
| 4007 | // Our graph structure ensures we never have 0 for `y` during |
| 4008 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4009 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4010 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4011 | return (y == -1) ? -x : x / y; |
| 4012 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4013 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4014 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4015 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4016 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4017 | } |
| 4018 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4019 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4020 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4021 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4022 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4023 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4024 | // The generated code can use a runtime call. |
| 4025 | return SideEffects::CanTriggerGC(); |
| 4026 | } |
| 4027 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4028 | DECLARE_INSTRUCTION(Div); |
| 4029 | |
| 4030 | private: |
| 4031 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 4032 | }; |
| 4033 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4034 | class HRem : public HBinaryOperation { |
| 4035 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4036 | HRem(Primitive::Type result_type, |
| 4037 | HInstruction* left, |
| 4038 | HInstruction* right, |
| 4039 | uint32_t dex_pc) |
| 4040 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4041 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4042 | template <typename T> |
| 4043 | T Compute(T x, T y) const { |
| 4044 | // Our graph structure ensures we never have 0 for `y` during |
| 4045 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4046 | DCHECK_NE(y, 0); |
| 4047 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 4048 | return (y == -1) ? 0 : x % y; |
| 4049 | } |
| 4050 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4051 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4052 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4053 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4054 | } |
| 4055 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4056 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4057 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4058 | } |
| 4059 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4060 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4061 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4062 | return SideEffects::CanTriggerGC(); |
| 4063 | } |
| 4064 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4065 | DECLARE_INSTRUCTION(Rem); |
| 4066 | |
| 4067 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4068 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 4069 | }; |
| 4070 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4071 | class HDivZeroCheck : public HExpression<1> { |
| 4072 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4073 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
| 4074 | // constructor. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4075 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4076 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4077 | SetRawInputAt(0, value); |
| 4078 | } |
| 4079 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4080 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 4081 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4082 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4083 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4084 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4085 | return true; |
| 4086 | } |
| 4087 | |
| 4088 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4089 | bool CanThrow() const OVERRIDE { return true; } |
| 4090 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4091 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 4092 | |
| 4093 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4094 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 4095 | }; |
| 4096 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4097 | class HShl : public HBinaryOperation { |
| 4098 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4099 | HShl(Primitive::Type result_type, |
| 4100 | HInstruction* left, |
| 4101 | HInstruction* right, |
| 4102 | uint32_t dex_pc = kNoDexPc) |
| 4103 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4104 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4105 | template <typename T, typename U, typename V> |
| 4106 | T Compute(T x, U y, V max_shift_value) const { |
| 4107 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4108 | "V is not the unsigned integer type corresponding to T"); |
| 4109 | return x << (y & max_shift_value); |
| 4110 | } |
| 4111 | |
| 4112 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4113 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4114 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4115 | } |
| 4116 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 4117 | // case is handled as `x << static_cast<int>(y)`. |
| 4118 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4119 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4120 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4121 | } |
| 4122 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4123 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4124 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4125 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4126 | |
| 4127 | DECLARE_INSTRUCTION(Shl); |
| 4128 | |
| 4129 | private: |
| 4130 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 4131 | }; |
| 4132 | |
| 4133 | class HShr : public HBinaryOperation { |
| 4134 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4135 | HShr(Primitive::Type result_type, |
| 4136 | HInstruction* left, |
| 4137 | HInstruction* right, |
| 4138 | uint32_t dex_pc = kNoDexPc) |
| 4139 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4140 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4141 | template <typename T, typename U, typename V> |
| 4142 | T Compute(T x, U y, V max_shift_value) const { |
| 4143 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4144 | "V is not the unsigned integer type corresponding to T"); |
| 4145 | return x >> (y & max_shift_value); |
| 4146 | } |
| 4147 | |
| 4148 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4149 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4150 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4151 | } |
| 4152 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 4153 | // case is handled as `x >> static_cast<int>(y)`. |
| 4154 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4155 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4156 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4157 | } |
| 4158 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4159 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4160 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4161 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4162 | |
| 4163 | DECLARE_INSTRUCTION(Shr); |
| 4164 | |
| 4165 | private: |
| 4166 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 4167 | }; |
| 4168 | |
| 4169 | class HUShr : public HBinaryOperation { |
| 4170 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4171 | HUShr(Primitive::Type result_type, |
| 4172 | HInstruction* left, |
| 4173 | HInstruction* right, |
| 4174 | uint32_t dex_pc = kNoDexPc) |
| 4175 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4176 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4177 | template <typename T, typename U, typename V> |
| 4178 | T Compute(T x, U y, V max_shift_value) const { |
| 4179 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4180 | "V is not the unsigned integer type corresponding to T"); |
| 4181 | V ux = static_cast<V>(x); |
| 4182 | return static_cast<T>(ux >> (y & max_shift_value)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4183 | } |
| 4184 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4185 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4186 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4187 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4188 | } |
| 4189 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 4190 | // case is handled as `x >>> static_cast<int>(y)`. |
| 4191 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4192 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4193 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4194 | } |
| 4195 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4196 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4197 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4198 | } |
| 4199 | |
| 4200 | DECLARE_INSTRUCTION(UShr); |
| 4201 | |
| 4202 | private: |
| 4203 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 4204 | }; |
| 4205 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4206 | class HAnd : public HBinaryOperation { |
| 4207 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4208 | HAnd(Primitive::Type result_type, |
| 4209 | HInstruction* left, |
| 4210 | HInstruction* right, |
| 4211 | uint32_t dex_pc = kNoDexPc) |
| 4212 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4213 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4214 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4215 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4216 | template <typename T, typename U> |
| 4217 | auto Compute(T x, U y) const -> decltype(x & y) { return x & y; } |
| 4218 | |
| 4219 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4220 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4221 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4222 | } |
| 4223 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4224 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4225 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4226 | } |
| 4227 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4228 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4229 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4230 | } |
| 4231 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4232 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4233 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4234 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4235 | |
| 4236 | DECLARE_INSTRUCTION(And); |
| 4237 | |
| 4238 | private: |
| 4239 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4240 | }; |
| 4241 | |
| 4242 | class HOr : public HBinaryOperation { |
| 4243 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4244 | HOr(Primitive::Type result_type, |
| 4245 | HInstruction* left, |
| 4246 | HInstruction* right, |
| 4247 | uint32_t dex_pc = kNoDexPc) |
| 4248 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4249 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4250 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4251 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4252 | template <typename T, typename U> |
| 4253 | auto Compute(T x, U y) const -> decltype(x | y) { return x | y; } |
| 4254 | |
| 4255 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4256 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4257 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4258 | } |
| 4259 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4260 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4261 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4262 | } |
| 4263 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4264 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4265 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4266 | } |
| 4267 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4268 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4269 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4270 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4271 | |
| 4272 | DECLARE_INSTRUCTION(Or); |
| 4273 | |
| 4274 | private: |
| 4275 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4276 | }; |
| 4277 | |
| 4278 | class HXor : public HBinaryOperation { |
| 4279 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4280 | HXor(Primitive::Type result_type, |
| 4281 | HInstruction* left, |
| 4282 | HInstruction* right, |
| 4283 | uint32_t dex_pc = kNoDexPc) |
| 4284 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4285 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4286 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4287 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4288 | template <typename T, typename U> |
| 4289 | auto Compute(T x, U y) const -> decltype(x ^ y) { return x ^ y; } |
| 4290 | |
| 4291 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4292 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4293 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4294 | } |
| 4295 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4296 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4297 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4298 | } |
| 4299 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4300 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4301 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4302 | } |
| 4303 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4304 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4305 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4306 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4307 | |
| 4308 | DECLARE_INSTRUCTION(Xor); |
| 4309 | |
| 4310 | private: |
| 4311 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 4312 | }; |
| 4313 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4314 | class HRor : public HBinaryOperation { |
| 4315 | public: |
| 4316 | HRor(Primitive::Type result_type, HInstruction* value, HInstruction* distance) |
| 4317 | : HBinaryOperation(result_type, value, distance) {} |
| 4318 | |
| 4319 | template <typename T, typename U, typename V> |
| 4320 | T Compute(T x, U y, V max_shift_value) const { |
| 4321 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4322 | "V is not the unsigned integer type corresponding to T"); |
| 4323 | V ux = static_cast<V>(x); |
| 4324 | if ((y & max_shift_value) == 0) { |
| 4325 | return static_cast<T>(ux); |
| 4326 | } else { |
| 4327 | const V reg_bits = sizeof(T) * 8; |
| 4328 | return static_cast<T>(ux >> (y & max_shift_value)) | |
| 4329 | (x << (reg_bits - (y & max_shift_value))); |
| 4330 | } |
| 4331 | } |
| 4332 | |
| 4333 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4334 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4335 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
| 4336 | } |
| 4337 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4338 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4339 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
| 4340 | } |
| 4341 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4342 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4343 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
| 4344 | } |
| 4345 | |
| 4346 | DECLARE_INSTRUCTION(Ror); |
| 4347 | |
| 4348 | private: |
| 4349 | DISALLOW_COPY_AND_ASSIGN(HRor); |
| 4350 | }; |
| 4351 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4352 | // The value of a parameter in this method. Its location depends on |
| 4353 | // the calling convention. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4354 | class HParameterValue : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4355 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4356 | HParameterValue(const DexFile& dex_file, |
| 4357 | uint16_t type_index, |
| 4358 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4359 | Primitive::Type parameter_type, |
| 4360 | bool is_this = false) |
| 4361 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4362 | dex_file_(dex_file), |
| 4363 | type_index_(type_index), |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4364 | index_(index), |
| 4365 | is_this_(is_this), |
| 4366 | can_be_null_(!is_this) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4367 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4368 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4369 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4370 | uint8_t GetIndex() const { return index_; } |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4371 | bool IsThis() const { return is_this_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4372 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4373 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4374 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4375 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4376 | DECLARE_INSTRUCTION(ParameterValue); |
| 4377 | |
| 4378 | private: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4379 | const DexFile& dex_file_; |
| 4380 | const uint16_t type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4381 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4382 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4383 | const uint8_t index_; |
| 4384 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4385 | // Whether or not the parameter value corresponds to 'this' argument. |
| 4386 | const bool is_this_; |
| 4387 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4388 | bool can_be_null_; |
| 4389 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4390 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 4391 | }; |
| 4392 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4393 | class HNot : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4394 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4395 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4396 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4397 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4398 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4399 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4400 | return true; |
| 4401 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4402 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4403 | template <typename T> T Compute(T x) const { return ~x; } |
| 4404 | |
| 4405 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4406 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4407 | } |
| 4408 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4409 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4410 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4411 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4412 | DECLARE_INSTRUCTION(Not); |
| 4413 | |
| 4414 | private: |
| 4415 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 4416 | }; |
| 4417 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4418 | class HBooleanNot : public HUnaryOperation { |
| 4419 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4420 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4421 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4422 | |
| 4423 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4424 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4425 | return true; |
| 4426 | } |
| 4427 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4428 | template <typename T> bool Compute(T x) const { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4429 | DCHECK(IsUint<1>(x)); |
| 4430 | return !x; |
| 4431 | } |
| 4432 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4433 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4434 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4435 | } |
| 4436 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4437 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4438 | UNREACHABLE(); |
| 4439 | } |
| 4440 | |
| 4441 | DECLARE_INSTRUCTION(BooleanNot); |
| 4442 | |
| 4443 | private: |
| 4444 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 4445 | }; |
| 4446 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4447 | class HTypeConversion : public HExpression<1> { |
| 4448 | public: |
| 4449 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4450 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4451 | : HExpression(result_type, |
| 4452 | SideEffectsForArchRuntimeCalls(input->GetType(), result_type), |
| 4453 | dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4454 | SetRawInputAt(0, input); |
| 4455 | DCHECK_NE(input->GetType(), result_type); |
| 4456 | } |
| 4457 | |
| 4458 | HInstruction* GetInput() const { return InputAt(0); } |
| 4459 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 4460 | Primitive::Type GetResultType() const { return GetType(); } |
| 4461 | |
| 4462 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | ed9b195 | 2014-11-06 11:10:17 +0000 | [diff] [blame] | 4463 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4464 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 4465 | // Try to statically evaluate the conversion and return a HConstant |
| 4466 | // containing the result. If the input cannot be converted, return nullptr. |
| 4467 | HConstant* TryStaticEvaluation() const; |
| 4468 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4469 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type input_type, |
| 4470 | Primitive::Type result_type) { |
| 4471 | // Some architectures may not require the 'GC' side effects, but at this point |
| 4472 | // in the compilation process we do not know what architecture we will |
| 4473 | // generate code for, so we must be conservative. |
Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 4474 | if ((Primitive::IsFloatingPointType(input_type) && Primitive::IsIntegralType(result_type)) |
| 4475 | || (input_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(result_type))) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4476 | return SideEffects::CanTriggerGC(); |
| 4477 | } |
| 4478 | return SideEffects::None(); |
| 4479 | } |
| 4480 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4481 | DECLARE_INSTRUCTION(TypeConversion); |
| 4482 | |
| 4483 | private: |
| 4484 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 4485 | }; |
| 4486 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 4487 | static constexpr uint32_t kNoRegNumber = -1; |
| 4488 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4489 | class HPhi : public HInstruction { |
| 4490 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4491 | HPhi(ArenaAllocator* arena, |
| 4492 | uint32_t reg_number, |
| 4493 | size_t number_of_inputs, |
| 4494 | Primitive::Type type, |
| 4495 | uint32_t dex_pc = kNoDexPc) |
| 4496 | : HInstruction(SideEffects::None(), dex_pc), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4497 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4498 | reg_number_(reg_number), |
David Brazdil | 809d70f | 2015-11-19 10:29:39 +0000 | [diff] [blame] | 4499 | type_(ToPhiType(type)), |
| 4500 | // Phis are constructed live and marked dead if conflicting or unused. |
| 4501 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 4502 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 4503 | is_live_(true), |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4504 | can_be_null_(true) { |
David Brazdil | 809d70f | 2015-11-19 10:29:39 +0000 | [diff] [blame] | 4505 | DCHECK_NE(type_, Primitive::kPrimVoid); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4506 | } |
| 4507 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 4508 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 4509 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 4510 | switch (type) { |
| 4511 | case Primitive::kPrimBoolean: |
| 4512 | case Primitive::kPrimByte: |
| 4513 | case Primitive::kPrimShort: |
| 4514 | case Primitive::kPrimChar: |
| 4515 | return Primitive::kPrimInt; |
| 4516 | default: |
| 4517 | return type; |
| 4518 | } |
| 4519 | } |
| 4520 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 4521 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 4522 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4523 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4524 | |
| 4525 | void AddInput(HInstruction* input); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 4526 | void RemoveInputAt(size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4527 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4528 | Primitive::Type GetType() const OVERRIDE { return type_; } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 4529 | void SetType(Primitive::Type new_type) { |
| 4530 | // Make sure that only valid type changes occur. The following are allowed: |
| 4531 | // (1) int -> float/ref (primitive type propagation), |
| 4532 | // (2) long -> double (primitive type propagation). |
| 4533 | DCHECK(type_ == new_type || |
| 4534 | (type_ == Primitive::kPrimInt && new_type == Primitive::kPrimFloat) || |
| 4535 | (type_ == Primitive::kPrimInt && new_type == Primitive::kPrimNot) || |
| 4536 | (type_ == Primitive::kPrimLong && new_type == Primitive::kPrimDouble)); |
| 4537 | type_ = new_type; |
| 4538 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4539 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4540 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4541 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
| 4542 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4543 | uint32_t GetRegNumber() const { return reg_number_; } |
| 4544 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4545 | void SetDead() { is_live_ = false; } |
| 4546 | void SetLive() { is_live_ = true; } |
| 4547 | bool IsDead() const { return !is_live_; } |
| 4548 | bool IsLive() const { return is_live_; } |
| 4549 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4550 | bool IsVRegEquivalentOf(HInstruction* other) const { |
| 4551 | return other != nullptr |
| 4552 | && other->IsPhi() |
| 4553 | && other->AsPhi()->GetBlock() == GetBlock() |
| 4554 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 4555 | } |
| 4556 | |
Calin Juravle | a4f8831 | 2015-04-16 12:57:19 +0100 | [diff] [blame] | 4557 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 4558 | // An equivalent phi is a phi having the same dex register and type. |
| 4559 | // It assumes that phis with the same dex register are adjacent. |
| 4560 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 4561 | HInstruction* next = GetNext(); |
| 4562 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 4563 | if (next->GetType() == GetType()) { |
| 4564 | return next->AsPhi(); |
| 4565 | } |
| 4566 | next = next->GetNext(); |
| 4567 | } |
| 4568 | return nullptr; |
| 4569 | } |
| 4570 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4571 | DECLARE_INSTRUCTION(Phi); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4572 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4573 | protected: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4574 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4575 | return inputs_[index]; |
| 4576 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4577 | |
| 4578 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4579 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4580 | } |
| 4581 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4582 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4583 | ArenaVector<HUserRecord<HInstruction*> > inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4584 | const uint32_t reg_number_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4585 | Primitive::Type type_; |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4586 | bool is_live_; |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4587 | bool can_be_null_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4588 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4589 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 4590 | }; |
| 4591 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4592 | class HNullCheck : public HExpression<1> { |
| 4593 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4594 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
| 4595 | // constructor. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4596 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4597 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4598 | SetRawInputAt(0, value); |
| 4599 | } |
| 4600 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4601 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4602 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4603 | return true; |
| 4604 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4605 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4606 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4607 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4608 | bool CanThrow() const OVERRIDE { return true; } |
| 4609 | |
| 4610 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4611 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4612 | |
| 4613 | DECLARE_INSTRUCTION(NullCheck); |
| 4614 | |
| 4615 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4616 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 4617 | }; |
| 4618 | |
| 4619 | class FieldInfo : public ValueObject { |
| 4620 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4621 | FieldInfo(MemberOffset field_offset, |
| 4622 | Primitive::Type field_type, |
| 4623 | bool is_volatile, |
| 4624 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4625 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4626 | const DexFile& dex_file, |
| 4627 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4628 | : field_offset_(field_offset), |
| 4629 | field_type_(field_type), |
| 4630 | is_volatile_(is_volatile), |
| 4631 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4632 | declaring_class_def_index_(declaring_class_def_index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4633 | dex_file_(dex_file), |
| 4634 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4635 | |
| 4636 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4637 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4638 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4639 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4640 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4641 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4642 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4643 | |
| 4644 | private: |
| 4645 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4646 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4647 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4648 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4649 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4650 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4651 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4652 | }; |
| 4653 | |
| 4654 | class HInstanceFieldGet : public HExpression<1> { |
| 4655 | public: |
| 4656 | HInstanceFieldGet(HInstruction* value, |
| 4657 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4658 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4659 | bool is_volatile, |
| 4660 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4661 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4662 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4663 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4664 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4665 | : HExpression(field_type, |
| 4666 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 4667 | dex_pc), |
| 4668 | field_info_(field_offset, |
| 4669 | field_type, |
| 4670 | is_volatile, |
| 4671 | field_idx, |
| 4672 | declaring_class_def_index, |
| 4673 | dex_file, |
| 4674 | dex_cache) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4675 | SetRawInputAt(0, value); |
| 4676 | } |
| 4677 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 4678 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4679 | |
| 4680 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4681 | HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
| 4682 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4683 | } |
| 4684 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4685 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4686 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4687 | } |
| 4688 | |
| 4689 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 4690 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 4691 | } |
| 4692 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4693 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4694 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4695 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4696 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4697 | |
| 4698 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 4699 | |
| 4700 | private: |
| 4701 | const FieldInfo field_info_; |
| 4702 | |
| 4703 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 4704 | }; |
| 4705 | |
| 4706 | class HInstanceFieldSet : public HTemplateInstruction<2> { |
| 4707 | public: |
| 4708 | HInstanceFieldSet(HInstruction* object, |
| 4709 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4710 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4711 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4712 | bool is_volatile, |
| 4713 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4714 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4715 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4716 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4717 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4718 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 4719 | dex_pc), |
| 4720 | field_info_(field_offset, |
| 4721 | field_type, |
| 4722 | is_volatile, |
| 4723 | field_idx, |
| 4724 | declaring_class_def_index, |
| 4725 | dex_file, |
| 4726 | dex_cache), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4727 | value_can_be_null_(true) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4728 | SetRawInputAt(0, object); |
| 4729 | SetRawInputAt(1, value); |
| 4730 | } |
| 4731 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4732 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4733 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4734 | } |
| 4735 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4736 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4737 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4738 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4739 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4740 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4741 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 4742 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4743 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4744 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 4745 | |
| 4746 | private: |
| 4747 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4748 | bool value_can_be_null_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4749 | |
| 4750 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 4751 | }; |
| 4752 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4753 | class HArrayGet : public HExpression<2> { |
| 4754 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4755 | HArrayGet(HInstruction* array, |
| 4756 | HInstruction* index, |
| 4757 | Primitive::Type type, |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4758 | uint32_t dex_pc, |
| 4759 | SideEffects additional_side_effects = SideEffects::None()) |
| 4760 | : HExpression(type, |
| 4761 | SideEffects::ArrayReadOfType(type).Union(additional_side_effects), |
David Brazdil | 2bd4c5c | 2015-11-04 22:48:45 +0000 | [diff] [blame] | 4762 | dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4763 | SetRawInputAt(0, array); |
| 4764 | SetRawInputAt(1, index); |
| 4765 | } |
| 4766 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4767 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4768 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4769 | return true; |
| 4770 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4771 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4772 | // TODO: We can be smarter here. |
| 4773 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 4774 | // which generates the implicit null check. There are cases when these can be removed |
| 4775 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 4776 | // implicit check here (as long as the address falls in the first page). |
| 4777 | return false; |
| 4778 | } |
| 4779 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 4780 | bool IsEquivalentOf(HArrayGet* other) const { |
| 4781 | bool result = (GetDexPc() == other->GetDexPc()); |
| 4782 | if (kIsDebugBuild && result) { |
| 4783 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 4784 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 4785 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
| 4786 | if (Primitive::IsIntOrLongType(GetType())) { |
| 4787 | DCHECK(Primitive::IsFloatingPointType(other->GetType())); |
| 4788 | } else { |
| 4789 | DCHECK(Primitive::IsFloatingPointType(GetType())); |
| 4790 | DCHECK(Primitive::IsIntOrLongType(other->GetType())); |
| 4791 | } |
| 4792 | } |
| 4793 | return result; |
| 4794 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4795 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4796 | HInstruction* GetArray() const { return InputAt(0); } |
| 4797 | HInstruction* GetIndex() const { return InputAt(1); } |
| 4798 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4799 | DECLARE_INSTRUCTION(ArrayGet); |
| 4800 | |
| 4801 | private: |
| 4802 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 4803 | }; |
| 4804 | |
| 4805 | class HArraySet : public HTemplateInstruction<3> { |
| 4806 | public: |
| 4807 | HArraySet(HInstruction* array, |
| 4808 | HInstruction* index, |
| 4809 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4810 | Primitive::Type expected_component_type, |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4811 | uint32_t dex_pc, |
| 4812 | SideEffects additional_side_effects = SideEffects::None()) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4813 | : HTemplateInstruction( |
| 4814 | SideEffects::ArrayWriteOfType(expected_component_type).Union( |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4815 | SideEffectsForArchRuntimeCalls(value->GetType())).Union( |
| 4816 | additional_side_effects), |
| 4817 | dex_pc), |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4818 | expected_component_type_(expected_component_type), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4819 | needs_type_check_(value->GetType() == Primitive::kPrimNot), |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4820 | value_can_be_null_(true), |
| 4821 | static_type_of_array_is_object_array_(false) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4822 | SetRawInputAt(0, array); |
| 4823 | SetRawInputAt(1, index); |
| 4824 | SetRawInputAt(2, value); |
| 4825 | } |
| 4826 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4827 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 4828 | // We call a runtime method to throw ArrayStoreException. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4829 | return needs_type_check_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4830 | } |
| 4831 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 4832 | // Can throw ArrayStoreException. |
| 4833 | bool CanThrow() const OVERRIDE { return needs_type_check_; } |
| 4834 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4835 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4836 | // TODO: Same as for ArrayGet. |
| 4837 | return false; |
| 4838 | } |
| 4839 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4840 | void ClearNeedsTypeCheck() { |
| 4841 | needs_type_check_ = false; |
| 4842 | } |
| 4843 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4844 | void ClearValueCanBeNull() { |
| 4845 | value_can_be_null_ = false; |
| 4846 | } |
| 4847 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4848 | void SetStaticTypeOfArrayIsObjectArray() { |
| 4849 | static_type_of_array_is_object_array_ = true; |
| 4850 | } |
| 4851 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4852 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4853 | bool NeedsTypeCheck() const { return needs_type_check_; } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4854 | bool StaticTypeOfArrayIsObjectArray() const { return static_type_of_array_is_object_array_; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4855 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4856 | HInstruction* GetArray() const { return InputAt(0); } |
| 4857 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4858 | HInstruction* GetValue() const { return InputAt(2); } |
| 4859 | |
| 4860 | Primitive::Type GetComponentType() const { |
| 4861 | // The Dex format does not type floating point index operations. Since the |
| 4862 | // `expected_component_type_` is set during building and can therefore not |
| 4863 | // be correct, we also check what is the value type. If it is a floating |
| 4864 | // point type, we must use that type. |
| 4865 | Primitive::Type value_type = GetValue()->GetType(); |
| 4866 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 4867 | ? value_type |
| 4868 | : expected_component_type_; |
| 4869 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4870 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4871 | Primitive::Type GetRawExpectedComponentType() const { |
| 4872 | return expected_component_type_; |
| 4873 | } |
| 4874 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4875 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 4876 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 4877 | } |
| 4878 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4879 | DECLARE_INSTRUCTION(ArraySet); |
| 4880 | |
| 4881 | private: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4882 | const Primitive::Type expected_component_type_; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4883 | bool needs_type_check_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4884 | bool value_can_be_null_; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4885 | // Cached information for the reference_type_info_ so that codegen |
| 4886 | // does not need to inspect the static type. |
| 4887 | bool static_type_of_array_is_object_array_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4888 | |
| 4889 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 4890 | }; |
| 4891 | |
| 4892 | class HArrayLength : public HExpression<1> { |
| 4893 | public: |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 4894 | HArrayLength(HInstruction* array, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4895 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4896 | // Note that arrays do not change length, so the instruction does not |
| 4897 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4898 | SetRawInputAt(0, array); |
| 4899 | } |
| 4900 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4901 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4902 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4903 | return true; |
| 4904 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4905 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4906 | return obj == InputAt(0); |
| 4907 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4908 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4909 | DECLARE_INSTRUCTION(ArrayLength); |
| 4910 | |
| 4911 | private: |
| 4912 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 4913 | }; |
| 4914 | |
| 4915 | class HBoundsCheck : public HExpression<2> { |
| 4916 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4917 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
| 4918 | // constructor. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4919 | HBoundsCheck(HInstruction* index, HInstruction* length, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4920 | : HExpression(index->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4921 | DCHECK(index->GetType() == Primitive::kPrimInt); |
| 4922 | SetRawInputAt(0, index); |
| 4923 | SetRawInputAt(1, length); |
| 4924 | } |
| 4925 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4926 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4927 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4928 | return true; |
| 4929 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4930 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4931 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4932 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4933 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4934 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4935 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4936 | |
| 4937 | DECLARE_INSTRUCTION(BoundsCheck); |
| 4938 | |
| 4939 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4940 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 4941 | }; |
| 4942 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4943 | class HSuspendCheck : public HTemplateInstruction<0> { |
| 4944 | public: |
| 4945 | explicit HSuspendCheck(uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4946 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4947 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4948 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4949 | return true; |
| 4950 | } |
| 4951 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4952 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 4953 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4954 | |
| 4955 | DECLARE_INSTRUCTION(SuspendCheck); |
| 4956 | |
| 4957 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4958 | // Only used for code generation, in order to share the same slow path between back edges |
| 4959 | // of a same loop. |
| 4960 | SlowPathCode* slow_path_; |
| 4961 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4962 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 4963 | }; |
| 4964 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4965 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 4966 | // It ensures that we can generate line number and local variables at this point. |
| 4967 | class HNativeDebugInfo : public HTemplateInstruction<0> { |
| 4968 | public: |
| 4969 | explicit HNativeDebugInfo(uint32_t dex_pc) |
| 4970 | : HTemplateInstruction<0>(SideEffects::None(), dex_pc) {} |
| 4971 | |
| 4972 | bool NeedsEnvironment() const OVERRIDE { |
| 4973 | return true; |
| 4974 | } |
| 4975 | |
| 4976 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 4977 | |
| 4978 | private: |
| 4979 | DISALLOW_COPY_AND_ASSIGN(HNativeDebugInfo); |
| 4980 | }; |
| 4981 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4982 | /** |
| 4983 | * Instruction to load a Class object. |
| 4984 | */ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4985 | class HLoadClass : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4986 | public: |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4987 | HLoadClass(HCurrentMethod* current_method, |
| 4988 | uint16_t type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4989 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4990 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4991 | uint32_t dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4992 | bool needs_access_check, |
| 4993 | bool is_in_dex_cache) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4994 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4995 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4996 | dex_file_(dex_file), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4997 | is_referrers_class_(is_referrers_class), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4998 | generate_clinit_check_(false), |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4999 | needs_access_check_(needs_access_check), |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5000 | is_in_dex_cache_(is_in_dex_cache), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5001 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5002 | // Referrers class should not need access check. We never inline unverified |
| 5003 | // methods so we can't possibly end up in this situation. |
| 5004 | DCHECK(!is_referrers_class_ || !needs_access_check_); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5005 | SetRawInputAt(0, current_method); |
| 5006 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5007 | |
| 5008 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5009 | |
| 5010 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | a9a306d | 2015-10-08 16:48:31 +0100 | [diff] [blame] | 5011 | // Note that we don't need to test for generate_clinit_check_. |
| 5012 | // Whether or not we need to generate the clinit check is processed in |
| 5013 | // prepare_for_register_allocator based on existing HInvokes and HClinitChecks. |
Calin Juravle | 386062d | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5014 | return other->AsLoadClass()->type_index_ == type_index_ && |
| 5015 | other->AsLoadClass()->needs_access_check_ == needs_access_check_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5016 | } |
| 5017 | |
| 5018 | size_t ComputeHashCode() const OVERRIDE { return type_index_; } |
| 5019 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5020 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5021 | bool IsReferrersClass() const { return is_referrers_class_; } |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 5022 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5023 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5024 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5025 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5026 | } |
| 5027 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5028 | bool MustGenerateClinitCheck() const { |
| 5029 | return generate_clinit_check_; |
| 5030 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5031 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 5032 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 5033 | // The entrypoint the code generator is going to call does not do |
| 5034 | // clinit of the class. |
| 5035 | DCHECK(!NeedsAccessCheck()); |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 5036 | generate_clinit_check_ = generate_clinit_check; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5037 | } |
| 5038 | |
| 5039 | bool CanCallRuntime() const { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5040 | return MustGenerateClinitCheck() || |
| 5041 | (!is_referrers_class_ && !is_in_dex_cache_) || |
| 5042 | needs_access_check_; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5043 | } |
| 5044 | |
| 5045 | bool NeedsAccessCheck() const { |
| 5046 | return needs_access_check_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5047 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5048 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5049 | bool CanThrow() const OVERRIDE { |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 5050 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5051 | } |
| 5052 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5053 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 5054 | return loaded_class_rti_; |
| 5055 | } |
| 5056 | |
| 5057 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 5058 | // Make sure we only set exact types (the loaded class should never be merged). |
| 5059 | DCHECK(rti.IsExact()); |
| 5060 | loaded_class_rti_ = rti; |
| 5061 | } |
| 5062 | |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5063 | const DexFile& GetDexFile() { return dex_file_; } |
| 5064 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5065 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return !is_referrers_class_; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 5066 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5067 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5068 | return SideEffects::CanTriggerGC(); |
| 5069 | } |
| 5070 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5071 | bool IsInDexCache() const { return is_in_dex_cache_; } |
| 5072 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5073 | DECLARE_INSTRUCTION(LoadClass); |
| 5074 | |
| 5075 | private: |
| 5076 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5077 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5078 | const bool is_referrers_class_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5079 | // Whether this instruction must generate the initialization check. |
| 5080 | // Used for code generation. |
| 5081 | bool generate_clinit_check_; |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5082 | const bool needs_access_check_; |
| 5083 | const bool is_in_dex_cache_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5084 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5085 | ReferenceTypeInfo loaded_class_rti_; |
| 5086 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5087 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 5088 | }; |
| 5089 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5090 | class HLoadString : public HExpression<1> { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5091 | public: |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5092 | HLoadString(HCurrentMethod* current_method, |
| 5093 | uint32_t string_index, |
| 5094 | uint32_t dex_pc, |
| 5095 | bool is_in_dex_cache) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5096 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5097 | string_index_(string_index), |
| 5098 | is_in_dex_cache_(is_in_dex_cache) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5099 | SetRawInputAt(0, current_method); |
| 5100 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5101 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5102 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5103 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5104 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 5105 | return other->AsLoadString()->string_index_ == string_index_; |
| 5106 | } |
| 5107 | |
| 5108 | size_t ComputeHashCode() const OVERRIDE { return string_index_; } |
| 5109 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5110 | uint32_t GetStringIndex() const { return string_index_; } |
| 5111 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5112 | // Will call the runtime if the string is not already in the dex cache. |
| 5113 | bool NeedsEnvironment() const OVERRIDE { return !IsInDexCache(); } |
| 5114 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5115 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return true; } |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 5116 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5117 | bool IsInDexCache() const { return is_in_dex_cache_; } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5118 | bool CanThrow() const OVERRIDE { return !IsInDexCache(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5119 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5120 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5121 | return SideEffects::CanTriggerGC(); |
| 5122 | } |
| 5123 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5124 | DECLARE_INSTRUCTION(LoadString); |
| 5125 | |
| 5126 | private: |
| 5127 | const uint32_t string_index_; |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5128 | const bool is_in_dex_cache_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5129 | |
| 5130 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 5131 | }; |
| 5132 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5133 | /** |
| 5134 | * Performs an initialization check on its Class object input. |
| 5135 | */ |
| 5136 | class HClinitCheck : public HExpression<1> { |
| 5137 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 5138 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 5139 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5140 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5141 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 5142 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5143 | SetRawInputAt(0, constant); |
| 5144 | } |
| 5145 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5146 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5147 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5148 | return true; |
| 5149 | } |
| 5150 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5151 | bool NeedsEnvironment() const OVERRIDE { |
| 5152 | // May call runtime to initialize the class. |
| 5153 | return true; |
| 5154 | } |
| 5155 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 5156 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5157 | |
| 5158 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 5159 | |
| 5160 | DECLARE_INSTRUCTION(ClinitCheck); |
| 5161 | |
| 5162 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5163 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 5164 | }; |
| 5165 | |
| 5166 | class HStaticFieldGet : public HExpression<1> { |
| 5167 | public: |
| 5168 | HStaticFieldGet(HInstruction* cls, |
| 5169 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5170 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5171 | bool is_volatile, |
| 5172 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5173 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5174 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5175 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5176 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5177 | : HExpression(field_type, |
| 5178 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5179 | dex_pc), |
| 5180 | field_info_(field_offset, |
| 5181 | field_type, |
| 5182 | is_volatile, |
| 5183 | field_idx, |
| 5184 | declaring_class_def_index, |
| 5185 | dex_file, |
| 5186 | dex_cache) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5187 | SetRawInputAt(0, cls); |
| 5188 | } |
| 5189 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5190 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5191 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5192 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5193 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5194 | HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
| 5195 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5196 | } |
| 5197 | |
| 5198 | size_t ComputeHashCode() const OVERRIDE { |
| 5199 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5200 | } |
| 5201 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5202 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5203 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5204 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5205 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5206 | |
| 5207 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 5208 | |
| 5209 | private: |
| 5210 | const FieldInfo field_info_; |
| 5211 | |
| 5212 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 5213 | }; |
| 5214 | |
| 5215 | class HStaticFieldSet : public HTemplateInstruction<2> { |
| 5216 | public: |
| 5217 | HStaticFieldSet(HInstruction* cls, |
| 5218 | HInstruction* value, |
| 5219 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5220 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5221 | bool is_volatile, |
| 5222 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5223 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5224 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5225 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5226 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5227 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5228 | dex_pc), |
| 5229 | field_info_(field_offset, |
| 5230 | field_type, |
| 5231 | is_volatile, |
| 5232 | field_idx, |
| 5233 | declaring_class_def_index, |
| 5234 | dex_file, |
| 5235 | dex_cache), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5236 | value_can_be_null_(true) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5237 | SetRawInputAt(0, cls); |
| 5238 | SetRawInputAt(1, value); |
| 5239 | } |
| 5240 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5241 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5242 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5243 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5244 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5245 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5246 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5247 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 5248 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5249 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5250 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 5251 | |
| 5252 | private: |
| 5253 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5254 | bool value_can_be_null_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5255 | |
| 5256 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 5257 | }; |
| 5258 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5259 | class HUnresolvedInstanceFieldGet : public HExpression<1> { |
| 5260 | public: |
| 5261 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 5262 | Primitive::Type field_type, |
| 5263 | uint32_t field_index, |
| 5264 | uint32_t dex_pc) |
| 5265 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5266 | field_index_(field_index) { |
| 5267 | SetRawInputAt(0, obj); |
| 5268 | } |
| 5269 | |
| 5270 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5271 | bool CanThrow() const OVERRIDE { return true; } |
| 5272 | |
| 5273 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5274 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5275 | |
| 5276 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 5277 | |
| 5278 | private: |
| 5279 | const uint32_t field_index_; |
| 5280 | |
| 5281 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 5282 | }; |
| 5283 | |
| 5284 | class HUnresolvedInstanceFieldSet : public HTemplateInstruction<2> { |
| 5285 | public: |
| 5286 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 5287 | HInstruction* value, |
| 5288 | Primitive::Type field_type, |
| 5289 | uint32_t field_index, |
| 5290 | uint32_t dex_pc) |
| 5291 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
| 5292 | field_type_(field_type), |
| 5293 | field_index_(field_index) { |
| 5294 | DCHECK_EQ(field_type, value->GetType()); |
| 5295 | SetRawInputAt(0, obj); |
| 5296 | SetRawInputAt(1, value); |
| 5297 | } |
| 5298 | |
| 5299 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5300 | bool CanThrow() const OVERRIDE { return true; } |
| 5301 | |
| 5302 | Primitive::Type GetFieldType() const { return field_type_; } |
| 5303 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5304 | |
| 5305 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 5306 | |
| 5307 | private: |
| 5308 | const Primitive::Type field_type_; |
| 5309 | const uint32_t field_index_; |
| 5310 | |
| 5311 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 5312 | }; |
| 5313 | |
| 5314 | class HUnresolvedStaticFieldGet : public HExpression<0> { |
| 5315 | public: |
| 5316 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 5317 | uint32_t field_index, |
| 5318 | uint32_t dex_pc) |
| 5319 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5320 | field_index_(field_index) { |
| 5321 | } |
| 5322 | |
| 5323 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5324 | bool CanThrow() const OVERRIDE { return true; } |
| 5325 | |
| 5326 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5327 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5328 | |
| 5329 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 5330 | |
| 5331 | private: |
| 5332 | const uint32_t field_index_; |
| 5333 | |
| 5334 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 5335 | }; |
| 5336 | |
| 5337 | class HUnresolvedStaticFieldSet : public HTemplateInstruction<1> { |
| 5338 | public: |
| 5339 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 5340 | Primitive::Type field_type, |
| 5341 | uint32_t field_index, |
| 5342 | uint32_t dex_pc) |
| 5343 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
| 5344 | field_type_(field_type), |
| 5345 | field_index_(field_index) { |
| 5346 | DCHECK_EQ(field_type, value->GetType()); |
| 5347 | SetRawInputAt(0, value); |
| 5348 | } |
| 5349 | |
| 5350 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5351 | bool CanThrow() const OVERRIDE { return true; } |
| 5352 | |
| 5353 | Primitive::Type GetFieldType() const { return field_type_; } |
| 5354 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5355 | |
| 5356 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 5357 | |
| 5358 | private: |
| 5359 | const Primitive::Type field_type_; |
| 5360 | const uint32_t field_index_; |
| 5361 | |
| 5362 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 5363 | }; |
| 5364 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5365 | // Implement the move-exception DEX instruction. |
| 5366 | class HLoadException : public HExpression<0> { |
| 5367 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5368 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 5369 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5370 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 5371 | bool CanBeNull() const OVERRIDE { return false; } |
| 5372 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5373 | DECLARE_INSTRUCTION(LoadException); |
| 5374 | |
| 5375 | private: |
| 5376 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 5377 | }; |
| 5378 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5379 | // Implicit part of move-exception which clears thread-local exception storage. |
| 5380 | // Must not be removed because the runtime expects the TLS to get cleared. |
| 5381 | class HClearException : public HTemplateInstruction<0> { |
| 5382 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5383 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 5384 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5385 | |
| 5386 | DECLARE_INSTRUCTION(ClearException); |
| 5387 | |
| 5388 | private: |
| 5389 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 5390 | }; |
| 5391 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5392 | class HThrow : public HTemplateInstruction<1> { |
| 5393 | public: |
| 5394 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5395 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5396 | SetRawInputAt(0, exception); |
| 5397 | } |
| 5398 | |
| 5399 | bool IsControlFlow() const OVERRIDE { return true; } |
| 5400 | |
| 5401 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5402 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5403 | bool CanThrow() const OVERRIDE { return true; } |
| 5404 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5405 | |
| 5406 | DECLARE_INSTRUCTION(Throw); |
| 5407 | |
| 5408 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5409 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 5410 | }; |
| 5411 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5412 | /** |
| 5413 | * Implementation strategies for the code generator of a HInstanceOf |
| 5414 | * or `HCheckCast`. |
| 5415 | */ |
| 5416 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5417 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5418 | kExactCheck, // Can do a single class compare. |
| 5419 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 5420 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 5421 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 5422 | kArrayObjectCheck, // Can just check if the array is not primitive. |
| 5423 | kArrayCheck // No optimization yet when checking against a generic array. |
| 5424 | }; |
| 5425 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5426 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 5427 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5428 | class HInstanceOf : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5429 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5430 | HInstanceOf(HInstruction* object, |
| 5431 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5432 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5433 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5434 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5435 | SideEffectsForArchRuntimeCalls(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5436 | dex_pc), |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5437 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5438 | must_do_null_check_(true) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5439 | SetRawInputAt(0, object); |
| 5440 | SetRawInputAt(1, constant); |
| 5441 | } |
| 5442 | |
| 5443 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5444 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5445 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5446 | return true; |
| 5447 | } |
| 5448 | |
| 5449 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5450 | return CanCallRuntime(check_kind_); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5451 | } |
| 5452 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5453 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
| 5454 | |
| 5455 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5456 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5457 | // Used only in code generation. |
| 5458 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 5459 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
| 5460 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5461 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 5462 | // Mips currently does runtime calls for any other checks. |
| 5463 | return check_kind != TypeCheckKind::kExactCheck; |
| 5464 | } |
| 5465 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5466 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5467 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5468 | } |
| 5469 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5470 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5471 | |
| 5472 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5473 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5474 | bool must_do_null_check_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5475 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5476 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 5477 | }; |
| 5478 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5479 | class HBoundType : public HExpression<1> { |
| 5480 | public: |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5481 | HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5482 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5483 | upper_bound_(ReferenceTypeInfo::CreateInvalid()), |
| 5484 | upper_can_be_null_(true), |
| 5485 | can_be_null_(true) { |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 5486 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5487 | SetRawInputAt(0, input); |
| 5488 | } |
| 5489 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5490 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5491 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
| 5492 | bool GetUpperCanBeNull() const { return upper_can_be_null_; } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5493 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5494 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5495 | void SetCanBeNull(bool can_be_null) { |
| 5496 | DCHECK(upper_can_be_null_ || !can_be_null); |
| 5497 | can_be_null_ = can_be_null; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5498 | } |
| 5499 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5500 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 5501 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5502 | DECLARE_INSTRUCTION(BoundType); |
| 5503 | |
| 5504 | private: |
| 5505 | // 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] | 5506 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 5507 | // It is used to bound the type in cases like: |
| 5508 | // if (x instanceof ClassX) { |
| 5509 | // // uper_bound_ will be ClassX |
| 5510 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5511 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5512 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 5513 | // is false then can_be_null_ cannot be true). |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5514 | bool upper_can_be_null_; |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5515 | bool can_be_null_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5516 | |
| 5517 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 5518 | }; |
| 5519 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5520 | class HCheckCast : public HTemplateInstruction<2> { |
| 5521 | public: |
| 5522 | HCheckCast(HInstruction* object, |
| 5523 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5524 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5525 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5526 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5527 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5528 | must_do_null_check_(true) { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5529 | SetRawInputAt(0, object); |
| 5530 | SetRawInputAt(1, constant); |
| 5531 | } |
| 5532 | |
| 5533 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5534 | |
| 5535 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5536 | return true; |
| 5537 | } |
| 5538 | |
| 5539 | bool NeedsEnvironment() const OVERRIDE { |
| 5540 | // Instruction may throw a CheckCastError. |
| 5541 | return true; |
| 5542 | } |
| 5543 | |
| 5544 | bool CanThrow() const OVERRIDE { return true; } |
| 5545 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5546 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 5547 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5548 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5549 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5550 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5551 | |
| 5552 | DECLARE_INSTRUCTION(CheckCast); |
| 5553 | |
| 5554 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5555 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5556 | bool must_do_null_check_; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5557 | |
| 5558 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5559 | }; |
| 5560 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5561 | class HMemoryBarrier : public HTemplateInstruction<0> { |
| 5562 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5563 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 5564 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5565 | SideEffects::AllWritesAndReads(), dex_pc), // Assume write/read on all fields/arrays. |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5566 | barrier_kind_(barrier_kind) {} |
| 5567 | |
| 5568 | MemBarrierKind GetBarrierKind() { return barrier_kind_; } |
| 5569 | |
| 5570 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 5571 | |
| 5572 | private: |
| 5573 | const MemBarrierKind barrier_kind_; |
| 5574 | |
| 5575 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 5576 | }; |
| 5577 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5578 | class HMonitorOperation : public HTemplateInstruction<1> { |
| 5579 | public: |
| 5580 | enum OperationKind { |
| 5581 | kEnter, |
| 5582 | kExit, |
| 5583 | }; |
| 5584 | |
| 5585 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5586 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5587 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
| 5588 | kind_(kind) { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5589 | SetRawInputAt(0, object); |
| 5590 | } |
| 5591 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5592 | // Instruction may go into runtime, so we need an environment. |
| 5593 | bool NeedsEnvironment() const OVERRIDE { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 5594 | |
| 5595 | bool CanThrow() const OVERRIDE { |
| 5596 | // Verifier guarantees that monitor-exit cannot throw. |
| 5597 | // This is important because it allows the HGraphBuilder to remove |
| 5598 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 5599 | return IsEnter(); |
| 5600 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5601 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5602 | |
| 5603 | bool IsEnter() const { return kind_ == kEnter; } |
| 5604 | |
| 5605 | DECLARE_INSTRUCTION(MonitorOperation); |
| 5606 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5607 | private: |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5608 | const OperationKind kind_; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5609 | |
| 5610 | private: |
| 5611 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 5612 | }; |
| 5613 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5614 | class HSelect : public HExpression<3> { |
| 5615 | public: |
| 5616 | HSelect(HInstruction* condition, |
| 5617 | HInstruction* true_value, |
| 5618 | HInstruction* false_value, |
| 5619 | uint32_t dex_pc) |
| 5620 | : HExpression(HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
| 5621 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 5622 | |
| 5623 | // First input must be `true_value` or `false_value` to allow codegens to |
| 5624 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 5625 | // that architectures which implement HSelect as a conditional move also |
| 5626 | // will not need to invert the condition. |
| 5627 | SetRawInputAt(0, false_value); |
| 5628 | SetRawInputAt(1, true_value); |
| 5629 | SetRawInputAt(2, condition); |
| 5630 | } |
| 5631 | |
| 5632 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 5633 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 5634 | HInstruction* GetCondition() const { return InputAt(2); } |
| 5635 | |
| 5636 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5637 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
| 5638 | |
| 5639 | bool CanBeNull() const OVERRIDE { |
| 5640 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 5641 | } |
| 5642 | |
| 5643 | DECLARE_INSTRUCTION(Select); |
| 5644 | |
| 5645 | private: |
| 5646 | DISALLOW_COPY_AND_ASSIGN(HSelect); |
| 5647 | }; |
| 5648 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 5649 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5650 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5651 | MoveOperands(Location source, |
| 5652 | Location destination, |
| 5653 | Primitive::Type type, |
| 5654 | HInstruction* instruction) |
| 5655 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5656 | |
| 5657 | Location GetSource() const { return source_; } |
| 5658 | Location GetDestination() const { return destination_; } |
| 5659 | |
| 5660 | void SetSource(Location value) { source_ = value; } |
| 5661 | void SetDestination(Location value) { destination_ = value; } |
| 5662 | |
| 5663 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 5664 | // destination (but not the source). |
| 5665 | Location MarkPending() { |
| 5666 | DCHECK(!IsPending()); |
| 5667 | Location dest = destination_; |
| 5668 | destination_ = Location::NoLocation(); |
| 5669 | return dest; |
| 5670 | } |
| 5671 | |
| 5672 | void ClearPending(Location dest) { |
| 5673 | DCHECK(IsPending()); |
| 5674 | destination_ = dest; |
| 5675 | } |
| 5676 | |
| 5677 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5678 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 5679 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5680 | } |
| 5681 | |
| 5682 | // True if this blocks a move from the given location. |
| 5683 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 5684 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5685 | } |
| 5686 | |
| 5687 | // A move is redundant if it's been eliminated, if its source and |
| 5688 | // destination are the same, or if its destination is unneeded. |
| 5689 | bool IsRedundant() const { |
| 5690 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 5691 | } |
| 5692 | |
| 5693 | // We clear both operands to indicate move that's been eliminated. |
| 5694 | void Eliminate() { |
| 5695 | source_ = destination_ = Location::NoLocation(); |
| 5696 | } |
| 5697 | |
| 5698 | bool IsEliminated() const { |
| 5699 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 5700 | return source_.IsInvalid(); |
| 5701 | } |
| 5702 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5703 | Primitive::Type GetType() const { return type_; } |
| 5704 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5705 | bool Is64BitMove() const { |
| 5706 | return Primitive::Is64BitType(type_); |
| 5707 | } |
| 5708 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5709 | HInstruction* GetInstruction() const { return instruction_; } |
| 5710 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5711 | private: |
| 5712 | Location source_; |
| 5713 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5714 | // The type this move is for. |
| 5715 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5716 | // The instruction this move is assocatied with. Null when this move is |
| 5717 | // for moving an input in the expected locations of user (including a phi user). |
| 5718 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 5719 | // in the same parallel move. |
| 5720 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5721 | }; |
| 5722 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5723 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 5724 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5725 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 5726 | |
| 5727 | class HParallelMove : public HTemplateInstruction<0> { |
| 5728 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5729 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5730 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 5731 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 5732 | moves_.reserve(kDefaultNumberOfMoves); |
| 5733 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5734 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5735 | void AddMove(Location source, |
| 5736 | Location destination, |
| 5737 | Primitive::Type type, |
| 5738 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5739 | DCHECK(source.IsValid()); |
| 5740 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5741 | if (kIsDebugBuild) { |
| 5742 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5743 | for (const MoveOperands& move : moves_) { |
| 5744 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5745 | // Special case the situation where the move is for the spill slot |
| 5746 | // of the instruction. |
| 5747 | if ((GetPrevious() == instruction) |
| 5748 | || ((GetPrevious() == nullptr) |
| 5749 | && instruction->IsPhi() |
| 5750 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5751 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5752 | << "Doing parallel moves for the same instruction."; |
| 5753 | } else { |
| 5754 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 5755 | } |
| 5756 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 5757 | } |
| 5758 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5759 | for (const MoveOperands& move : moves_) { |
| 5760 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5761 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5762 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5763 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5764 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5765 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5766 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5767 | } |
| 5768 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5769 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5770 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5771 | } |
| 5772 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5773 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5774 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 5775 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5776 | |
| 5777 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5778 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5779 | |
| 5780 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 5781 | }; |
| 5782 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5783 | } // namespace art |
| 5784 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 5785 | #ifdef ART_ENABLE_CODEGEN_arm |
| 5786 | #include "nodes_arm.h" |
| 5787 | #endif |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5788 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| 5789 | #include "nodes_arm64.h" |
| 5790 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5791 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 5792 | #include "nodes_x86.h" |
| 5793 | #endif |
| 5794 | |
| 5795 | namespace art { |
| 5796 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5797 | class HGraphVisitor : public ValueObject { |
| 5798 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 5799 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 5800 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5801 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5802 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5803 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 5804 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5805 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5806 | void VisitInsertionOrder(); |
| 5807 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5808 | // Visit the graph following dominator tree reverse post-order. |
| 5809 | void VisitReversePostOrder(); |
| 5810 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 5811 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 5812 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5813 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5814 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5815 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 5816 | |
| 5817 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5818 | |
| 5819 | #undef DECLARE_VISIT_INSTRUCTION |
| 5820 | |
| 5821 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 5822 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5823 | |
| 5824 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 5825 | }; |
| 5826 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5827 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 5828 | public: |
| 5829 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 5830 | virtual ~HGraphDelegateVisitor() {} |
| 5831 | |
| 5832 | // Visit functions that delegate to to super class. |
| 5833 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5834 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5835 | |
| 5836 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5837 | |
| 5838 | #undef DECLARE_VISIT_INSTRUCTION |
| 5839 | |
| 5840 | private: |
| 5841 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 5842 | }; |
| 5843 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5844 | class HInsertionOrderIterator : public ValueObject { |
| 5845 | public: |
| 5846 | explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {} |
| 5847 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5848 | bool Done() const { return index_ == graph_.GetBlocks().size(); } |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 5849 | HBasicBlock* Current() const { return graph_.GetBlocks()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5850 | void Advance() { ++index_; } |
| 5851 | |
| 5852 | private: |
| 5853 | const HGraph& graph_; |
| 5854 | size_t index_; |
| 5855 | |
| 5856 | DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator); |
| 5857 | }; |
| 5858 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5859 | class HReversePostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5860 | public: |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5861 | explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) { |
| 5862 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5863 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5864 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5865 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5866 | bool Done() const { return index_ == graph_.GetReversePostOrder().size(); } |
| 5867 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5868 | void Advance() { ++index_; } |
| 5869 | |
| 5870 | private: |
| 5871 | const HGraph& graph_; |
| 5872 | size_t index_; |
| 5873 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5874 | DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5875 | }; |
| 5876 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5877 | class HPostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5878 | public: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5879 | explicit HPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5880 | : graph_(graph), index_(graph_.GetReversePostOrder().size()) { |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5881 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5882 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5883 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5884 | |
| 5885 | bool Done() const { return index_ == 0; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5886 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_ - 1u]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5887 | void Advance() { --index_; } |
| 5888 | |
| 5889 | private: |
| 5890 | const HGraph& graph_; |
| 5891 | size_t index_; |
| 5892 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5893 | DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5894 | }; |
| 5895 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5896 | class HLinearPostOrderIterator : public ValueObject { |
| 5897 | public: |
| 5898 | explicit HLinearPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5899 | : order_(graph.GetLinearOrder()), index_(graph.GetLinearOrder().size()) {} |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5900 | |
| 5901 | bool Done() const { return index_ == 0; } |
| 5902 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5903 | HBasicBlock* Current() const { return order_[index_ - 1u]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5904 | |
| 5905 | void Advance() { |
| 5906 | --index_; |
| 5907 | DCHECK_GE(index_, 0U); |
| 5908 | } |
| 5909 | |
| 5910 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5911 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5912 | size_t index_; |
| 5913 | |
| 5914 | DISALLOW_COPY_AND_ASSIGN(HLinearPostOrderIterator); |
| 5915 | }; |
| 5916 | |
| 5917 | class HLinearOrderIterator : public ValueObject { |
| 5918 | public: |
| 5919 | explicit HLinearOrderIterator(const HGraph& graph) |
| 5920 | : order_(graph.GetLinearOrder()), index_(0) {} |
| 5921 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5922 | bool Done() const { return index_ == order_.size(); } |
| 5923 | HBasicBlock* Current() const { return order_[index_]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5924 | void Advance() { ++index_; } |
| 5925 | |
| 5926 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5927 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5928 | size_t index_; |
| 5929 | |
| 5930 | DISALLOW_COPY_AND_ASSIGN(HLinearOrderIterator); |
| 5931 | }; |
| 5932 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5933 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5934 | // of an inner loop. The order in which the blocks are iterated is on their |
| 5935 | // block id. |
| 5936 | class HBlocksInLoopIterator : public ValueObject { |
| 5937 | public: |
| 5938 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 5939 | : blocks_in_loop_(info.GetBlocks()), |
| 5940 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 5941 | index_(0) { |
| 5942 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 5943 | Advance(); |
| 5944 | } |
| 5945 | } |
| 5946 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5947 | bool Done() const { return index_ == blocks_.size(); } |
| 5948 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5949 | void Advance() { |
| 5950 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5951 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5952 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 5953 | break; |
| 5954 | } |
| 5955 | } |
| 5956 | } |
| 5957 | |
| 5958 | private: |
| 5959 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5960 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5961 | size_t index_; |
| 5962 | |
| 5963 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 5964 | }; |
| 5965 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5966 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5967 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 5968 | // post order. |
| 5969 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 5970 | public: |
| 5971 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 5972 | : blocks_in_loop_(info.GetBlocks()), |
| 5973 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 5974 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5975 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5976 | Advance(); |
| 5977 | } |
| 5978 | } |
| 5979 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5980 | bool Done() const { return index_ == blocks_.size(); } |
| 5981 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5982 | void Advance() { |
| 5983 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5984 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 5985 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5986 | break; |
| 5987 | } |
| 5988 | } |
| 5989 | } |
| 5990 | |
| 5991 | private: |
| 5992 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5993 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5994 | size_t index_; |
| 5995 | |
| 5996 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 5997 | }; |
| 5998 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 5999 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6000 | if (constant->IsIntConstant()) { |
| 6001 | return constant->AsIntConstant()->GetValue(); |
| 6002 | } else if (constant->IsLongConstant()) { |
| 6003 | return constant->AsLongConstant()->GetValue(); |
| 6004 | } else { |
| 6005 | DCHECK(constant->IsNullConstant()); |
| 6006 | return 0; |
| 6007 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6008 | } |
| 6009 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6010 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 6011 | // For the purposes of the compiler, the dex files must actually be the same object |
| 6012 | // if we want to safely treat them as the same. This is especially important for JIT |
| 6013 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 6014 | // times and provide different class resolution but no two class loaders should ever |
| 6015 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 6016 | // all sorts of weird failures. |
| 6017 | return &lhs == &rhs; |
| 6018 | } |
| 6019 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6020 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 6021 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } \ |
| 6022 | inline const H##type* HInstruction::As##type() const { \ |
| 6023 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 6024 | } \ |
| 6025 | inline H##type* HInstruction::As##type() { \ |
| 6026 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 6027 | } |
| 6028 | |
| 6029 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 6030 | #undef INSTRUCTION_TYPE_CHECK |
| 6031 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 6032 | class SwitchTable : public ValueObject { |
| 6033 | public: |
| 6034 | SwitchTable(const Instruction& instruction, uint32_t dex_pc, bool sparse) |
| 6035 | : instruction_(instruction), dex_pc_(dex_pc), sparse_(sparse) { |
| 6036 | int32_t table_offset = instruction.VRegB_31t(); |
| 6037 | const uint16_t* table = reinterpret_cast<const uint16_t*>(&instruction) + table_offset; |
| 6038 | if (sparse) { |
| 6039 | CHECK_EQ(table[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature)); |
| 6040 | } else { |
| 6041 | CHECK_EQ(table[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature)); |
| 6042 | } |
| 6043 | num_entries_ = table[1]; |
| 6044 | values_ = reinterpret_cast<const int32_t*>(&table[2]); |
| 6045 | } |
| 6046 | |
| 6047 | uint16_t GetNumEntries() const { |
| 6048 | return num_entries_; |
| 6049 | } |
| 6050 | |
| 6051 | void CheckIndex(size_t index) const { |
| 6052 | if (sparse_) { |
| 6053 | // In a sparse table, we have num_entries_ keys and num_entries_ values, in that order. |
| 6054 | DCHECK_LT(index, 2 * static_cast<size_t>(num_entries_)); |
| 6055 | } else { |
| 6056 | // In a packed table, we have the starting key and num_entries_ values. |
| 6057 | DCHECK_LT(index, 1 + static_cast<size_t>(num_entries_)); |
| 6058 | } |
| 6059 | } |
| 6060 | |
| 6061 | int32_t GetEntryAt(size_t index) const { |
| 6062 | CheckIndex(index); |
| 6063 | return values_[index]; |
| 6064 | } |
| 6065 | |
| 6066 | uint32_t GetDexPcForIndex(size_t index) const { |
| 6067 | CheckIndex(index); |
| 6068 | return dex_pc_ + |
| 6069 | (reinterpret_cast<const int16_t*>(values_ + index) - |
| 6070 | reinterpret_cast<const int16_t*>(&instruction_)); |
| 6071 | } |
| 6072 | |
| 6073 | // Index of the first value in the table. |
| 6074 | size_t GetFirstValueIndex() const { |
| 6075 | if (sparse_) { |
| 6076 | // In a sparse table, we have num_entries_ keys and num_entries_ values, in that order. |
| 6077 | return num_entries_; |
| 6078 | } else { |
| 6079 | // In a packed table, we have the starting key and num_entries_ values. |
| 6080 | return 1; |
| 6081 | } |
| 6082 | } |
| 6083 | |
| 6084 | private: |
| 6085 | const Instruction& instruction_; |
| 6086 | const uint32_t dex_pc_; |
| 6087 | |
| 6088 | // Whether this is a sparse-switch table (or a packed-switch one). |
| 6089 | const bool sparse_; |
| 6090 | |
| 6091 | // This can't be const as it needs to be computed off of the given instruction, and complicated |
| 6092 | // expressions in the initializer list seemed very ugly. |
| 6093 | uint16_t num_entries_; |
| 6094 | |
| 6095 | const int32_t* values_; |
| 6096 | |
| 6097 | DISALLOW_COPY_AND_ASSIGN(SwitchTable); |
| 6098 | }; |
| 6099 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6100 | } // namespace art |
| 6101 | |
| 6102 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |