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" |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 39 | #include "utils/intrusive_forward_list.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 40 | |
| 41 | namespace art { |
| 42 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 43 | class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 44 | class HBasicBlock; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 45 | class HCurrentMethod; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 46 | class HDoubleConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 47 | class HEnvironment; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 48 | class HFloatConstant; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 49 | class HGraphBuilder; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 50 | class HGraphVisitor; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 51 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 52 | class HIntConstant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 53 | class HInvoke; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 54 | class HLongConstant; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 55 | class HNullConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 56 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 57 | class HSuspendCheck; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 58 | class HTryBoundary; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 59 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 60 | class LocationSummary; |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 61 | class SlowPathCode; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 62 | class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 63 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 64 | namespace mirror { |
| 65 | class DexCache; |
| 66 | } // namespace mirror |
| 67 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 68 | static const int kDefaultNumberOfBlocks = 8; |
| 69 | static const int kDefaultNumberOfSuccessors = 2; |
| 70 | static const int kDefaultNumberOfPredecessors = 2; |
David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 71 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 72 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 73 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 74 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 75 | // The maximum (meaningful) distance (31) that can be used in an integer shift/rotate operation. |
| 76 | static constexpr int32_t kMaxIntShiftDistance = 0x1f; |
| 77 | // The maximum (meaningful) distance (63) that can be used in a long shift/rotate operation. |
| 78 | static constexpr int32_t kMaxLongShiftDistance = 0x3f; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 79 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 80 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 81 | static constexpr uint16_t kUnknownClassDefIndex = static_cast<uint16_t>(-1); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 82 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 83 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 84 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 85 | static constexpr uint32_t kNoDexPc = -1; |
| 86 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 87 | enum IfCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 88 | // All types. |
| 89 | kCondEQ, // == |
| 90 | kCondNE, // != |
| 91 | // Signed integers and floating-point numbers. |
| 92 | kCondLT, // < |
| 93 | kCondLE, // <= |
| 94 | kCondGT, // > |
| 95 | kCondGE, // >= |
| 96 | // Unsigned integers. |
| 97 | kCondB, // < |
| 98 | kCondBE, // <= |
| 99 | kCondA, // > |
| 100 | kCondAE, // >= |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 101 | }; |
| 102 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 103 | enum GraphAnalysisResult { |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 104 | kAnalysisSkipped, |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 105 | kAnalysisInvalidBytecode, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 106 | kAnalysisFailThrowCatchLoop, |
| 107 | kAnalysisFailAmbiguousArrayOp, |
| 108 | kAnalysisSuccess, |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 109 | }; |
| 110 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 111 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 112 | public: |
| 113 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 114 | |
| 115 | void AddInstruction(HInstruction* instruction); |
| 116 | void RemoveInstruction(HInstruction* instruction); |
| 117 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 118 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 119 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 120 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 121 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 122 | // Return true if this list contains `instruction`. |
| 123 | bool Contains(HInstruction* instruction) const; |
| 124 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 125 | // Return true if `instruction1` is found before `instruction2` in |
| 126 | // this instruction list and false otherwise. Abort if none |
| 127 | // of these instructions is found. |
| 128 | bool FoundBefore(const HInstruction* instruction1, |
| 129 | const HInstruction* instruction2) const; |
| 130 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 131 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 132 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 133 | |
| 134 | // Update the block of all instructions to be `block`. |
| 135 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 136 | |
| 137 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 138 | void AddBefore(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 139 | void Add(const HInstructionList& instruction_list); |
| 140 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 141 | // Return the number of instructions in the list. This is an expensive operation. |
| 142 | size_t CountSize() const; |
| 143 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 144 | private: |
| 145 | HInstruction* first_instruction_; |
| 146 | HInstruction* last_instruction_; |
| 147 | |
| 148 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 149 | friend class HGraph; |
| 150 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 151 | friend class HInstructionIterator; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 152 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 153 | |
| 154 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 155 | }; |
| 156 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 157 | class ReferenceTypeInfo : ValueObject { |
| 158 | public: |
| 159 | typedef Handle<mirror::Class> TypeHandle; |
| 160 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 161 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact); |
| 162 | |
| 163 | static ReferenceTypeInfo CreateUnchecked(TypeHandle type_handle, bool is_exact) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 164 | return ReferenceTypeInfo(type_handle, is_exact); |
| 165 | } |
| 166 | |
| 167 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 168 | |
Vladimir Marko | f39745e | 2016-01-26 12:16:55 +0000 | [diff] [blame] | 169 | static bool IsValidHandle(TypeHandle handle) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 170 | return handle.GetReference() != nullptr; |
| 171 | } |
| 172 | |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 173 | bool IsValid() const { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 174 | return IsValidHandle(type_handle_); |
| 175 | } |
| 176 | |
| 177 | bool IsExact() const { return is_exact_; } |
| 178 | |
| 179 | bool IsObjectClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 180 | DCHECK(IsValid()); |
| 181 | return GetTypeHandle()->IsObjectClass(); |
| 182 | } |
| 183 | |
| 184 | bool IsStringClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 185 | DCHECK(IsValid()); |
| 186 | return GetTypeHandle()->IsStringClass(); |
| 187 | } |
| 188 | |
| 189 | bool IsObjectArray() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 190 | DCHECK(IsValid()); |
| 191 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 192 | } |
| 193 | |
| 194 | bool IsInterface() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 195 | DCHECK(IsValid()); |
| 196 | return GetTypeHandle()->IsInterface(); |
| 197 | } |
| 198 | |
| 199 | bool IsArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 200 | DCHECK(IsValid()); |
| 201 | return GetTypeHandle()->IsArrayClass(); |
| 202 | } |
| 203 | |
| 204 | bool IsPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 205 | DCHECK(IsValid()); |
| 206 | return GetTypeHandle()->IsPrimitiveArray(); |
| 207 | } |
| 208 | |
| 209 | bool IsNonPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 210 | DCHECK(IsValid()); |
| 211 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 212 | } |
| 213 | |
| 214 | bool CanArrayHold(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 215 | DCHECK(IsValid()); |
| 216 | if (!IsExact()) return false; |
| 217 | if (!IsArrayClass()) return false; |
| 218 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 219 | } |
| 220 | |
| 221 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 222 | DCHECK(IsValid()); |
| 223 | if (!IsExact()) return false; |
| 224 | if (!IsArrayClass()) return false; |
| 225 | if (!rti.IsArrayClass()) return false; |
| 226 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 227 | rti.GetTypeHandle()->GetComponentType()); |
| 228 | } |
| 229 | |
| 230 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 231 | |
| 232 | bool IsSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 233 | DCHECK(IsValid()); |
| 234 | DCHECK(rti.IsValid()); |
| 235 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 236 | } |
| 237 | |
| 238 | bool IsStrictSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 239 | DCHECK(IsValid()); |
| 240 | DCHECK(rti.IsValid()); |
| 241 | return GetTypeHandle().Get() != rti.GetTypeHandle().Get() && |
| 242 | GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 243 | } |
| 244 | |
| 245 | // Returns true if the type information provide the same amount of details. |
| 246 | // Note that it does not mean that the instructions have the same actual type |
| 247 | // (because the type can be the result of a merge). |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 248 | bool IsEqual(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 249 | if (!IsValid() && !rti.IsValid()) { |
| 250 | // Invalid types are equal. |
| 251 | return true; |
| 252 | } |
| 253 | if (!IsValid() || !rti.IsValid()) { |
| 254 | // One is valid, the other not. |
| 255 | return false; |
| 256 | } |
| 257 | return IsExact() == rti.IsExact() |
| 258 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
| 259 | } |
| 260 | |
| 261 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 262 | ReferenceTypeInfo() : type_handle_(TypeHandle()), is_exact_(false) {} |
| 263 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact) |
| 264 | : type_handle_(type_handle), is_exact_(is_exact) { } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 265 | |
| 266 | // The class of the object. |
| 267 | TypeHandle type_handle_; |
| 268 | // Whether or not the type is exact or a superclass of the actual type. |
| 269 | // Whether or not we have any information about this type. |
| 270 | bool is_exact_; |
| 271 | }; |
| 272 | |
| 273 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 274 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 275 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 276 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 277 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 278 | HGraph(ArenaAllocator* arena, |
| 279 | const DexFile& dex_file, |
| 280 | uint32_t method_idx, |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 281 | bool should_generate_constructor_barrier, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 282 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 283 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 284 | bool debuggable = false, |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 285 | bool osr = false, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 286 | int start_instruction_id = 0) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 287 | : arena_(arena), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 288 | blocks_(arena->Adapter(kArenaAllocBlockList)), |
| 289 | reverse_post_order_(arena->Adapter(kArenaAllocReversePostOrder)), |
| 290 | linear_order_(arena->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 291 | entry_block_(nullptr), |
| 292 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 293 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 294 | number_of_vregs_(0), |
| 295 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 296 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 297 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 298 | has_try_catch_(false), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 299 | has_irreducible_loops_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 300 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 301 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 302 | dex_file_(dex_file), |
| 303 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 304 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 305 | in_ssa_form_(false), |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 306 | should_generate_constructor_barrier_(should_generate_constructor_barrier), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 307 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 308 | cached_null_constant_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 309 | cached_int_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 310 | cached_float_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 311 | cached_long_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 312 | cached_double_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 313 | cached_current_method_(nullptr), |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 314 | inexact_object_rti_(ReferenceTypeInfo::CreateInvalid()), |
| 315 | osr_(osr) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 316 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 317 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 318 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 319 | // Acquires and stores RTI of inexact Object to be used when creating HNullConstant. |
| 320 | void InitializeInexactObjectRTI(StackHandleScopeCollection* handles); |
| 321 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 322 | ArenaAllocator* GetArena() const { return arena_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 323 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 324 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 325 | bool IsInSsaForm() const { return in_ssa_form_; } |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 326 | void SetInSsaForm() { in_ssa_form_ = true; } |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 327 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 328 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 329 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 330 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 331 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 332 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 333 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 334 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 335 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 336 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 337 | void ComputeDominanceInformation(); |
| 338 | void ClearDominanceInformation(); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 339 | void ClearLoopInformation(); |
| 340 | void FindBackEdges(ArenaBitVector* visited); |
| 341 | GraphAnalysisResult BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 342 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 343 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 344 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 345 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 346 | // 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] | 347 | // 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] | 348 | GraphAnalysisResult AnalyzeLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 349 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 350 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 351 | // order and loop information. |
| 352 | void ComputeTryBlockInformation(); |
| 353 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 354 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 355 | // Returns the instruction to replace the invoke expression or null if the |
| 356 | // invoke is for a void method. Note that the caller is responsible for replacing |
| 357 | // and removing the invoke instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 358 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 359 | |
Nicolas Geoffray | a1d8ddf | 2016-02-29 11:46:58 +0000 | [diff] [blame] | 360 | // Update the loop and try membership of `block`, which was spawned from `reference`. |
| 361 | // In case `reference` is a back edge, `replace_if_back_edge` notifies whether `block` |
| 362 | // should be the new back edge. |
| 363 | void UpdateLoopAndTryInformationOfNewBlock(HBasicBlock* block, |
| 364 | HBasicBlock* reference, |
| 365 | bool replace_if_back_edge); |
| 366 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 367 | // Need to add a couple of blocks to test if the loop body is entered and |
| 368 | // put deoptimization instructions, etc. |
| 369 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 370 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 371 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 372 | // other blocks and has no instructions or phis. |
| 373 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 374 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 375 | // Splits the edge between `block` and `successor` while preserving the |
| 376 | // indices in the predecessor/successor lists. If there are multiple edges |
| 377 | // between the blocks, the lowest indices are used. |
| 378 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 379 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 380 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 381 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 382 | void SimplifyLoop(HBasicBlock* header); |
| 383 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 384 | int32_t GetNextInstructionId() { |
| 385 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 386 | return current_instruction_id_++; |
| 387 | } |
| 388 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 389 | int32_t GetCurrentInstructionId() const { |
| 390 | return current_instruction_id_; |
| 391 | } |
| 392 | |
| 393 | void SetCurrentInstructionId(int32_t id) { |
David Brazdil | 3f52306 | 2016-02-29 16:53:33 +0000 | [diff] [blame] | 394 | DCHECK_GE(id, current_instruction_id_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 395 | current_instruction_id_ = id; |
| 396 | } |
| 397 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 398 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 399 | return maximum_number_of_out_vregs_; |
| 400 | } |
| 401 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 402 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 403 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 404 | } |
| 405 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 406 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 407 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 408 | } |
| 409 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 410 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 411 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 412 | } |
| 413 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 414 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 415 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 416 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 417 | } |
| 418 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 419 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 420 | number_of_vregs_ = number_of_vregs; |
| 421 | } |
| 422 | |
| 423 | uint16_t GetNumberOfVRegs() const { |
| 424 | return number_of_vregs_; |
| 425 | } |
| 426 | |
| 427 | void SetNumberOfInVRegs(uint16_t value) { |
| 428 | number_of_in_vregs_ = value; |
| 429 | } |
| 430 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 431 | uint16_t GetNumberOfInVRegs() const { |
| 432 | return number_of_in_vregs_; |
| 433 | } |
| 434 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 435 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 436 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 437 | return number_of_vregs_ - number_of_in_vregs_; |
| 438 | } |
| 439 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 440 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 441 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 442 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 443 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 444 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 445 | return linear_order_; |
| 446 | } |
| 447 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 448 | bool HasBoundsChecks() const { |
| 449 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 450 | } |
| 451 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 452 | void SetHasBoundsChecks(bool value) { |
| 453 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 454 | } |
| 455 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 456 | bool ShouldGenerateConstructorBarrier() const { |
| 457 | return should_generate_constructor_barrier_; |
| 458 | } |
| 459 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 460 | bool IsDebuggable() const { return debuggable_; } |
| 461 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 462 | // 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] | 463 | // already, it is created and inserted into the graph. This method is only for |
| 464 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 465 | 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] | 466 | |
| 467 | // TODO: This is problematic for the consistency of reference type propagation |
| 468 | // because it can be created anytime after the pass and thus it will be left |
| 469 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 470 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 471 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 472 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 473 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 474 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 475 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 476 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 477 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 478 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 479 | 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] | 480 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 481 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 482 | 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] | 483 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 484 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 485 | HCurrentMethod* GetCurrentMethod(); |
| 486 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 487 | const DexFile& GetDexFile() const { |
| 488 | return dex_file_; |
| 489 | } |
| 490 | |
| 491 | uint32_t GetMethodIdx() const { |
| 492 | return method_idx_; |
| 493 | } |
| 494 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 495 | InvokeType GetInvokeType() const { |
| 496 | return invoke_type_; |
| 497 | } |
| 498 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 499 | InstructionSet GetInstructionSet() const { |
| 500 | return instruction_set_; |
| 501 | } |
| 502 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 503 | bool IsCompilingOsr() const { return osr_; } |
| 504 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 505 | bool HasTryCatch() const { return has_try_catch_; } |
| 506 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 507 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 508 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 509 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 510 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 511 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 512 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 513 | |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 514 | // Returns an instruction with the opposite boolean value from 'cond'. |
| 515 | // The instruction has been inserted into the graph, either as a constant, or |
| 516 | // before cursor. |
| 517 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 518 | |
Nicolas Geoffray | 18401b7 | 2016-03-11 13:35:51 +0000 | [diff] [blame] | 519 | ReferenceTypeInfo GetInexactObjectRti() const { return inexact_object_rti_; } |
| 520 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 521 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 522 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 523 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 524 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 525 | template <class InstructionType, typename ValueType> |
| 526 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 527 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 528 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 529 | // Try to find an existing constant of the given value. |
| 530 | InstructionType* constant = nullptr; |
| 531 | auto cached_constant = cache->find(value); |
| 532 | if (cached_constant != cache->end()) { |
| 533 | constant = cached_constant->second; |
| 534 | } |
| 535 | |
| 536 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 537 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 538 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 539 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 540 | cache->Overwrite(value, constant); |
| 541 | InsertConstant(constant); |
| 542 | } |
| 543 | return constant; |
| 544 | } |
| 545 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 546 | void InsertConstant(HConstant* instruction); |
| 547 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 548 | // Cache a float constant into the graph. This method should only be |
| 549 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 550 | void CacheFloatConstant(HFloatConstant* constant); |
| 551 | |
| 552 | // See CacheFloatConstant comment. |
| 553 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 554 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 555 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 556 | |
| 557 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 558 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 559 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 560 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 561 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 562 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 563 | // List of blocks to perform a linear order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 564 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 565 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 566 | HBasicBlock* entry_block_; |
| 567 | HBasicBlock* exit_block_; |
| 568 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 569 | // 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] | 570 | uint16_t maximum_number_of_out_vregs_; |
| 571 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 572 | // The number of virtual registers in this method. Contains the parameters. |
| 573 | uint16_t number_of_vregs_; |
| 574 | |
| 575 | // The number of virtual registers used by parameters of this method. |
| 576 | uint16_t number_of_in_vregs_; |
| 577 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 578 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 579 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 580 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 581 | // Has bounds checks. We can totally skip BCE if it's false. |
| 582 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 583 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 584 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 585 | // try/catch-related passes if false. |
| 586 | bool has_try_catch_; |
| 587 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 588 | // Flag whether there are any irreducible loops in the graph. |
| 589 | bool has_irreducible_loops_; |
| 590 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 591 | // Indicates whether the graph should be compiled in a way that |
| 592 | // ensures full debuggability. If false, we can apply more |
| 593 | // aggressive optimizations that may limit the level of debugging. |
| 594 | const bool debuggable_; |
| 595 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 596 | // 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] | 597 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 598 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 599 | // The dex file from which the method is from. |
| 600 | const DexFile& dex_file_; |
| 601 | |
| 602 | // The method index in the dex file. |
| 603 | const uint32_t method_idx_; |
| 604 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 605 | // If inlined, this encodes how the callee is being invoked. |
| 606 | const InvokeType invoke_type_; |
| 607 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 608 | // Whether the graph has been transformed to SSA form. Only used |
| 609 | // in debug mode to ensure we are not using properties only valid |
| 610 | // for non-SSA form (like the number of temporaries). |
| 611 | bool in_ssa_form_; |
| 612 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 613 | const bool should_generate_constructor_barrier_; |
| 614 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 615 | const InstructionSet instruction_set_; |
| 616 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 617 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 618 | HNullConstant* cached_null_constant_; |
| 619 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 620 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 621 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 622 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 623 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 624 | HCurrentMethod* cached_current_method_; |
| 625 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 626 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 627 | // for example for methods whose declaring class could not be resolved |
| 628 | // (such as when the superclass could not be found). |
| 629 | ArtMethod* art_method_; |
| 630 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 631 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 632 | // collection pointer to passes which may create NullConstant. |
| 633 | ReferenceTypeInfo inexact_object_rti_; |
| 634 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 635 | // Whether we are compiling this graph for on stack replacement: this will |
| 636 | // make all loops seen as irreducible and emit special stack maps to mark |
| 637 | // compiled code entries which the interpreter can directly jump to. |
| 638 | const bool osr_; |
| 639 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 640 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 641 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 642 | friend class HInliner; // For the reverse post order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 643 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 644 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 645 | }; |
| 646 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 647 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 648 | public: |
| 649 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 650 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 651 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 652 | irreducible_(false), |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 653 | contains_irreducible_loop_(false), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 654 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 655 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | f6a35de | 2016-03-21 12:01:50 +0000 | [diff] [blame] | 656 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true, kArenaAllocLoopInfoBackEdges) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 657 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 658 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 659 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 660 | bool IsIrreducible() const { return irreducible_; } |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 661 | bool ContainsIrreducibleLoop() const { return contains_irreducible_loop_; } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 662 | |
| 663 | void Dump(std::ostream& os); |
| 664 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 665 | HBasicBlock* GetHeader() const { |
| 666 | return header_; |
| 667 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 668 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 669 | void SetHeader(HBasicBlock* block) { |
| 670 | header_ = block; |
| 671 | } |
| 672 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 673 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 674 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 675 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 676 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 677 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 678 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 679 | } |
| 680 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 681 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 682 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 683 | } |
| 684 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 685 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 686 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 687 | } |
| 688 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 689 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 690 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 691 | } |
| 692 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 693 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 694 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 695 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 696 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 697 | } |
| 698 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 699 | // Returns the lifetime position of the back edge that has the |
| 700 | // greatest lifetime position. |
| 701 | size_t GetLifetimeEnd() const; |
| 702 | |
| 703 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 704 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 705 | } |
| 706 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 707 | // Finds blocks that are part of this loop. |
| 708 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 709 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 710 | // Returns whether this loop information contains `block`. |
| 711 | // Note that this loop information *must* be populated before entering this function. |
| 712 | bool Contains(const HBasicBlock& block) const; |
| 713 | |
| 714 | // Returns whether this loop information is an inner loop of `other`. |
| 715 | // Note that `other` *must* be populated before entering this function. |
| 716 | bool IsIn(const HLoopInformation& other) const; |
| 717 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 718 | // Returns true if instruction is not defined within this loop. |
| 719 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 720 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 721 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 722 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 723 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 724 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 725 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 726 | void ClearAllBlocks() { |
| 727 | blocks_.ClearAllBits(); |
| 728 | } |
| 729 | |
David Brazdil | 3f4a522 | 2016-05-06 12:46:21 +0100 | [diff] [blame] | 730 | bool HasBackEdgeNotDominatedByHeader() const; |
| 731 | |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 732 | bool IsPopulated() const { |
| 733 | return blocks_.GetHighestBitSet() != -1; |
| 734 | } |
| 735 | |
Anton Shamin | f89381f | 2016-05-16 16:44:13 +0600 | [diff] [blame^] | 736 | bool DominatesAllBackEdges(HBasicBlock* block); |
| 737 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 738 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 739 | // Internal recursive implementation of `Populate`. |
| 740 | void PopulateRecursive(HBasicBlock* block); |
David Brazdil | c2e8af9 | 2016-04-05 17:15:19 +0100 | [diff] [blame] | 741 | void PopulateIrreducibleRecursive(HBasicBlock* block, ArenaBitVector* finalized); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 742 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 743 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 744 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 745 | bool irreducible_; |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 746 | bool contains_irreducible_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 747 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 748 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 749 | |
| 750 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 751 | }; |
| 752 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 753 | // Stores try/catch information for basic blocks. |
| 754 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 755 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 756 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 757 | public: |
| 758 | // Try block information constructor. |
| 759 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 760 | : try_entry_(&try_entry), |
| 761 | catch_dex_file_(nullptr), |
| 762 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 763 | DCHECK(try_entry_ != nullptr); |
| 764 | } |
| 765 | |
| 766 | // Catch block information constructor. |
| 767 | TryCatchInformation(uint16_t catch_type_index, const DexFile& dex_file) |
| 768 | : try_entry_(nullptr), |
| 769 | catch_dex_file_(&dex_file), |
| 770 | catch_type_index_(catch_type_index) {} |
| 771 | |
| 772 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 773 | |
| 774 | const HTryBoundary& GetTryEntry() const { |
| 775 | DCHECK(IsTryBlock()); |
| 776 | return *try_entry_; |
| 777 | } |
| 778 | |
| 779 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 780 | |
| 781 | bool IsCatchAllTypeIndex() const { |
| 782 | DCHECK(IsCatchBlock()); |
| 783 | return catch_type_index_ == DexFile::kDexNoIndex16; |
| 784 | } |
| 785 | |
| 786 | uint16_t GetCatchTypeIndex() const { |
| 787 | DCHECK(IsCatchBlock()); |
| 788 | return catch_type_index_; |
| 789 | } |
| 790 | |
| 791 | const DexFile& GetCatchDexFile() const { |
| 792 | DCHECK(IsCatchBlock()); |
| 793 | return *catch_dex_file_; |
| 794 | } |
| 795 | |
| 796 | private: |
| 797 | // One of possibly several TryBoundary instructions entering the block's try. |
| 798 | // Only set for try blocks. |
| 799 | const HTryBoundary* try_entry_; |
| 800 | |
| 801 | // Exception type information. Only set for catch blocks. |
| 802 | const DexFile* catch_dex_file_; |
| 803 | const uint16_t catch_type_index_; |
| 804 | }; |
| 805 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 806 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 807 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 808 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 809 | // A block in a method. Contains the list of instructions represented |
| 810 | // as a double linked list. Each block knows its predecessors and |
| 811 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 812 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 813 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 814 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 815 | HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 816 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 817 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 818 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 819 | loop_information_(nullptr), |
| 820 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 821 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 822 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 823 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 824 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 825 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 826 | try_catch_information_(nullptr) { |
| 827 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 828 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 829 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 830 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 831 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 832 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 833 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 834 | } |
| 835 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 836 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 837 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 838 | } |
| 839 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 840 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 841 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 842 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 843 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 844 | return ContainsElement(successors_, block, start_from); |
| 845 | } |
| 846 | |
| 847 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 848 | return dominated_blocks_; |
| 849 | } |
| 850 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 851 | bool IsEntryBlock() const { |
| 852 | return graph_->GetEntryBlock() == this; |
| 853 | } |
| 854 | |
| 855 | bool IsExitBlock() const { |
| 856 | return graph_->GetExitBlock() == this; |
| 857 | } |
| 858 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 859 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 860 | bool IsSingleTryBoundary() const; |
| 861 | |
| 862 | // Returns true if this block emits nothing but a jump. |
| 863 | bool IsSingleJump() const { |
| 864 | HLoopInformation* loop_info = GetLoopInformation(); |
| 865 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 866 | // Back edges generate a suspend check. |
| 867 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 868 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 869 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 870 | void AddBackEdge(HBasicBlock* back_edge) { |
| 871 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 872 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 873 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 874 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 875 | loop_information_->AddBackEdge(back_edge); |
| 876 | } |
| 877 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 878 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 879 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 880 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 881 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 882 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 883 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 884 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 885 | HBasicBlock* GetDominator() const { return dominator_; } |
| 886 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 887 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 888 | |
| 889 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 890 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 891 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 892 | |
| 893 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 894 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 895 | } |
| 896 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 897 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 898 | |
| 899 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 900 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 901 | } |
| 902 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 903 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 904 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 905 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 906 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 907 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 908 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 909 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 910 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 911 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 912 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 913 | successors_.push_back(block); |
| 914 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 915 | } |
| 916 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 917 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 918 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 919 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 920 | new_block->predecessors_.push_back(this); |
| 921 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 922 | } |
| 923 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 924 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 925 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 926 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 927 | new_block->successors_.push_back(this); |
| 928 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 929 | } |
| 930 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 931 | // Insert `this` between `predecessor` and `successor. This method |
| 932 | // preserves the indicies, and will update the first edge found between |
| 933 | // `predecessor` and `successor`. |
| 934 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 935 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 936 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 937 | successor->predecessors_[predecessor_index] = this; |
| 938 | predecessor->successors_[successor_index] = this; |
| 939 | successors_.push_back(successor); |
| 940 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 941 | } |
| 942 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 943 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 944 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 945 | } |
| 946 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 947 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 948 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 949 | } |
| 950 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 951 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 952 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 956 | predecessors_.push_back(block); |
| 957 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 958 | } |
| 959 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 960 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 961 | DCHECK_EQ(predecessors_.size(), 2u); |
| 962 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 963 | } |
| 964 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 965 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 966 | DCHECK_EQ(successors_.size(), 2u); |
| 967 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 968 | } |
| 969 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 970 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 971 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 972 | } |
| 973 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 974 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 975 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 976 | } |
| 977 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 978 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 979 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 980 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 984 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 985 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | // Returns whether the first occurrence of `predecessor` in the list of |
| 989 | // predecessors is at index `idx`. |
| 990 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 991 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 992 | return GetPredecessorIndexOf(predecessor) == idx; |
| 993 | } |
| 994 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 995 | // Create a new block between this block and its predecessors. The new block |
| 996 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 997 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 998 | // loop and try/catch information are not updated. |
| 999 | HBasicBlock* CreateImmediateDominator(); |
| 1000 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1001 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 1002 | // created, latter block. Note that this method will add the block to the |
| 1003 | // graph, create a Goto at the end of the former block and will create an edge |
| 1004 | // 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] | 1005 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1006 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 1007 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1008 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1009 | // created block. Note that this method just updates raw block information, |
| 1010 | // like predecessors, successors, dominators, and instruction list. It does not |
| 1011 | // update the graph, reverse post order, loop information, nor make sure the |
| 1012 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1013 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 1014 | |
| 1015 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 1016 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1017 | |
| 1018 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1019 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1020 | // that this method does not update the graph, reverse post order, loop |
| 1021 | // information, nor make sure the blocks are consistent (for example ending |
| 1022 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1023 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1024 | |
| 1025 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1026 | // of `this` are moved to `other`. |
| 1027 | // Note that this method does not update the graph, reverse post order, loop |
| 1028 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1029 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1030 | void ReplaceWith(HBasicBlock* other); |
| 1031 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1032 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1033 | // order, links to predecessors, successors, dominators and deletes the block |
| 1034 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1035 | // predecessor of `other` and vice versa. |
| 1036 | void MergeWith(HBasicBlock* other); |
| 1037 | |
| 1038 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1039 | // removes it from all loops it is included in and eventually from the graph. |
| 1040 | // The block must not dominate any other block. Predecessors and successors |
| 1041 | // are safely updated. |
| 1042 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1043 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1044 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1045 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1046 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1047 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1048 | // Replace instruction `initial` with `replacement` within this block. |
| 1049 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1050 | HInstruction* replacement); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1051 | void MoveInstructionBefore(HInstruction* insn, HInstruction* cursor); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1052 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1053 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1054 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1055 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1056 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1057 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1058 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1059 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1060 | |
| 1061 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1062 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1063 | } |
| 1064 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1065 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1066 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1067 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1068 | } |
| 1069 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1070 | bool IsFirstPredecessorBackEdge() const { |
| 1071 | DCHECK(IsLoopHeader()); |
| 1072 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1073 | } |
| 1074 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1075 | HLoopInformation* GetLoopInformation() const { |
| 1076 | return loop_information_; |
| 1077 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1078 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1079 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1080 | // 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] | 1081 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1082 | void SetInLoop(HLoopInformation* info) { |
| 1083 | if (IsLoopHeader()) { |
| 1084 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1085 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1086 | loop_information_ = info; |
| 1087 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1088 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1089 | // Note that a non loop header having a loop information means this loop information |
| 1090 | // has already been populated |
| 1091 | loop_information_ = info; |
| 1092 | } else { |
| 1093 | // Block is part of an inner loop. Do not update the loop information. |
| 1094 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1095 | // at this point, because this method is being called while populating `info`. |
| 1096 | } |
| 1097 | } |
| 1098 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1099 | // Raw update of the loop information. |
| 1100 | void SetLoopInformation(HLoopInformation* info) { |
| 1101 | loop_information_ = info; |
| 1102 | } |
| 1103 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1104 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1105 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1106 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1107 | |
| 1108 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1109 | try_catch_information_ = try_catch_information; |
| 1110 | } |
| 1111 | |
| 1112 | bool IsTryBlock() const { |
| 1113 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1114 | } |
| 1115 | |
| 1116 | bool IsCatchBlock() const { |
| 1117 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1118 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1119 | |
| 1120 | // Returns the try entry that this block's successors should have. They will |
| 1121 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1122 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1123 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1124 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1125 | bool HasThrowingInstructions() const; |
| 1126 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1127 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1128 | bool Dominates(HBasicBlock* block) const; |
| 1129 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1130 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1131 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1132 | |
| 1133 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1134 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1135 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1136 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1137 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1138 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1139 | bool HasSinglePhi() const; |
| 1140 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1141 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1142 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1143 | ArenaVector<HBasicBlock*> predecessors_; |
| 1144 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1145 | HInstructionList instructions_; |
| 1146 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1147 | HLoopInformation* loop_information_; |
| 1148 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1149 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1150 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1151 | // The dex program counter of the first instruction of this block. |
| 1152 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1153 | size_t lifetime_start_; |
| 1154 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1155 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1156 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1157 | friend class HGraph; |
| 1158 | friend class HInstruction; |
| 1159 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1160 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1161 | }; |
| 1162 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1163 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1164 | // from the innermost to the outermost. |
| 1165 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1166 | public: |
| 1167 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1168 | : current_(block.GetLoopInformation()) {} |
| 1169 | |
| 1170 | bool Done() const { return current_ == nullptr; } |
| 1171 | |
| 1172 | void Advance() { |
| 1173 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1174 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | HLoopInformation* Current() const { |
| 1178 | DCHECK(!Done()); |
| 1179 | return current_; |
| 1180 | } |
| 1181 | |
| 1182 | private: |
| 1183 | HLoopInformation* current_; |
| 1184 | |
| 1185 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1186 | }; |
| 1187 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1188 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1189 | M(Above, Condition) \ |
| 1190 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1191 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1192 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1193 | M(ArrayGet, Instruction) \ |
| 1194 | M(ArrayLength, Instruction) \ |
| 1195 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1196 | M(Below, Condition) \ |
| 1197 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1198 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1199 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1200 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1201 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1202 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1203 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1204 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1205 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1206 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1207 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1208 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1209 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1210 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1211 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1212 | M(Exit, Instruction) \ |
| 1213 | M(FloatConstant, Constant) \ |
| 1214 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1215 | M(GreaterThan, Condition) \ |
| 1216 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1217 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1218 | M(InstanceFieldGet, Instruction) \ |
| 1219 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1220 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1221 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1222 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1223 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1224 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1225 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1226 | M(LessThan, Condition) \ |
| 1227 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1228 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1229 | M(LoadException, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1230 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1231 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1232 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1233 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1234 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1235 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1236 | M(Neg, UnaryOperation) \ |
| 1237 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1238 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1239 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1240 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1241 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1242 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1243 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1244 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1245 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1246 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1247 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1248 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1249 | M(Return, Instruction) \ |
| 1250 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1251 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1252 | M(Shl, BinaryOperation) \ |
| 1253 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1254 | M(StaticFieldGet, Instruction) \ |
| 1255 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1256 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1257 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1258 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1259 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1260 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1261 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1262 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1263 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1264 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1265 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1266 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1267 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1268 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1269 | /* |
| 1270 | * Instructions, shared across several (not all) architectures. |
| 1271 | */ |
| 1272 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1273 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1274 | #else |
| 1275 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1276 | M(BitwiseNegatedRight, Instruction) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1277 | M(MultiplyAccumulate, Instruction) |
| 1278 | #endif |
| 1279 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1280 | #ifndef ART_ENABLE_CODEGEN_arm |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1281 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1282 | #else |
| 1283 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1284 | M(ArmDexCacheArraysBase, Instruction) |
| 1285 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1286 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1287 | #ifndef ART_ENABLE_CODEGEN_arm64 |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1288 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1289 | #else |
| 1290 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1291 | M(Arm64DataProcWithShifterOp, Instruction) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1292 | M(Arm64IntermediateAddress, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1293 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1294 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1295 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
| 1296 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1297 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1298 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1299 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1300 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1301 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1302 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1303 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1304 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1305 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1306 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1307 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1308 | |
| 1309 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1310 | |
| 1311 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1312 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1313 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1314 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1315 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1316 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1317 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1318 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1319 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1320 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1321 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1322 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1323 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1324 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1325 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1326 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1327 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1328 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1329 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1330 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1331 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1332 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1333 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1334 | #undef FORWARD_DECLARATION |
| 1335 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1336 | #define DECLARE_INSTRUCTION(type) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1337 | InstructionKind GetKindInternal() const OVERRIDE { return k##type; } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1338 | const char* DebugName() const OVERRIDE { return #type; } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1339 | bool InstructionTypeEquals(HInstruction* other) const OVERRIDE { \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1340 | return other->Is##type(); \ |
| 1341 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1342 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1343 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1344 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
| 1345 | bool Is##type() const { return As##type() != nullptr; } \ |
| 1346 | const H##type* As##type() const { return this; } \ |
| 1347 | H##type* As##type() { return this; } |
| 1348 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1349 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1350 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1351 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1352 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1353 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1354 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1355 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1356 | // Hook for the IntrusiveForwardList<>. |
| 1357 | // TODO: Hide this better. |
| 1358 | IntrusiveForwardListHook hook; |
| 1359 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1360 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1361 | HUseListNode(T user, size_t index) |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1362 | : user_(user), index_(index) {} |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1363 | |
| 1364 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1365 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1366 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1367 | friend class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1368 | |
| 1369 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1370 | }; |
| 1371 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1372 | template <typename T> |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1373 | using HUseList = IntrusiveForwardList<HUseListNode<T>>; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1374 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1375 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1376 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1377 | // by the used instructions. |
| 1378 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1379 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1380 | public: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1381 | HUserRecord() : instruction_(nullptr), before_use_node_() {} |
| 1382 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), before_use_node_() {} |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1383 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1384 | HUserRecord(const HUserRecord<T>& old_record, typename HUseList<T>::iterator before_use_node) |
| 1385 | : HUserRecord(old_record.instruction_, before_use_node) {} |
| 1386 | HUserRecord(HInstruction* instruction, typename HUseList<T>::iterator before_use_node) |
| 1387 | : instruction_(instruction), before_use_node_(before_use_node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1388 | DCHECK(instruction_ != nullptr); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | HInstruction* GetInstruction() const { return instruction_; } |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1392 | typename HUseList<T>::iterator GetBeforeUseNode() const { return before_use_node_; } |
| 1393 | typename HUseList<T>::iterator GetUseNode() const { return ++GetBeforeUseNode(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1394 | |
| 1395 | private: |
| 1396 | // Instruction used by the user. |
| 1397 | HInstruction* instruction_; |
| 1398 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1399 | // Iterator before the corresponding entry in the use list kept by 'instruction_'. |
| 1400 | typename HUseList<T>::iterator before_use_node_; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1401 | }; |
| 1402 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1403 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1404 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1405 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1406 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1407 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1408 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1409 | * modify the value of a reference field read [although it may modify the |
| 1410 | * reference fetch prior to reading the field, which is represented by its own |
| 1411 | * write/read dependence]). The analysis makes conservative points-to |
| 1412 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1413 | * the same, and any reference read depends on any reference read without |
| 1414 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1415 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1416 | * The internal representation uses 38-bit and is described in the table below. |
| 1417 | * The first line indicates the side effect, and for field/array accesses the |
| 1418 | * second line indicates the type of the access (in the order of the |
| 1419 | * Primitive::Type enum). |
| 1420 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1421 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1422 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1423 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1424 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1425 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1426 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1427 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1428 | * |
| 1429 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1430 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1431 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1432 | class SideEffects : public ValueObject { |
| 1433 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1434 | SideEffects() : flags_(0) {} |
| 1435 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1436 | static SideEffects None() { |
| 1437 | return SideEffects(0); |
| 1438 | } |
| 1439 | |
| 1440 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1441 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1442 | } |
| 1443 | |
| 1444 | static SideEffects AllChanges() { |
| 1445 | return SideEffects(kAllChangeBits); |
| 1446 | } |
| 1447 | |
| 1448 | static SideEffects AllDependencies() { |
| 1449 | return SideEffects(kAllDependOnBits); |
| 1450 | } |
| 1451 | |
| 1452 | static SideEffects AllExceptGCDependency() { |
| 1453 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1454 | } |
| 1455 | |
| 1456 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1457 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1458 | } |
| 1459 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1460 | static SideEffects AllWrites() { |
| 1461 | return SideEffects(kAllWrites); |
| 1462 | } |
| 1463 | |
| 1464 | static SideEffects AllReads() { |
| 1465 | return SideEffects(kAllReads); |
| 1466 | } |
| 1467 | |
| 1468 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1469 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1470 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1471 | : SideEffects(TypeFlag(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1472 | } |
| 1473 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1474 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1475 | return SideEffects(TypeFlag(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1476 | } |
| 1477 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1478 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1479 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1480 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1481 | : SideEffects(TypeFlag(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1485 | return SideEffects(TypeFlag(type, kArrayReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1486 | } |
| 1487 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1488 | static SideEffects CanTriggerGC() { |
| 1489 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1490 | } |
| 1491 | |
| 1492 | static SideEffects DependsOnGC() { |
| 1493 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1494 | } |
| 1495 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1496 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1497 | SideEffects Union(SideEffects other) const { |
| 1498 | return SideEffects(flags_ | other.flags_); |
| 1499 | } |
| 1500 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1501 | SideEffects Exclusion(SideEffects other) const { |
| 1502 | return SideEffects(flags_ & ~other.flags_); |
| 1503 | } |
| 1504 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1505 | void Add(SideEffects other) { |
| 1506 | flags_ |= other.flags_; |
| 1507 | } |
| 1508 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1509 | bool Includes(SideEffects other) const { |
| 1510 | return (other.flags_ & flags_) == other.flags_; |
| 1511 | } |
| 1512 | |
| 1513 | bool HasSideEffects() const { |
| 1514 | return (flags_ & kAllChangeBits); |
| 1515 | } |
| 1516 | |
| 1517 | bool HasDependencies() const { |
| 1518 | return (flags_ & kAllDependOnBits); |
| 1519 | } |
| 1520 | |
| 1521 | // Returns true if there are no side effects or dependencies. |
| 1522 | bool DoesNothing() const { |
| 1523 | return flags_ == 0; |
| 1524 | } |
| 1525 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1526 | // Returns true if something is written. |
| 1527 | bool DoesAnyWrite() const { |
| 1528 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1529 | } |
| 1530 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1531 | // Returns true if something is read. |
| 1532 | bool DoesAnyRead() const { |
| 1533 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1534 | } |
| 1535 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1536 | // Returns true if potentially everything is written and read |
| 1537 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1538 | bool DoesAllReadWrite() const { |
| 1539 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1540 | } |
| 1541 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1542 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1543 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1544 | } |
| 1545 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1546 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1547 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1548 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1549 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1553 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1554 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1555 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1556 | for (int s = kLastBit; s >= 0; s--) { |
| 1557 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1558 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1559 | // This is a bit for the GC side effect. |
| 1560 | if (current_bit_is_set) { |
| 1561 | flags += "GC"; |
| 1562 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1563 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1564 | } else { |
| 1565 | // This is a bit for the array/field analysis. |
| 1566 | // The underscore character stands for the 'can trigger GC' bit. |
| 1567 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1568 | if (current_bit_is_set) { |
| 1569 | flags += kDebug[s]; |
| 1570 | } |
| 1571 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1572 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1573 | flags += "|"; |
| 1574 | } |
| 1575 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1576 | } |
| 1577 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1578 | } |
| 1579 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1580 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1581 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1582 | private: |
| 1583 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1584 | |
| 1585 | static constexpr int kFieldWriteOffset = 0; |
| 1586 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1587 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1588 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1589 | |
| 1590 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1591 | |
| 1592 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1593 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1594 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1595 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1596 | |
| 1597 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1598 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1599 | |
| 1600 | // Aliases. |
| 1601 | |
| 1602 | static_assert(kChangeBits == kDependOnBits, |
| 1603 | "the 'change' bits should match the 'depend on' bits."); |
| 1604 | |
| 1605 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1606 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1607 | static constexpr uint64_t kAllWrites = |
| 1608 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1609 | static constexpr uint64_t kAllReads = |
| 1610 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1611 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1612 | // Translates type to bit flag. |
| 1613 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1614 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1615 | const uint64_t one = 1; |
| 1616 | const int shift = type; // 0-based consecutive enum |
| 1617 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1618 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1619 | return one << (type + offset); |
| 1620 | } |
| 1621 | |
| 1622 | // Private constructor on direct flags value. |
| 1623 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1624 | |
| 1625 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1626 | }; |
| 1627 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1628 | // 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] | 1629 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1630 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1631 | HEnvironment(ArenaAllocator* arena, |
| 1632 | size_t number_of_vregs, |
| 1633 | const DexFile& dex_file, |
| 1634 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1635 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1636 | InvokeType invoke_type, |
| 1637 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1638 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1639 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1640 | parent_(nullptr), |
| 1641 | dex_file_(dex_file), |
| 1642 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1643 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1644 | invoke_type_(invoke_type), |
| 1645 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1646 | } |
| 1647 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1648 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1649 | : HEnvironment(arena, |
| 1650 | to_copy.Size(), |
| 1651 | to_copy.GetDexFile(), |
| 1652 | to_copy.GetMethodIdx(), |
| 1653 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1654 | to_copy.GetInvokeType(), |
| 1655 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1656 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1657 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1658 | if (parent_ != nullptr) { |
| 1659 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1660 | } else { |
| 1661 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1662 | parent_->CopyFrom(parent); |
| 1663 | if (parent->GetParent() != nullptr) { |
| 1664 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1665 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1666 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1667 | } |
| 1668 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1669 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1670 | void CopyFrom(HEnvironment* environment); |
| 1671 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1672 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1673 | // input to the loop phi instead. This is for inserting instructions that |
| 1674 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1675 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1676 | |
| 1677 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1678 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1679 | } |
| 1680 | |
| 1681 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1682 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1683 | } |
| 1684 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1685 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1686 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1687 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1688 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1689 | HEnvironment* GetParent() const { return parent_; } |
| 1690 | |
| 1691 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1692 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1696 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1697 | } |
| 1698 | |
| 1699 | uint32_t GetDexPc() const { |
| 1700 | return dex_pc_; |
| 1701 | } |
| 1702 | |
| 1703 | uint32_t GetMethodIdx() const { |
| 1704 | return method_idx_; |
| 1705 | } |
| 1706 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1707 | InvokeType GetInvokeType() const { |
| 1708 | return invoke_type_; |
| 1709 | } |
| 1710 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1711 | const DexFile& GetDexFile() const { |
| 1712 | return dex_file_; |
| 1713 | } |
| 1714 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1715 | HInstruction* GetHolder() const { |
| 1716 | return holder_; |
| 1717 | } |
| 1718 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1719 | |
| 1720 | bool IsFromInlinedInvoke() const { |
| 1721 | return GetParent() != nullptr; |
| 1722 | } |
| 1723 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1724 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1725 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1726 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1727 | HEnvironment* parent_; |
| 1728 | const DexFile& dex_file_; |
| 1729 | const uint32_t method_idx_; |
| 1730 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1731 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1732 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1733 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1734 | HInstruction* const holder_; |
| 1735 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1736 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1737 | |
| 1738 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1739 | }; |
| 1740 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1741 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1742 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1743 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1744 | : previous_(nullptr), |
| 1745 | next_(nullptr), |
| 1746 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1747 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1748 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1749 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1750 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1751 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1752 | locations_(nullptr), |
| 1753 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1754 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1755 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1756 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
| 1757 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 1758 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1759 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1760 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1761 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1762 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1763 | enum InstructionKind { |
| 1764 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1765 | }; |
| 1766 | #undef DECLARE_KIND |
| 1767 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1768 | HInstruction* GetNext() const { return next_; } |
| 1769 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1770 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1771 | HInstruction* GetNextDisregardingMoves() const; |
| 1772 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1773 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1774 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1775 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1776 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1777 | bool IsInBlock() const { return block_ != nullptr; } |
| 1778 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1779 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 1780 | bool IsIrreducibleLoopHeaderPhi() const { |
| 1781 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 1782 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1783 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1784 | virtual size_t InputCount() const = 0; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1785 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1786 | |
| 1787 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1788 | virtual const char* DebugName() const = 0; |
| 1789 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1790 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1791 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1792 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1793 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1794 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1795 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1796 | |
| 1797 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1798 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1799 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1800 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1801 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1802 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1803 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1804 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1805 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1806 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1807 | // Does not apply for all instructions, but having this at top level greatly |
| 1808 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1809 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1810 | virtual bool CanBeNull() const { |
| 1811 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1812 | return true; |
| 1813 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1814 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1815 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1816 | return false; |
| 1817 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1818 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 1819 | virtual bool IsActualObject() const { |
| 1820 | return GetType() == Primitive::kPrimNot; |
| 1821 | } |
| 1822 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1823 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1824 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1825 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1826 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1827 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 1828 | GetPackedFlag<kFlagReferenceTypeIsExact>()); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1829 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1830 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1831 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1832 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1833 | // Note: fixup_end remains valid across push_front(). |
| 1834 | auto fixup_end = uses_.empty() ? uses_.begin() : ++uses_.begin(); |
| 1835 | HUseListNode<HInstruction*>* new_node = |
| 1836 | new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HInstruction*>(user, index); |
| 1837 | uses_.push_front(*new_node); |
| 1838 | FixUpUserRecordsAfterUseInsertion(fixup_end); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1839 | } |
| 1840 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1841 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1842 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1843 | // Note: env_fixup_end remains valid across push_front(). |
| 1844 | auto env_fixup_end = env_uses_.empty() ? env_uses_.begin() : ++env_uses_.begin(); |
| 1845 | HUseListNode<HEnvironment*>* new_node = |
| 1846 | new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HEnvironment*>(user, index); |
| 1847 | env_uses_.push_front(*new_node); |
| 1848 | FixUpUserRecordsAfterEnvUseInsertion(env_fixup_end); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1849 | } |
| 1850 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1851 | void RemoveAsUserOfInput(size_t input) { |
| 1852 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1853 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 1854 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 1855 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1856 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1857 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1858 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1859 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1860 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1861 | bool HasUses() const { return !uses_.empty() || !env_uses_.empty(); } |
| 1862 | bool HasEnvironmentUses() const { return !env_uses_.empty(); } |
| 1863 | bool HasNonEnvironmentUses() const { return !uses_.empty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1864 | bool HasOnlyOneNonEnvironmentUse() const { |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1865 | return !HasEnvironmentUses() && GetUses().HasExactlyOneElement(); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1866 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1867 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1868 | // Does this instruction strictly dominate `other_instruction`? |
| 1869 | // Returns false if this instruction and `other_instruction` are the same. |
| 1870 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1871 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1872 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1873 | int GetId() const { return id_; } |
| 1874 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1875 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1876 | int GetSsaIndex() const { return ssa_index_; } |
| 1877 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 1878 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 1879 | |
| 1880 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 1881 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1882 | // Set the `environment_` field. Raw because this method does not |
| 1883 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1884 | void SetRawEnvironment(HEnvironment* environment) { |
| 1885 | DCHECK(environment_ == nullptr); |
| 1886 | DCHECK_EQ(environment->GetHolder(), this); |
| 1887 | environment_ = environment; |
| 1888 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1889 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1890 | void RemoveEnvironment(); |
| 1891 | |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1892 | // Set the environment of this instruction, copying it from `environment`. While |
| 1893 | // copying, the uses lists are being updated. |
| 1894 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1895 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1896 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1897 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1898 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1899 | if (environment->GetParent() != nullptr) { |
| 1900 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1901 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1902 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1903 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1904 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 1905 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1906 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1907 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1908 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1909 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1910 | if (environment->GetParent() != nullptr) { |
| 1911 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1912 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1913 | } |
| 1914 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1915 | // Returns the number of entries in the environment. Typically, that is the |
| 1916 | // number of dex registers in a method. It could be more in case of inlining. |
| 1917 | size_t EnvironmentSize() const; |
| 1918 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1919 | LocationSummary* GetLocations() const { return locations_; } |
| 1920 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1921 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1922 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1923 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1924 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1925 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 1926 | // uses of this instruction by `other` are *not* updated. |
| 1927 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 1928 | ReplaceWith(other); |
| 1929 | other->ReplaceInput(this, use_index); |
| 1930 | } |
| 1931 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 1932 | // Move `this` instruction before `cursor`. |
| 1933 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1934 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 1935 | // Move `this` before its first user and out of any loops. If there is no |
| 1936 | // out-of-loop user that dominates all other users, move the instruction |
| 1937 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 1938 | // |
| 1939 | // This can be used only on non-throwing instructions with no side effects that |
| 1940 | // have at least one use but no environment uses. |
| 1941 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 1942 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1943 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1944 | bool Is##type() const; \ |
| 1945 | const H##type* As##type() const; \ |
| 1946 | H##type* As##type(); |
| 1947 | |
| 1948 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 1949 | #undef INSTRUCTION_TYPE_CHECK |
| 1950 | |
| 1951 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1952 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 1953 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1954 | virtual H##type* As##type() { return nullptr; } |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1955 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1956 | #undef INSTRUCTION_TYPE_CHECK |
| 1957 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1958 | // Returns whether the instruction can be moved within the graph. |
| 1959 | virtual bool CanBeMoved() const { return false; } |
| 1960 | |
| 1961 | // Returns whether the two instructions are of the same kind. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1962 | virtual bool InstructionTypeEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1963 | return false; |
| 1964 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1965 | |
| 1966 | // Returns whether any data encoded in the two instructions is equal. |
| 1967 | // This method does not look at the inputs. Both instructions must be |
| 1968 | // of the same type, otherwise the method has undefined behavior. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1969 | virtual bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1970 | return false; |
| 1971 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1972 | |
| 1973 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1974 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1975 | // 2) Their inputs are identical. |
| 1976 | bool Equals(HInstruction* other) const; |
| 1977 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1978 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 1979 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 1980 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 1981 | // apply the strong requirement for virtual functions, preventing optimizations. |
| 1982 | InstructionKind GetKind() const PURE; |
| 1983 | virtual InstructionKind GetKindInternal() const = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1984 | |
| 1985 | virtual size_t ComputeHashCode() const { |
| 1986 | size_t result = GetKind(); |
| 1987 | for (size_t i = 0, e = InputCount(); i < e; ++i) { |
| 1988 | result = (result * 31) + InputAt(i)->GetId(); |
| 1989 | } |
| 1990 | return result; |
| 1991 | } |
| 1992 | |
| 1993 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 1994 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1995 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1996 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1997 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 1998 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 1999 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2000 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2001 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2002 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2003 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2004 | |
| 2005 | // Returns whether the code generation of the instruction will require to have access |
| 2006 | // to the current method. Such instructions are: |
| 2007 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2008 | // to walk the stack and have the current method stored at a specific stack address. |
| 2009 | // (2): Object literals like classes and strings, that are loaded from the dex cache |
| 2010 | // fields of the current method. |
| 2011 | bool NeedsCurrentMethod() const { |
| 2012 | return NeedsEnvironment() || IsLoadClass() || IsLoadString(); |
| 2013 | } |
| 2014 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2015 | // Returns whether the code generation of the instruction will require to have access |
| 2016 | // to the dex cache of the current method's declaring class via the current method. |
| 2017 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2018 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2019 | // Does this instruction have any use in an environment before |
| 2020 | // control flow hits 'other'? |
| 2021 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2022 | |
| 2023 | // Remove all references to environment uses of this instruction. |
| 2024 | // The caller must ensure that this is safe to do. |
| 2025 | void RemoveEnvironmentUsers(); |
| 2026 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2027 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2028 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2029 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2030 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2031 | // If set, the machine code for this instruction is assumed to be generated by |
| 2032 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2033 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2034 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
| 2035 | static constexpr size_t kNumberOfGenericPackedBits = kFlagReferenceTypeIsExact + 1; |
| 2036 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2037 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2038 | virtual const HUserRecord<HInstruction*> InputRecordAt(size_t i) const = 0; |
| 2039 | virtual void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) = 0; |
| 2040 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2041 | uint32_t GetPackedFields() const { |
| 2042 | return packed_fields_; |
| 2043 | } |
| 2044 | |
| 2045 | template <size_t flag> |
| 2046 | bool GetPackedFlag() const { |
| 2047 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2048 | } |
| 2049 | |
| 2050 | template <size_t flag> |
| 2051 | void SetPackedFlag(bool value = true) { |
| 2052 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2053 | } |
| 2054 | |
| 2055 | template <typename BitFieldType> |
| 2056 | typename BitFieldType::value_type GetPackedField() const { |
| 2057 | return BitFieldType::Decode(packed_fields_); |
| 2058 | } |
| 2059 | |
| 2060 | template <typename BitFieldType> |
| 2061 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2062 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2063 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2064 | } |
| 2065 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2066 | private: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2067 | void FixUpUserRecordsAfterUseInsertion(HUseList<HInstruction*>::iterator fixup_end) { |
| 2068 | auto before_use_node = uses_.before_begin(); |
| 2069 | for (auto use_node = uses_.begin(); use_node != fixup_end; ++use_node) { |
| 2070 | HInstruction* user = use_node->GetUser(); |
| 2071 | size_t input_index = use_node->GetIndex(); |
| 2072 | user->SetRawInputRecordAt(input_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2073 | before_use_node = use_node; |
| 2074 | } |
| 2075 | } |
| 2076 | |
| 2077 | void FixUpUserRecordsAfterUseRemoval(HUseList<HInstruction*>::iterator before_use_node) { |
| 2078 | auto next = ++HUseList<HInstruction*>::iterator(before_use_node); |
| 2079 | if (next != uses_.end()) { |
| 2080 | HInstruction* next_user = next->GetUser(); |
| 2081 | size_t next_index = next->GetIndex(); |
| 2082 | DCHECK(next_user->InputRecordAt(next_index).GetInstruction() == this); |
| 2083 | next_user->SetRawInputRecordAt(next_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2084 | } |
| 2085 | } |
| 2086 | |
| 2087 | void FixUpUserRecordsAfterEnvUseInsertion(HUseList<HEnvironment*>::iterator env_fixup_end) { |
| 2088 | auto before_env_use_node = env_uses_.before_begin(); |
| 2089 | for (auto env_use_node = env_uses_.begin(); env_use_node != env_fixup_end; ++env_use_node) { |
| 2090 | HEnvironment* user = env_use_node->GetUser(); |
| 2091 | size_t input_index = env_use_node->GetIndex(); |
| 2092 | user->vregs_[input_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2093 | before_env_use_node = env_use_node; |
| 2094 | } |
| 2095 | } |
| 2096 | |
| 2097 | void FixUpUserRecordsAfterEnvUseRemoval(HUseList<HEnvironment*>::iterator before_env_use_node) { |
| 2098 | auto next = ++HUseList<HEnvironment*>::iterator(before_env_use_node); |
| 2099 | if (next != env_uses_.end()) { |
| 2100 | HEnvironment* next_user = next->GetUser(); |
| 2101 | size_t next_index = next->GetIndex(); |
| 2102 | DCHECK(next_user->vregs_[next_index].GetInstruction() == this); |
| 2103 | next_user->vregs_[next_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2104 | } |
| 2105 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2106 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2107 | HInstruction* previous_; |
| 2108 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2109 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2110 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2111 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2112 | // An instruction gets an id when it is added to the graph. |
| 2113 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2114 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2115 | int id_; |
| 2116 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2117 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2118 | int ssa_index_; |
| 2119 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2120 | // Packed fields. |
| 2121 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2122 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2123 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2124 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2125 | |
| 2126 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2127 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2128 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2129 | // The environment associated with this instruction. Not null if the instruction |
| 2130 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2131 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2132 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2133 | // Set by the code generator. |
| 2134 | LocationSummary* locations_; |
| 2135 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2136 | // Set by the liveness analysis. |
| 2137 | LiveInterval* live_interval_; |
| 2138 | |
| 2139 | // Set by the liveness analysis, this is the position in a linear |
| 2140 | // order of blocks where this instruction's live interval start. |
| 2141 | size_t lifetime_position_; |
| 2142 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2143 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2144 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2145 | // The reference handle part of the reference type info. |
| 2146 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2147 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2148 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 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) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2274 | : HTemplateInstruction<N>(side_effects, dex_pc) { |
| 2275 | this->template SetPackedField<TypeField>(type); |
| 2276 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2277 | virtual ~HExpression() {} |
| 2278 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2279 | Primitive::Type GetType() const OVERRIDE { |
| 2280 | return TypeField::Decode(this->GetPackedFields()); |
| 2281 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2282 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2283 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2284 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2285 | static constexpr size_t kFieldTypeSize = |
| 2286 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2287 | static constexpr size_t kNumberOfExpressionPackedBits = kFieldType + kFieldTypeSize; |
| 2288 | static_assert(kNumberOfExpressionPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 2289 | "Too many packed fields."); |
| 2290 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2291 | }; |
| 2292 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2293 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2294 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2295 | class HReturnVoid FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2296 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2297 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2298 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2299 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2300 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2301 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2302 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2303 | |
| 2304 | private: |
| 2305 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2306 | }; |
| 2307 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2308 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2309 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2310 | class HReturn FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2311 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2312 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2313 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2314 | SetRawInputAt(0, value); |
| 2315 | } |
| 2316 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2317 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2318 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2319 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2320 | |
| 2321 | private: |
| 2322 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2323 | }; |
| 2324 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2325 | class HPhi FINAL : public HInstruction { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2326 | public: |
| 2327 | HPhi(ArenaAllocator* arena, |
| 2328 | uint32_t reg_number, |
| 2329 | size_t number_of_inputs, |
| 2330 | Primitive::Type type, |
| 2331 | uint32_t dex_pc = kNoDexPc) |
| 2332 | : HInstruction(SideEffects::None(), dex_pc), |
| 2333 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
| 2334 | reg_number_(reg_number) { |
| 2335 | SetPackedField<TypeField>(ToPhiType(type)); |
| 2336 | DCHECK_NE(GetType(), Primitive::kPrimVoid); |
| 2337 | // Phis are constructed live and marked dead if conflicting or unused. |
| 2338 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 2339 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 2340 | SetPackedFlag<kFlagIsLive>(true); |
| 2341 | SetPackedFlag<kFlagCanBeNull>(true); |
| 2342 | } |
| 2343 | |
| 2344 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 2345 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 2346 | return Primitive::PrimitiveKind(type); |
| 2347 | } |
| 2348 | |
| 2349 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 2350 | |
| 2351 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
| 2352 | |
| 2353 | void AddInput(HInstruction* input); |
| 2354 | void RemoveInputAt(size_t index); |
| 2355 | |
| 2356 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<TypeField>(); } |
| 2357 | void SetType(Primitive::Type new_type) { |
| 2358 | // Make sure that only valid type changes occur. The following are allowed: |
| 2359 | // (1) int -> float/ref (primitive type propagation), |
| 2360 | // (2) long -> double (primitive type propagation). |
| 2361 | DCHECK(GetType() == new_type || |
| 2362 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimFloat) || |
| 2363 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimNot) || |
| 2364 | (GetType() == Primitive::kPrimLong && new_type == Primitive::kPrimDouble)); |
| 2365 | SetPackedField<TypeField>(new_type); |
| 2366 | } |
| 2367 | |
| 2368 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 2369 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
| 2370 | |
| 2371 | uint32_t GetRegNumber() const { return reg_number_; } |
| 2372 | |
| 2373 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 2374 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 2375 | bool IsDead() const { return !IsLive(); } |
| 2376 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
| 2377 | |
| 2378 | bool IsVRegEquivalentOf(HInstruction* other) const { |
| 2379 | return other != nullptr |
| 2380 | && other->IsPhi() |
| 2381 | && other->AsPhi()->GetBlock() == GetBlock() |
| 2382 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 2383 | } |
| 2384 | |
| 2385 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 2386 | // An equivalent phi is a phi having the same dex register and type. |
| 2387 | // It assumes that phis with the same dex register are adjacent. |
| 2388 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 2389 | HInstruction* next = GetNext(); |
| 2390 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 2391 | if (next->GetType() == GetType()) { |
| 2392 | return next->AsPhi(); |
| 2393 | } |
| 2394 | next = next->GetNext(); |
| 2395 | } |
| 2396 | return nullptr; |
| 2397 | } |
| 2398 | |
| 2399 | DECLARE_INSTRUCTION(Phi); |
| 2400 | |
| 2401 | protected: |
| 2402 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
| 2403 | return inputs_[index]; |
| 2404 | } |
| 2405 | |
| 2406 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
| 2407 | inputs_[index] = input; |
| 2408 | } |
| 2409 | |
| 2410 | private: |
| 2411 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2412 | static constexpr size_t kFieldTypeSize = |
| 2413 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2414 | static constexpr size_t kFlagIsLive = kFieldType + kFieldTypeSize; |
| 2415 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 2416 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 2417 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 2418 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
| 2419 | |
| 2420 | ArenaVector<HUserRecord<HInstruction*> > inputs_; |
| 2421 | const uint32_t reg_number_; |
| 2422 | |
| 2423 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 2424 | }; |
| 2425 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2426 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2427 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2428 | // exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2429 | class HExit FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2430 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2431 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2432 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2433 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2434 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2435 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2436 | |
| 2437 | private: |
| 2438 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2439 | }; |
| 2440 | |
| 2441 | // Jumps from one block to another. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2442 | class HGoto FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2443 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2444 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2445 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2446 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2447 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2448 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2449 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2450 | } |
| 2451 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2452 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2453 | |
| 2454 | private: |
| 2455 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2456 | }; |
| 2457 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2458 | class HConstant : public HExpression<0> { |
| 2459 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2460 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2461 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2462 | |
| 2463 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2464 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2465 | // Is this constant -1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2466 | virtual bool IsMinusOne() const { return false; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2467 | // Is this constant 0 in the arithmetic sense? |
| 2468 | virtual bool IsArithmeticZero() const { return false; } |
| 2469 | // Is this constant a 0-bit pattern? |
| 2470 | virtual bool IsZeroBitPattern() const { return false; } |
| 2471 | // Is this constant 1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2472 | virtual bool IsOne() const { return false; } |
| 2473 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2474 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2475 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2476 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2477 | |
| 2478 | private: |
| 2479 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2480 | }; |
| 2481 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2482 | class HNullConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2483 | public: |
| 2484 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2485 | return true; |
| 2486 | } |
| 2487 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2488 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2489 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2490 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2491 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2492 | // The null constant representation is a 0-bit pattern. |
| 2493 | virtual bool IsZeroBitPattern() const { return true; } |
| 2494 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2495 | DECLARE_INSTRUCTION(NullConstant); |
| 2496 | |
| 2497 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2498 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2499 | |
| 2500 | friend class HGraph; |
| 2501 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2502 | }; |
| 2503 | |
| 2504 | // Constants of the type int. Those can be from Dex instructions, or |
| 2505 | // synthesized (for example with the if-eqz instruction). |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2506 | class HIntConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2507 | public: |
| 2508 | int32_t GetValue() const { return value_; } |
| 2509 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2510 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2511 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2512 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2513 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2514 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2515 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2516 | return other->AsIntConstant()->value_ == value_; |
| 2517 | } |
| 2518 | |
| 2519 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2520 | |
| 2521 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2522 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2523 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2524 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2525 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2526 | // Integer constants are used to encode Boolean values as well, |
| 2527 | // where 1 means true and 0 means false. |
| 2528 | bool IsTrue() const { return GetValue() == 1; } |
| 2529 | bool IsFalse() const { return GetValue() == 0; } |
| 2530 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2531 | DECLARE_INSTRUCTION(IntConstant); |
| 2532 | |
| 2533 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2534 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2535 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2536 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2537 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2538 | |
| 2539 | const int32_t value_; |
| 2540 | |
| 2541 | friend class HGraph; |
| 2542 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2543 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2544 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2545 | }; |
| 2546 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2547 | class HLongConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2548 | public: |
| 2549 | int64_t GetValue() const { return value_; } |
| 2550 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2551 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2552 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2553 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2554 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2555 | return other->AsLongConstant()->value_ == value_; |
| 2556 | } |
| 2557 | |
| 2558 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2559 | |
| 2560 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2561 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2562 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2563 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2564 | |
| 2565 | DECLARE_INSTRUCTION(LongConstant); |
| 2566 | |
| 2567 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2568 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2569 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2570 | |
| 2571 | const int64_t value_; |
| 2572 | |
| 2573 | friend class HGraph; |
| 2574 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2575 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2576 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2577 | class HFloatConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2578 | public: |
| 2579 | float GetValue() const { return value_; } |
| 2580 | |
| 2581 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2582 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2583 | } |
| 2584 | |
| 2585 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2586 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 2587 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2588 | } |
| 2589 | |
| 2590 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2591 | |
| 2592 | bool IsMinusOne() const OVERRIDE { |
| 2593 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 2594 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2595 | bool IsArithmeticZero() const OVERRIDE { |
| 2596 | return std::fpclassify(value_) == FP_ZERO; |
| 2597 | } |
| 2598 | bool IsArithmeticPositiveZero() const { |
| 2599 | return IsArithmeticZero() && !std::signbit(value_); |
| 2600 | } |
| 2601 | bool IsArithmeticNegativeZero() const { |
| 2602 | return IsArithmeticZero() && std::signbit(value_); |
| 2603 | } |
| 2604 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2605 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(0.0f); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2606 | } |
| 2607 | bool IsOne() const OVERRIDE { |
| 2608 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 2609 | } |
| 2610 | bool IsNaN() const { |
| 2611 | return std::isnan(value_); |
| 2612 | } |
| 2613 | |
| 2614 | DECLARE_INSTRUCTION(FloatConstant); |
| 2615 | |
| 2616 | private: |
| 2617 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 2618 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 2619 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2620 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
| 2621 | |
| 2622 | const float value_; |
| 2623 | |
| 2624 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2625 | friend class SsaBuilder; |
| 2626 | friend class HGraph; |
| 2627 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 2628 | }; |
| 2629 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2630 | class HDoubleConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2631 | public: |
| 2632 | double GetValue() const { return value_; } |
| 2633 | |
| 2634 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 2635 | |
| 2636 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2637 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 2638 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2639 | } |
| 2640 | |
| 2641 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2642 | |
| 2643 | bool IsMinusOne() const OVERRIDE { |
| 2644 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 2645 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2646 | bool IsArithmeticZero() const OVERRIDE { |
| 2647 | return std::fpclassify(value_) == FP_ZERO; |
| 2648 | } |
| 2649 | bool IsArithmeticPositiveZero() const { |
| 2650 | return IsArithmeticZero() && !std::signbit(value_); |
| 2651 | } |
| 2652 | bool IsArithmeticNegativeZero() const { |
| 2653 | return IsArithmeticZero() && std::signbit(value_); |
| 2654 | } |
| 2655 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2656 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((0.0)); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2657 | } |
| 2658 | bool IsOne() const OVERRIDE { |
| 2659 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 2660 | } |
| 2661 | bool IsNaN() const { |
| 2662 | return std::isnan(value_); |
| 2663 | } |
| 2664 | |
| 2665 | DECLARE_INSTRUCTION(DoubleConstant); |
| 2666 | |
| 2667 | private: |
| 2668 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 2669 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 2670 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2671 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
| 2672 | |
| 2673 | const double value_; |
| 2674 | |
| 2675 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2676 | friend class SsaBuilder; |
| 2677 | friend class HGraph; |
| 2678 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 2679 | }; |
| 2680 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2681 | // Conditional branch. A block ending with an HIf instruction must have |
| 2682 | // two successors. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2683 | class HIf FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2684 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2685 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2686 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2687 | SetRawInputAt(0, input); |
| 2688 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2689 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2690 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2691 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2692 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2693 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2694 | } |
| 2695 | |
| 2696 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2697 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2698 | } |
| 2699 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2700 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2701 | |
| 2702 | private: |
| 2703 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2704 | }; |
| 2705 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2706 | |
| 2707 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2708 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2709 | // non-exceptional control flow. |
| 2710 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2711 | // higher indices in no particular order. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2712 | class HTryBoundary FINAL : public HTemplateInstruction<0> { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2713 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2714 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2715 | kEntry, |
| 2716 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2717 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2718 | }; |
| 2719 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2720 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2721 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
| 2722 | SetPackedField<BoundaryKindField>(kind); |
| 2723 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2724 | |
| 2725 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2726 | |
| 2727 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2728 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2729 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 2730 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 2731 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 2732 | } |
| 2733 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2734 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2735 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2736 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2737 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2738 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2739 | } |
| 2740 | |
| 2741 | // If not present already, adds `handler` to its block's list of exception |
| 2742 | // handlers. |
| 2743 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2744 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2745 | GetBlock()->AddSuccessor(handler); |
| 2746 | } |
| 2747 | } |
| 2748 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2749 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 2750 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2751 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2752 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2753 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2754 | DECLARE_INSTRUCTION(TryBoundary); |
| 2755 | |
| 2756 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2757 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 2758 | static constexpr size_t kFieldBoundaryKindSize = |
| 2759 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 2760 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 2761 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 2762 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 2763 | "Too many packed fields."); |
| 2764 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2765 | |
| 2766 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2767 | }; |
| 2768 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2769 | // Deoptimize to interpreter, upon checking a condition. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2770 | class HDeoptimize FINAL : public HTemplateInstruction<1> { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2771 | public: |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2772 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 2773 | // at the point of the `HDeoptimize`. |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2774 | HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2775 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2776 | SetRawInputAt(0, cond); |
| 2777 | } |
| 2778 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2779 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2780 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2781 | return true; |
| 2782 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2783 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2784 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2785 | |
| 2786 | DECLARE_INSTRUCTION(Deoptimize); |
| 2787 | |
| 2788 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2789 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2790 | }; |
| 2791 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2792 | // Represents the ArtMethod that was passed as a first argument to |
| 2793 | // the method. It is used by instructions that depend on it, like |
| 2794 | // instructions that work with the dex cache. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2795 | class HCurrentMethod FINAL : public HExpression<0> { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2796 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2797 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2798 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2799 | |
| 2800 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2801 | |
| 2802 | private: |
| 2803 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2804 | }; |
| 2805 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2806 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 2807 | // of a class. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2808 | class HClassTableGet FINAL : public HExpression<1> { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2809 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2810 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2811 | kVTable, |
| 2812 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2813 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2814 | }; |
| 2815 | HClassTableGet(HInstruction* cls, |
| 2816 | Primitive::Type type, |
| 2817 | TableKind kind, |
| 2818 | size_t index, |
| 2819 | uint32_t dex_pc) |
| 2820 | : HExpression(type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2821 | index_(index) { |
| 2822 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2823 | SetRawInputAt(0, cls); |
| 2824 | } |
| 2825 | |
| 2826 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2827 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2828 | return other->AsClassTableGet()->GetIndex() == index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2829 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2830 | } |
| 2831 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2832 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2833 | size_t GetIndex() const { return index_; } |
| 2834 | |
| 2835 | DECLARE_INSTRUCTION(ClassTableGet); |
| 2836 | |
| 2837 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2838 | static constexpr size_t kFieldTableKind = kNumberOfExpressionPackedBits; |
| 2839 | static constexpr size_t kFieldTableKindSize = |
| 2840 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 2841 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 2842 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 2843 | "Too many packed fields."); |
| 2844 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 2845 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2846 | // The index of the ArtMethod in the table. |
| 2847 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2848 | |
| 2849 | DISALLOW_COPY_AND_ASSIGN(HClassTableGet); |
| 2850 | }; |
| 2851 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2852 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 2853 | // have one successor for each entry in the switch table, and the final successor |
| 2854 | // will be the block containing the next Dex opcode. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2855 | class HPackedSwitch FINAL : public HTemplateInstruction<1> { |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2856 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2857 | HPackedSwitch(int32_t start_value, |
| 2858 | uint32_t num_entries, |
| 2859 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2860 | uint32_t dex_pc = kNoDexPc) |
| 2861 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 2862 | start_value_(start_value), |
| 2863 | num_entries_(num_entries) { |
| 2864 | SetRawInputAt(0, input); |
| 2865 | } |
| 2866 | |
| 2867 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2868 | |
| 2869 | int32_t GetStartValue() const { return start_value_; } |
| 2870 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 2871 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2872 | |
| 2873 | HBasicBlock* GetDefaultBlock() const { |
| 2874 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2875 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2876 | } |
| 2877 | DECLARE_INSTRUCTION(PackedSwitch); |
| 2878 | |
| 2879 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2880 | const int32_t start_value_; |
| 2881 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2882 | |
| 2883 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 2884 | }; |
| 2885 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2886 | class HUnaryOperation : public HExpression<1> { |
| 2887 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2888 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2889 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2890 | SetRawInputAt(0, input); |
| 2891 | } |
| 2892 | |
| 2893 | HInstruction* GetInput() const { return InputAt(0); } |
| 2894 | Primitive::Type GetResultType() const { return GetType(); } |
| 2895 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2896 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2897 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2898 | return true; |
| 2899 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2900 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2901 | // Try to statically evaluate `this` and return a HConstant |
| 2902 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2903 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2904 | HConstant* TryStaticEvaluation() const; |
| 2905 | |
| 2906 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2907 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 2908 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2909 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 2910 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2911 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2912 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2913 | |
| 2914 | private: |
| 2915 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 2916 | }; |
| 2917 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2918 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2919 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2920 | HBinaryOperation(Primitive::Type result_type, |
| 2921 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2922 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2923 | SideEffects side_effects = SideEffects::None(), |
| 2924 | uint32_t dex_pc = kNoDexPc) |
| 2925 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2926 | SetRawInputAt(0, left); |
| 2927 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2928 | } |
| 2929 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2930 | HInstruction* GetLeft() const { return InputAt(0); } |
| 2931 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2932 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2933 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2934 | virtual bool IsCommutative() const { return false; } |
| 2935 | |
| 2936 | // Put constant on the right. |
| 2937 | // Returns whether order is changed. |
| 2938 | bool OrderInputsWithConstantOnTheRight() { |
| 2939 | HInstruction* left = InputAt(0); |
| 2940 | HInstruction* right = InputAt(1); |
| 2941 | if (left->IsConstant() && !right->IsConstant()) { |
| 2942 | ReplaceInput(right, 0); |
| 2943 | ReplaceInput(left, 1); |
| 2944 | return true; |
| 2945 | } |
| 2946 | return false; |
| 2947 | } |
| 2948 | |
| 2949 | // Order inputs by instruction id, but favor constant on the right side. |
| 2950 | // This helps GVN for commutative ops. |
| 2951 | void OrderInputs() { |
| 2952 | DCHECK(IsCommutative()); |
| 2953 | HInstruction* left = InputAt(0); |
| 2954 | HInstruction* right = InputAt(1); |
| 2955 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 2956 | return; |
| 2957 | } |
| 2958 | if (OrderInputsWithConstantOnTheRight()) { |
| 2959 | return; |
| 2960 | } |
| 2961 | // Order according to instruction id. |
| 2962 | if (left->GetId() > right->GetId()) { |
| 2963 | ReplaceInput(right, 0); |
| 2964 | ReplaceInput(left, 1); |
| 2965 | } |
| 2966 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2967 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2968 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2969 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2970 | return true; |
| 2971 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2972 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2973 | // Try to statically evaluate `this` and return a HConstant |
| 2974 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2975 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2976 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2977 | |
| 2978 | // Apply this operation to `x` and `y`. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2979 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2980 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 2981 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 2982 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2983 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2984 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 2985 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2986 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 2987 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 2988 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 2989 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2990 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2991 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 2992 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2993 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2994 | // 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] | 2995 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2996 | HConstant* GetConstantRight() const; |
| 2997 | |
| 2998 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2999 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3000 | HInstruction* GetLeastConstantLeft() const; |
| 3001 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3002 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 3003 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3004 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3005 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 3006 | }; |
| 3007 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3008 | // The comparison bias applies for floating point operations and indicates how NaN |
| 3009 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3010 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3011 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 3012 | kGtBias, // return 1 for NaN comparisons |
| 3013 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3014 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3015 | }; |
| 3016 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3017 | std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs); |
| 3018 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3019 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3020 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3021 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3022 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc) { |
| 3023 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 3024 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3025 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3026 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3027 | // `instruction`, and disregard moves in between. |
| 3028 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3029 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3030 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3031 | |
| 3032 | virtual IfCondition GetCondition() const = 0; |
| 3033 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3034 | virtual IfCondition GetOppositeCondition() const = 0; |
| 3035 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3036 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3037 | bool IsLtBias() const { return GetBias() == ComparisonBias::kLtBias; } |
| 3038 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3039 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 3040 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3041 | |
| 3042 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3043 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3044 | } |
| 3045 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3046 | bool IsFPConditionTrueIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3047 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3048 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3049 | if (if_cond == kCondNE) { |
| 3050 | return true; |
| 3051 | } else if (if_cond == kCondEQ) { |
| 3052 | return false; |
| 3053 | } |
| 3054 | return ((if_cond == kCondGT) || (if_cond == kCondGE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3055 | } |
| 3056 | |
| 3057 | bool IsFPConditionFalseIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3058 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3059 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3060 | if (if_cond == kCondEQ) { |
| 3061 | return true; |
| 3062 | } else if (if_cond == kCondNE) { |
| 3063 | return false; |
| 3064 | } |
| 3065 | return ((if_cond == kCondLT) || (if_cond == kCondLE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3066 | } |
| 3067 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3068 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3069 | // Needed if we merge a HCompare into a HCondition. |
| 3070 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3071 | static constexpr size_t kFieldComparisonBiasSize = |
| 3072 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3073 | static constexpr size_t kNumberOfConditionPackedBits = |
| 3074 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3075 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3076 | using ComparisonBiasField = |
| 3077 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3078 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3079 | template <typename T> |
| 3080 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3081 | |
| 3082 | template <typename T> |
| 3083 | int32_t CompareFP(T x, T y) const { |
| 3084 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3085 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3086 | // Handle the bias. |
| 3087 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 3088 | } |
| 3089 | |
| 3090 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3091 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3092 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3093 | } |
| 3094 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3095 | private: |
| 3096 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 3097 | }; |
| 3098 | |
| 3099 | // Instruction to check if two inputs are equal to each other. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3100 | class HEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3101 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3102 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3103 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3104 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3105 | bool IsCommutative() const OVERRIDE { return true; } |
| 3106 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3107 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3108 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3109 | return MakeConstantCondition(true, GetDexPc()); |
| 3110 | } |
| 3111 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3112 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3113 | } |
| 3114 | // In the following Evaluate methods, a HCompare instruction has |
| 3115 | // been merged into this HEqual instruction; evaluate it as |
| 3116 | // `Compare(x, y) == 0`. |
| 3117 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3118 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3119 | GetDexPc()); |
| 3120 | } |
| 3121 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3122 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3123 | } |
| 3124 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3125 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3126 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3127 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3128 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3129 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3130 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3131 | return kCondEQ; |
| 3132 | } |
| 3133 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3134 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3135 | return kCondNE; |
| 3136 | } |
| 3137 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3138 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3139 | template <typename T> bool Compute(T x, T y) const { return x == y; } |
| 3140 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3141 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 3142 | }; |
| 3143 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3144 | class HNotEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3145 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3146 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3147 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3148 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3149 | bool IsCommutative() const OVERRIDE { return true; } |
| 3150 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3151 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3152 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3153 | return MakeConstantCondition(false, GetDexPc()); |
| 3154 | } |
| 3155 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3156 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3157 | } |
| 3158 | // In the following Evaluate methods, a HCompare instruction has |
| 3159 | // been merged into this HNotEqual instruction; evaluate it as |
| 3160 | // `Compare(x, y) != 0`. |
| 3161 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3162 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3163 | } |
| 3164 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3165 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3166 | } |
| 3167 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3168 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3169 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3170 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3171 | DECLARE_INSTRUCTION(NotEqual); |
| 3172 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3173 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3174 | return kCondNE; |
| 3175 | } |
| 3176 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3177 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3178 | return kCondEQ; |
| 3179 | } |
| 3180 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3181 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3182 | template <typename T> bool Compute(T x, T y) const { return x != y; } |
| 3183 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3184 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 3185 | }; |
| 3186 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3187 | class HLessThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3188 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3189 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3190 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3191 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3192 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3193 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3194 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3195 | // In the following Evaluate methods, a HCompare instruction has |
| 3196 | // been merged into this HLessThan instruction; evaluate it as |
| 3197 | // `Compare(x, y) < 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3198 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3199 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3200 | } |
| 3201 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3202 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3203 | } |
| 3204 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3205 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3206 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3207 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3208 | DECLARE_INSTRUCTION(LessThan); |
| 3209 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3210 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3211 | return kCondLT; |
| 3212 | } |
| 3213 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3214 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3215 | return kCondGE; |
| 3216 | } |
| 3217 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3218 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3219 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 3220 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3221 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 3222 | }; |
| 3223 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3224 | class HLessThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3225 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3226 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3227 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3228 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3229 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3230 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3231 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3232 | // In the following Evaluate methods, a HCompare instruction has |
| 3233 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 3234 | // `Compare(x, y) <= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3235 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3236 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3237 | } |
| 3238 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3239 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3240 | } |
| 3241 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3242 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3243 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3244 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3245 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 3246 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3247 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3248 | return kCondLE; |
| 3249 | } |
| 3250 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3251 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3252 | return kCondGT; |
| 3253 | } |
| 3254 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3255 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3256 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 3257 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3258 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 3259 | }; |
| 3260 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3261 | class HGreaterThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3262 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3263 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3264 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3265 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3266 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3267 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3268 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3269 | // In the following Evaluate methods, a HCompare instruction has |
| 3270 | // been merged into this HGreaterThan instruction; evaluate it as |
| 3271 | // `Compare(x, y) > 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3272 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3273 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3274 | } |
| 3275 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3276 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3277 | } |
| 3278 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3279 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3280 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3281 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3282 | DECLARE_INSTRUCTION(GreaterThan); |
| 3283 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3284 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3285 | return kCondGT; |
| 3286 | } |
| 3287 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3288 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3289 | return kCondLE; |
| 3290 | } |
| 3291 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3292 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3293 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 3294 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3295 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 3296 | }; |
| 3297 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3298 | class HGreaterThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3299 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3300 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3301 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3302 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3303 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3304 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3305 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3306 | // In the following Evaluate methods, a HCompare instruction has |
| 3307 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 3308 | // `Compare(x, y) >= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3309 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3310 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3311 | } |
| 3312 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3313 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3314 | } |
| 3315 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3316 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3317 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3318 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3319 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 3320 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3321 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3322 | return kCondGE; |
| 3323 | } |
| 3324 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3325 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3326 | return kCondLT; |
| 3327 | } |
| 3328 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3329 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3330 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 3331 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3332 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 3333 | }; |
| 3334 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3335 | class HBelow FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3336 | public: |
| 3337 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3338 | : HCondition(first, second, dex_pc) {} |
| 3339 | |
| 3340 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3341 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3342 | } |
| 3343 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3344 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3345 | } |
| 3346 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3347 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3348 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3349 | UNREACHABLE(); |
| 3350 | } |
| 3351 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3352 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3353 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3354 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3355 | } |
| 3356 | |
| 3357 | DECLARE_INSTRUCTION(Below); |
| 3358 | |
| 3359 | IfCondition GetCondition() const OVERRIDE { |
| 3360 | return kCondB; |
| 3361 | } |
| 3362 | |
| 3363 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3364 | return kCondAE; |
| 3365 | } |
| 3366 | |
| 3367 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3368 | template <typename T> bool Compute(T x, T y) const { |
| 3369 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 3370 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3371 | |
| 3372 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 3373 | }; |
| 3374 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3375 | class HBelowOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3376 | public: |
| 3377 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3378 | : HCondition(first, second, dex_pc) {} |
| 3379 | |
| 3380 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3381 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3382 | } |
| 3383 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3384 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3385 | } |
| 3386 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3387 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3388 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3389 | UNREACHABLE(); |
| 3390 | } |
| 3391 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3392 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3393 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3394 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3395 | } |
| 3396 | |
| 3397 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 3398 | |
| 3399 | IfCondition GetCondition() const OVERRIDE { |
| 3400 | return kCondBE; |
| 3401 | } |
| 3402 | |
| 3403 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3404 | return kCondA; |
| 3405 | } |
| 3406 | |
| 3407 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3408 | template <typename T> bool Compute(T x, T y) const { |
| 3409 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 3410 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3411 | |
| 3412 | DISALLOW_COPY_AND_ASSIGN(HBelowOrEqual); |
| 3413 | }; |
| 3414 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3415 | class HAbove FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3416 | public: |
| 3417 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3418 | : HCondition(first, second, dex_pc) {} |
| 3419 | |
| 3420 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3421 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3422 | } |
| 3423 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3424 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3425 | } |
| 3426 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3427 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3428 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3429 | UNREACHABLE(); |
| 3430 | } |
| 3431 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3432 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3433 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3434 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3435 | } |
| 3436 | |
| 3437 | DECLARE_INSTRUCTION(Above); |
| 3438 | |
| 3439 | IfCondition GetCondition() const OVERRIDE { |
| 3440 | return kCondA; |
| 3441 | } |
| 3442 | |
| 3443 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3444 | return kCondBE; |
| 3445 | } |
| 3446 | |
| 3447 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3448 | template <typename T> bool Compute(T x, T y) const { |
| 3449 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 3450 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3451 | |
| 3452 | DISALLOW_COPY_AND_ASSIGN(HAbove); |
| 3453 | }; |
| 3454 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3455 | class HAboveOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3456 | public: |
| 3457 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3458 | : HCondition(first, second, dex_pc) {} |
| 3459 | |
| 3460 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3461 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3462 | } |
| 3463 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3464 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3465 | } |
| 3466 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3467 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3468 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3469 | UNREACHABLE(); |
| 3470 | } |
| 3471 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3472 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3473 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3474 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3475 | } |
| 3476 | |
| 3477 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 3478 | |
| 3479 | IfCondition GetCondition() const OVERRIDE { |
| 3480 | return kCondAE; |
| 3481 | } |
| 3482 | |
| 3483 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3484 | return kCondB; |
| 3485 | } |
| 3486 | |
| 3487 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3488 | template <typename T> bool Compute(T x, T y) const { |
| 3489 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 3490 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3491 | |
| 3492 | DISALLOW_COPY_AND_ASSIGN(HAboveOrEqual); |
| 3493 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3494 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3495 | // Instruction to check how two inputs compare to each other. |
| 3496 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3497 | class HCompare FINAL : public HBinaryOperation { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3498 | public: |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3499 | // Note that `comparison_type` is the type of comparison performed |
| 3500 | // between the comparison's inputs, not the type of the instantiated |
| 3501 | // HCompare instruction (which is always Primitive::kPrimInt). |
| 3502 | HCompare(Primitive::Type comparison_type, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3503 | HInstruction* first, |
| 3504 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3505 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3506 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3507 | : HBinaryOperation(Primitive::kPrimInt, |
| 3508 | first, |
| 3509 | second, |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3510 | SideEffectsForArchRuntimeCalls(comparison_type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3511 | dex_pc) { |
| 3512 | SetPackedField<ComparisonBiasField>(bias); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3513 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(first->GetType())); |
| 3514 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(second->GetType())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3515 | } |
| 3516 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3517 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3518 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3519 | |
| 3520 | template <typename T> |
| 3521 | int32_t ComputeFP(T x, T y) const { |
| 3522 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3523 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3524 | // Handle the bias. |
| 3525 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 3526 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3527 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3528 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3529 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 3530 | // reach this code path when processing a freshly built HIR |
| 3531 | // graph. However HCompare integer instructions can be synthesized |
| 3532 | // by the instruction simplifier to implement IntegerCompare and |
| 3533 | // IntegerSignum intrinsics, so we have to handle this case. |
| 3534 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3535 | } |
| 3536 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3537 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3538 | } |
| 3539 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3540 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3541 | } |
| 3542 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3543 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3544 | } |
| 3545 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3546 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3547 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3548 | } |
| 3549 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3550 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3551 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3552 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3553 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3554 | bool IsGtBias() const { |
| 3555 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3556 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3557 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3558 | |
Roland Levillain | 1693a1f | 2016-03-15 14:57:31 +0000 | [diff] [blame] | 3559 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type ATTRIBUTE_UNUSED) { |
| 3560 | // Comparisons do not require a runtime call in any back end. |
| 3561 | return SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3562 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3563 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3564 | DECLARE_INSTRUCTION(Compare); |
| 3565 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3566 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3567 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3568 | static constexpr size_t kFieldComparisonBiasSize = |
| 3569 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3570 | static constexpr size_t kNumberOfComparePackedBits = |
| 3571 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3572 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3573 | using ComparisonBiasField = |
| 3574 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3575 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3576 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 3577 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 3578 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 3579 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3580 | } |
| 3581 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3582 | private: |
| 3583 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3584 | }; |
| 3585 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3586 | class HNewInstance FINAL : public HExpression<2> { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3587 | public: |
| 3588 | HNewInstance(HInstruction* cls, |
| 3589 | HCurrentMethod* current_method, |
| 3590 | uint32_t dex_pc, |
| 3591 | uint16_t type_index, |
| 3592 | const DexFile& dex_file, |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3593 | bool needs_access_check, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3594 | bool finalizable, |
| 3595 | QuickEntrypointEnum entrypoint) |
| 3596 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
| 3597 | type_index_(type_index), |
| 3598 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3599 | entrypoint_(entrypoint) { |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3600 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3601 | SetPackedFlag<kFlagFinalizable>(finalizable); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3602 | SetRawInputAt(0, cls); |
| 3603 | SetRawInputAt(1, current_method); |
| 3604 | } |
| 3605 | |
| 3606 | uint16_t GetTypeIndex() const { return type_index_; } |
| 3607 | const DexFile& GetDexFile() const { return dex_file_; } |
| 3608 | |
| 3609 | // Calls runtime so needs an environment. |
| 3610 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3611 | |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3612 | // Can throw errors when out-of-memory or if it's not instantiable/accessible. |
| 3613 | bool CanThrow() const OVERRIDE { return true; } |
| 3614 | |
| 3615 | // Needs to call into runtime to make sure it's instantiable/accessible. |
| 3616 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3617 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3618 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3619 | |
| 3620 | bool CanBeNull() const OVERRIDE { return false; } |
| 3621 | |
| 3622 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3623 | |
| 3624 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 3625 | entrypoint_ = entrypoint; |
| 3626 | } |
| 3627 | |
| 3628 | bool IsStringAlloc() const; |
| 3629 | |
| 3630 | DECLARE_INSTRUCTION(NewInstance); |
| 3631 | |
| 3632 | private: |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3633 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfExpressionPackedBits; |
| 3634 | static constexpr size_t kFlagFinalizable = kFlagNeedsAccessCheck + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3635 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagFinalizable + 1; |
| 3636 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 3637 | "Too many packed fields."); |
| 3638 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3639 | const uint16_t type_index_; |
| 3640 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3641 | QuickEntrypointEnum entrypoint_; |
| 3642 | |
| 3643 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3644 | }; |
| 3645 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3646 | enum class Intrinsics { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3647 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache, SideEffects, Exceptions) \ |
| 3648 | k ## Name, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3649 | #include "intrinsics_list.h" |
| 3650 | kNone, |
| 3651 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
| 3652 | #undef INTRINSICS_LIST |
| 3653 | #undef OPTIMIZING_INTRINSICS |
| 3654 | }; |
| 3655 | std::ostream& operator<<(std::ostream& os, const Intrinsics& intrinsic); |
| 3656 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3657 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3658 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3659 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3660 | }; |
| 3661 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3662 | enum IntrinsicSideEffects { |
| 3663 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 3664 | kReadSideEffects, // Intrinsic may read heap memory. |
| 3665 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 3666 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 3667 | }; |
| 3668 | |
| 3669 | enum IntrinsicExceptions { |
| 3670 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 3671 | kCanThrow // Intrinsic may throw exceptions. |
| 3672 | }; |
| 3673 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3674 | class HInvoke : public HInstruction { |
| 3675 | public: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3676 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3677 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3678 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3679 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3680 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3681 | SetRawInputAt(index, argument); |
| 3682 | } |
| 3683 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3684 | // Return the number of arguments. This number can be lower than |
| 3685 | // the number of inputs returned by InputCount(), as some invoke |
| 3686 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3687 | // inputs at the end of their list of inputs. |
| 3688 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3689 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3690 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<ReturnTypeField>(); } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3691 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3692 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3693 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3694 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3695 | InvokeType GetOriginalInvokeType() const { |
| 3696 | return GetPackedField<OriginalInvokeTypeField>(); |
| 3697 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3698 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3699 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3700 | return intrinsic_; |
| 3701 | } |
| 3702 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3703 | void SetIntrinsic(Intrinsics intrinsic, |
| 3704 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 3705 | IntrinsicSideEffects side_effects, |
| 3706 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3707 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3708 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 3709 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3710 | } |
| 3711 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3712 | bool CanThrow() const OVERRIDE { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3713 | |
| 3714 | bool CanBeMoved() const OVERRIDE { return IsIntrinsic(); } |
| 3715 | |
| 3716 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3717 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 3718 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3719 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3720 | uint32_t* GetIntrinsicOptimizations() { |
| 3721 | return &intrinsic_optimizations_; |
| 3722 | } |
| 3723 | |
| 3724 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3725 | return &intrinsic_optimizations_; |
| 3726 | } |
| 3727 | |
| 3728 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3729 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3730 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3731 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3732 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3733 | static constexpr size_t kFieldOriginalInvokeType = kNumberOfGenericPackedBits; |
| 3734 | static constexpr size_t kFieldOriginalInvokeTypeSize = |
| 3735 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 3736 | static constexpr size_t kFieldReturnType = |
| 3737 | kFieldOriginalInvokeType + kFieldOriginalInvokeTypeSize; |
| 3738 | static constexpr size_t kFieldReturnTypeSize = |
| 3739 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 3740 | static constexpr size_t kFlagCanThrow = kFieldReturnType + kFieldReturnTypeSize; |
| 3741 | static constexpr size_t kNumberOfInvokePackedBits = kFlagCanThrow + 1; |
| 3742 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3743 | using OriginalInvokeTypeField = |
| 3744 | BitField<InvokeType, kFieldOriginalInvokeType, kFieldOriginalInvokeTypeSize>; |
| 3745 | using ReturnTypeField = BitField<Primitive::Type, kFieldReturnType, kFieldReturnTypeSize>; |
| 3746 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3747 | HInvoke(ArenaAllocator* arena, |
| 3748 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3749 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3750 | Primitive::Type return_type, |
| 3751 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3752 | uint32_t dex_method_index, |
| 3753 | InvokeType original_invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3754 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3755 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3756 | number_of_arguments_(number_of_arguments), |
Vladimir Marko | b7d8e8c | 2015-09-17 15:47:05 +0100 | [diff] [blame] | 3757 | inputs_(number_of_arguments + number_of_other_inputs, |
| 3758 | arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3759 | dex_method_index_(dex_method_index), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3760 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3761 | intrinsic_optimizations_(0) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3762 | SetPackedField<ReturnTypeField>(return_type); |
| 3763 | SetPackedField<OriginalInvokeTypeField>(original_invoke_type); |
| 3764 | SetPackedFlag<kFlagCanThrow>(true); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3765 | } |
| 3766 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3767 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3768 | return inputs_[index]; |
| 3769 | } |
| 3770 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3771 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3772 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3773 | } |
| 3774 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3775 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3776 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3777 | uint32_t number_of_arguments_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3778 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3779 | const uint32_t dex_method_index_; |
| 3780 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3781 | |
| 3782 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3783 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3784 | |
| 3785 | private: |
| 3786 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3787 | }; |
| 3788 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3789 | class HInvokeUnresolved FINAL : public HInvoke { |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3790 | public: |
| 3791 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3792 | uint32_t number_of_arguments, |
| 3793 | Primitive::Type return_type, |
| 3794 | uint32_t dex_pc, |
| 3795 | uint32_t dex_method_index, |
| 3796 | InvokeType invoke_type) |
| 3797 | : HInvoke(arena, |
| 3798 | number_of_arguments, |
| 3799 | 0u /* number_of_other_inputs */, |
| 3800 | return_type, |
| 3801 | dex_pc, |
| 3802 | dex_method_index, |
| 3803 | invoke_type) { |
| 3804 | } |
| 3805 | |
| 3806 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3807 | |
| 3808 | private: |
| 3809 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3810 | }; |
| 3811 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3812 | class HInvokeStaticOrDirect FINAL : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3813 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3814 | // Requirements of this method call regarding the class |
| 3815 | // initialization (clinit) check of its declaring class. |
| 3816 | enum class ClinitCheckRequirement { |
| 3817 | kNone, // Class already initialized. |
| 3818 | kExplicit, // Static call having explicit clinit check as last input. |
| 3819 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3820 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3821 | }; |
| 3822 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3823 | // Determines how to load the target ArtMethod*. |
| 3824 | enum class MethodLoadKind { |
| 3825 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3826 | kStringInit, |
| 3827 | |
| 3828 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3829 | kRecursive, |
| 3830 | |
| 3831 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3832 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3833 | kDirectAddress, |
| 3834 | |
| 3835 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3836 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3837 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3838 | // the image relocatable or not. |
| 3839 | kDirectAddressWithFixup, |
| 3840 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3841 | // Load from resolved methods array in the dex cache using a PC-relative load. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3842 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3843 | // may cause class initialization (the entry may point to a resolution method), |
| 3844 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3845 | kDexCachePcRelative, |
| 3846 | |
| 3847 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3848 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3849 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3850 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3851 | kDexCacheViaMethod, |
| 3852 | }; |
| 3853 | |
| 3854 | // Determines the location of the code pointer. |
| 3855 | enum class CodePtrLocation { |
| 3856 | // Recursive call, use local PC-relative call instruction. |
| 3857 | kCallSelf, |
| 3858 | |
| 3859 | // Use PC-relative call instruction patched at link time. |
| 3860 | // Used for calls within an oat file, boot->boot or app->app. |
| 3861 | kCallPCRelative, |
| 3862 | |
| 3863 | // Call to a known target address, embed the direct address in code. |
| 3864 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3865 | kCallDirect, |
| 3866 | |
| 3867 | // Call to a target address that will be known at link time, embed the direct |
| 3868 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3869 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3870 | // the image relocatable or not. |
| 3871 | kCallDirectWithFixup, |
| 3872 | |
| 3873 | // Use code pointer from the ArtMethod*. |
| 3874 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3875 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3876 | kCallArtMethod, |
| 3877 | }; |
| 3878 | |
| 3879 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3880 | MethodLoadKind method_load_kind; |
| 3881 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3882 | // The method load data holds |
| 3883 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3884 | // Note that there are multiple string init methods, each having its own offset. |
| 3885 | // - the method address for kDirectAddress |
| 3886 | // - the dex cache arrays offset for kDexCachePcRel. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3887 | uint64_t method_load_data; |
| 3888 | uint64_t direct_code_ptr; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3889 | }; |
| 3890 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3891 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 3892 | uint32_t number_of_arguments, |
| 3893 | Primitive::Type return_type, |
| 3894 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3895 | uint32_t method_index, |
| 3896 | MethodReference target_method, |
| 3897 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 7904129 | 2015-03-26 10:05:54 +0000 | [diff] [blame] | 3898 | InvokeType original_invoke_type, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3899 | InvokeType optimized_invoke_type, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3900 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3901 | : HInvoke(arena, |
| 3902 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3903 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 3904 | // potentially one other if the clinit check is explicit, and potentially |
| 3905 | // one other if the method is a string factory. |
| 3906 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3907 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3908 | return_type, |
| 3909 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3910 | method_index, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3911 | original_invoke_type), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3912 | target_method_(target_method), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3913 | dispatch_info_(dispatch_info) { |
| 3914 | SetPackedField<OptimizedInvokeTypeField>(optimized_invoke_type); |
| 3915 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 3916 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3917 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3918 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3919 | bool had_current_method_input = HasCurrentMethodInput(); |
| 3920 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 3921 | |
| 3922 | // Using the current method is the default and once we find a better |
| 3923 | // method load kind, we should not go back to using the current method. |
| 3924 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 3925 | |
| 3926 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3927 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 3928 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3929 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3930 | dispatch_info_ = dispatch_info; |
| 3931 | } |
| 3932 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3933 | void AddSpecialInput(HInstruction* input) { |
| 3934 | // We allow only one special input. |
| 3935 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 3936 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3937 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 3938 | InsertInputAt(GetSpecialInputIndex(), input); |
| 3939 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3940 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3941 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3942 | // We access the method via the dex cache so we can't do an implicit null check. |
| 3943 | // TODO: for intrinsics we can generate implicit null checks. |
| 3944 | return false; |
| 3945 | } |
| 3946 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3947 | bool CanBeNull() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3948 | return GetPackedField<ReturnTypeField>() == Primitive::kPrimNot && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3949 | } |
| 3950 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3951 | // Get the index of the special input, if any. |
| 3952 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3953 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 3954 | // method pointer; otherwise there may be one platform-specific special input, |
| 3955 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3956 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
Nicolas Geoffray | 9779307 | 2016-02-16 15:33:54 +0000 | [diff] [blame] | 3957 | bool HasSpecialInput() const { return GetNumberOfArguments() != InputCount(); } |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3958 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3959 | InvokeType GetOptimizedInvokeType() const { |
| 3960 | return GetPackedField<OptimizedInvokeTypeField>(); |
| 3961 | } |
| 3962 | |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3963 | void SetOptimizedInvokeType(InvokeType invoke_type) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3964 | SetPackedField<OptimizedInvokeTypeField>(invoke_type); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3965 | } |
| 3966 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3967 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 3968 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 3969 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3970 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3971 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3972 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3973 | bool HasPcRelativeDexCache() const { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3974 | return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; |
| 3975 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3976 | bool HasCurrentMethodInput() const { |
| 3977 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 3978 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3979 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3980 | return true; |
| 3981 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3982 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3983 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3984 | return false; |
| 3985 | } |
| 3986 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3987 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
| 3988 | MethodReference GetTargetMethod() const { return target_method_; } |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3989 | void SetTargetMethod(MethodReference method) { target_method_ = method; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3990 | |
| 3991 | int32_t GetStringInitOffset() const { |
| 3992 | DCHECK(IsStringInit()); |
| 3993 | return dispatch_info_.method_load_data; |
| 3994 | } |
| 3995 | |
| 3996 | uint64_t GetMethodAddress() const { |
| 3997 | DCHECK(HasMethodAddress()); |
| 3998 | return dispatch_info_.method_load_data; |
| 3999 | } |
| 4000 | |
| 4001 | uint32_t GetDexCacheArrayOffset() const { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4002 | DCHECK(HasPcRelativeDexCache()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4003 | return dispatch_info_.method_load_data; |
| 4004 | } |
| 4005 | |
| 4006 | uint64_t GetDirectCodePtr() const { |
| 4007 | DCHECK(HasDirectCodePtr()); |
| 4008 | return dispatch_info_.direct_code_ptr; |
| 4009 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4010 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4011 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 4012 | return GetPackedField<ClinitCheckRequirementField>(); |
| 4013 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 4014 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4015 | // Is this instruction a call to a static method? |
| 4016 | bool IsStatic() const { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4017 | return GetOriginalInvokeType() == kStatic; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4018 | } |
| 4019 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4020 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 4021 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 4022 | // instruction; only relevant for static calls with explicit clinit check. |
| 4023 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4024 | DCHECK(IsStaticWithExplicitClinitCheck()); |
| 4025 | size_t last_input_index = InputCount() - 1; |
| 4026 | HInstruction* last_input = InputAt(last_input_index); |
| 4027 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4028 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4029 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4030 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4031 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4032 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4033 | } |
| 4034 | |
| 4035 | // 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] | 4036 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4037 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4038 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4039 | } |
| 4040 | |
| 4041 | // Is this a call to a static method whose declaring class has an |
| 4042 | // implicit intialization check requirement? |
| 4043 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4044 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4045 | } |
| 4046 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4047 | // Does this method load kind need the current method as an input? |
| 4048 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
| 4049 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kDexCacheViaMethod; |
| 4050 | } |
| 4051 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4052 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4053 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4054 | protected: |
| 4055 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 4056 | const HUserRecord<HInstruction*> input_record = HInvoke::InputRecordAt(i); |
| 4057 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck() && (i == InputCount() - 1)) { |
| 4058 | HInstruction* input = input_record.GetInstruction(); |
| 4059 | // `input` is the last input of a static invoke marked as having |
| 4060 | // an explicit clinit check. It must either be: |
| 4061 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 4062 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 4063 | DCHECK(input != nullptr); |
| 4064 | DCHECK(input->IsClinitCheck() || input->IsLoadClass()) << input->DebugName(); |
| 4065 | } |
| 4066 | return input_record; |
| 4067 | } |
| 4068 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4069 | void InsertInputAt(size_t index, HInstruction* input); |
| 4070 | void RemoveInputAt(size_t index); |
| 4071 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4072 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4073 | static constexpr size_t kFieldOptimizedInvokeType = kNumberOfInvokePackedBits; |
| 4074 | static constexpr size_t kFieldOptimizedInvokeTypeSize = |
| 4075 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 4076 | static constexpr size_t kFieldClinitCheckRequirement = |
| 4077 | kFieldOptimizedInvokeType + kFieldOptimizedInvokeTypeSize; |
| 4078 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 4079 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 4080 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 4081 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 4082 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 4083 | "Too many packed fields."); |
| 4084 | using OptimizedInvokeTypeField = |
| 4085 | BitField<InvokeType, kFieldOptimizedInvokeType, kFieldOptimizedInvokeTypeSize>; |
| 4086 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 4087 | kFieldClinitCheckRequirement, |
| 4088 | kFieldClinitCheckRequirementSize>; |
| 4089 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4090 | // The target method may refer to different dex file or method index than the original |
| 4091 | // invoke. This happens for sharpened calls and for calls where a method was redeclared |
| 4092 | // in derived class to increase visibility. |
| 4093 | MethodReference target_method_; |
| 4094 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4095 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4096 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4097 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 4098 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4099 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4100 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4101 | class HInvokeVirtual FINAL : public HInvoke { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4102 | public: |
| 4103 | HInvokeVirtual(ArenaAllocator* arena, |
| 4104 | uint32_t number_of_arguments, |
| 4105 | Primitive::Type return_type, |
| 4106 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4107 | uint32_t dex_method_index, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4108 | uint32_t vtable_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4109 | : 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] | 4110 | vtable_index_(vtable_index) {} |
| 4111 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4112 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4113 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4114 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4115 | } |
| 4116 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4117 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 4118 | |
| 4119 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 4120 | |
| 4121 | private: |
| 4122 | const uint32_t vtable_index_; |
| 4123 | |
| 4124 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 4125 | }; |
| 4126 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4127 | class HInvokeInterface FINAL : public HInvoke { |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4128 | public: |
| 4129 | HInvokeInterface(ArenaAllocator* arena, |
| 4130 | uint32_t number_of_arguments, |
| 4131 | Primitive::Type return_type, |
| 4132 | uint32_t dex_pc, |
| 4133 | uint32_t dex_method_index, |
| 4134 | uint32_t imt_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4135 | : 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] | 4136 | imt_index_(imt_index) {} |
| 4137 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4138 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4139 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4140 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4141 | } |
| 4142 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4143 | uint32_t GetImtIndex() const { return imt_index_; } |
| 4144 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 4145 | |
| 4146 | DECLARE_INSTRUCTION(InvokeInterface); |
| 4147 | |
| 4148 | private: |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4149 | const uint32_t imt_index_; |
| 4150 | |
| 4151 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 4152 | }; |
| 4153 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4154 | class HNeg FINAL : public HUnaryOperation { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4155 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4156 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 937e6cd | 2016-03-22 11:54:37 +0000 | [diff] [blame] | 4157 | : HUnaryOperation(result_type, input, dex_pc) { |
| 4158 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(input->GetType())); |
| 4159 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4160 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4161 | template <typename T> T Compute(T x) const { return -x; } |
| 4162 | |
| 4163 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4164 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4165 | } |
| 4166 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4167 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4168 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4169 | HConstant* Evaluate(HFloatConstant* x) const OVERRIDE { |
| 4170 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 4171 | } |
| 4172 | HConstant* Evaluate(HDoubleConstant* x) const OVERRIDE { |
| 4173 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 4174 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 4175 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4176 | DECLARE_INSTRUCTION(Neg); |
| 4177 | |
| 4178 | private: |
| 4179 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 4180 | }; |
| 4181 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4182 | class HNewArray FINAL : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4183 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4184 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4185 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4186 | uint32_t dex_pc, |
| 4187 | uint16_t type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4188 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4189 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4190 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4191 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4192 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4193 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4194 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4195 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4196 | } |
| 4197 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4198 | uint16_t GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4199 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4200 | |
| 4201 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4202 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4203 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4204 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 4205 | bool CanThrow() const OVERRIDE { return true; } |
| 4206 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4207 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4208 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4209 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 4210 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4211 | DECLARE_INSTRUCTION(NewArray); |
| 4212 | |
| 4213 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4214 | const uint16_t type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4215 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4216 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4217 | |
| 4218 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 4219 | }; |
| 4220 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4221 | class HAdd FINAL : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4222 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4223 | HAdd(Primitive::Type result_type, |
| 4224 | HInstruction* left, |
| 4225 | HInstruction* right, |
| 4226 | uint32_t dex_pc = kNoDexPc) |
| 4227 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4228 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4229 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4230 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4231 | template <typename T> T Compute(T x, T y) const { return x + y; } |
| 4232 | |
| 4233 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4234 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4235 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4236 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4237 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4238 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4239 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4240 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4241 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4242 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4243 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4244 | } |
| 4245 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4246 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4247 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4248 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4249 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4250 | DECLARE_INSTRUCTION(Add); |
| 4251 | |
| 4252 | private: |
| 4253 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 4254 | }; |
| 4255 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4256 | class HSub FINAL : public HBinaryOperation { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4257 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4258 | HSub(Primitive::Type result_type, |
| 4259 | HInstruction* left, |
| 4260 | HInstruction* right, |
| 4261 | uint32_t dex_pc = kNoDexPc) |
| 4262 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4263 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4264 | template <typename T> T Compute(T x, T y) const { return x - y; } |
| 4265 | |
| 4266 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4267 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4268 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4269 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4270 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4271 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4272 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4273 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4274 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4275 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4276 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4277 | } |
| 4278 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4279 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4280 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4281 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4282 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4283 | DECLARE_INSTRUCTION(Sub); |
| 4284 | |
| 4285 | private: |
| 4286 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 4287 | }; |
| 4288 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4289 | class HMul FINAL : public HBinaryOperation { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4290 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4291 | HMul(Primitive::Type result_type, |
| 4292 | HInstruction* left, |
| 4293 | HInstruction* right, |
| 4294 | uint32_t dex_pc = kNoDexPc) |
| 4295 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4296 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4297 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4298 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4299 | template <typename T> T Compute(T x, T y) const { return x * y; } |
| 4300 | |
| 4301 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4302 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4303 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4304 | } |
| 4305 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4306 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4307 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4308 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4309 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4310 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4311 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4312 | } |
| 4313 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4314 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4315 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4316 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4317 | |
| 4318 | DECLARE_INSTRUCTION(Mul); |
| 4319 | |
| 4320 | private: |
| 4321 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 4322 | }; |
| 4323 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4324 | class HDiv FINAL : public HBinaryOperation { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4325 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4326 | HDiv(Primitive::Type result_type, |
| 4327 | HInstruction* left, |
| 4328 | HInstruction* right, |
| 4329 | uint32_t dex_pc) |
| 4330 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4331 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4332 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4333 | T ComputeIntegral(T x, T y) const { |
| 4334 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4335 | // Our graph structure ensures we never have 0 for `y` during |
| 4336 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4337 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4338 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4339 | return (y == -1) ? -x : x / y; |
| 4340 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4341 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4342 | template <typename T> |
| 4343 | T ComputeFP(T x, T y) const { |
| 4344 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4345 | return x / y; |
| 4346 | } |
| 4347 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4348 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4349 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4350 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4351 | } |
| 4352 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4353 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4354 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4355 | } |
| 4356 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4357 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4358 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4359 | } |
| 4360 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4361 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4362 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4363 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4364 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4365 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4366 | // The generated code can use a runtime call. |
| 4367 | return SideEffects::CanTriggerGC(); |
| 4368 | } |
| 4369 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4370 | DECLARE_INSTRUCTION(Div); |
| 4371 | |
| 4372 | private: |
| 4373 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 4374 | }; |
| 4375 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4376 | class HRem FINAL : public HBinaryOperation { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4377 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4378 | HRem(Primitive::Type result_type, |
| 4379 | HInstruction* left, |
| 4380 | HInstruction* right, |
| 4381 | uint32_t dex_pc) |
| 4382 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4383 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4384 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4385 | T ComputeIntegral(T x, T y) const { |
| 4386 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4387 | // Our graph structure ensures we never have 0 for `y` during |
| 4388 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4389 | DCHECK_NE(y, 0); |
| 4390 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 4391 | return (y == -1) ? 0 : x % y; |
| 4392 | } |
| 4393 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4394 | template <typename T> |
| 4395 | T ComputeFP(T x, T y) const { |
| 4396 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4397 | return std::fmod(x, y); |
| 4398 | } |
| 4399 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4400 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4401 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4402 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4403 | } |
| 4404 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4405 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4406 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4407 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4408 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4409 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4410 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4411 | } |
| 4412 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4413 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4414 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4415 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4416 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4417 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4418 | return SideEffects::CanTriggerGC(); |
| 4419 | } |
| 4420 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4421 | DECLARE_INSTRUCTION(Rem); |
| 4422 | |
| 4423 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4424 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 4425 | }; |
| 4426 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4427 | class HDivZeroCheck FINAL : public HExpression<1> { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4428 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4429 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
| 4430 | // constructor. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4431 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4432 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4433 | SetRawInputAt(0, value); |
| 4434 | } |
| 4435 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4436 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 4437 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4438 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4439 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4440 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4441 | return true; |
| 4442 | } |
| 4443 | |
| 4444 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4445 | bool CanThrow() const OVERRIDE { return true; } |
| 4446 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4447 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 4448 | |
| 4449 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4450 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 4451 | }; |
| 4452 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4453 | class HShl FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4454 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4455 | HShl(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4456 | HInstruction* value, |
| 4457 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4458 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4459 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4460 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4461 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4462 | } |
| 4463 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4464 | template <typename T> |
| 4465 | T Compute(T value, int32_t distance, int32_t max_shift_distance) const { |
| 4466 | return value << (distance & max_shift_distance); |
| 4467 | } |
| 4468 | |
| 4469 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4470 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4471 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4472 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4473 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4474 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4475 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4476 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4477 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4478 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4479 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4480 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4481 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4482 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4483 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4484 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4485 | UNREACHABLE(); |
| 4486 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4487 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4488 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4489 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4490 | UNREACHABLE(); |
| 4491 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4492 | |
| 4493 | DECLARE_INSTRUCTION(Shl); |
| 4494 | |
| 4495 | private: |
| 4496 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 4497 | }; |
| 4498 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4499 | class HShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4500 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4501 | HShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4502 | HInstruction* value, |
| 4503 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4504 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4505 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4506 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4507 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4508 | } |
| 4509 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4510 | template <typename T> |
| 4511 | T Compute(T value, int32_t distance, int32_t max_shift_distance) const { |
| 4512 | return value >> (distance & max_shift_distance); |
| 4513 | } |
| 4514 | |
| 4515 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4516 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4517 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4518 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4519 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4520 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4521 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4522 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4523 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4524 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4525 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4526 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4527 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4528 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4529 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4530 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4531 | UNREACHABLE(); |
| 4532 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4533 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4534 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4535 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4536 | UNREACHABLE(); |
| 4537 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4538 | |
| 4539 | DECLARE_INSTRUCTION(Shr); |
| 4540 | |
| 4541 | private: |
| 4542 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 4543 | }; |
| 4544 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4545 | class HUShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4546 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4547 | HUShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4548 | HInstruction* value, |
| 4549 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4550 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4551 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4552 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4553 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4554 | } |
| 4555 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4556 | template <typename T> |
| 4557 | T Compute(T value, int32_t distance, int32_t max_shift_distance) const { |
| 4558 | typedef typename std::make_unsigned<T>::type V; |
| 4559 | V ux = static_cast<V>(value); |
| 4560 | return static_cast<T>(ux >> (distance & max_shift_distance)); |
| 4561 | } |
| 4562 | |
| 4563 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4564 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4565 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4566 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4567 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4568 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4569 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4570 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4571 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4572 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4573 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4574 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4575 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4576 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4577 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4578 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4579 | UNREACHABLE(); |
| 4580 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4581 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4582 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4583 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4584 | UNREACHABLE(); |
| 4585 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4586 | |
| 4587 | DECLARE_INSTRUCTION(UShr); |
| 4588 | |
| 4589 | private: |
| 4590 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 4591 | }; |
| 4592 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4593 | class HAnd FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4594 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4595 | HAnd(Primitive::Type result_type, |
| 4596 | HInstruction* left, |
| 4597 | HInstruction* right, |
| 4598 | uint32_t dex_pc = kNoDexPc) |
| 4599 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4600 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4601 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4602 | |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 4603 | template <typename T> T Compute(T x, T y) const { return x & y; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4604 | |
| 4605 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4606 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4607 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4608 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4609 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4610 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4611 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4612 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4613 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4614 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4615 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4616 | UNREACHABLE(); |
| 4617 | } |
| 4618 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4619 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4620 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4621 | UNREACHABLE(); |
| 4622 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4623 | |
| 4624 | DECLARE_INSTRUCTION(And); |
| 4625 | |
| 4626 | private: |
| 4627 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4628 | }; |
| 4629 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4630 | class HOr FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4631 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4632 | HOr(Primitive::Type result_type, |
| 4633 | HInstruction* left, |
| 4634 | HInstruction* right, |
| 4635 | uint32_t dex_pc = kNoDexPc) |
| 4636 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4637 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4638 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4639 | |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 4640 | template <typename T> T Compute(T x, T y) const { return x | y; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4641 | |
| 4642 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4643 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4644 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4645 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4646 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4647 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4648 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4649 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4650 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4651 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4652 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4653 | UNREACHABLE(); |
| 4654 | } |
| 4655 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4656 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4657 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4658 | UNREACHABLE(); |
| 4659 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4660 | |
| 4661 | DECLARE_INSTRUCTION(Or); |
| 4662 | |
| 4663 | private: |
| 4664 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4665 | }; |
| 4666 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4667 | class HXor FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4668 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4669 | HXor(Primitive::Type result_type, |
| 4670 | HInstruction* left, |
| 4671 | HInstruction* right, |
| 4672 | uint32_t dex_pc = kNoDexPc) |
| 4673 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4674 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4675 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4676 | |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 4677 | template <typename T> T Compute(T x, T y) const { return x ^ y; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4678 | |
| 4679 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4680 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4681 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4682 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4683 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4684 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4685 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4686 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4687 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4688 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4689 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4690 | UNREACHABLE(); |
| 4691 | } |
| 4692 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4693 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4694 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4695 | UNREACHABLE(); |
| 4696 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4697 | |
| 4698 | DECLARE_INSTRUCTION(Xor); |
| 4699 | |
| 4700 | private: |
| 4701 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 4702 | }; |
| 4703 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4704 | class HRor FINAL : public HBinaryOperation { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4705 | public: |
| 4706 | HRor(Primitive::Type result_type, HInstruction* value, HInstruction* distance) |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4707 | : HBinaryOperation(result_type, value, distance) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4708 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4709 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4710 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4711 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4712 | template <typename T> |
| 4713 | T Compute(T value, int32_t distance, int32_t max_shift_value) const { |
| 4714 | typedef typename std::make_unsigned<T>::type V; |
| 4715 | V ux = static_cast<V>(value); |
| 4716 | if ((distance & max_shift_value) == 0) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4717 | return static_cast<T>(ux); |
| 4718 | } else { |
| 4719 | const V reg_bits = sizeof(T) * 8; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4720 | return static_cast<T>(ux >> (distance & max_shift_value)) | |
| 4721 | (value << (reg_bits - (distance & max_shift_value))); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4722 | } |
| 4723 | } |
| 4724 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4725 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4726 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4727 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4728 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4729 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4730 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4731 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4732 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4733 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4734 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4735 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4736 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4737 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4738 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4739 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4740 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4741 | UNREACHABLE(); |
| 4742 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4743 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4744 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4745 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4746 | UNREACHABLE(); |
| 4747 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4748 | |
| 4749 | DECLARE_INSTRUCTION(Ror); |
| 4750 | |
| 4751 | private: |
| 4752 | DISALLOW_COPY_AND_ASSIGN(HRor); |
| 4753 | }; |
| 4754 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4755 | // The value of a parameter in this method. Its location depends on |
| 4756 | // the calling convention. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4757 | class HParameterValue FINAL : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4758 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4759 | HParameterValue(const DexFile& dex_file, |
| 4760 | uint16_t type_index, |
| 4761 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4762 | Primitive::Type parameter_type, |
| 4763 | bool is_this = false) |
| 4764 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4765 | dex_file_(dex_file), |
| 4766 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4767 | index_(index) { |
| 4768 | SetPackedFlag<kFlagIsThis>(is_this); |
| 4769 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 4770 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4771 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4772 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4773 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4774 | uint8_t GetIndex() const { return index_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4775 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4776 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4777 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 4778 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4779 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4780 | DECLARE_INSTRUCTION(ParameterValue); |
| 4781 | |
| 4782 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4783 | // Whether or not the parameter value corresponds to 'this' argument. |
| 4784 | static constexpr size_t kFlagIsThis = kNumberOfExpressionPackedBits; |
| 4785 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 4786 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 4787 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 4788 | "Too many packed fields."); |
| 4789 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4790 | const DexFile& dex_file_; |
| 4791 | const uint16_t type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4792 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4793 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4794 | const uint8_t index_; |
| 4795 | |
| 4796 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 4797 | }; |
| 4798 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4799 | class HNot FINAL : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4800 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4801 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4802 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4803 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4804 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4805 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4806 | return true; |
| 4807 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4808 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4809 | template <typename T> T Compute(T x) const { return ~x; } |
| 4810 | |
| 4811 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4812 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4813 | } |
| 4814 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4815 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4816 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4817 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4818 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4819 | UNREACHABLE(); |
| 4820 | } |
| 4821 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4822 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4823 | UNREACHABLE(); |
| 4824 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4825 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4826 | DECLARE_INSTRUCTION(Not); |
| 4827 | |
| 4828 | private: |
| 4829 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 4830 | }; |
| 4831 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4832 | class HBooleanNot FINAL : public HUnaryOperation { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4833 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4834 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4835 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4836 | |
| 4837 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4838 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4839 | return true; |
| 4840 | } |
| 4841 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4842 | template <typename T> bool Compute(T x) const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4843 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4844 | return !x; |
| 4845 | } |
| 4846 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4847 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4848 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4849 | } |
| 4850 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4851 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4852 | UNREACHABLE(); |
| 4853 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4854 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4855 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4856 | UNREACHABLE(); |
| 4857 | } |
| 4858 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4859 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4860 | UNREACHABLE(); |
| 4861 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4862 | |
| 4863 | DECLARE_INSTRUCTION(BooleanNot); |
| 4864 | |
| 4865 | private: |
| 4866 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 4867 | }; |
| 4868 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4869 | class HTypeConversion FINAL : public HExpression<1> { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4870 | public: |
| 4871 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4872 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4873 | : HExpression(result_type, |
| 4874 | SideEffectsForArchRuntimeCalls(input->GetType(), result_type), |
| 4875 | dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4876 | SetRawInputAt(0, input); |
Roland Levillain | f355c3f | 2016-03-30 19:09:03 +0100 | [diff] [blame] | 4877 | // Invariant: We should never generate a conversion to a Boolean value. |
| 4878 | DCHECK_NE(Primitive::kPrimBoolean, result_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4879 | } |
| 4880 | |
| 4881 | HInstruction* GetInput() const { return InputAt(0); } |
| 4882 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 4883 | Primitive::Type GetResultType() const { return GetType(); } |
| 4884 | |
| 4885 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | ed9b195 | 2014-11-06 11:10:17 +0000 | [diff] [blame] | 4886 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4887 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 4888 | // Try to statically evaluate the conversion and return a HConstant |
| 4889 | // containing the result. If the input cannot be converted, return nullptr. |
| 4890 | HConstant* TryStaticEvaluation() const; |
| 4891 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4892 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type input_type, |
| 4893 | Primitive::Type result_type) { |
| 4894 | // Some architectures may not require the 'GC' side effects, but at this point |
| 4895 | // in the compilation process we do not know what architecture we will |
| 4896 | // generate code for, so we must be conservative. |
Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 4897 | if ((Primitive::IsFloatingPointType(input_type) && Primitive::IsIntegralType(result_type)) |
| 4898 | || (input_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(result_type))) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4899 | return SideEffects::CanTriggerGC(); |
| 4900 | } |
| 4901 | return SideEffects::None(); |
| 4902 | } |
| 4903 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4904 | DECLARE_INSTRUCTION(TypeConversion); |
| 4905 | |
| 4906 | private: |
| 4907 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 4908 | }; |
| 4909 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 4910 | static constexpr uint32_t kNoRegNumber = -1; |
| 4911 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4912 | class HNullCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4913 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4914 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
| 4915 | // constructor. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4916 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4917 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4918 | SetRawInputAt(0, value); |
| 4919 | } |
| 4920 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4921 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4922 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4923 | return true; |
| 4924 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4925 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4926 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4927 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4928 | bool CanThrow() const OVERRIDE { return true; } |
| 4929 | |
| 4930 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4931 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4932 | |
| 4933 | DECLARE_INSTRUCTION(NullCheck); |
| 4934 | |
| 4935 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4936 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 4937 | }; |
| 4938 | |
| 4939 | class FieldInfo : public ValueObject { |
| 4940 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4941 | FieldInfo(MemberOffset field_offset, |
| 4942 | Primitive::Type field_type, |
| 4943 | bool is_volatile, |
| 4944 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4945 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4946 | const DexFile& dex_file, |
| 4947 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4948 | : field_offset_(field_offset), |
| 4949 | field_type_(field_type), |
| 4950 | is_volatile_(is_volatile), |
| 4951 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4952 | declaring_class_def_index_(declaring_class_def_index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4953 | dex_file_(dex_file), |
| 4954 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4955 | |
| 4956 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4957 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4958 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4959 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4960 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4961 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4962 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4963 | |
| 4964 | private: |
| 4965 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4966 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4967 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4968 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4969 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4970 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4971 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4972 | }; |
| 4973 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4974 | class HInstanceFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4975 | public: |
| 4976 | HInstanceFieldGet(HInstruction* value, |
| 4977 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4978 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4979 | bool is_volatile, |
| 4980 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4981 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4982 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4983 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4984 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4985 | : HExpression(field_type, |
| 4986 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 4987 | dex_pc), |
| 4988 | field_info_(field_offset, |
| 4989 | field_type, |
| 4990 | is_volatile, |
| 4991 | field_idx, |
| 4992 | declaring_class_def_index, |
| 4993 | dex_file, |
| 4994 | dex_cache) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4995 | SetRawInputAt(0, value); |
| 4996 | } |
| 4997 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 4998 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4999 | |
| 5000 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 5001 | HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
| 5002 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5003 | } |
| 5004 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5005 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5006 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5007 | } |
| 5008 | |
| 5009 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 5010 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5011 | } |
| 5012 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5013 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5014 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5015 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5016 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5017 | |
| 5018 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 5019 | |
| 5020 | private: |
| 5021 | const FieldInfo field_info_; |
| 5022 | |
| 5023 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 5024 | }; |
| 5025 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5026 | class HInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5027 | public: |
| 5028 | HInstanceFieldSet(HInstruction* object, |
| 5029 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5030 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5031 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5032 | bool is_volatile, |
| 5033 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5034 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5035 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5036 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5037 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5038 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5039 | dex_pc), |
| 5040 | field_info_(field_offset, |
| 5041 | field_type, |
| 5042 | is_volatile, |
| 5043 | field_idx, |
| 5044 | declaring_class_def_index, |
| 5045 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5046 | dex_cache) { |
| 5047 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5048 | SetRawInputAt(0, object); |
| 5049 | SetRawInputAt(1, value); |
| 5050 | } |
| 5051 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5052 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5053 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5054 | } |
| 5055 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5056 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5057 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5058 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5059 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5060 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5061 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5062 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5063 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5064 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 5065 | |
| 5066 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5067 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5068 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5069 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5070 | "Too many packed fields."); |
| 5071 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5072 | const FieldInfo field_info_; |
| 5073 | |
| 5074 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 5075 | }; |
| 5076 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5077 | class HArrayGet FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5078 | public: |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5079 | HArrayGet(HInstruction* array, HInstruction* index, Primitive::Type type, uint32_t dex_pc) |
| 5080 | : HExpression(type, SideEffects::ArrayReadOfType(type), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5081 | SetRawInputAt(0, array); |
| 5082 | SetRawInputAt(1, index); |
| 5083 | } |
| 5084 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5085 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5086 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5087 | return true; |
| 5088 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5089 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5090 | // TODO: We can be smarter here. |
| 5091 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 5092 | // which generates the implicit null check. There are cases when these can be removed |
| 5093 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 5094 | // implicit check here (as long as the address falls in the first page). |
| 5095 | return false; |
| 5096 | } |
| 5097 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5098 | bool IsEquivalentOf(HArrayGet* other) const { |
| 5099 | bool result = (GetDexPc() == other->GetDexPc()); |
| 5100 | if (kIsDebugBuild && result) { |
| 5101 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 5102 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 5103 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
| 5104 | if (Primitive::IsIntOrLongType(GetType())) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5105 | DCHECK(Primitive::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5106 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5107 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 5108 | DCHECK(Primitive::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5109 | } |
| 5110 | } |
| 5111 | return result; |
| 5112 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5113 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5114 | HInstruction* GetArray() const { return InputAt(0); } |
| 5115 | HInstruction* GetIndex() const { return InputAt(1); } |
| 5116 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5117 | DECLARE_INSTRUCTION(ArrayGet); |
| 5118 | |
| 5119 | private: |
| 5120 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 5121 | }; |
| 5122 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5123 | class HArraySet FINAL : public HTemplateInstruction<3> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5124 | public: |
| 5125 | HArraySet(HInstruction* array, |
| 5126 | HInstruction* index, |
| 5127 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5128 | Primitive::Type expected_component_type, |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5129 | uint32_t dex_pc) |
| 5130 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5131 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
| 5132 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == Primitive::kPrimNot); |
| 5133 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 5134 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5135 | SetRawInputAt(0, array); |
| 5136 | SetRawInputAt(1, index); |
| 5137 | SetRawInputAt(2, value); |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5138 | // Make a best guess now, may be refined during SSA building. |
| 5139 | ComputeSideEffects(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5140 | } |
| 5141 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5142 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5143 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5144 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5145 | } |
| 5146 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5147 | // Can throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5148 | bool CanThrow() const OVERRIDE { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5149 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5150 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5151 | // TODO: Same as for ArrayGet. |
| 5152 | return false; |
| 5153 | } |
| 5154 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5155 | void ClearNeedsTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5156 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5157 | } |
| 5158 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5159 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5160 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5161 | } |
| 5162 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5163 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5164 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5165 | } |
| 5166 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5167 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5168 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 5169 | bool StaticTypeOfArrayIsObjectArray() const { |
| 5170 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 5171 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5172 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5173 | HInstruction* GetArray() const { return InputAt(0); } |
| 5174 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5175 | HInstruction* GetValue() const { return InputAt(2); } |
| 5176 | |
| 5177 | Primitive::Type GetComponentType() const { |
| 5178 | // The Dex format does not type floating point index operations. Since the |
| 5179 | // `expected_component_type_` is set during building and can therefore not |
| 5180 | // be correct, we also check what is the value type. If it is a floating |
| 5181 | // point type, we must use that type. |
| 5182 | Primitive::Type value_type = GetValue()->GetType(); |
| 5183 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 5184 | ? value_type |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5185 | : GetRawExpectedComponentType(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5186 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5187 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5188 | Primitive::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5189 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5190 | } |
| 5191 | |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5192 | void ComputeSideEffects() { |
| 5193 | Primitive::Type type = GetComponentType(); |
| 5194 | SetSideEffects(SideEffects::ArrayWriteOfType(type).Union( |
| 5195 | SideEffectsForArchRuntimeCalls(type))); |
| 5196 | } |
| 5197 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5198 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 5199 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 5200 | } |
| 5201 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5202 | DECLARE_INSTRUCTION(ArraySet); |
| 5203 | |
| 5204 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5205 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 5206 | static constexpr size_t kFieldExpectedComponentTypeSize = |
| 5207 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5208 | static constexpr size_t kFlagNeedsTypeCheck = |
| 5209 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 5210 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5211 | // Cached information for the reference_type_info_ so that codegen |
| 5212 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5213 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 5214 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 5215 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 5216 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5217 | using ExpectedComponentTypeField = |
| 5218 | BitField<Primitive::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5219 | |
| 5220 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 5221 | }; |
| 5222 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5223 | class HArrayLength FINAL : public HExpression<1> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5224 | public: |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 5225 | HArrayLength(HInstruction* array, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5226 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5227 | // Note that arrays do not change length, so the instruction does not |
| 5228 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5229 | SetRawInputAt(0, array); |
| 5230 | } |
| 5231 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5232 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5233 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5234 | return true; |
| 5235 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5236 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5237 | return obj == InputAt(0); |
| 5238 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5239 | |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5240 | void MarkAsStringLength() { SetPackedFlag<kFlagIsStringLength>(); } |
| 5241 | bool IsStringLength() const { return GetPackedFlag<kFlagIsStringLength>(); } |
| 5242 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5243 | DECLARE_INSTRUCTION(ArrayLength); |
| 5244 | |
| 5245 | private: |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5246 | // We treat a String as an array, creating the HArrayLength from String.length() |
| 5247 | // or String.isEmpty() intrinsic in the instruction simplifier. We can always |
| 5248 | // determine whether a particular HArrayLength is actually a String.length() by |
| 5249 | // looking at the type of the input but that requires holding the mutator lock, so |
| 5250 | // we prefer to use a flag, so that code generators don't need to do the locking. |
| 5251 | static constexpr size_t kFlagIsStringLength = kNumberOfExpressionPackedBits; |
| 5252 | static constexpr size_t kNumberOfArrayLengthPackedBits = kFlagIsStringLength + 1; |
| 5253 | static_assert(kNumberOfArrayLengthPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5254 | "Too many packed fields."); |
| 5255 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5256 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 5257 | }; |
| 5258 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5259 | class HBoundsCheck FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5260 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5261 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
| 5262 | // constructor. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5263 | HBoundsCheck(HInstruction* index, HInstruction* length, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5264 | : HExpression(index->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 5265 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(index->GetType())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5266 | SetRawInputAt(0, index); |
| 5267 | SetRawInputAt(1, length); |
| 5268 | } |
| 5269 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5270 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5271 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5272 | return true; |
| 5273 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5274 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5275 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5276 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5277 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5278 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5279 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5280 | |
| 5281 | DECLARE_INSTRUCTION(BoundsCheck); |
| 5282 | |
| 5283 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5284 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 5285 | }; |
| 5286 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5287 | class HSuspendCheck FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5288 | public: |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 5289 | explicit HSuspendCheck(uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5290 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5291 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5292 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5293 | return true; |
| 5294 | } |
| 5295 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5296 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 5297 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5298 | |
| 5299 | DECLARE_INSTRUCTION(SuspendCheck); |
| 5300 | |
| 5301 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5302 | // Only used for code generation, in order to share the same slow path between back edges |
| 5303 | // of a same loop. |
| 5304 | SlowPathCode* slow_path_; |
| 5305 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5306 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 5307 | }; |
| 5308 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 5309 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 5310 | // It ensures that we can generate line number and local variables at this point. |
| 5311 | class HNativeDebugInfo : public HTemplateInstruction<0> { |
| 5312 | public: |
| 5313 | explicit HNativeDebugInfo(uint32_t dex_pc) |
| 5314 | : HTemplateInstruction<0>(SideEffects::None(), dex_pc) {} |
| 5315 | |
| 5316 | bool NeedsEnvironment() const OVERRIDE { |
| 5317 | return true; |
| 5318 | } |
| 5319 | |
| 5320 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 5321 | |
| 5322 | private: |
| 5323 | DISALLOW_COPY_AND_ASSIGN(HNativeDebugInfo); |
| 5324 | }; |
| 5325 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5326 | /** |
| 5327 | * Instruction to load a Class object. |
| 5328 | */ |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5329 | class HLoadClass FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5330 | public: |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5331 | HLoadClass(HCurrentMethod* current_method, |
| 5332 | uint16_t type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5333 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5334 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5335 | uint32_t dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5336 | bool needs_access_check, |
| 5337 | bool is_in_dex_cache) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5338 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5339 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5340 | dex_file_(dex_file), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5341 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5342 | // Referrers class should not need access check. We never inline unverified |
| 5343 | // methods so we can't possibly end up in this situation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5344 | DCHECK(!is_referrers_class || !needs_access_check); |
| 5345 | |
| 5346 | SetPackedFlag<kFlagIsReferrersClass>(is_referrers_class); |
| 5347 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
| 5348 | SetPackedFlag<kFlagIsInDexCache>(is_in_dex_cache); |
| 5349 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5350 | SetRawInputAt(0, current_method); |
| 5351 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5352 | |
| 5353 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5354 | |
| 5355 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | a9a306d | 2015-10-08 16:48:31 +0100 | [diff] [blame] | 5356 | // Note that we don't need to test for generate_clinit_check_. |
| 5357 | // Whether or not we need to generate the clinit check is processed in |
| 5358 | // prepare_for_register_allocator based on existing HInvokes and HClinitChecks. |
Calin Juravle | 386062d | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5359 | return other->AsLoadClass()->type_index_ == type_index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5360 | other->AsLoadClass()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5361 | } |
| 5362 | |
| 5363 | size_t ComputeHashCode() const OVERRIDE { return type_index_; } |
| 5364 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5365 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 5366 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5367 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5368 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5369 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5370 | } |
| 5371 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 5372 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 5373 | // The entrypoint the code generator is going to call does not do |
| 5374 | // clinit of the class. |
| 5375 | DCHECK(!NeedsAccessCheck()); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5376 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5377 | } |
| 5378 | |
| 5379 | bool CanCallRuntime() const { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5380 | return MustGenerateClinitCheck() || |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5381 | (!IsReferrersClass() && !IsInDexCache()) || |
| 5382 | NeedsAccessCheck(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5383 | } |
| 5384 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5385 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5386 | bool CanThrow() const OVERRIDE { |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 5387 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5388 | } |
| 5389 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5390 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 5391 | return loaded_class_rti_; |
| 5392 | } |
| 5393 | |
| 5394 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 5395 | // Make sure we only set exact types (the loaded class should never be merged). |
| 5396 | DCHECK(rti.IsExact()); |
| 5397 | loaded_class_rti_ = rti; |
| 5398 | } |
| 5399 | |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5400 | const DexFile& GetDexFile() { return dex_file_; } |
| 5401 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5402 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return !IsReferrersClass(); } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 5403 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5404 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5405 | return SideEffects::CanTriggerGC(); |
| 5406 | } |
| 5407 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5408 | bool IsReferrersClass() const { return GetPackedFlag<kFlagIsReferrersClass>(); } |
| 5409 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
| 5410 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
| 5411 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5412 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5413 | DECLARE_INSTRUCTION(LoadClass); |
| 5414 | |
| 5415 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5416 | static constexpr size_t kFlagIsReferrersClass = kNumberOfExpressionPackedBits; |
| 5417 | static constexpr size_t kFlagNeedsAccessCheck = kFlagIsReferrersClass + 1; |
| 5418 | static constexpr size_t kFlagIsInDexCache = kFlagNeedsAccessCheck + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5419 | // Whether this instruction must generate the initialization check. |
| 5420 | // Used for code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5421 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInDexCache + 1; |
| 5422 | static constexpr size_t kNumberOfLoadClassPackedBits = kFlagGenerateClInitCheck + 1; |
| 5423 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5424 | |
| 5425 | const uint16_t type_index_; |
| 5426 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5427 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5428 | ReferenceTypeInfo loaded_class_rti_; |
| 5429 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5430 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 5431 | }; |
| 5432 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5433 | class HLoadString FINAL : public HExpression<1> { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5434 | public: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5435 | // Determines how to load the String. |
| 5436 | enum class LoadKind { |
| 5437 | // Use boot image String* address that will be known at link time. |
| 5438 | // Used for boot image strings referenced by boot image code in non-PIC mode. |
| 5439 | kBootImageLinkTimeAddress, |
| 5440 | |
| 5441 | // Use PC-relative boot image String* address that will be known at link time. |
| 5442 | // Used for boot image strings referenced by boot image code in PIC mode. |
| 5443 | kBootImageLinkTimePcRelative, |
| 5444 | |
| 5445 | // Use a known boot image String* address, embedded in the code by the codegen. |
| 5446 | // Used for boot image strings referenced by apps in AOT- and JIT-compiled code. |
| 5447 | // Note: codegen needs to emit a linker patch if indicated by compiler options' |
| 5448 | // GetIncludePatchInformation(). |
| 5449 | kBootImageAddress, |
| 5450 | |
| 5451 | // Load from the resolved strings array at an absolute address. |
| 5452 | // Used for strings outside the boot image referenced by JIT-compiled code. |
| 5453 | kDexCacheAddress, |
| 5454 | |
| 5455 | // Load from resolved strings array in the dex cache using a PC-relative load. |
| 5456 | // Used for strings outside boot image when we know that we can access |
| 5457 | // the dex cache arrays using a PC-relative load. |
| 5458 | kDexCachePcRelative, |
| 5459 | |
| 5460 | // Load from resolved strings array accessed through the class loaded from |
| 5461 | // the compiled method's own ArtMethod*. This is the default access type when |
| 5462 | // all other types are unavailable. |
| 5463 | kDexCacheViaMethod, |
| 5464 | |
| 5465 | kLast = kDexCacheViaMethod |
| 5466 | }; |
| 5467 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5468 | HLoadString(HCurrentMethod* current_method, |
| 5469 | uint32_t string_index, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5470 | const DexFile& dex_file, |
| 5471 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5472 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5473 | string_index_(string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5474 | SetPackedFlag<kFlagIsInDexCache>(false); |
| 5475 | SetPackedField<LoadKindField>(LoadKind::kDexCacheViaMethod); |
| 5476 | load_data_.ref.dex_file = &dex_file; |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5477 | SetRawInputAt(0, current_method); |
| 5478 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5479 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5480 | void SetLoadKindWithAddress(LoadKind load_kind, uint64_t address) { |
| 5481 | DCHECK(HasAddress(load_kind)); |
| 5482 | load_data_.address = address; |
| 5483 | SetLoadKindInternal(load_kind); |
| 5484 | } |
| 5485 | |
| 5486 | void SetLoadKindWithStringReference(LoadKind load_kind, |
| 5487 | const DexFile& dex_file, |
| 5488 | uint32_t string_index) { |
| 5489 | DCHECK(HasStringReference(load_kind)); |
| 5490 | load_data_.ref.dex_file = &dex_file; |
| 5491 | string_index_ = string_index; |
| 5492 | SetLoadKindInternal(load_kind); |
| 5493 | } |
| 5494 | |
| 5495 | void SetLoadKindWithDexCacheReference(LoadKind load_kind, |
| 5496 | const DexFile& dex_file, |
| 5497 | uint32_t element_index) { |
| 5498 | DCHECK(HasDexCacheReference(load_kind)); |
| 5499 | load_data_.ref.dex_file = &dex_file; |
| 5500 | load_data_.ref.dex_cache_element_index = element_index; |
| 5501 | SetLoadKindInternal(load_kind); |
| 5502 | } |
| 5503 | |
| 5504 | LoadKind GetLoadKind() const { |
| 5505 | return GetPackedField<LoadKindField>(); |
| 5506 | } |
| 5507 | |
| 5508 | const DexFile& GetDexFile() const; |
| 5509 | |
| 5510 | uint32_t GetStringIndex() const { |
| 5511 | DCHECK(HasStringReference(GetLoadKind()) || /* For slow paths. */ !IsInDexCache()); |
| 5512 | return string_index_; |
| 5513 | } |
| 5514 | |
| 5515 | uint32_t GetDexCacheElementOffset() const; |
| 5516 | |
| 5517 | uint64_t GetAddress() const { |
| 5518 | DCHECK(HasAddress(GetLoadKind())); |
| 5519 | return load_data_.address; |
| 5520 | } |
| 5521 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5522 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5523 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5524 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5525 | |
| 5526 | size_t ComputeHashCode() const OVERRIDE { return string_index_; } |
| 5527 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5528 | // Will call the runtime if we need to load the string through |
| 5529 | // the dex cache and the string is not guaranteed to be there yet. |
| 5530 | bool NeedsEnvironment() const OVERRIDE { |
| 5531 | LoadKind load_kind = GetLoadKind(); |
| 5532 | if (load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5533 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
| 5534 | load_kind == LoadKind::kBootImageAddress) { |
| 5535 | return false; |
| 5536 | } |
| 5537 | return !IsInDexCache(); |
| 5538 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5539 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5540 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
| 5541 | return GetLoadKind() == LoadKind::kDexCacheViaMethod; |
| 5542 | } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5543 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 5544 | bool CanBeNull() const OVERRIDE { return false; } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5545 | bool CanThrow() const OVERRIDE { return NeedsEnvironment(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5546 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5547 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5548 | return SideEffects::CanTriggerGC(); |
| 5549 | } |
| 5550 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5551 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
| 5552 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5553 | void MarkInDexCache() { |
| 5554 | SetPackedFlag<kFlagIsInDexCache>(true); |
| 5555 | DCHECK(!NeedsEnvironment()); |
| 5556 | RemoveEnvironment(); |
Vladimir Marko | ace7a00 | 2016-04-05 11:18:49 +0100 | [diff] [blame] | 5557 | SetSideEffects(SideEffects::None()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5558 | } |
| 5559 | |
| 5560 | size_t InputCount() const OVERRIDE { |
| 5561 | return (InputAt(0) != nullptr) ? 1u : 0u; |
| 5562 | } |
| 5563 | |
| 5564 | void AddSpecialInput(HInstruction* special_input); |
| 5565 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5566 | DECLARE_INSTRUCTION(LoadString); |
| 5567 | |
| 5568 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5569 | static constexpr size_t kFlagIsInDexCache = kNumberOfExpressionPackedBits; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5570 | static constexpr size_t kFieldLoadKind = kFlagIsInDexCache + 1; |
| 5571 | static constexpr size_t kFieldLoadKindSize = |
| 5572 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 5573 | static constexpr size_t kNumberOfLoadStringPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5574 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5575 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5576 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5577 | static bool HasStringReference(LoadKind load_kind) { |
| 5578 | return load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5579 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
| 5580 | load_kind == LoadKind::kDexCacheViaMethod; |
| 5581 | } |
| 5582 | |
| 5583 | static bool HasAddress(LoadKind load_kind) { |
| 5584 | return load_kind == LoadKind::kBootImageAddress || load_kind == LoadKind::kDexCacheAddress; |
| 5585 | } |
| 5586 | |
| 5587 | static bool HasDexCacheReference(LoadKind load_kind) { |
| 5588 | return load_kind == LoadKind::kDexCachePcRelative; |
| 5589 | } |
| 5590 | |
| 5591 | void SetLoadKindInternal(LoadKind load_kind); |
| 5592 | |
| 5593 | // String index serves also as the hash code and it's also needed for slow-paths, |
| 5594 | // so it must not be overwritten with other load data. |
| 5595 | uint32_t string_index_; |
| 5596 | |
| 5597 | union { |
| 5598 | struct { |
| 5599 | const DexFile* dex_file; // For string reference and dex cache reference. |
| 5600 | uint32_t dex_cache_element_index; // Only for dex cache reference. |
| 5601 | } ref; |
| 5602 | uint64_t address; // Up to 64-bit, needed for kDexCacheAddress on 64-bit targets. |
| 5603 | } load_data_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5604 | |
| 5605 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 5606 | }; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5607 | std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs); |
| 5608 | |
| 5609 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5610 | inline const DexFile& HLoadString::GetDexFile() const { |
| 5611 | DCHECK(HasStringReference(GetLoadKind()) || HasDexCacheReference(GetLoadKind())) |
| 5612 | << GetLoadKind(); |
| 5613 | return *load_data_.ref.dex_file; |
| 5614 | } |
| 5615 | |
| 5616 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5617 | inline uint32_t HLoadString::GetDexCacheElementOffset() const { |
| 5618 | DCHECK(HasDexCacheReference(GetLoadKind())) << GetLoadKind(); |
| 5619 | return load_data_.ref.dex_cache_element_index; |
| 5620 | } |
| 5621 | |
| 5622 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5623 | inline void HLoadString::AddSpecialInput(HInstruction* special_input) { |
| 5624 | // The special input is used for PC-relative loads on some architectures. |
| 5625 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
| 5626 | GetLoadKind() == LoadKind::kDexCachePcRelative) << GetLoadKind(); |
| 5627 | DCHECK(InputAt(0) == nullptr); |
| 5628 | SetRawInputAt(0u, special_input); |
| 5629 | special_input->AddUseAt(this, 0); |
| 5630 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5631 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5632 | /** |
| 5633 | * Performs an initialization check on its Class object input. |
| 5634 | */ |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5635 | class HClinitCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5636 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 5637 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 5638 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5639 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5640 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 5641 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5642 | SetRawInputAt(0, constant); |
| 5643 | } |
| 5644 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5645 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5646 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5647 | return true; |
| 5648 | } |
| 5649 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5650 | bool NeedsEnvironment() const OVERRIDE { |
| 5651 | // May call runtime to initialize the class. |
| 5652 | return true; |
| 5653 | } |
| 5654 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 5655 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5656 | |
| 5657 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 5658 | |
| 5659 | DECLARE_INSTRUCTION(ClinitCheck); |
| 5660 | |
| 5661 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5662 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 5663 | }; |
| 5664 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5665 | class HStaticFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5666 | public: |
| 5667 | HStaticFieldGet(HInstruction* cls, |
| 5668 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5669 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5670 | bool is_volatile, |
| 5671 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5672 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5673 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5674 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5675 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5676 | : HExpression(field_type, |
| 5677 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5678 | dex_pc), |
| 5679 | field_info_(field_offset, |
| 5680 | field_type, |
| 5681 | is_volatile, |
| 5682 | field_idx, |
| 5683 | declaring_class_def_index, |
| 5684 | dex_file, |
| 5685 | dex_cache) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5686 | SetRawInputAt(0, cls); |
| 5687 | } |
| 5688 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5689 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5690 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5691 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5692 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5693 | HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
| 5694 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5695 | } |
| 5696 | |
| 5697 | size_t ComputeHashCode() const OVERRIDE { |
| 5698 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5699 | } |
| 5700 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5701 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5702 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5703 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5704 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5705 | |
| 5706 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 5707 | |
| 5708 | private: |
| 5709 | const FieldInfo field_info_; |
| 5710 | |
| 5711 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 5712 | }; |
| 5713 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5714 | class HStaticFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5715 | public: |
| 5716 | HStaticFieldSet(HInstruction* cls, |
| 5717 | HInstruction* value, |
| 5718 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5719 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5720 | bool is_volatile, |
| 5721 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5722 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5723 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5724 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5725 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5726 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5727 | dex_pc), |
| 5728 | field_info_(field_offset, |
| 5729 | field_type, |
| 5730 | is_volatile, |
| 5731 | field_idx, |
| 5732 | declaring_class_def_index, |
| 5733 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5734 | dex_cache) { |
| 5735 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5736 | SetRawInputAt(0, cls); |
| 5737 | SetRawInputAt(1, value); |
| 5738 | } |
| 5739 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5740 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5741 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5742 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5743 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5744 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5745 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5746 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5747 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5748 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5749 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 5750 | |
| 5751 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5752 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5753 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5754 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5755 | "Too many packed fields."); |
| 5756 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5757 | const FieldInfo field_info_; |
| 5758 | |
| 5759 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 5760 | }; |
| 5761 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5762 | class HUnresolvedInstanceFieldGet FINAL : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5763 | public: |
| 5764 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 5765 | Primitive::Type field_type, |
| 5766 | uint32_t field_index, |
| 5767 | uint32_t dex_pc) |
| 5768 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5769 | field_index_(field_index) { |
| 5770 | SetRawInputAt(0, obj); |
| 5771 | } |
| 5772 | |
| 5773 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5774 | bool CanThrow() const OVERRIDE { return true; } |
| 5775 | |
| 5776 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5777 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5778 | |
| 5779 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 5780 | |
| 5781 | private: |
| 5782 | const uint32_t field_index_; |
| 5783 | |
| 5784 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 5785 | }; |
| 5786 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5787 | class HUnresolvedInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5788 | public: |
| 5789 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 5790 | HInstruction* value, |
| 5791 | Primitive::Type field_type, |
| 5792 | uint32_t field_index, |
| 5793 | uint32_t dex_pc) |
| 5794 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5795 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5796 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 5797 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5798 | SetRawInputAt(0, obj); |
| 5799 | SetRawInputAt(1, value); |
| 5800 | } |
| 5801 | |
| 5802 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5803 | bool CanThrow() const OVERRIDE { return true; } |
| 5804 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5805 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5806 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5807 | |
| 5808 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 5809 | |
| 5810 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5811 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 5812 | static constexpr size_t kFieldFieldTypeSize = |
| 5813 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5814 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 5815 | kFieldFieldType + kFieldFieldTypeSize; |
| 5816 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5817 | "Too many packed fields."); |
| 5818 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 5819 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5820 | const uint32_t field_index_; |
| 5821 | |
| 5822 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 5823 | }; |
| 5824 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5825 | class HUnresolvedStaticFieldGet FINAL : public HExpression<0> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5826 | public: |
| 5827 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 5828 | uint32_t field_index, |
| 5829 | uint32_t dex_pc) |
| 5830 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5831 | field_index_(field_index) { |
| 5832 | } |
| 5833 | |
| 5834 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5835 | bool CanThrow() const OVERRIDE { return true; } |
| 5836 | |
| 5837 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5838 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5839 | |
| 5840 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 5841 | |
| 5842 | private: |
| 5843 | const uint32_t field_index_; |
| 5844 | |
| 5845 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 5846 | }; |
| 5847 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5848 | class HUnresolvedStaticFieldSet FINAL : public HTemplateInstruction<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5849 | public: |
| 5850 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 5851 | Primitive::Type field_type, |
| 5852 | uint32_t field_index, |
| 5853 | uint32_t dex_pc) |
| 5854 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5855 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5856 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 5857 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5858 | SetRawInputAt(0, value); |
| 5859 | } |
| 5860 | |
| 5861 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5862 | bool CanThrow() const OVERRIDE { return true; } |
| 5863 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5864 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5865 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5866 | |
| 5867 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 5868 | |
| 5869 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5870 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 5871 | static constexpr size_t kFieldFieldTypeSize = |
| 5872 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5873 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 5874 | kFieldFieldType + kFieldFieldTypeSize; |
| 5875 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5876 | "Too many packed fields."); |
| 5877 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 5878 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5879 | const uint32_t field_index_; |
| 5880 | |
| 5881 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 5882 | }; |
| 5883 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5884 | // Implement the move-exception DEX instruction. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5885 | class HLoadException FINAL : public HExpression<0> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5886 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5887 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 5888 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5889 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 5890 | bool CanBeNull() const OVERRIDE { return false; } |
| 5891 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5892 | DECLARE_INSTRUCTION(LoadException); |
| 5893 | |
| 5894 | private: |
| 5895 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 5896 | }; |
| 5897 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5898 | // Implicit part of move-exception which clears thread-local exception storage. |
| 5899 | // Must not be removed because the runtime expects the TLS to get cleared. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5900 | class HClearException FINAL : public HTemplateInstruction<0> { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5901 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5902 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 5903 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5904 | |
| 5905 | DECLARE_INSTRUCTION(ClearException); |
| 5906 | |
| 5907 | private: |
| 5908 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 5909 | }; |
| 5910 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5911 | class HThrow FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5912 | public: |
| 5913 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5914 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5915 | SetRawInputAt(0, exception); |
| 5916 | } |
| 5917 | |
| 5918 | bool IsControlFlow() const OVERRIDE { return true; } |
| 5919 | |
| 5920 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5921 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5922 | bool CanThrow() const OVERRIDE { return true; } |
| 5923 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5924 | |
| 5925 | DECLARE_INSTRUCTION(Throw); |
| 5926 | |
| 5927 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5928 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 5929 | }; |
| 5930 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5931 | /** |
| 5932 | * Implementation strategies for the code generator of a HInstanceOf |
| 5933 | * or `HCheckCast`. |
| 5934 | */ |
| 5935 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5936 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5937 | kExactCheck, // Can do a single class compare. |
| 5938 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 5939 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 5940 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 5941 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5942 | kArrayCheck, // No optimization yet when checking against a generic array. |
| 5943 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5944 | }; |
| 5945 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5946 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 5947 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5948 | class HInstanceOf FINAL : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5949 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5950 | HInstanceOf(HInstruction* object, |
| 5951 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5952 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5953 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5954 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5955 | SideEffectsForArchRuntimeCalls(check_kind), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5956 | dex_pc) { |
| 5957 | SetPackedField<TypeCheckKindField>(check_kind); |
| 5958 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5959 | SetRawInputAt(0, object); |
| 5960 | SetRawInputAt(1, constant); |
| 5961 | } |
| 5962 | |
| 5963 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5964 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5965 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5966 | return true; |
| 5967 | } |
| 5968 | |
| 5969 | bool NeedsEnvironment() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5970 | return CanCallRuntime(GetTypeCheckKind()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5971 | } |
| 5972 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5973 | // Used only in code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5974 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 5975 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 5976 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 5977 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5978 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5979 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 5980 | // Mips currently does runtime calls for any other checks. |
| 5981 | return check_kind != TypeCheckKind::kExactCheck; |
| 5982 | } |
| 5983 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5984 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5985 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5986 | } |
| 5987 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5988 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5989 | |
| 5990 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5991 | static constexpr size_t kFieldTypeCheckKind = kNumberOfExpressionPackedBits; |
| 5992 | static constexpr size_t kFieldTypeCheckKindSize = |
| 5993 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 5994 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 5995 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagMustDoNullCheck + 1; |
| 5996 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5997 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5998 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5999 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 6000 | }; |
| 6001 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6002 | class HBoundType FINAL : public HExpression<1> { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6003 | public: |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6004 | HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6005 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6006 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 6007 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 6008 | SetPackedFlag<kFlagCanBeNull>(true); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 6009 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6010 | SetRawInputAt(0, input); |
| 6011 | } |
| 6012 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6013 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6014 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6015 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6016 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6017 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6018 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6019 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 6020 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6021 | } |
| 6022 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6023 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6024 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6025 | DECLARE_INSTRUCTION(BoundType); |
| 6026 | |
| 6027 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6028 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 6029 | // is false then CanBeNull() cannot be true). |
| 6030 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfExpressionPackedBits; |
| 6031 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 6032 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 6033 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6034 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6035 | // 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] | 6036 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 6037 | // It is used to bound the type in cases like: |
| 6038 | // if (x instanceof ClassX) { |
| 6039 | // // uper_bound_ will be ClassX |
| 6040 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6041 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6042 | |
| 6043 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 6044 | }; |
| 6045 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6046 | class HCheckCast FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6047 | public: |
| 6048 | HCheckCast(HInstruction* object, |
| 6049 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6050 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6051 | uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6052 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
| 6053 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6054 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6055 | SetRawInputAt(0, object); |
| 6056 | SetRawInputAt(1, constant); |
| 6057 | } |
| 6058 | |
| 6059 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6060 | |
| 6061 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 6062 | return true; |
| 6063 | } |
| 6064 | |
| 6065 | bool NeedsEnvironment() const OVERRIDE { |
| 6066 | // Instruction may throw a CheckCastError. |
| 6067 | return true; |
| 6068 | } |
| 6069 | |
| 6070 | bool CanThrow() const OVERRIDE { return true; } |
| 6071 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6072 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6073 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6074 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6075 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6076 | |
| 6077 | DECLARE_INSTRUCTION(CheckCast); |
| 6078 | |
| 6079 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6080 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 6081 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6082 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6083 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6084 | static constexpr size_t kNumberOfCheckCastPackedBits = kFlagMustDoNullCheck + 1; |
| 6085 | static_assert(kNumberOfCheckCastPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6086 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6087 | |
| 6088 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6089 | }; |
| 6090 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6091 | class HMemoryBarrier FINAL : public HTemplateInstruction<0> { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6092 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6093 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 6094 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6095 | SideEffects::AllWritesAndReads(), dex_pc) { // Assume write/read on all fields/arrays. |
| 6096 | SetPackedField<BarrierKindField>(barrier_kind); |
| 6097 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6098 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6099 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6100 | |
| 6101 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 6102 | |
| 6103 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6104 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 6105 | static constexpr size_t kFieldBarrierKindSize = |
| 6106 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 6107 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 6108 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 6109 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 6110 | "Too many packed fields."); |
| 6111 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6112 | |
| 6113 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 6114 | }; |
| 6115 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6116 | class HMonitorOperation FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6117 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6118 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6119 | kEnter, |
| 6120 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6121 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6122 | }; |
| 6123 | |
| 6124 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6125 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6126 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 6127 | dex_pc) { |
| 6128 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6129 | SetRawInputAt(0, object); |
| 6130 | } |
| 6131 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6132 | // Instruction may go into runtime, so we need an environment. |
| 6133 | bool NeedsEnvironment() const OVERRIDE { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 6134 | |
| 6135 | bool CanThrow() const OVERRIDE { |
| 6136 | // Verifier guarantees that monitor-exit cannot throw. |
| 6137 | // This is important because it allows the HGraphBuilder to remove |
| 6138 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 6139 | return IsEnter(); |
| 6140 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6141 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6142 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 6143 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6144 | |
| 6145 | DECLARE_INSTRUCTION(MonitorOperation); |
| 6146 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6147 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6148 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 6149 | static constexpr size_t kFieldOperationKindSize = |
| 6150 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 6151 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 6152 | kFieldOperationKind + kFieldOperationKindSize; |
| 6153 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6154 | "Too many packed fields."); |
| 6155 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6156 | |
| 6157 | private: |
| 6158 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 6159 | }; |
| 6160 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6161 | class HSelect FINAL : public HExpression<3> { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6162 | public: |
| 6163 | HSelect(HInstruction* condition, |
| 6164 | HInstruction* true_value, |
| 6165 | HInstruction* false_value, |
| 6166 | uint32_t dex_pc) |
| 6167 | : HExpression(HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
| 6168 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 6169 | |
| 6170 | // First input must be `true_value` or `false_value` to allow codegens to |
| 6171 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 6172 | // that architectures which implement HSelect as a conditional move also |
| 6173 | // will not need to invert the condition. |
| 6174 | SetRawInputAt(0, false_value); |
| 6175 | SetRawInputAt(1, true_value); |
| 6176 | SetRawInputAt(2, condition); |
| 6177 | } |
| 6178 | |
| 6179 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 6180 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 6181 | HInstruction* GetCondition() const { return InputAt(2); } |
| 6182 | |
| 6183 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6184 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
| 6185 | |
| 6186 | bool CanBeNull() const OVERRIDE { |
| 6187 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 6188 | } |
| 6189 | |
| 6190 | DECLARE_INSTRUCTION(Select); |
| 6191 | |
| 6192 | private: |
| 6193 | DISALLOW_COPY_AND_ASSIGN(HSelect); |
| 6194 | }; |
| 6195 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 6196 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6197 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6198 | MoveOperands(Location source, |
| 6199 | Location destination, |
| 6200 | Primitive::Type type, |
| 6201 | HInstruction* instruction) |
| 6202 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6203 | |
| 6204 | Location GetSource() const { return source_; } |
| 6205 | Location GetDestination() const { return destination_; } |
| 6206 | |
| 6207 | void SetSource(Location value) { source_ = value; } |
| 6208 | void SetDestination(Location value) { destination_ = value; } |
| 6209 | |
| 6210 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 6211 | // destination (but not the source). |
| 6212 | Location MarkPending() { |
| 6213 | DCHECK(!IsPending()); |
| 6214 | Location dest = destination_; |
| 6215 | destination_ = Location::NoLocation(); |
| 6216 | return dest; |
| 6217 | } |
| 6218 | |
| 6219 | void ClearPending(Location dest) { |
| 6220 | DCHECK(IsPending()); |
| 6221 | destination_ = dest; |
| 6222 | } |
| 6223 | |
| 6224 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6225 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 6226 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6227 | } |
| 6228 | |
| 6229 | // True if this blocks a move from the given location. |
| 6230 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 6231 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6232 | } |
| 6233 | |
| 6234 | // A move is redundant if it's been eliminated, if its source and |
| 6235 | // destination are the same, or if its destination is unneeded. |
| 6236 | bool IsRedundant() const { |
| 6237 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 6238 | } |
| 6239 | |
| 6240 | // We clear both operands to indicate move that's been eliminated. |
| 6241 | void Eliminate() { |
| 6242 | source_ = destination_ = Location::NoLocation(); |
| 6243 | } |
| 6244 | |
| 6245 | bool IsEliminated() const { |
| 6246 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 6247 | return source_.IsInvalid(); |
| 6248 | } |
| 6249 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6250 | Primitive::Type GetType() const { return type_; } |
| 6251 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6252 | bool Is64BitMove() const { |
| 6253 | return Primitive::Is64BitType(type_); |
| 6254 | } |
| 6255 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6256 | HInstruction* GetInstruction() const { return instruction_; } |
| 6257 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6258 | private: |
| 6259 | Location source_; |
| 6260 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6261 | // The type this move is for. |
| 6262 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6263 | // The instruction this move is assocatied with. Null when this move is |
| 6264 | // for moving an input in the expected locations of user (including a phi user). |
| 6265 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 6266 | // in the same parallel move. |
| 6267 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6268 | }; |
| 6269 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6270 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 6271 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6272 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 6273 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6274 | class HParallelMove FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6275 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6276 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6277 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 6278 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 6279 | moves_.reserve(kDefaultNumberOfMoves); |
| 6280 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6281 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6282 | void AddMove(Location source, |
| 6283 | Location destination, |
| 6284 | Primitive::Type type, |
| 6285 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6286 | DCHECK(source.IsValid()); |
| 6287 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6288 | if (kIsDebugBuild) { |
| 6289 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6290 | for (const MoveOperands& move : moves_) { |
| 6291 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6292 | // Special case the situation where the move is for the spill slot |
| 6293 | // of the instruction. |
| 6294 | if ((GetPrevious() == instruction) |
| 6295 | || ((GetPrevious() == nullptr) |
| 6296 | && instruction->IsPhi() |
| 6297 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6298 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6299 | << "Doing parallel moves for the same instruction."; |
| 6300 | } else { |
| 6301 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 6302 | } |
| 6303 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 6304 | } |
| 6305 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6306 | for (const MoveOperands& move : moves_) { |
| 6307 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6308 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6309 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6310 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6311 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6312 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6313 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6314 | } |
| 6315 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6316 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6317 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6318 | } |
| 6319 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6320 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6321 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 6322 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6323 | |
| 6324 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6325 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6326 | |
| 6327 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 6328 | }; |
| 6329 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6330 | } // namespace art |
| 6331 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 6332 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 6333 | #include "nodes_shared.h" |
| 6334 | #endif |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6335 | #ifdef ART_ENABLE_CODEGEN_arm |
| 6336 | #include "nodes_arm.h" |
| 6337 | #endif |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6338 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| 6339 | #include "nodes_arm64.h" |
| 6340 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6341 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 6342 | #include "nodes_x86.h" |
| 6343 | #endif |
| 6344 | |
| 6345 | namespace art { |
| 6346 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6347 | class HGraphVisitor : public ValueObject { |
| 6348 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 6349 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 6350 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6351 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6352 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6353 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 6354 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6355 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6356 | void VisitInsertionOrder(); |
| 6357 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6358 | // Visit the graph following dominator tree reverse post-order. |
| 6359 | void VisitReversePostOrder(); |
| 6360 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 6361 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 6362 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6363 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6364 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6365 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 6366 | |
| 6367 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6368 | |
| 6369 | #undef DECLARE_VISIT_INSTRUCTION |
| 6370 | |
| 6371 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 6372 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6373 | |
| 6374 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 6375 | }; |
| 6376 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6377 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 6378 | public: |
| 6379 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 6380 | virtual ~HGraphDelegateVisitor() {} |
| 6381 | |
| 6382 | // Visit functions that delegate to to super class. |
| 6383 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6384 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6385 | |
| 6386 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6387 | |
| 6388 | #undef DECLARE_VISIT_INSTRUCTION |
| 6389 | |
| 6390 | private: |
| 6391 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 6392 | }; |
| 6393 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6394 | class HInsertionOrderIterator : public ValueObject { |
| 6395 | public: |
| 6396 | explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {} |
| 6397 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6398 | bool Done() const { return index_ == graph_.GetBlocks().size(); } |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 6399 | HBasicBlock* Current() const { return graph_.GetBlocks()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6400 | void Advance() { ++index_; } |
| 6401 | |
| 6402 | private: |
| 6403 | const HGraph& graph_; |
| 6404 | size_t index_; |
| 6405 | |
| 6406 | DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator); |
| 6407 | }; |
| 6408 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6409 | class HReversePostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6410 | public: |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6411 | explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) { |
| 6412 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6413 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6414 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6415 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6416 | bool Done() const { return index_ == graph_.GetReversePostOrder().size(); } |
| 6417 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6418 | void Advance() { ++index_; } |
| 6419 | |
| 6420 | private: |
| 6421 | const HGraph& graph_; |
| 6422 | size_t index_; |
| 6423 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6424 | DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6425 | }; |
| 6426 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6427 | class HPostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6428 | public: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6429 | explicit HPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6430 | : graph_(graph), index_(graph_.GetReversePostOrder().size()) { |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6431 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6432 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6433 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6434 | |
| 6435 | bool Done() const { return index_ == 0; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6436 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_ - 1u]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6437 | void Advance() { --index_; } |
| 6438 | |
| 6439 | private: |
| 6440 | const HGraph& graph_; |
| 6441 | size_t index_; |
| 6442 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6443 | DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6444 | }; |
| 6445 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6446 | class HLinearPostOrderIterator : public ValueObject { |
| 6447 | public: |
| 6448 | explicit HLinearPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6449 | : order_(graph.GetLinearOrder()), index_(graph.GetLinearOrder().size()) {} |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6450 | |
| 6451 | bool Done() const { return index_ == 0; } |
| 6452 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6453 | HBasicBlock* Current() const { return order_[index_ - 1u]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6454 | |
| 6455 | void Advance() { |
| 6456 | --index_; |
| 6457 | DCHECK_GE(index_, 0U); |
| 6458 | } |
| 6459 | |
| 6460 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6461 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6462 | size_t index_; |
| 6463 | |
| 6464 | DISALLOW_COPY_AND_ASSIGN(HLinearPostOrderIterator); |
| 6465 | }; |
| 6466 | |
| 6467 | class HLinearOrderIterator : public ValueObject { |
| 6468 | public: |
| 6469 | explicit HLinearOrderIterator(const HGraph& graph) |
| 6470 | : order_(graph.GetLinearOrder()), index_(0) {} |
| 6471 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6472 | bool Done() const { return index_ == order_.size(); } |
| 6473 | HBasicBlock* Current() const { return order_[index_]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6474 | void Advance() { ++index_; } |
| 6475 | |
| 6476 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6477 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6478 | size_t index_; |
| 6479 | |
| 6480 | DISALLOW_COPY_AND_ASSIGN(HLinearOrderIterator); |
| 6481 | }; |
| 6482 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6483 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6484 | // of an inner loop. The order in which the blocks are iterated is on their |
| 6485 | // block id. |
| 6486 | class HBlocksInLoopIterator : public ValueObject { |
| 6487 | public: |
| 6488 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 6489 | : blocks_in_loop_(info.GetBlocks()), |
| 6490 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 6491 | index_(0) { |
| 6492 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 6493 | Advance(); |
| 6494 | } |
| 6495 | } |
| 6496 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6497 | bool Done() const { return index_ == blocks_.size(); } |
| 6498 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6499 | void Advance() { |
| 6500 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6501 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6502 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 6503 | break; |
| 6504 | } |
| 6505 | } |
| 6506 | } |
| 6507 | |
| 6508 | private: |
| 6509 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6510 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6511 | size_t index_; |
| 6512 | |
| 6513 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 6514 | }; |
| 6515 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6516 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6517 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 6518 | // post order. |
| 6519 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 6520 | public: |
| 6521 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 6522 | : blocks_in_loop_(info.GetBlocks()), |
| 6523 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 6524 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6525 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6526 | Advance(); |
| 6527 | } |
| 6528 | } |
| 6529 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6530 | bool Done() const { return index_ == blocks_.size(); } |
| 6531 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6532 | void Advance() { |
| 6533 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6534 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 6535 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6536 | break; |
| 6537 | } |
| 6538 | } |
| 6539 | } |
| 6540 | |
| 6541 | private: |
| 6542 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6543 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6544 | size_t index_; |
| 6545 | |
| 6546 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 6547 | }; |
| 6548 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6549 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6550 | if (constant->IsIntConstant()) { |
| 6551 | return constant->AsIntConstant()->GetValue(); |
| 6552 | } else if (constant->IsLongConstant()) { |
| 6553 | return constant->AsLongConstant()->GetValue(); |
| 6554 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6555 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6556 | return 0; |
| 6557 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6558 | } |
| 6559 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6560 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 6561 | // For the purposes of the compiler, the dex files must actually be the same object |
| 6562 | // if we want to safely treat them as the same. This is especially important for JIT |
| 6563 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 6564 | // times and provide different class resolution but no two class loaders should ever |
| 6565 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 6566 | // all sorts of weird failures. |
| 6567 | return &lhs == &rhs; |
| 6568 | } |
| 6569 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6570 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 6571 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } \ |
| 6572 | inline const H##type* HInstruction::As##type() const { \ |
| 6573 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 6574 | } \ |
| 6575 | inline H##type* HInstruction::As##type() { \ |
| 6576 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 6577 | } |
| 6578 | |
| 6579 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 6580 | #undef INSTRUCTION_TYPE_CHECK |
| 6581 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 6582 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 6583 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 6584 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 6585 | size_t number_of_new_blocks, |
| 6586 | size_t after) { |
| 6587 | DCHECK_LT(after, blocks->size()); |
| 6588 | size_t old_size = blocks->size(); |
| 6589 | size_t new_size = old_size + number_of_new_blocks; |
| 6590 | blocks->resize(new_size); |
| 6591 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 6592 | } |
| 6593 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6594 | } // namespace art |
| 6595 | |
| 6596 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |