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" |
David Brazdil | d9c9037 | 2016-09-14 16:53:55 +0100 | [diff] [blame] | 27 | #include "base/array_ref.h" |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 28 | #include "base/iteration_range.h" |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 29 | #include "base/stl_util.h" |
David Brazdil | d9c9037 | 2016-09-14 16:53:55 +0100 | [diff] [blame] | 30 | #include "base/transform_array_ref.h" |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 31 | #include "dex_file.h" |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 32 | #include "dex_file_types.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 33 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 34 | #include "handle.h" |
| 35 | #include "handle_scope.h" |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 36 | #include "invoke_type.h" |
Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 37 | #include "intrinsics_enum.h" |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 38 | #include "locations.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 39 | #include "method_reference.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 40 | #include "mirror/class.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 41 | #include "offsets.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 42 | #include "primitive.h" |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 43 | #include "utils/intrusive_forward_list.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 44 | |
| 45 | namespace art { |
| 46 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 47 | class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 48 | class HBasicBlock; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 49 | class HCurrentMethod; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 50 | class HDoubleConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 51 | class HEnvironment; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 52 | class HFloatConstant; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 53 | class HGraphBuilder; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 54 | class HGraphVisitor; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 55 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 56 | class HIntConstant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 57 | class HInvoke; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 58 | class HLongConstant; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 59 | class HNullConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 60 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 61 | class HSuspendCheck; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 62 | class HTryBoundary; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 63 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 64 | class LocationSummary; |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 65 | class SlowPathCode; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 66 | class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 67 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 68 | namespace mirror { |
| 69 | class DexCache; |
| 70 | } // namespace mirror |
| 71 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 72 | static const int kDefaultNumberOfBlocks = 8; |
| 73 | static const int kDefaultNumberOfSuccessors = 2; |
| 74 | static const int kDefaultNumberOfPredecessors = 2; |
David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 75 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 76 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 77 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 78 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 79 | // The maximum (meaningful) distance (31) that can be used in an integer shift/rotate operation. |
| 80 | static constexpr int32_t kMaxIntShiftDistance = 0x1f; |
| 81 | // The maximum (meaningful) distance (63) that can be used in a long shift/rotate operation. |
| 82 | static constexpr int32_t kMaxLongShiftDistance = 0x3f; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 83 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 84 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 85 | static constexpr uint16_t kUnknownClassDefIndex = static_cast<uint16_t>(-1); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 86 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 87 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 88 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 89 | static constexpr uint32_t kNoDexPc = -1; |
| 90 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 91 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 92 | // For the purposes of the compiler, the dex files must actually be the same object |
| 93 | // if we want to safely treat them as the same. This is especially important for JIT |
| 94 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 95 | // times and provide different class resolution but no two class loaders should ever |
| 96 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 97 | // all sorts of weird failures. |
| 98 | return &lhs == &rhs; |
| 99 | } |
| 100 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 101 | enum IfCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 102 | // All types. |
| 103 | kCondEQ, // == |
| 104 | kCondNE, // != |
| 105 | // Signed integers and floating-point numbers. |
| 106 | kCondLT, // < |
| 107 | kCondLE, // <= |
| 108 | kCondGT, // > |
| 109 | kCondGE, // >= |
| 110 | // Unsigned integers. |
| 111 | kCondB, // < |
| 112 | kCondBE, // <= |
| 113 | kCondA, // > |
| 114 | kCondAE, // >= |
Scott Wakeling | 2c76e06 | 2016-08-31 09:48:54 +0100 | [diff] [blame] | 115 | // First and last aliases. |
| 116 | kCondFirst = kCondEQ, |
| 117 | kCondLast = kCondAE, |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 120 | enum GraphAnalysisResult { |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 121 | kAnalysisSkipped, |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 122 | kAnalysisInvalidBytecode, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 123 | kAnalysisFailThrowCatchLoop, |
| 124 | kAnalysisFailAmbiguousArrayOp, |
| 125 | kAnalysisSuccess, |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 126 | }; |
| 127 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 128 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 129 | public: |
| 130 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 131 | |
| 132 | void AddInstruction(HInstruction* instruction); |
| 133 | void RemoveInstruction(HInstruction* instruction); |
| 134 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 135 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 136 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 137 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 138 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 139 | // Return true if this list contains `instruction`. |
| 140 | bool Contains(HInstruction* instruction) const; |
| 141 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 142 | // Return true if `instruction1` is found before `instruction2` in |
| 143 | // this instruction list and false otherwise. Abort if none |
| 144 | // of these instructions is found. |
| 145 | bool FoundBefore(const HInstruction* instruction1, |
| 146 | const HInstruction* instruction2) const; |
| 147 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 148 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 149 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 150 | |
| 151 | // Update the block of all instructions to be `block`. |
| 152 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 153 | |
| 154 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 155 | void AddBefore(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 156 | void Add(const HInstructionList& instruction_list); |
| 157 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 158 | // Return the number of instructions in the list. This is an expensive operation. |
| 159 | size_t CountSize() const; |
| 160 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 161 | private: |
| 162 | HInstruction* first_instruction_; |
| 163 | HInstruction* last_instruction_; |
| 164 | |
| 165 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 166 | friend class HGraph; |
| 167 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 168 | friend class HInstructionIterator; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 169 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 170 | |
| 171 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 172 | }; |
| 173 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 174 | class ReferenceTypeInfo : ValueObject { |
| 175 | public: |
| 176 | typedef Handle<mirror::Class> TypeHandle; |
| 177 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 178 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact); |
| 179 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 180 | static ReferenceTypeInfo Create(TypeHandle type_handle) REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 94ab38f | 2016-06-21 17:48:19 +0100 | [diff] [blame] | 181 | return Create(type_handle, type_handle->CannotBeAssignedFromOtherTypes()); |
| 182 | } |
| 183 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 184 | static ReferenceTypeInfo CreateUnchecked(TypeHandle type_handle, bool is_exact) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 185 | return ReferenceTypeInfo(type_handle, is_exact); |
| 186 | } |
| 187 | |
| 188 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 189 | |
Vladimir Marko | f39745e | 2016-01-26 12:16:55 +0000 | [diff] [blame] | 190 | static bool IsValidHandle(TypeHandle handle) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 191 | return handle.GetReference() != nullptr; |
| 192 | } |
| 193 | |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 194 | bool IsValid() const { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 195 | return IsValidHandle(type_handle_); |
| 196 | } |
| 197 | |
| 198 | bool IsExact() const { return is_exact_; } |
| 199 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 200 | bool IsObjectClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 201 | DCHECK(IsValid()); |
| 202 | return GetTypeHandle()->IsObjectClass(); |
| 203 | } |
| 204 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 205 | bool IsStringClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 206 | DCHECK(IsValid()); |
| 207 | return GetTypeHandle()->IsStringClass(); |
| 208 | } |
| 209 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 210 | bool IsObjectArray() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 211 | DCHECK(IsValid()); |
| 212 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 213 | } |
| 214 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 215 | bool IsInterface() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 216 | DCHECK(IsValid()); |
| 217 | return GetTypeHandle()->IsInterface(); |
| 218 | } |
| 219 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 220 | bool IsArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 221 | DCHECK(IsValid()); |
| 222 | return GetTypeHandle()->IsArrayClass(); |
| 223 | } |
| 224 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 225 | bool IsPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 226 | DCHECK(IsValid()); |
| 227 | return GetTypeHandle()->IsPrimitiveArray(); |
| 228 | } |
| 229 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 230 | bool IsNonPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 231 | DCHECK(IsValid()); |
| 232 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 233 | } |
| 234 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 235 | bool CanArrayHold(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 236 | DCHECK(IsValid()); |
| 237 | if (!IsExact()) return false; |
| 238 | if (!IsArrayClass()) return false; |
| 239 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 240 | } |
| 241 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 242 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 243 | DCHECK(IsValid()); |
| 244 | if (!IsExact()) return false; |
| 245 | if (!IsArrayClass()) return false; |
| 246 | if (!rti.IsArrayClass()) return false; |
| 247 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 248 | rti.GetTypeHandle()->GetComponentType()); |
| 249 | } |
| 250 | |
| 251 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 252 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 253 | bool IsSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 254 | DCHECK(IsValid()); |
| 255 | DCHECK(rti.IsValid()); |
| 256 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 257 | } |
| 258 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 259 | bool IsStrictSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 260 | DCHECK(IsValid()); |
| 261 | DCHECK(rti.IsValid()); |
| 262 | return GetTypeHandle().Get() != rti.GetTypeHandle().Get() && |
| 263 | GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 264 | } |
| 265 | |
| 266 | // Returns true if the type information provide the same amount of details. |
| 267 | // Note that it does not mean that the instructions have the same actual type |
| 268 | // (because the type can be the result of a merge). |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 269 | bool IsEqual(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 270 | if (!IsValid() && !rti.IsValid()) { |
| 271 | // Invalid types are equal. |
| 272 | return true; |
| 273 | } |
| 274 | if (!IsValid() || !rti.IsValid()) { |
| 275 | // One is valid, the other not. |
| 276 | return false; |
| 277 | } |
| 278 | return IsExact() == rti.IsExact() |
| 279 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
| 280 | } |
| 281 | |
| 282 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 283 | ReferenceTypeInfo() : type_handle_(TypeHandle()), is_exact_(false) {} |
| 284 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact) |
| 285 | : type_handle_(type_handle), is_exact_(is_exact) { } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 286 | |
| 287 | // The class of the object. |
| 288 | TypeHandle type_handle_; |
| 289 | // Whether or not the type is exact or a superclass of the actual type. |
| 290 | // Whether or not we have any information about this type. |
| 291 | bool is_exact_; |
| 292 | }; |
| 293 | |
| 294 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 295 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 296 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 297 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 298 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 299 | HGraph(ArenaAllocator* arena, |
| 300 | const DexFile& dex_file, |
| 301 | uint32_t method_idx, |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 302 | bool should_generate_constructor_barrier, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 303 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 304 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 305 | bool debuggable = false, |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 306 | bool osr = false, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 307 | int start_instruction_id = 0) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 308 | : arena_(arena), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 309 | blocks_(arena->Adapter(kArenaAllocBlockList)), |
| 310 | reverse_post_order_(arena->Adapter(kArenaAllocReversePostOrder)), |
| 311 | linear_order_(arena->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 312 | entry_block_(nullptr), |
| 313 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 314 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 315 | number_of_vregs_(0), |
| 316 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 317 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 318 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 319 | has_try_catch_(false), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 320 | has_irreducible_loops_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 321 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 322 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 323 | dex_file_(dex_file), |
| 324 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 325 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 326 | in_ssa_form_(false), |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 327 | should_generate_constructor_barrier_(should_generate_constructor_barrier), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 328 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 329 | cached_null_constant_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 330 | cached_int_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 331 | cached_float_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 332 | cached_long_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 333 | cached_double_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 334 | cached_current_method_(nullptr), |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 335 | inexact_object_rti_(ReferenceTypeInfo::CreateInvalid()), |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame^] | 336 | osr_(osr), |
| 337 | cha_single_implementation_list_(arena->Adapter(kArenaAllocCHA)) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 338 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 339 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 340 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 341 | // Acquires and stores RTI of inexact Object to be used when creating HNullConstant. |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 342 | void InitializeInexactObjectRTI(VariableSizedHandleScope* handles); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 343 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 344 | ArenaAllocator* GetArena() const { return arena_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 345 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 346 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 347 | bool IsInSsaForm() const { return in_ssa_form_; } |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 348 | void SetInSsaForm() { in_ssa_form_ = true; } |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 349 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 350 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 351 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 352 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 353 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 354 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 355 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 356 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 357 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 358 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 359 | void ComputeDominanceInformation(); |
| 360 | void ClearDominanceInformation(); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 361 | void ClearLoopInformation(); |
| 362 | void FindBackEdges(ArenaBitVector* visited); |
| 363 | GraphAnalysisResult BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 364 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 365 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 366 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 367 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 368 | // 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] | 369 | // 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] | 370 | GraphAnalysisResult AnalyzeLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 371 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 372 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 373 | // order and loop information. |
| 374 | void ComputeTryBlockInformation(); |
| 375 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 376 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 377 | // Returns the instruction to replace the invoke expression or null if the |
| 378 | // invoke is for a void method. Note that the caller is responsible for replacing |
| 379 | // and removing the invoke instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 380 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 381 | |
Nicolas Geoffray | a1d8ddf | 2016-02-29 11:46:58 +0000 | [diff] [blame] | 382 | // Update the loop and try membership of `block`, which was spawned from `reference`. |
| 383 | // In case `reference` is a back edge, `replace_if_back_edge` notifies whether `block` |
| 384 | // should be the new back edge. |
| 385 | void UpdateLoopAndTryInformationOfNewBlock(HBasicBlock* block, |
| 386 | HBasicBlock* reference, |
| 387 | bool replace_if_back_edge); |
| 388 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 389 | // Need to add a couple of blocks to test if the loop body is entered and |
| 390 | // put deoptimization instructions, etc. |
| 391 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 392 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 393 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 394 | // other blocks and has no instructions or phis. |
| 395 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 396 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 397 | // Splits the edge between `block` and `successor` while preserving the |
| 398 | // indices in the predecessor/successor lists. If there are multiple edges |
| 399 | // between the blocks, the lowest indices are used. |
| 400 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 401 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 402 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 403 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 404 | void SimplifyLoop(HBasicBlock* header); |
| 405 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 406 | int32_t GetNextInstructionId() { |
| 407 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 408 | return current_instruction_id_++; |
| 409 | } |
| 410 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 411 | int32_t GetCurrentInstructionId() const { |
| 412 | return current_instruction_id_; |
| 413 | } |
| 414 | |
| 415 | void SetCurrentInstructionId(int32_t id) { |
David Brazdil | 3f52306 | 2016-02-29 16:53:33 +0000 | [diff] [blame] | 416 | DCHECK_GE(id, current_instruction_id_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 417 | current_instruction_id_ = id; |
| 418 | } |
| 419 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 420 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 421 | return maximum_number_of_out_vregs_; |
| 422 | } |
| 423 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 424 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 425 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 426 | } |
| 427 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 428 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 429 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 430 | } |
| 431 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 432 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 433 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 434 | } |
| 435 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 436 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 437 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 438 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 439 | } |
| 440 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 441 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 442 | number_of_vregs_ = number_of_vregs; |
| 443 | } |
| 444 | |
| 445 | uint16_t GetNumberOfVRegs() const { |
| 446 | return number_of_vregs_; |
| 447 | } |
| 448 | |
| 449 | void SetNumberOfInVRegs(uint16_t value) { |
| 450 | number_of_in_vregs_ = value; |
| 451 | } |
| 452 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 453 | uint16_t GetNumberOfInVRegs() const { |
| 454 | return number_of_in_vregs_; |
| 455 | } |
| 456 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 457 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 458 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 459 | return number_of_vregs_ - number_of_in_vregs_; |
| 460 | } |
| 461 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 462 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 463 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 464 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 465 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 466 | ArrayRef<HBasicBlock* const> GetReversePostOrderSkipEntryBlock() { |
| 467 | DCHECK(GetReversePostOrder()[0] == entry_block_); |
| 468 | return ArrayRef<HBasicBlock* const>(GetReversePostOrder()).SubArray(1); |
| 469 | } |
| 470 | |
| 471 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetPostOrder() const { |
| 472 | return ReverseRange(GetReversePostOrder()); |
| 473 | } |
| 474 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 475 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 476 | return linear_order_; |
| 477 | } |
| 478 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 479 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetLinearPostOrder() const { |
| 480 | return ReverseRange(GetLinearOrder()); |
| 481 | } |
| 482 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 483 | bool HasBoundsChecks() const { |
| 484 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 485 | } |
| 486 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 487 | void SetHasBoundsChecks(bool value) { |
| 488 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 489 | } |
| 490 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 491 | bool ShouldGenerateConstructorBarrier() const { |
| 492 | return should_generate_constructor_barrier_; |
| 493 | } |
| 494 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 495 | bool IsDebuggable() const { return debuggable_; } |
| 496 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 497 | // 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] | 498 | // already, it is created and inserted into the graph. This method is only for |
| 499 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 500 | 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] | 501 | |
| 502 | // TODO: This is problematic for the consistency of reference type propagation |
| 503 | // because it can be created anytime after the pass and thus it will be left |
| 504 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 505 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 506 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 507 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 508 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 509 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 510 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 511 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 512 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 513 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 514 | 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] | 515 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 516 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 517 | 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] | 518 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 519 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 520 | HCurrentMethod* GetCurrentMethod(); |
| 521 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 522 | const DexFile& GetDexFile() const { |
| 523 | return dex_file_; |
| 524 | } |
| 525 | |
| 526 | uint32_t GetMethodIdx() const { |
| 527 | return method_idx_; |
| 528 | } |
| 529 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 530 | InvokeType GetInvokeType() const { |
| 531 | return invoke_type_; |
| 532 | } |
| 533 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 534 | InstructionSet GetInstructionSet() const { |
| 535 | return instruction_set_; |
| 536 | } |
| 537 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 538 | bool IsCompilingOsr() const { return osr_; } |
| 539 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame^] | 540 | ArenaSet<ArtMethod*>& GetCHASingleImplementationList() { |
| 541 | return cha_single_implementation_list_; |
| 542 | } |
| 543 | |
| 544 | void AddCHASingleImplementationDependency(ArtMethod* method) { |
| 545 | cha_single_implementation_list_.insert(method); |
| 546 | } |
| 547 | |
| 548 | bool HasShouldDeoptimizeFlag() const { |
| 549 | // TODO: if all CHA guards can be eliminated, there is no need for the flag |
| 550 | // even if cha_single_implementation_list_ is not empty. |
| 551 | return !cha_single_implementation_list_.empty(); |
| 552 | } |
| 553 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 554 | bool HasTryCatch() const { return has_try_catch_; } |
| 555 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 556 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 557 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 558 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 559 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 560 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 561 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 562 | |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 563 | // Returns an instruction with the opposite boolean value from 'cond'. |
| 564 | // The instruction has been inserted into the graph, either as a constant, or |
| 565 | // before cursor. |
| 566 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 567 | |
Nicolas Geoffray | 18401b7 | 2016-03-11 13:35:51 +0000 | [diff] [blame] | 568 | ReferenceTypeInfo GetInexactObjectRti() const { return inexact_object_rti_; } |
| 569 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 570 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 571 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 572 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 573 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 574 | template <class InstructionType, typename ValueType> |
| 575 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 576 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 577 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 578 | // Try to find an existing constant of the given value. |
| 579 | InstructionType* constant = nullptr; |
| 580 | auto cached_constant = cache->find(value); |
| 581 | if (cached_constant != cache->end()) { |
| 582 | constant = cached_constant->second; |
| 583 | } |
| 584 | |
| 585 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 586 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 587 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 588 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 589 | cache->Overwrite(value, constant); |
| 590 | InsertConstant(constant); |
| 591 | } |
| 592 | return constant; |
| 593 | } |
| 594 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 595 | void InsertConstant(HConstant* instruction); |
| 596 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 597 | // Cache a float constant into the graph. This method should only be |
| 598 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 599 | void CacheFloatConstant(HFloatConstant* constant); |
| 600 | |
| 601 | // See CacheFloatConstant comment. |
| 602 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 603 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 604 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 605 | |
| 606 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 607 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 608 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 609 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 610 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 611 | |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 612 | // List of blocks to perform a linear order tree traversal. Unlike the reverse |
| 613 | // post order, this order is not incrementally kept up-to-date. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 614 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 615 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 616 | HBasicBlock* entry_block_; |
| 617 | HBasicBlock* exit_block_; |
| 618 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 619 | // 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] | 620 | uint16_t maximum_number_of_out_vregs_; |
| 621 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 622 | // The number of virtual registers in this method. Contains the parameters. |
| 623 | uint16_t number_of_vregs_; |
| 624 | |
| 625 | // The number of virtual registers used by parameters of this method. |
| 626 | uint16_t number_of_in_vregs_; |
| 627 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 628 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 629 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 630 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 631 | // Has bounds checks. We can totally skip BCE if it's false. |
| 632 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 633 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 634 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 635 | // try/catch-related passes if false. |
| 636 | bool has_try_catch_; |
| 637 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 638 | // Flag whether there are any irreducible loops in the graph. |
| 639 | bool has_irreducible_loops_; |
| 640 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 641 | // Indicates whether the graph should be compiled in a way that |
| 642 | // ensures full debuggability. If false, we can apply more |
| 643 | // aggressive optimizations that may limit the level of debugging. |
| 644 | const bool debuggable_; |
| 645 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 646 | // 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] | 647 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 648 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 649 | // The dex file from which the method is from. |
| 650 | const DexFile& dex_file_; |
| 651 | |
| 652 | // The method index in the dex file. |
| 653 | const uint32_t method_idx_; |
| 654 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 655 | // If inlined, this encodes how the callee is being invoked. |
| 656 | const InvokeType invoke_type_; |
| 657 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 658 | // Whether the graph has been transformed to SSA form. Only used |
| 659 | // in debug mode to ensure we are not using properties only valid |
| 660 | // for non-SSA form (like the number of temporaries). |
| 661 | bool in_ssa_form_; |
| 662 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 663 | const bool should_generate_constructor_barrier_; |
| 664 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 665 | const InstructionSet instruction_set_; |
| 666 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 667 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 668 | HNullConstant* cached_null_constant_; |
| 669 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 670 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 671 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 672 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 673 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 674 | HCurrentMethod* cached_current_method_; |
| 675 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 676 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 677 | // for example for methods whose declaring class could not be resolved |
| 678 | // (such as when the superclass could not be found). |
| 679 | ArtMethod* art_method_; |
| 680 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 681 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 682 | // collection pointer to passes which may create NullConstant. |
| 683 | ReferenceTypeInfo inexact_object_rti_; |
| 684 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 685 | // Whether we are compiling this graph for on stack replacement: this will |
| 686 | // make all loops seen as irreducible and emit special stack maps to mark |
| 687 | // compiled code entries which the interpreter can directly jump to. |
| 688 | const bool osr_; |
| 689 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame^] | 690 | // List of methods that are assumed to have single implementation. |
| 691 | ArenaSet<ArtMethod*> cha_single_implementation_list_; |
| 692 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 693 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 694 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 695 | friend class HInliner; // For the reverse post order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 696 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 697 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 698 | }; |
| 699 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 700 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 701 | public: |
| 702 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 703 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 704 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 705 | irreducible_(false), |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 706 | contains_irreducible_loop_(false), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 707 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 708 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | f6a35de | 2016-03-21 12:01:50 +0000 | [diff] [blame] | 709 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true, kArenaAllocLoopInfoBackEdges) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 710 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 711 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 712 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 713 | bool IsIrreducible() const { return irreducible_; } |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 714 | bool ContainsIrreducibleLoop() const { return contains_irreducible_loop_; } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 715 | |
| 716 | void Dump(std::ostream& os); |
| 717 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 718 | HBasicBlock* GetHeader() const { |
| 719 | return header_; |
| 720 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 721 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 722 | void SetHeader(HBasicBlock* block) { |
| 723 | header_ = block; |
| 724 | } |
| 725 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 726 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 727 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 728 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 729 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 730 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 731 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 732 | } |
| 733 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 734 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 735 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 736 | } |
| 737 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 738 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 739 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 740 | } |
| 741 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 742 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 743 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 744 | } |
| 745 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 746 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 747 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 748 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 749 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 750 | } |
| 751 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 752 | // Returns the lifetime position of the back edge that has the |
| 753 | // greatest lifetime position. |
| 754 | size_t GetLifetimeEnd() const; |
| 755 | |
| 756 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 757 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 758 | } |
| 759 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 760 | // Finds blocks that are part of this loop. |
| 761 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 762 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 763 | // Returns whether this loop information contains `block`. |
| 764 | // Note that this loop information *must* be populated before entering this function. |
| 765 | bool Contains(const HBasicBlock& block) const; |
| 766 | |
| 767 | // Returns whether this loop information is an inner loop of `other`. |
| 768 | // Note that `other` *must* be populated before entering this function. |
| 769 | bool IsIn(const HLoopInformation& other) const; |
| 770 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 771 | // Returns true if instruction is not defined within this loop. |
| 772 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 773 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 774 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 775 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 776 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 777 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 778 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 779 | void ClearAllBlocks() { |
| 780 | blocks_.ClearAllBits(); |
| 781 | } |
| 782 | |
David Brazdil | 3f4a522 | 2016-05-06 12:46:21 +0100 | [diff] [blame] | 783 | bool HasBackEdgeNotDominatedByHeader() const; |
| 784 | |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 785 | bool IsPopulated() const { |
| 786 | return blocks_.GetHighestBitSet() != -1; |
| 787 | } |
| 788 | |
Anton Shamin | f89381f | 2016-05-16 16:44:13 +0600 | [diff] [blame] | 789 | bool DominatesAllBackEdges(HBasicBlock* block); |
| 790 | |
David Sehr | c757dec | 2016-11-04 15:48:34 -0700 | [diff] [blame] | 791 | bool HasExitEdge() const; |
| 792 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 793 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 794 | // Internal recursive implementation of `Populate`. |
| 795 | void PopulateRecursive(HBasicBlock* block); |
David Brazdil | c2e8af9 | 2016-04-05 17:15:19 +0100 | [diff] [blame] | 796 | void PopulateIrreducibleRecursive(HBasicBlock* block, ArenaBitVector* finalized); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 797 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 798 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 799 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 800 | bool irreducible_; |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 801 | bool contains_irreducible_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 802 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 803 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 804 | |
| 805 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 806 | }; |
| 807 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 808 | // Stores try/catch information for basic blocks. |
| 809 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 810 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 811 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 812 | public: |
| 813 | // Try block information constructor. |
| 814 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 815 | : try_entry_(&try_entry), |
| 816 | catch_dex_file_(nullptr), |
| 817 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 818 | DCHECK(try_entry_ != nullptr); |
| 819 | } |
| 820 | |
| 821 | // Catch block information constructor. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 822 | TryCatchInformation(dex::TypeIndex catch_type_index, const DexFile& dex_file) |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 823 | : try_entry_(nullptr), |
| 824 | catch_dex_file_(&dex_file), |
| 825 | catch_type_index_(catch_type_index) {} |
| 826 | |
| 827 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 828 | |
| 829 | const HTryBoundary& GetTryEntry() const { |
| 830 | DCHECK(IsTryBlock()); |
| 831 | return *try_entry_; |
| 832 | } |
| 833 | |
| 834 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 835 | |
| 836 | bool IsCatchAllTypeIndex() const { |
| 837 | DCHECK(IsCatchBlock()); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 838 | return !catch_type_index_.IsValid(); |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 839 | } |
| 840 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 841 | dex::TypeIndex GetCatchTypeIndex() const { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 842 | DCHECK(IsCatchBlock()); |
| 843 | return catch_type_index_; |
| 844 | } |
| 845 | |
| 846 | const DexFile& GetCatchDexFile() const { |
| 847 | DCHECK(IsCatchBlock()); |
| 848 | return *catch_dex_file_; |
| 849 | } |
| 850 | |
| 851 | private: |
| 852 | // One of possibly several TryBoundary instructions entering the block's try. |
| 853 | // Only set for try blocks. |
| 854 | const HTryBoundary* try_entry_; |
| 855 | |
| 856 | // Exception type information. Only set for catch blocks. |
| 857 | const DexFile* catch_dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 858 | const dex::TypeIndex catch_type_index_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 859 | }; |
| 860 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 861 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 862 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 863 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 864 | // A block in a method. Contains the list of instructions represented |
| 865 | // as a double linked list. Each block knows its predecessors and |
| 866 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 867 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 868 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 869 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 870 | explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 871 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 872 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 873 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 874 | loop_information_(nullptr), |
| 875 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 876 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 877 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 878 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 879 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 880 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 881 | try_catch_information_(nullptr) { |
| 882 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 883 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 884 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 885 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 886 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 887 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 888 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 889 | } |
| 890 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 891 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 892 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 893 | } |
| 894 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 895 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 896 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 897 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 898 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 899 | return ContainsElement(successors_, block, start_from); |
| 900 | } |
| 901 | |
| 902 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 903 | return dominated_blocks_; |
| 904 | } |
| 905 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 906 | bool IsEntryBlock() const { |
| 907 | return graph_->GetEntryBlock() == this; |
| 908 | } |
| 909 | |
| 910 | bool IsExitBlock() const { |
| 911 | return graph_->GetExitBlock() == this; |
| 912 | } |
| 913 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 914 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 915 | bool IsSingleTryBoundary() const; |
| 916 | |
| 917 | // Returns true if this block emits nothing but a jump. |
| 918 | bool IsSingleJump() const { |
| 919 | HLoopInformation* loop_info = GetLoopInformation(); |
| 920 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 921 | // Back edges generate a suspend check. |
| 922 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 923 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 924 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 925 | void AddBackEdge(HBasicBlock* back_edge) { |
| 926 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 927 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 928 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 929 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 930 | loop_information_->AddBackEdge(back_edge); |
| 931 | } |
| 932 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 933 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 934 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 935 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 936 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 937 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 938 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 939 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 940 | HBasicBlock* GetDominator() const { return dominator_; } |
| 941 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 942 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 943 | |
| 944 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 945 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 946 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 947 | |
| 948 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 949 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 950 | } |
| 951 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 952 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 953 | |
| 954 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 955 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 956 | } |
| 957 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 958 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 959 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 960 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 961 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 962 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 963 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 964 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 965 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 966 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 967 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 968 | successors_.push_back(block); |
| 969 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 970 | } |
| 971 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 972 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 973 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 974 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 975 | new_block->predecessors_.push_back(this); |
| 976 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 977 | } |
| 978 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 979 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 980 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 981 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 982 | new_block->successors_.push_back(this); |
| 983 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 984 | } |
| 985 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 986 | // Insert `this` between `predecessor` and `successor. This method |
| 987 | // preserves the indicies, and will update the first edge found between |
| 988 | // `predecessor` and `successor`. |
| 989 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 990 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 991 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 992 | successor->predecessors_[predecessor_index] = this; |
| 993 | predecessor->successors_[successor_index] = this; |
| 994 | successors_.push_back(successor); |
| 995 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 996 | } |
| 997 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 998 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 999 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1000 | } |
| 1001 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1002 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1003 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1004 | } |
| 1005 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1006 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1007 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1011 | predecessors_.push_back(block); |
| 1012 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1013 | } |
| 1014 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1015 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1016 | DCHECK_EQ(predecessors_.size(), 2u); |
| 1017 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1018 | } |
| 1019 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1020 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1021 | DCHECK_EQ(successors_.size(), 2u); |
| 1022 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1023 | } |
| 1024 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1025 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1026 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1027 | } |
| 1028 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1029 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1030 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1031 | } |
| 1032 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1033 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1034 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1035 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1039 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1040 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | // Returns whether the first occurrence of `predecessor` in the list of |
| 1044 | // predecessors is at index `idx`. |
| 1045 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1046 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1047 | return GetPredecessorIndexOf(predecessor) == idx; |
| 1048 | } |
| 1049 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1050 | // Create a new block between this block and its predecessors. The new block |
| 1051 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 1052 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 1053 | // loop and try/catch information are not updated. |
| 1054 | HBasicBlock* CreateImmediateDominator(); |
| 1055 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1056 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 1057 | // created, latter block. Note that this method will add the block to the |
| 1058 | // graph, create a Goto at the end of the former block and will create an edge |
| 1059 | // 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] | 1060 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1061 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 1062 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1063 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1064 | // created block. Note that this method just updates raw block information, |
| 1065 | // like predecessors, successors, dominators, and instruction list. It does not |
| 1066 | // update the graph, reverse post order, loop information, nor make sure the |
| 1067 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1068 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 1069 | |
| 1070 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 1071 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1072 | |
| 1073 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1074 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1075 | // that this method does not update the graph, reverse post order, loop |
| 1076 | // information, nor make sure the blocks are consistent (for example ending |
| 1077 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1078 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1079 | |
| 1080 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1081 | // of `this` are moved to `other`. |
| 1082 | // Note that this method does not update the graph, reverse post order, loop |
| 1083 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1084 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1085 | void ReplaceWith(HBasicBlock* other); |
| 1086 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1087 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1088 | // order, links to predecessors, successors, dominators and deletes the block |
| 1089 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1090 | // predecessor of `other` and vice versa. |
| 1091 | void MergeWith(HBasicBlock* other); |
| 1092 | |
| 1093 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1094 | // removes it from all loops it is included in and eventually from the graph. |
| 1095 | // The block must not dominate any other block. Predecessors and successors |
| 1096 | // are safely updated. |
| 1097 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1098 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1099 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1100 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1101 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1102 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1103 | // Replace instruction `initial` with `replacement` within this block. |
| 1104 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1105 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1106 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1107 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1108 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1109 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1110 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1111 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1112 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1113 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1114 | |
| 1115 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1116 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1117 | } |
| 1118 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1119 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1120 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1121 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1122 | } |
| 1123 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1124 | bool IsFirstPredecessorBackEdge() const { |
| 1125 | DCHECK(IsLoopHeader()); |
| 1126 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1127 | } |
| 1128 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1129 | HLoopInformation* GetLoopInformation() const { |
| 1130 | return loop_information_; |
| 1131 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1132 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1133 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1134 | // 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] | 1135 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1136 | void SetInLoop(HLoopInformation* info) { |
| 1137 | if (IsLoopHeader()) { |
| 1138 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1139 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1140 | loop_information_ = info; |
| 1141 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1142 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1143 | // Note that a non loop header having a loop information means this loop information |
| 1144 | // has already been populated |
| 1145 | loop_information_ = info; |
| 1146 | } else { |
| 1147 | // Block is part of an inner loop. Do not update the loop information. |
| 1148 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1149 | // at this point, because this method is being called while populating `info`. |
| 1150 | } |
| 1151 | } |
| 1152 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1153 | // Raw update of the loop information. |
| 1154 | void SetLoopInformation(HLoopInformation* info) { |
| 1155 | loop_information_ = info; |
| 1156 | } |
| 1157 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1158 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1159 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1160 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1161 | |
| 1162 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1163 | try_catch_information_ = try_catch_information; |
| 1164 | } |
| 1165 | |
| 1166 | bool IsTryBlock() const { |
| 1167 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1168 | } |
| 1169 | |
| 1170 | bool IsCatchBlock() const { |
| 1171 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1172 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1173 | |
| 1174 | // Returns the try entry that this block's successors should have. They will |
| 1175 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1176 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1177 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1178 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1179 | bool HasThrowingInstructions() const; |
| 1180 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1181 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1182 | bool Dominates(HBasicBlock* block) const; |
| 1183 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1184 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1185 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1186 | |
| 1187 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1188 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1189 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1190 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1191 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1192 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1193 | bool HasSinglePhi() const; |
| 1194 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1195 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1196 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1197 | ArenaVector<HBasicBlock*> predecessors_; |
| 1198 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1199 | HInstructionList instructions_; |
| 1200 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1201 | HLoopInformation* loop_information_; |
| 1202 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1203 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1204 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1205 | // The dex program counter of the first instruction of this block. |
| 1206 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1207 | size_t lifetime_start_; |
| 1208 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1209 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1210 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1211 | friend class HGraph; |
| 1212 | friend class HInstruction; |
| 1213 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1214 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1215 | }; |
| 1216 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1217 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1218 | // from the innermost to the outermost. |
| 1219 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1220 | public: |
| 1221 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1222 | : current_(block.GetLoopInformation()) {} |
| 1223 | |
| 1224 | bool Done() const { return current_ == nullptr; } |
| 1225 | |
| 1226 | void Advance() { |
| 1227 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1228 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | HLoopInformation* Current() const { |
| 1232 | DCHECK(!Done()); |
| 1233 | return current_; |
| 1234 | } |
| 1235 | |
| 1236 | private: |
| 1237 | HLoopInformation* current_; |
| 1238 | |
| 1239 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1240 | }; |
| 1241 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1242 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1243 | M(Above, Condition) \ |
| 1244 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1245 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1246 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1247 | M(ArrayGet, Instruction) \ |
| 1248 | M(ArrayLength, Instruction) \ |
| 1249 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1250 | M(Below, Condition) \ |
| 1251 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1252 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1253 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1254 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1255 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1256 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1257 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1258 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1259 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1260 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame^] | 1261 | M(ShouldDeoptimizeFlag, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1262 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1263 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1264 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1265 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1266 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1267 | M(Exit, Instruction) \ |
| 1268 | M(FloatConstant, Constant) \ |
| 1269 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1270 | M(GreaterThan, Condition) \ |
| 1271 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1272 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1273 | M(InstanceFieldGet, Instruction) \ |
| 1274 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1275 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1276 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1277 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1278 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1279 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1280 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1281 | M(LessThan, Condition) \ |
| 1282 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1283 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1284 | M(LoadException, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1285 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1286 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1287 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1288 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1289 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1290 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1291 | M(Neg, UnaryOperation) \ |
| 1292 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1293 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1294 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1295 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1296 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1297 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1298 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1299 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1300 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1301 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1302 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1303 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1304 | M(Return, Instruction) \ |
| 1305 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1306 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1307 | M(Shl, BinaryOperation) \ |
| 1308 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1309 | M(StaticFieldGet, Instruction) \ |
| 1310 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1311 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1312 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1313 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1314 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1315 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1316 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1317 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1318 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1319 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1320 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1321 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1322 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1323 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1324 | /* |
| 1325 | * Instructions, shared across several (not all) architectures. |
| 1326 | */ |
| 1327 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1328 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1329 | #else |
| 1330 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1331 | M(BitwiseNegatedRight, Instruction) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1332 | M(MultiplyAccumulate, Instruction) \ |
| 1333 | M(IntermediateAddress, Instruction) |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1334 | #endif |
| 1335 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1336 | #ifndef ART_ENABLE_CODEGEN_arm |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1337 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1338 | #else |
| 1339 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1340 | M(ArmDexCacheArraysBase, Instruction) |
| 1341 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1342 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1343 | #ifndef ART_ENABLE_CODEGEN_arm64 |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1344 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1345 | #else |
| 1346 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1347 | M(Arm64DataProcWithShifterOp, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1348 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1349 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1350 | #ifndef ART_ENABLE_CODEGEN_mips |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1351 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1352 | #else |
| 1353 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
| 1354 | M(MipsComputeBaseMethodAddress, Instruction) \ |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 1355 | M(MipsDexCacheArraysBase, Instruction) \ |
| 1356 | M(MipsPackedSwitch, Instruction) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1357 | #endif |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1358 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1359 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1360 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1361 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1362 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1363 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1364 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1365 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1366 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1367 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1368 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1369 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1370 | |
| 1371 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1372 | |
| 1373 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1374 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1375 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1376 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1377 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1378 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1379 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1380 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1381 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1382 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1383 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1384 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1385 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1386 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1387 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1388 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1389 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1390 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1391 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1392 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1393 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1394 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1395 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1396 | #undef FORWARD_DECLARATION |
| 1397 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1398 | #define DECLARE_INSTRUCTION(type) \ |
| 1399 | InstructionKind GetKindInternal() const OVERRIDE { return k##type; } \ |
| 1400 | const char* DebugName() const OVERRIDE { return #type; } \ |
| 1401 | bool InstructionTypeEquals(const HInstruction* other) const OVERRIDE { \ |
| 1402 | return other->Is##type(); \ |
| 1403 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1404 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1405 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1406 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
| 1407 | bool Is##type() const { return As##type() != nullptr; } \ |
| 1408 | const H##type* As##type() const { return this; } \ |
| 1409 | H##type* As##type() { return this; } |
| 1410 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1411 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1412 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1413 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1414 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1415 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1416 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1417 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1418 | // Hook for the IntrusiveForwardList<>. |
| 1419 | // TODO: Hide this better. |
| 1420 | IntrusiveForwardListHook hook; |
| 1421 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1422 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1423 | HUseListNode(T user, size_t index) |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1424 | : user_(user), index_(index) {} |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1425 | |
| 1426 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1427 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1428 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1429 | friend class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1430 | |
| 1431 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1432 | }; |
| 1433 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1434 | template <typename T> |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1435 | using HUseList = IntrusiveForwardList<HUseListNode<T>>; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1436 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1437 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1438 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1439 | // by the used instructions. |
| 1440 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1441 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1442 | public: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1443 | HUserRecord() : instruction_(nullptr), before_use_node_() {} |
| 1444 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), before_use_node_() {} |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1445 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1446 | HUserRecord(const HUserRecord<T>& old_record, typename HUseList<T>::iterator before_use_node) |
| 1447 | : HUserRecord(old_record.instruction_, before_use_node) {} |
| 1448 | HUserRecord(HInstruction* instruction, typename HUseList<T>::iterator before_use_node) |
| 1449 | : instruction_(instruction), before_use_node_(before_use_node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1450 | DCHECK(instruction_ != nullptr); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1451 | } |
| 1452 | |
| 1453 | HInstruction* GetInstruction() const { return instruction_; } |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1454 | typename HUseList<T>::iterator GetBeforeUseNode() const { return before_use_node_; } |
| 1455 | typename HUseList<T>::iterator GetUseNode() const { return ++GetBeforeUseNode(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1456 | |
| 1457 | private: |
| 1458 | // Instruction used by the user. |
| 1459 | HInstruction* instruction_; |
| 1460 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1461 | // Iterator before the corresponding entry in the use list kept by 'instruction_'. |
| 1462 | typename HUseList<T>::iterator before_use_node_; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1463 | }; |
| 1464 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1465 | // Helper class that extracts the input instruction from HUserRecord<HInstruction*>. |
| 1466 | // This is used for HInstruction::GetInputs() to return a container wrapper providing |
| 1467 | // HInstruction* values even though the underlying container has HUserRecord<>s. |
| 1468 | struct HInputExtractor { |
| 1469 | HInstruction* operator()(HUserRecord<HInstruction*>& record) const { |
| 1470 | return record.GetInstruction(); |
| 1471 | } |
| 1472 | const HInstruction* operator()(const HUserRecord<HInstruction*>& record) const { |
| 1473 | return record.GetInstruction(); |
| 1474 | } |
| 1475 | }; |
| 1476 | |
| 1477 | using HInputsRef = TransformArrayRef<HUserRecord<HInstruction*>, HInputExtractor>; |
| 1478 | using HConstInputsRef = TransformArrayRef<const HUserRecord<HInstruction*>, HInputExtractor>; |
| 1479 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1480 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1481 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1482 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1483 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1484 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1485 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1486 | * modify the value of a reference field read [although it may modify the |
| 1487 | * reference fetch prior to reading the field, which is represented by its own |
| 1488 | * write/read dependence]). The analysis makes conservative points-to |
| 1489 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1490 | * the same, and any reference read depends on any reference read without |
| 1491 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1492 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1493 | * The internal representation uses 38-bit and is described in the table below. |
| 1494 | * The first line indicates the side effect, and for field/array accesses the |
| 1495 | * second line indicates the type of the access (in the order of the |
| 1496 | * Primitive::Type enum). |
| 1497 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1498 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1499 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1500 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1501 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1502 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1503 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1504 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1505 | * |
| 1506 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1507 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1508 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1509 | class SideEffects : public ValueObject { |
| 1510 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1511 | SideEffects() : flags_(0) {} |
| 1512 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1513 | static SideEffects None() { |
| 1514 | return SideEffects(0); |
| 1515 | } |
| 1516 | |
| 1517 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1518 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1519 | } |
| 1520 | |
| 1521 | static SideEffects AllChanges() { |
| 1522 | return SideEffects(kAllChangeBits); |
| 1523 | } |
| 1524 | |
| 1525 | static SideEffects AllDependencies() { |
| 1526 | return SideEffects(kAllDependOnBits); |
| 1527 | } |
| 1528 | |
| 1529 | static SideEffects AllExceptGCDependency() { |
| 1530 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1531 | } |
| 1532 | |
| 1533 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1534 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1535 | } |
| 1536 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1537 | static SideEffects AllWrites() { |
| 1538 | return SideEffects(kAllWrites); |
| 1539 | } |
| 1540 | |
| 1541 | static SideEffects AllReads() { |
| 1542 | return SideEffects(kAllReads); |
| 1543 | } |
| 1544 | |
| 1545 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1546 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1547 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1548 | : SideEffects(TypeFlag(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1549 | } |
| 1550 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1551 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1552 | return SideEffects(TypeFlag(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1553 | } |
| 1554 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1555 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1556 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1557 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1558 | : SideEffects(TypeFlag(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1562 | return SideEffects(TypeFlag(type, kArrayReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1563 | } |
| 1564 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1565 | static SideEffects CanTriggerGC() { |
| 1566 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1567 | } |
| 1568 | |
| 1569 | static SideEffects DependsOnGC() { |
| 1570 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1571 | } |
| 1572 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1573 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1574 | SideEffects Union(SideEffects other) const { |
| 1575 | return SideEffects(flags_ | other.flags_); |
| 1576 | } |
| 1577 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1578 | SideEffects Exclusion(SideEffects other) const { |
| 1579 | return SideEffects(flags_ & ~other.flags_); |
| 1580 | } |
| 1581 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1582 | void Add(SideEffects other) { |
| 1583 | flags_ |= other.flags_; |
| 1584 | } |
| 1585 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1586 | bool Includes(SideEffects other) const { |
| 1587 | return (other.flags_ & flags_) == other.flags_; |
| 1588 | } |
| 1589 | |
| 1590 | bool HasSideEffects() const { |
| 1591 | return (flags_ & kAllChangeBits); |
| 1592 | } |
| 1593 | |
| 1594 | bool HasDependencies() const { |
| 1595 | return (flags_ & kAllDependOnBits); |
| 1596 | } |
| 1597 | |
| 1598 | // Returns true if there are no side effects or dependencies. |
| 1599 | bool DoesNothing() const { |
| 1600 | return flags_ == 0; |
| 1601 | } |
| 1602 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1603 | // Returns true if something is written. |
| 1604 | bool DoesAnyWrite() const { |
| 1605 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1606 | } |
| 1607 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1608 | // Returns true if something is read. |
| 1609 | bool DoesAnyRead() const { |
| 1610 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1611 | } |
| 1612 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1613 | // Returns true if potentially everything is written and read |
| 1614 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1615 | bool DoesAllReadWrite() const { |
| 1616 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1617 | } |
| 1618 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1619 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1620 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1621 | } |
| 1622 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1623 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1624 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1625 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1626 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1630 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1631 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1632 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1633 | for (int s = kLastBit; s >= 0; s--) { |
| 1634 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1635 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1636 | // This is a bit for the GC side effect. |
| 1637 | if (current_bit_is_set) { |
| 1638 | flags += "GC"; |
| 1639 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1640 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1641 | } else { |
| 1642 | // This is a bit for the array/field analysis. |
| 1643 | // The underscore character stands for the 'can trigger GC' bit. |
| 1644 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1645 | if (current_bit_is_set) { |
| 1646 | flags += kDebug[s]; |
| 1647 | } |
| 1648 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1649 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1650 | flags += "|"; |
| 1651 | } |
| 1652 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1653 | } |
| 1654 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1655 | } |
| 1656 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1657 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1658 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1659 | private: |
| 1660 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1661 | |
| 1662 | static constexpr int kFieldWriteOffset = 0; |
| 1663 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1664 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1665 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1666 | |
| 1667 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1668 | |
| 1669 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1670 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1671 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1672 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1673 | |
| 1674 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1675 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1676 | |
| 1677 | // Aliases. |
| 1678 | |
| 1679 | static_assert(kChangeBits == kDependOnBits, |
| 1680 | "the 'change' bits should match the 'depend on' bits."); |
| 1681 | |
| 1682 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1683 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1684 | static constexpr uint64_t kAllWrites = |
| 1685 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1686 | static constexpr uint64_t kAllReads = |
| 1687 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1688 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1689 | // Translates type to bit flag. |
| 1690 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1691 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1692 | const uint64_t one = 1; |
| 1693 | const int shift = type; // 0-based consecutive enum |
| 1694 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1695 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1696 | return one << (type + offset); |
| 1697 | } |
| 1698 | |
| 1699 | // Private constructor on direct flags value. |
| 1700 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1701 | |
| 1702 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1703 | }; |
| 1704 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1705 | // A HEnvironment object contains the values of virtual registers at a given location. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1706 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1707 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1708 | HEnvironment(ArenaAllocator* arena, |
| 1709 | size_t number_of_vregs, |
| 1710 | const DexFile& dex_file, |
| 1711 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1712 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1713 | InvokeType invoke_type, |
| 1714 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1715 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1716 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1717 | parent_(nullptr), |
| 1718 | dex_file_(dex_file), |
| 1719 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1720 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1721 | invoke_type_(invoke_type), |
| 1722 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1723 | } |
| 1724 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1725 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1726 | : HEnvironment(arena, |
| 1727 | to_copy.Size(), |
| 1728 | to_copy.GetDexFile(), |
| 1729 | to_copy.GetMethodIdx(), |
| 1730 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1731 | to_copy.GetInvokeType(), |
| 1732 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1733 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1734 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1735 | if (parent_ != nullptr) { |
| 1736 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1737 | } else { |
| 1738 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1739 | parent_->CopyFrom(parent); |
| 1740 | if (parent->GetParent() != nullptr) { |
| 1741 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1742 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1743 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1744 | } |
| 1745 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1746 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1747 | void CopyFrom(HEnvironment* environment); |
| 1748 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1749 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1750 | // input to the loop phi instead. This is for inserting instructions that |
| 1751 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1752 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1753 | |
| 1754 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1755 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1759 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1760 | } |
| 1761 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1762 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1763 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1764 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1765 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1766 | HEnvironment* GetParent() const { return parent_; } |
| 1767 | |
| 1768 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1769 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1773 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | uint32_t GetDexPc() const { |
| 1777 | return dex_pc_; |
| 1778 | } |
| 1779 | |
| 1780 | uint32_t GetMethodIdx() const { |
| 1781 | return method_idx_; |
| 1782 | } |
| 1783 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1784 | InvokeType GetInvokeType() const { |
| 1785 | return invoke_type_; |
| 1786 | } |
| 1787 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1788 | const DexFile& GetDexFile() const { |
| 1789 | return dex_file_; |
| 1790 | } |
| 1791 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1792 | HInstruction* GetHolder() const { |
| 1793 | return holder_; |
| 1794 | } |
| 1795 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1796 | |
| 1797 | bool IsFromInlinedInvoke() const { |
| 1798 | return GetParent() != nullptr; |
| 1799 | } |
| 1800 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1801 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1802 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1803 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1804 | HEnvironment* parent_; |
| 1805 | const DexFile& dex_file_; |
| 1806 | const uint32_t method_idx_; |
| 1807 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1808 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1809 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1810 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1811 | HInstruction* const holder_; |
| 1812 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1813 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1814 | |
| 1815 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1816 | }; |
| 1817 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1818 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1819 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1820 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1821 | : previous_(nullptr), |
| 1822 | next_(nullptr), |
| 1823 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1824 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1825 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1826 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1827 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1828 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1829 | locations_(nullptr), |
| 1830 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1831 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1832 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1833 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
| 1834 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 1835 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1836 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1837 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1838 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1839 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1840 | enum InstructionKind { |
| 1841 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1842 | }; |
| 1843 | #undef DECLARE_KIND |
| 1844 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1845 | HInstruction* GetNext() const { return next_; } |
| 1846 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1847 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1848 | HInstruction* GetNextDisregardingMoves() const; |
| 1849 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1850 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1851 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1852 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1853 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1854 | bool IsInBlock() const { return block_ != nullptr; } |
| 1855 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1856 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 1857 | bool IsIrreducibleLoopHeaderPhi() const { |
| 1858 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 1859 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1860 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1861 | virtual ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() = 0; |
| 1862 | |
| 1863 | ArrayRef<const HUserRecord<HInstruction*>> GetInputRecords() const { |
| 1864 | // One virtual method is enough, just const_cast<> and then re-add the const. |
| 1865 | return ArrayRef<const HUserRecord<HInstruction*>>( |
| 1866 | const_cast<HInstruction*>(this)->GetInputRecords()); |
| 1867 | } |
| 1868 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1869 | HInputsRef GetInputs() { |
| 1870 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1871 | } |
| 1872 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1873 | HConstInputsRef GetInputs() const { |
| 1874 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1875 | } |
| 1876 | |
| 1877 | size_t InputCount() const { return GetInputRecords().size(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1878 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1879 | |
Aart Bik | 2767f4b | 2016-10-28 15:03:53 -0700 | [diff] [blame] | 1880 | bool HasInput(HInstruction* input) const { |
| 1881 | for (const HInstruction* i : GetInputs()) { |
| 1882 | if (i == input) { |
| 1883 | return true; |
| 1884 | } |
| 1885 | } |
| 1886 | return false; |
| 1887 | } |
| 1888 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1889 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1890 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1891 | } |
| 1892 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1893 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1894 | virtual const char* DebugName() const = 0; |
| 1895 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1896 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
| 1897 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1898 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1899 | |
| 1900 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1901 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1902 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1903 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1904 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1905 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1906 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1907 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1908 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1909 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1910 | // Does not apply for all instructions, but having this at top level greatly |
| 1911 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1912 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1913 | virtual bool CanBeNull() const { |
| 1914 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1915 | return true; |
| 1916 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1917 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1918 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1919 | return false; |
| 1920 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1921 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 1922 | virtual bool IsActualObject() const { |
| 1923 | return GetType() == Primitive::kPrimNot; |
| 1924 | } |
| 1925 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1926 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1927 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1928 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1929 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1930 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 1931 | GetPackedFlag<kFlagReferenceTypeIsExact>()); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1932 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1933 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1934 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1935 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1936 | // Note: fixup_end remains valid across push_front(). |
| 1937 | auto fixup_end = uses_.empty() ? uses_.begin() : ++uses_.begin(); |
| 1938 | HUseListNode<HInstruction*>* new_node = |
| 1939 | new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HInstruction*>(user, index); |
| 1940 | uses_.push_front(*new_node); |
| 1941 | FixUpUserRecordsAfterUseInsertion(fixup_end); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1942 | } |
| 1943 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1944 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1945 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1946 | // Note: env_fixup_end remains valid across push_front(). |
| 1947 | auto env_fixup_end = env_uses_.empty() ? env_uses_.begin() : ++env_uses_.begin(); |
| 1948 | HUseListNode<HEnvironment*>* new_node = |
| 1949 | new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HEnvironment*>(user, index); |
| 1950 | env_uses_.push_front(*new_node); |
| 1951 | FixUpUserRecordsAfterEnvUseInsertion(env_fixup_end); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1952 | } |
| 1953 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1954 | void RemoveAsUserOfInput(size_t input) { |
| 1955 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1956 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 1957 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 1958 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1959 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1960 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1961 | void RemoveAsUserOfAllInputs() { |
| 1962 | for (const HUserRecord<HInstruction*>& input_use : GetInputRecords()) { |
| 1963 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 1964 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 1965 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
| 1966 | } |
| 1967 | } |
| 1968 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1969 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1970 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1971 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1972 | bool HasUses() const { return !uses_.empty() || !env_uses_.empty(); } |
| 1973 | bool HasEnvironmentUses() const { return !env_uses_.empty(); } |
| 1974 | bool HasNonEnvironmentUses() const { return !uses_.empty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1975 | bool HasOnlyOneNonEnvironmentUse() const { |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1976 | return !HasEnvironmentUses() && GetUses().HasExactlyOneElement(); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1977 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1978 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 1979 | bool IsRemovable() const { |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 1980 | return |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 1981 | !DoesAnyWrite() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 1982 | !CanThrow() && |
| 1983 | !IsSuspendCheck() && |
| 1984 | !IsControlFlow() && |
| 1985 | !IsNativeDebugInfo() && |
| 1986 | !IsParameterValue() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 1987 | // If we added an explicit barrier then we should keep it. |
| 1988 | !IsMemoryBarrier(); |
| 1989 | } |
| 1990 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 1991 | bool IsDeadAndRemovable() const { |
| 1992 | return IsRemovable() && !HasUses(); |
| 1993 | } |
| 1994 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1995 | // Does this instruction strictly dominate `other_instruction`? |
| 1996 | // Returns false if this instruction and `other_instruction` are the same. |
| 1997 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1998 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1999 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2000 | int GetId() const { return id_; } |
| 2001 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2002 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2003 | int GetSsaIndex() const { return ssa_index_; } |
| 2004 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 2005 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 2006 | |
| 2007 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 2008 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2009 | // Set the `environment_` field. Raw because this method does not |
| 2010 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2011 | void SetRawEnvironment(HEnvironment* environment) { |
| 2012 | DCHECK(environment_ == nullptr); |
| 2013 | DCHECK_EQ(environment->GetHolder(), this); |
| 2014 | environment_ = environment; |
| 2015 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2016 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2017 | void InsertRawEnvironment(HEnvironment* environment) { |
| 2018 | DCHECK(environment_ != nullptr); |
| 2019 | DCHECK_EQ(environment->GetHolder(), this); |
| 2020 | DCHECK(environment->GetParent() == nullptr); |
| 2021 | environment->parent_ = environment_; |
| 2022 | environment_ = environment; |
| 2023 | } |
| 2024 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2025 | void RemoveEnvironment(); |
| 2026 | |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2027 | // Set the environment of this instruction, copying it from `environment`. While |
| 2028 | // copying, the uses lists are being updated. |
| 2029 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2030 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2031 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2032 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2033 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2034 | if (environment->GetParent() != nullptr) { |
| 2035 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2036 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2037 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2038 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2039 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 2040 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2041 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2042 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2043 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2044 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2045 | if (environment->GetParent() != nullptr) { |
| 2046 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2047 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2048 | } |
| 2049 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2050 | // Returns the number of entries in the environment. Typically, that is the |
| 2051 | // number of dex registers in a method. It could be more in case of inlining. |
| 2052 | size_t EnvironmentSize() const; |
| 2053 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2054 | LocationSummary* GetLocations() const { return locations_; } |
| 2055 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2056 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2057 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2058 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2059 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2060 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 2061 | // uses of this instruction by `other` are *not* updated. |
| 2062 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 2063 | ReplaceWith(other); |
| 2064 | other->ReplaceInput(this, use_index); |
| 2065 | } |
| 2066 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 2067 | // Move `this` instruction before `cursor`. |
| 2068 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2069 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2070 | // Move `this` before its first user and out of any loops. If there is no |
| 2071 | // out-of-loop user that dominates all other users, move the instruction |
| 2072 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2073 | // |
| 2074 | // This can be used only on non-throwing instructions with no side effects that |
| 2075 | // have at least one use but no environment uses. |
| 2076 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2077 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2078 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2079 | bool Is##type() const; \ |
| 2080 | const H##type* As##type() const; \ |
| 2081 | H##type* As##type(); |
| 2082 | |
| 2083 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2084 | #undef INSTRUCTION_TYPE_CHECK |
| 2085 | |
| 2086 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2087 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 2088 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2089 | virtual H##type* As##type() { return nullptr; } |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2090 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2091 | #undef INSTRUCTION_TYPE_CHECK |
| 2092 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2093 | // Returns whether the instruction can be moved within the graph. |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 2094 | // TODO: this method is used by LICM and GVN with possibly different |
| 2095 | // meanings? split and rename? |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2096 | virtual bool CanBeMoved() const { return false; } |
| 2097 | |
| 2098 | // Returns whether the two instructions are of the same kind. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2099 | virtual bool InstructionTypeEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2100 | return false; |
| 2101 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2102 | |
| 2103 | // Returns whether any data encoded in the two instructions is equal. |
| 2104 | // This method does not look at the inputs. Both instructions must be |
| 2105 | // of the same type, otherwise the method has undefined behavior. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2106 | virtual bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2107 | return false; |
| 2108 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2109 | |
| 2110 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2111 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2112 | // 2) Their inputs are identical. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2113 | bool Equals(const HInstruction* other) const; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2114 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2115 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2116 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2117 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2118 | // apply the strong requirement for virtual functions, preventing optimizations. |
| 2119 | InstructionKind GetKind() const PURE; |
| 2120 | virtual InstructionKind GetKindInternal() const = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2121 | |
| 2122 | virtual size_t ComputeHashCode() const { |
| 2123 | size_t result = GetKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2124 | for (const HInstruction* input : GetInputs()) { |
| 2125 | result = (result * 31) + input->GetId(); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2126 | } |
| 2127 | return result; |
| 2128 | } |
| 2129 | |
| 2130 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2131 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2132 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2133 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2134 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2135 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2136 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2137 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2138 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2139 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2140 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2141 | |
| 2142 | // Returns whether the code generation of the instruction will require to have access |
| 2143 | // to the current method. Such instructions are: |
| 2144 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2145 | // to walk the stack and have the current method stored at a specific stack address. |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2146 | // (2): HCurrentMethod, potentially used by HInvokeStaticOrDirect, HLoadString, or HLoadClass |
| 2147 | // to access the dex cache. |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2148 | bool NeedsCurrentMethod() const { |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2149 | return NeedsEnvironment() || IsCurrentMethod(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2150 | } |
| 2151 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2152 | // Returns whether the code generation of the instruction will require to have access |
| 2153 | // to the dex cache of the current method's declaring class via the current method. |
| 2154 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2155 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2156 | // Does this instruction have any use in an environment before |
| 2157 | // control flow hits 'other'? |
| 2158 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2159 | |
| 2160 | // Remove all references to environment uses of this instruction. |
| 2161 | // The caller must ensure that this is safe to do. |
| 2162 | void RemoveEnvironmentUsers(); |
| 2163 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2164 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2165 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2166 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2167 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2168 | // If set, the machine code for this instruction is assumed to be generated by |
| 2169 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2170 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2171 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
| 2172 | static constexpr size_t kNumberOfGenericPackedBits = kFlagReferenceTypeIsExact + 1; |
| 2173 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2174 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2175 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const { |
| 2176 | return GetInputRecords()[i]; |
| 2177 | } |
| 2178 | |
| 2179 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) { |
| 2180 | ArrayRef<HUserRecord<HInstruction*>> input_records = GetInputRecords(); |
| 2181 | input_records[index] = input; |
| 2182 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2183 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2184 | uint32_t GetPackedFields() const { |
| 2185 | return packed_fields_; |
| 2186 | } |
| 2187 | |
| 2188 | template <size_t flag> |
| 2189 | bool GetPackedFlag() const { |
| 2190 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2191 | } |
| 2192 | |
| 2193 | template <size_t flag> |
| 2194 | void SetPackedFlag(bool value = true) { |
| 2195 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2196 | } |
| 2197 | |
| 2198 | template <typename BitFieldType> |
| 2199 | typename BitFieldType::value_type GetPackedField() const { |
| 2200 | return BitFieldType::Decode(packed_fields_); |
| 2201 | } |
| 2202 | |
| 2203 | template <typename BitFieldType> |
| 2204 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2205 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2206 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2207 | } |
| 2208 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2209 | private: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2210 | void FixUpUserRecordsAfterUseInsertion(HUseList<HInstruction*>::iterator fixup_end) { |
| 2211 | auto before_use_node = uses_.before_begin(); |
| 2212 | for (auto use_node = uses_.begin(); use_node != fixup_end; ++use_node) { |
| 2213 | HInstruction* user = use_node->GetUser(); |
| 2214 | size_t input_index = use_node->GetIndex(); |
| 2215 | user->SetRawInputRecordAt(input_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2216 | before_use_node = use_node; |
| 2217 | } |
| 2218 | } |
| 2219 | |
| 2220 | void FixUpUserRecordsAfterUseRemoval(HUseList<HInstruction*>::iterator before_use_node) { |
| 2221 | auto next = ++HUseList<HInstruction*>::iterator(before_use_node); |
| 2222 | if (next != uses_.end()) { |
| 2223 | HInstruction* next_user = next->GetUser(); |
| 2224 | size_t next_index = next->GetIndex(); |
| 2225 | DCHECK(next_user->InputRecordAt(next_index).GetInstruction() == this); |
| 2226 | next_user->SetRawInputRecordAt(next_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2227 | } |
| 2228 | } |
| 2229 | |
| 2230 | void FixUpUserRecordsAfterEnvUseInsertion(HUseList<HEnvironment*>::iterator env_fixup_end) { |
| 2231 | auto before_env_use_node = env_uses_.before_begin(); |
| 2232 | for (auto env_use_node = env_uses_.begin(); env_use_node != env_fixup_end; ++env_use_node) { |
| 2233 | HEnvironment* user = env_use_node->GetUser(); |
| 2234 | size_t input_index = env_use_node->GetIndex(); |
| 2235 | user->vregs_[input_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2236 | before_env_use_node = env_use_node; |
| 2237 | } |
| 2238 | } |
| 2239 | |
| 2240 | void FixUpUserRecordsAfterEnvUseRemoval(HUseList<HEnvironment*>::iterator before_env_use_node) { |
| 2241 | auto next = ++HUseList<HEnvironment*>::iterator(before_env_use_node); |
| 2242 | if (next != env_uses_.end()) { |
| 2243 | HEnvironment* next_user = next->GetUser(); |
| 2244 | size_t next_index = next->GetIndex(); |
| 2245 | DCHECK(next_user->vregs_[next_index].GetInstruction() == this); |
| 2246 | next_user->vregs_[next_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2247 | } |
| 2248 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2249 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2250 | HInstruction* previous_; |
| 2251 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2252 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2253 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2254 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2255 | // An instruction gets an id when it is added to the graph. |
| 2256 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2257 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2258 | int id_; |
| 2259 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2260 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2261 | int ssa_index_; |
| 2262 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2263 | // Packed fields. |
| 2264 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2265 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2266 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2267 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2268 | |
| 2269 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2270 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2271 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2272 | // The environment associated with this instruction. Not null if the instruction |
| 2273 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2274 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2275 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2276 | // Set by the code generator. |
| 2277 | LocationSummary* locations_; |
| 2278 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2279 | // Set by the liveness analysis. |
| 2280 | LiveInterval* live_interval_; |
| 2281 | |
| 2282 | // Set by the liveness analysis, this is the position in a linear |
| 2283 | // order of blocks where this instruction's live interval start. |
| 2284 | size_t lifetime_position_; |
| 2285 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2286 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2287 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2288 | // The reference handle part of the reference type info. |
| 2289 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2290 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2291 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2292 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2293 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2294 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2295 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2296 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2297 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2298 | |
| 2299 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2300 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2301 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2302 | |
| 2303 | class HInstructionIterator : public ValueObject { |
| 2304 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2305 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2306 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2307 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2308 | } |
| 2309 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2310 | bool Done() const { return instruction_ == nullptr; } |
| 2311 | HInstruction* Current() const { return instruction_; } |
| 2312 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2313 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2314 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2315 | } |
| 2316 | |
| 2317 | private: |
| 2318 | HInstruction* instruction_; |
| 2319 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2320 | |
| 2321 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2322 | }; |
| 2323 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2324 | class HBackwardInstructionIterator : public ValueObject { |
| 2325 | public: |
| 2326 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2327 | : instruction_(instructions.last_instruction_) { |
| 2328 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2329 | } |
| 2330 | |
| 2331 | bool Done() const { return instruction_ == nullptr; } |
| 2332 | HInstruction* Current() const { return instruction_; } |
| 2333 | void Advance() { |
| 2334 | instruction_ = next_; |
| 2335 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2336 | } |
| 2337 | |
| 2338 | private: |
| 2339 | HInstruction* instruction_; |
| 2340 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2341 | |
| 2342 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2343 | }; |
| 2344 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2345 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2346 | class HTemplateInstruction: public HInstruction { |
| 2347 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2348 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2349 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2350 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2351 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2352 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2353 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2354 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2355 | } |
| 2356 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2357 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2358 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2359 | |
| 2360 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2361 | }; |
| 2362 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2363 | // HTemplateInstruction specialization for N=0. |
| 2364 | template<> |
| 2365 | class HTemplateInstruction<0>: public HInstruction { |
| 2366 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2367 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2368 | : HInstruction(side_effects, dex_pc) {} |
| 2369 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2370 | virtual ~HTemplateInstruction() {} |
| 2371 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2372 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2373 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2374 | return ArrayRef<HUserRecord<HInstruction*>>(); |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2375 | } |
| 2376 | |
| 2377 | private: |
| 2378 | friend class SsaBuilder; |
| 2379 | }; |
| 2380 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2381 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2382 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2383 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2384 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2385 | : HTemplateInstruction<N>(side_effects, dex_pc) { |
| 2386 | this->template SetPackedField<TypeField>(type); |
| 2387 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2388 | virtual ~HExpression() {} |
| 2389 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2390 | Primitive::Type GetType() const OVERRIDE { |
| 2391 | return TypeField::Decode(this->GetPackedFields()); |
| 2392 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2393 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2394 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2395 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2396 | static constexpr size_t kFieldTypeSize = |
| 2397 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2398 | static constexpr size_t kNumberOfExpressionPackedBits = kFieldType + kFieldTypeSize; |
| 2399 | static_assert(kNumberOfExpressionPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 2400 | "Too many packed fields."); |
| 2401 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2402 | }; |
| 2403 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2404 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2405 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2406 | class HReturnVoid FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2407 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2408 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2409 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2410 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2411 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2412 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2413 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2414 | |
| 2415 | private: |
| 2416 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2417 | }; |
| 2418 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2419 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2420 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2421 | class HReturn FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2422 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2423 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2424 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2425 | SetRawInputAt(0, value); |
| 2426 | } |
| 2427 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2428 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2429 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2430 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2431 | |
| 2432 | private: |
| 2433 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2434 | }; |
| 2435 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2436 | class HPhi FINAL : public HInstruction { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2437 | public: |
| 2438 | HPhi(ArenaAllocator* arena, |
| 2439 | uint32_t reg_number, |
| 2440 | size_t number_of_inputs, |
| 2441 | Primitive::Type type, |
| 2442 | uint32_t dex_pc = kNoDexPc) |
| 2443 | : HInstruction(SideEffects::None(), dex_pc), |
| 2444 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
| 2445 | reg_number_(reg_number) { |
| 2446 | SetPackedField<TypeField>(ToPhiType(type)); |
| 2447 | DCHECK_NE(GetType(), Primitive::kPrimVoid); |
| 2448 | // Phis are constructed live and marked dead if conflicting or unused. |
| 2449 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 2450 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 2451 | SetPackedFlag<kFlagIsLive>(true); |
| 2452 | SetPackedFlag<kFlagCanBeNull>(true); |
| 2453 | } |
| 2454 | |
| 2455 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 2456 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 2457 | return Primitive::PrimitiveKind(type); |
| 2458 | } |
| 2459 | |
| 2460 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 2461 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2462 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2463 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2464 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 2465 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2466 | |
| 2467 | void AddInput(HInstruction* input); |
| 2468 | void RemoveInputAt(size_t index); |
| 2469 | |
| 2470 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<TypeField>(); } |
| 2471 | void SetType(Primitive::Type new_type) { |
| 2472 | // Make sure that only valid type changes occur. The following are allowed: |
| 2473 | // (1) int -> float/ref (primitive type propagation), |
| 2474 | // (2) long -> double (primitive type propagation). |
| 2475 | DCHECK(GetType() == new_type || |
| 2476 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimFloat) || |
| 2477 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimNot) || |
| 2478 | (GetType() == Primitive::kPrimLong && new_type == Primitive::kPrimDouble)); |
| 2479 | SetPackedField<TypeField>(new_type); |
| 2480 | } |
| 2481 | |
| 2482 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 2483 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
| 2484 | |
| 2485 | uint32_t GetRegNumber() const { return reg_number_; } |
| 2486 | |
| 2487 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 2488 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 2489 | bool IsDead() const { return !IsLive(); } |
| 2490 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
| 2491 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2492 | bool IsVRegEquivalentOf(const HInstruction* other) const { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2493 | return other != nullptr |
| 2494 | && other->IsPhi() |
| 2495 | && other->AsPhi()->GetBlock() == GetBlock() |
| 2496 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 2497 | } |
| 2498 | |
| 2499 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 2500 | // An equivalent phi is a phi having the same dex register and type. |
| 2501 | // It assumes that phis with the same dex register are adjacent. |
| 2502 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 2503 | HInstruction* next = GetNext(); |
| 2504 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 2505 | if (next->GetType() == GetType()) { |
| 2506 | return next->AsPhi(); |
| 2507 | } |
| 2508 | next = next->GetNext(); |
| 2509 | } |
| 2510 | return nullptr; |
| 2511 | } |
| 2512 | |
| 2513 | DECLARE_INSTRUCTION(Phi); |
| 2514 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2515 | private: |
| 2516 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2517 | static constexpr size_t kFieldTypeSize = |
| 2518 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2519 | static constexpr size_t kFlagIsLive = kFieldType + kFieldTypeSize; |
| 2520 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 2521 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 2522 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 2523 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
| 2524 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2525 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2526 | const uint32_t reg_number_; |
| 2527 | |
| 2528 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 2529 | }; |
| 2530 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2531 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2532 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2533 | // exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2534 | class HExit FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2535 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2536 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2537 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2538 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2539 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2540 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2541 | |
| 2542 | private: |
| 2543 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2544 | }; |
| 2545 | |
| 2546 | // Jumps from one block to another. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2547 | class HGoto FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2548 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2549 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2550 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2551 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2552 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2553 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2554 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2555 | } |
| 2556 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2557 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2558 | |
| 2559 | private: |
| 2560 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2561 | }; |
| 2562 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2563 | class HConstant : public HExpression<0> { |
| 2564 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2565 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2566 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2567 | |
| 2568 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2569 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2570 | // Is this constant -1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2571 | virtual bool IsMinusOne() const { return false; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2572 | // Is this constant 0 in the arithmetic sense? |
| 2573 | virtual bool IsArithmeticZero() const { return false; } |
| 2574 | // Is this constant a 0-bit pattern? |
| 2575 | virtual bool IsZeroBitPattern() const { return false; } |
| 2576 | // Is this constant 1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2577 | virtual bool IsOne() const { return false; } |
| 2578 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2579 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2580 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2581 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2582 | |
| 2583 | private: |
| 2584 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2585 | }; |
| 2586 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2587 | class HNullConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2588 | public: |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2589 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2590 | return true; |
| 2591 | } |
| 2592 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2593 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2594 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2595 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2596 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2597 | // The null constant representation is a 0-bit pattern. |
| 2598 | virtual bool IsZeroBitPattern() const { return true; } |
| 2599 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2600 | DECLARE_INSTRUCTION(NullConstant); |
| 2601 | |
| 2602 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2603 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2604 | |
| 2605 | friend class HGraph; |
| 2606 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2607 | }; |
| 2608 | |
| 2609 | // Constants of the type int. Those can be from Dex instructions, or |
| 2610 | // synthesized (for example with the if-eqz instruction). |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2611 | class HIntConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2612 | public: |
| 2613 | int32_t GetValue() const { return value_; } |
| 2614 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2615 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2616 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2617 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2618 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2619 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2620 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2621 | return other->AsIntConstant()->value_ == value_; |
| 2622 | } |
| 2623 | |
| 2624 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2625 | |
| 2626 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2627 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2628 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2629 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2630 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2631 | // Integer constants are used to encode Boolean values as well, |
| 2632 | // where 1 means true and 0 means false. |
| 2633 | bool IsTrue() const { return GetValue() == 1; } |
| 2634 | bool IsFalse() const { return GetValue() == 0; } |
| 2635 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2636 | DECLARE_INSTRUCTION(IntConstant); |
| 2637 | |
| 2638 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2639 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2640 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2641 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2642 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2643 | |
| 2644 | const int32_t value_; |
| 2645 | |
| 2646 | friend class HGraph; |
| 2647 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2648 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2649 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2650 | }; |
| 2651 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2652 | class HLongConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2653 | public: |
| 2654 | int64_t GetValue() const { return value_; } |
| 2655 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2656 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2657 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2658 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2659 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2660 | return other->AsLongConstant()->value_ == value_; |
| 2661 | } |
| 2662 | |
| 2663 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2664 | |
| 2665 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2666 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2667 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2668 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2669 | |
| 2670 | DECLARE_INSTRUCTION(LongConstant); |
| 2671 | |
| 2672 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2673 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2674 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2675 | |
| 2676 | const int64_t value_; |
| 2677 | |
| 2678 | friend class HGraph; |
| 2679 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2680 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2681 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2682 | class HFloatConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2683 | public: |
| 2684 | float GetValue() const { return value_; } |
| 2685 | |
| 2686 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2687 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2688 | } |
| 2689 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2690 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2691 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 2692 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2693 | } |
| 2694 | |
| 2695 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2696 | |
| 2697 | bool IsMinusOne() const OVERRIDE { |
| 2698 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 2699 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2700 | bool IsArithmeticZero() const OVERRIDE { |
| 2701 | return std::fpclassify(value_) == FP_ZERO; |
| 2702 | } |
| 2703 | bool IsArithmeticPositiveZero() const { |
| 2704 | return IsArithmeticZero() && !std::signbit(value_); |
| 2705 | } |
| 2706 | bool IsArithmeticNegativeZero() const { |
| 2707 | return IsArithmeticZero() && std::signbit(value_); |
| 2708 | } |
| 2709 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2710 | 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] | 2711 | } |
| 2712 | bool IsOne() const OVERRIDE { |
| 2713 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 2714 | } |
| 2715 | bool IsNaN() const { |
| 2716 | return std::isnan(value_); |
| 2717 | } |
| 2718 | |
| 2719 | DECLARE_INSTRUCTION(FloatConstant); |
| 2720 | |
| 2721 | private: |
| 2722 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 2723 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 2724 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2725 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
| 2726 | |
| 2727 | const float value_; |
| 2728 | |
| 2729 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2730 | friend class SsaBuilder; |
| 2731 | friend class HGraph; |
| 2732 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 2733 | }; |
| 2734 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2735 | class HDoubleConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2736 | public: |
| 2737 | double GetValue() const { return value_; } |
| 2738 | |
| 2739 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 2740 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2741 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2742 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 2743 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2744 | } |
| 2745 | |
| 2746 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2747 | |
| 2748 | bool IsMinusOne() const OVERRIDE { |
| 2749 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 2750 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2751 | bool IsArithmeticZero() const OVERRIDE { |
| 2752 | return std::fpclassify(value_) == FP_ZERO; |
| 2753 | } |
| 2754 | bool IsArithmeticPositiveZero() const { |
| 2755 | return IsArithmeticZero() && !std::signbit(value_); |
| 2756 | } |
| 2757 | bool IsArithmeticNegativeZero() const { |
| 2758 | return IsArithmeticZero() && std::signbit(value_); |
| 2759 | } |
| 2760 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2761 | 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] | 2762 | } |
| 2763 | bool IsOne() const OVERRIDE { |
| 2764 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 2765 | } |
| 2766 | bool IsNaN() const { |
| 2767 | return std::isnan(value_); |
| 2768 | } |
| 2769 | |
| 2770 | DECLARE_INSTRUCTION(DoubleConstant); |
| 2771 | |
| 2772 | private: |
| 2773 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 2774 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 2775 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2776 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
| 2777 | |
| 2778 | const double value_; |
| 2779 | |
| 2780 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2781 | friend class SsaBuilder; |
| 2782 | friend class HGraph; |
| 2783 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 2784 | }; |
| 2785 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2786 | // Conditional branch. A block ending with an HIf instruction must have |
| 2787 | // two successors. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2788 | class HIf FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2789 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2790 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2791 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2792 | SetRawInputAt(0, input); |
| 2793 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2794 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2795 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2796 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2797 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2798 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2799 | } |
| 2800 | |
| 2801 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2802 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2803 | } |
| 2804 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2805 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2806 | |
| 2807 | private: |
| 2808 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2809 | }; |
| 2810 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2811 | |
| 2812 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2813 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2814 | // non-exceptional control flow. |
| 2815 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2816 | // higher indices in no particular order. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2817 | class HTryBoundary FINAL : public HTemplateInstruction<0> { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2818 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2819 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2820 | kEntry, |
| 2821 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2822 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2823 | }; |
| 2824 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2825 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2826 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
| 2827 | SetPackedField<BoundaryKindField>(kind); |
| 2828 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2829 | |
| 2830 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2831 | |
| 2832 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2833 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2834 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 2835 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 2836 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 2837 | } |
| 2838 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2839 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2840 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2841 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2842 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2843 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2844 | } |
| 2845 | |
| 2846 | // If not present already, adds `handler` to its block's list of exception |
| 2847 | // handlers. |
| 2848 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2849 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2850 | GetBlock()->AddSuccessor(handler); |
| 2851 | } |
| 2852 | } |
| 2853 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2854 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 2855 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2856 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2857 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2858 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2859 | DECLARE_INSTRUCTION(TryBoundary); |
| 2860 | |
| 2861 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2862 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 2863 | static constexpr size_t kFieldBoundaryKindSize = |
| 2864 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 2865 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 2866 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 2867 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 2868 | "Too many packed fields."); |
| 2869 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2870 | |
| 2871 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2872 | }; |
| 2873 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2874 | // Deoptimize to interpreter, upon checking a condition. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2875 | class HDeoptimize FINAL : public HTemplateInstruction<1> { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2876 | public: |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2877 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 2878 | // at the point of the `HDeoptimize`. |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2879 | HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2880 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2881 | SetRawInputAt(0, cond); |
| 2882 | } |
| 2883 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2884 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2885 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2886 | return true; |
| 2887 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2888 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2889 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2890 | |
| 2891 | DECLARE_INSTRUCTION(Deoptimize); |
| 2892 | |
| 2893 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2894 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2895 | }; |
| 2896 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame^] | 2897 | // Represents a should_deoptimize flag. Currently used for CHA-based devirtualization. |
| 2898 | // The compiled code checks this flag value in a guard before devirtualized call and |
| 2899 | // if it's true, starts to do deoptimization. |
| 2900 | // It has a 4-byte slot on stack. |
| 2901 | // TODO: allocate a register for this flag. |
| 2902 | class HShouldDeoptimizeFlag FINAL : public HExpression<0> { |
| 2903 | public: |
| 2904 | // TODO: use SideEffects to aid eliminating some CHA guards. |
| 2905 | explicit HShouldDeoptimizeFlag(uint32_t dex_pc) |
| 2906 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
| 2907 | } |
| 2908 | |
| 2909 | // We don't eliminate CHA guards yet. |
| 2910 | bool CanBeMoved() const OVERRIDE { return false; } |
| 2911 | |
| 2912 | DECLARE_INSTRUCTION(ShouldDeoptimizeFlag); |
| 2913 | |
| 2914 | private: |
| 2915 | DISALLOW_COPY_AND_ASSIGN(HShouldDeoptimizeFlag); |
| 2916 | }; |
| 2917 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2918 | // Represents the ArtMethod that was passed as a first argument to |
| 2919 | // the method. It is used by instructions that depend on it, like |
| 2920 | // instructions that work with the dex cache. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2921 | class HCurrentMethod FINAL : public HExpression<0> { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2922 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2923 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2924 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2925 | |
| 2926 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2927 | |
| 2928 | private: |
| 2929 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2930 | }; |
| 2931 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2932 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 2933 | // of a class. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2934 | class HClassTableGet FINAL : public HExpression<1> { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2935 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2936 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2937 | kVTable, |
| 2938 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2939 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2940 | }; |
| 2941 | HClassTableGet(HInstruction* cls, |
| 2942 | Primitive::Type type, |
| 2943 | TableKind kind, |
| 2944 | size_t index, |
| 2945 | uint32_t dex_pc) |
| 2946 | : HExpression(type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2947 | index_(index) { |
| 2948 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2949 | SetRawInputAt(0, cls); |
| 2950 | } |
| 2951 | |
| 2952 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2953 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2954 | return other->AsClassTableGet()->GetIndex() == index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2955 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2956 | } |
| 2957 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2958 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2959 | size_t GetIndex() const { return index_; } |
| 2960 | |
| 2961 | DECLARE_INSTRUCTION(ClassTableGet); |
| 2962 | |
| 2963 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2964 | static constexpr size_t kFieldTableKind = kNumberOfExpressionPackedBits; |
| 2965 | static constexpr size_t kFieldTableKindSize = |
| 2966 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 2967 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 2968 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 2969 | "Too many packed fields."); |
| 2970 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 2971 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2972 | // The index of the ArtMethod in the table. |
| 2973 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2974 | |
| 2975 | DISALLOW_COPY_AND_ASSIGN(HClassTableGet); |
| 2976 | }; |
| 2977 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2978 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 2979 | // have one successor for each entry in the switch table, and the final successor |
| 2980 | // will be the block containing the next Dex opcode. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2981 | class HPackedSwitch FINAL : public HTemplateInstruction<1> { |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2982 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2983 | HPackedSwitch(int32_t start_value, |
| 2984 | uint32_t num_entries, |
| 2985 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2986 | uint32_t dex_pc = kNoDexPc) |
| 2987 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 2988 | start_value_(start_value), |
| 2989 | num_entries_(num_entries) { |
| 2990 | SetRawInputAt(0, input); |
| 2991 | } |
| 2992 | |
| 2993 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2994 | |
| 2995 | int32_t GetStartValue() const { return start_value_; } |
| 2996 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 2997 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2998 | |
| 2999 | HBasicBlock* GetDefaultBlock() const { |
| 3000 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3001 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3002 | } |
| 3003 | DECLARE_INSTRUCTION(PackedSwitch); |
| 3004 | |
| 3005 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3006 | const int32_t start_value_; |
| 3007 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3008 | |
| 3009 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 3010 | }; |
| 3011 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3012 | class HUnaryOperation : public HExpression<1> { |
| 3013 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3014 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3015 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3016 | SetRawInputAt(0, input); |
| 3017 | } |
| 3018 | |
| 3019 | HInstruction* GetInput() const { return InputAt(0); } |
| 3020 | Primitive::Type GetResultType() const { return GetType(); } |
| 3021 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3022 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3023 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3024 | return true; |
| 3025 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3026 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3027 | // Try to statically evaluate `this` and return a HConstant |
| 3028 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3029 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3030 | HConstant* TryStaticEvaluation() const; |
| 3031 | |
| 3032 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3033 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 3034 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3035 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 3036 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3037 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3038 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3039 | |
| 3040 | private: |
| 3041 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 3042 | }; |
| 3043 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3044 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3045 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3046 | HBinaryOperation(Primitive::Type result_type, |
| 3047 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3048 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3049 | SideEffects side_effects = SideEffects::None(), |
| 3050 | uint32_t dex_pc = kNoDexPc) |
| 3051 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3052 | SetRawInputAt(0, left); |
| 3053 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3054 | } |
| 3055 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3056 | HInstruction* GetLeft() const { return InputAt(0); } |
| 3057 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3058 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3059 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3060 | virtual bool IsCommutative() const { return false; } |
| 3061 | |
| 3062 | // Put constant on the right. |
| 3063 | // Returns whether order is changed. |
| 3064 | bool OrderInputsWithConstantOnTheRight() { |
| 3065 | HInstruction* left = InputAt(0); |
| 3066 | HInstruction* right = InputAt(1); |
| 3067 | if (left->IsConstant() && !right->IsConstant()) { |
| 3068 | ReplaceInput(right, 0); |
| 3069 | ReplaceInput(left, 1); |
| 3070 | return true; |
| 3071 | } |
| 3072 | return false; |
| 3073 | } |
| 3074 | |
| 3075 | // Order inputs by instruction id, but favor constant on the right side. |
| 3076 | // This helps GVN for commutative ops. |
| 3077 | void OrderInputs() { |
| 3078 | DCHECK(IsCommutative()); |
| 3079 | HInstruction* left = InputAt(0); |
| 3080 | HInstruction* right = InputAt(1); |
| 3081 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 3082 | return; |
| 3083 | } |
| 3084 | if (OrderInputsWithConstantOnTheRight()) { |
| 3085 | return; |
| 3086 | } |
| 3087 | // Order according to instruction id. |
| 3088 | if (left->GetId() > right->GetId()) { |
| 3089 | ReplaceInput(right, 0); |
| 3090 | ReplaceInput(left, 1); |
| 3091 | } |
| 3092 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3093 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3094 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3095 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3096 | return true; |
| 3097 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3098 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3099 | // Try to statically evaluate `this` and return a HConstant |
| 3100 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3101 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3102 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3103 | |
| 3104 | // Apply this operation to `x` and `y`. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3105 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3106 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3107 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 3108 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3109 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3110 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 3111 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3112 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 3113 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3114 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 3115 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3116 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3117 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 3118 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3119 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3120 | // 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] | 3121 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3122 | HConstant* GetConstantRight() const; |
| 3123 | |
| 3124 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3125 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3126 | HInstruction* GetLeastConstantLeft() const; |
| 3127 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3128 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 3129 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3130 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3131 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 3132 | }; |
| 3133 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3134 | // The comparison bias applies for floating point operations and indicates how NaN |
| 3135 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3136 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3137 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 3138 | kGtBias, // return 1 for NaN comparisons |
| 3139 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3140 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3141 | }; |
| 3142 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3143 | std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs); |
| 3144 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3145 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3146 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3147 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3148 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc) { |
| 3149 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 3150 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3151 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3152 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3153 | // `instruction`, and disregard moves in between. |
| 3154 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3155 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3156 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3157 | |
| 3158 | virtual IfCondition GetCondition() const = 0; |
| 3159 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3160 | virtual IfCondition GetOppositeCondition() const = 0; |
| 3161 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3162 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3163 | bool IsLtBias() const { return GetBias() == ComparisonBias::kLtBias; } |
| 3164 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3165 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 3166 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3167 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3168 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3169 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3170 | } |
| 3171 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3172 | bool IsFPConditionTrueIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3173 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3174 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3175 | if (if_cond == kCondNE) { |
| 3176 | return true; |
| 3177 | } else if (if_cond == kCondEQ) { |
| 3178 | return false; |
| 3179 | } |
| 3180 | return ((if_cond == kCondGT) || (if_cond == kCondGE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3181 | } |
| 3182 | |
| 3183 | bool IsFPConditionFalseIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3184 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3185 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3186 | if (if_cond == kCondEQ) { |
| 3187 | return true; |
| 3188 | } else if (if_cond == kCondNE) { |
| 3189 | return false; |
| 3190 | } |
| 3191 | return ((if_cond == kCondLT) || (if_cond == kCondLE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3192 | } |
| 3193 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3194 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3195 | // Needed if we merge a HCompare into a HCondition. |
| 3196 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3197 | static constexpr size_t kFieldComparisonBiasSize = |
| 3198 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3199 | static constexpr size_t kNumberOfConditionPackedBits = |
| 3200 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3201 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3202 | using ComparisonBiasField = |
| 3203 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3204 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3205 | template <typename T> |
| 3206 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3207 | |
| 3208 | template <typename T> |
| 3209 | int32_t CompareFP(T x, T y) const { |
| 3210 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3211 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3212 | // Handle the bias. |
| 3213 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 3214 | } |
| 3215 | |
| 3216 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3217 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3218 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3219 | } |
| 3220 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3221 | private: |
| 3222 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 3223 | }; |
| 3224 | |
| 3225 | // Instruction to check if two inputs are equal to each other. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3226 | class HEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3227 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3228 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3229 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3230 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3231 | bool IsCommutative() const OVERRIDE { return true; } |
| 3232 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3233 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3234 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3235 | return MakeConstantCondition(true, GetDexPc()); |
| 3236 | } |
| 3237 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3238 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3239 | } |
| 3240 | // In the following Evaluate methods, a HCompare instruction has |
| 3241 | // been merged into this HEqual instruction; evaluate it as |
| 3242 | // `Compare(x, y) == 0`. |
| 3243 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3244 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3245 | GetDexPc()); |
| 3246 | } |
| 3247 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3248 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3249 | } |
| 3250 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3251 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3252 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3253 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3254 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3255 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3256 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3257 | return kCondEQ; |
| 3258 | } |
| 3259 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3260 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3261 | return kCondNE; |
| 3262 | } |
| 3263 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3264 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3265 | template <typename T> static bool Compute(T x, T y) { return x == y; } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3266 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3267 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 3268 | }; |
| 3269 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3270 | class HNotEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3271 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3272 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3273 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3274 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3275 | bool IsCommutative() const OVERRIDE { return true; } |
| 3276 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3277 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3278 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3279 | return MakeConstantCondition(false, GetDexPc()); |
| 3280 | } |
| 3281 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3282 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3283 | } |
| 3284 | // In the following Evaluate methods, a HCompare instruction has |
| 3285 | // been merged into this HNotEqual instruction; evaluate it as |
| 3286 | // `Compare(x, y) != 0`. |
| 3287 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3288 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3289 | } |
| 3290 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3291 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3292 | } |
| 3293 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3294 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3295 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3296 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3297 | DECLARE_INSTRUCTION(NotEqual); |
| 3298 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3299 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3300 | return kCondNE; |
| 3301 | } |
| 3302 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3303 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3304 | return kCondEQ; |
| 3305 | } |
| 3306 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3307 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3308 | template <typename T> static bool Compute(T x, T y) { return x != y; } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3309 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3310 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 3311 | }; |
| 3312 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3313 | class HLessThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3314 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3315 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3316 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3317 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3318 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3319 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3320 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3321 | // In the following Evaluate methods, a HCompare instruction has |
| 3322 | // been merged into this HLessThan instruction; evaluate it as |
| 3323 | // `Compare(x, y) < 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3324 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3325 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3326 | } |
| 3327 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3328 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3329 | } |
| 3330 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3331 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3332 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3333 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3334 | DECLARE_INSTRUCTION(LessThan); |
| 3335 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3336 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3337 | return kCondLT; |
| 3338 | } |
| 3339 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3340 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3341 | return kCondGE; |
| 3342 | } |
| 3343 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3344 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3345 | template <typename T> static bool Compute(T x, T y) { return x < y; } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3346 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3347 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 3348 | }; |
| 3349 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3350 | class HLessThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3351 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3352 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3353 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3354 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3355 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3356 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3357 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3358 | // In the following Evaluate methods, a HCompare instruction has |
| 3359 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 3360 | // `Compare(x, y) <= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3361 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3362 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3363 | } |
| 3364 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3365 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3366 | } |
| 3367 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3368 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3369 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3370 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3371 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 3372 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3373 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3374 | return kCondLE; |
| 3375 | } |
| 3376 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3377 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3378 | return kCondGT; |
| 3379 | } |
| 3380 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3381 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3382 | template <typename T> static bool Compute(T x, T y) { return x <= y; } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3383 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3384 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 3385 | }; |
| 3386 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3387 | class HGreaterThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3388 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3389 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3390 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3391 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3392 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3393 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3394 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3395 | // In the following Evaluate methods, a HCompare instruction has |
| 3396 | // been merged into this HGreaterThan instruction; evaluate it as |
| 3397 | // `Compare(x, y) > 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3398 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3399 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3400 | } |
| 3401 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3402 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3403 | } |
| 3404 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3405 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3406 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3407 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3408 | DECLARE_INSTRUCTION(GreaterThan); |
| 3409 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3410 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3411 | return kCondGT; |
| 3412 | } |
| 3413 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3414 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3415 | return kCondLE; |
| 3416 | } |
| 3417 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3418 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3419 | template <typename T> static bool Compute(T x, T y) { return x > y; } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3420 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3421 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 3422 | }; |
| 3423 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3424 | class HGreaterThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3425 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3426 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3427 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3428 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3429 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3430 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3431 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3432 | // In the following Evaluate methods, a HCompare instruction has |
| 3433 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 3434 | // `Compare(x, y) >= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3435 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3436 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3437 | } |
| 3438 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3439 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3440 | } |
| 3441 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3442 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3443 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3444 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3445 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 3446 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3447 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3448 | return kCondGE; |
| 3449 | } |
| 3450 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3451 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3452 | return kCondLT; |
| 3453 | } |
| 3454 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3455 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3456 | template <typename T> static bool Compute(T x, T y) { return x >= y; } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3457 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3458 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 3459 | }; |
| 3460 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3461 | class HBelow FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3462 | public: |
| 3463 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3464 | : HCondition(first, second, dex_pc) {} |
| 3465 | |
| 3466 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3467 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3468 | } |
| 3469 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3470 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3471 | } |
| 3472 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3473 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3474 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3475 | UNREACHABLE(); |
| 3476 | } |
| 3477 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3478 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3479 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3480 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3481 | } |
| 3482 | |
| 3483 | DECLARE_INSTRUCTION(Below); |
| 3484 | |
| 3485 | IfCondition GetCondition() const OVERRIDE { |
| 3486 | return kCondB; |
| 3487 | } |
| 3488 | |
| 3489 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3490 | return kCondAE; |
| 3491 | } |
| 3492 | |
| 3493 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3494 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3495 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 3496 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3497 | |
| 3498 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 3499 | }; |
| 3500 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3501 | class HBelowOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3502 | public: |
| 3503 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3504 | : HCondition(first, second, dex_pc) {} |
| 3505 | |
| 3506 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3507 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3508 | } |
| 3509 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3510 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3511 | } |
| 3512 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3513 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3514 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3515 | UNREACHABLE(); |
| 3516 | } |
| 3517 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3518 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3519 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3520 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3521 | } |
| 3522 | |
| 3523 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 3524 | |
| 3525 | IfCondition GetCondition() const OVERRIDE { |
| 3526 | return kCondBE; |
| 3527 | } |
| 3528 | |
| 3529 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3530 | return kCondA; |
| 3531 | } |
| 3532 | |
| 3533 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3534 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3535 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 3536 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3537 | |
| 3538 | DISALLOW_COPY_AND_ASSIGN(HBelowOrEqual); |
| 3539 | }; |
| 3540 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3541 | class HAbove FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3542 | public: |
| 3543 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3544 | : HCondition(first, second, dex_pc) {} |
| 3545 | |
| 3546 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3547 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3548 | } |
| 3549 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3550 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3551 | } |
| 3552 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3553 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3554 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3555 | UNREACHABLE(); |
| 3556 | } |
| 3557 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3558 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3559 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3560 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3561 | } |
| 3562 | |
| 3563 | DECLARE_INSTRUCTION(Above); |
| 3564 | |
| 3565 | IfCondition GetCondition() const OVERRIDE { |
| 3566 | return kCondA; |
| 3567 | } |
| 3568 | |
| 3569 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3570 | return kCondBE; |
| 3571 | } |
| 3572 | |
| 3573 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3574 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3575 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 3576 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3577 | |
| 3578 | DISALLOW_COPY_AND_ASSIGN(HAbove); |
| 3579 | }; |
| 3580 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3581 | class HAboveOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3582 | public: |
| 3583 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3584 | : HCondition(first, second, dex_pc) {} |
| 3585 | |
| 3586 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3587 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3588 | } |
| 3589 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3590 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3591 | } |
| 3592 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3593 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3594 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3595 | UNREACHABLE(); |
| 3596 | } |
| 3597 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3598 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3599 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3600 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3601 | } |
| 3602 | |
| 3603 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 3604 | |
| 3605 | IfCondition GetCondition() const OVERRIDE { |
| 3606 | return kCondAE; |
| 3607 | } |
| 3608 | |
| 3609 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3610 | return kCondB; |
| 3611 | } |
| 3612 | |
| 3613 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3614 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3615 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 3616 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3617 | |
| 3618 | DISALLOW_COPY_AND_ASSIGN(HAboveOrEqual); |
| 3619 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3620 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3621 | // Instruction to check how two inputs compare to each other. |
| 3622 | // 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] | 3623 | class HCompare FINAL : public HBinaryOperation { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3624 | public: |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3625 | // Note that `comparison_type` is the type of comparison performed |
| 3626 | // between the comparison's inputs, not the type of the instantiated |
| 3627 | // HCompare instruction (which is always Primitive::kPrimInt). |
| 3628 | HCompare(Primitive::Type comparison_type, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3629 | HInstruction* first, |
| 3630 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3631 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3632 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3633 | : HBinaryOperation(Primitive::kPrimInt, |
| 3634 | first, |
| 3635 | second, |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3636 | SideEffectsForArchRuntimeCalls(comparison_type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3637 | dex_pc) { |
| 3638 | SetPackedField<ComparisonBiasField>(bias); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3639 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(first->GetType())); |
| 3640 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(second->GetType())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3641 | } |
| 3642 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3643 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3644 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3645 | |
| 3646 | template <typename T> |
| 3647 | int32_t ComputeFP(T x, T y) const { |
| 3648 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3649 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3650 | // Handle the bias. |
| 3651 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 3652 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3653 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3654 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3655 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 3656 | // reach this code path when processing a freshly built HIR |
| 3657 | // graph. However HCompare integer instructions can be synthesized |
| 3658 | // by the instruction simplifier to implement IntegerCompare and |
| 3659 | // IntegerSignum intrinsics, so we have to handle this case. |
| 3660 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3661 | } |
| 3662 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3663 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3664 | } |
| 3665 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3666 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3667 | } |
| 3668 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3669 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3670 | } |
| 3671 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3672 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3673 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3674 | } |
| 3675 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3676 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3677 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3678 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3679 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3680 | bool IsGtBias() const { |
| 3681 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3682 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3683 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3684 | |
Roland Levillain | 1693a1f | 2016-03-15 14:57:31 +0000 | [diff] [blame] | 3685 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type ATTRIBUTE_UNUSED) { |
| 3686 | // Comparisons do not require a runtime call in any back end. |
| 3687 | return SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3688 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3689 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3690 | DECLARE_INSTRUCTION(Compare); |
| 3691 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3692 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3693 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3694 | static constexpr size_t kFieldComparisonBiasSize = |
| 3695 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3696 | static constexpr size_t kNumberOfComparePackedBits = |
| 3697 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3698 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3699 | using ComparisonBiasField = |
| 3700 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3701 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3702 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 3703 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 3704 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 3705 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3706 | } |
| 3707 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3708 | private: |
| 3709 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3710 | }; |
| 3711 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3712 | class HNewInstance FINAL : public HExpression<2> { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3713 | public: |
| 3714 | HNewInstance(HInstruction* cls, |
| 3715 | HCurrentMethod* current_method, |
| 3716 | uint32_t dex_pc, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3717 | dex::TypeIndex type_index, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3718 | const DexFile& dex_file, |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3719 | bool needs_access_check, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3720 | bool finalizable, |
| 3721 | QuickEntrypointEnum entrypoint) |
| 3722 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
| 3723 | type_index_(type_index), |
| 3724 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3725 | entrypoint_(entrypoint) { |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3726 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3727 | SetPackedFlag<kFlagFinalizable>(finalizable); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3728 | SetRawInputAt(0, cls); |
| 3729 | SetRawInputAt(1, current_method); |
| 3730 | } |
| 3731 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3732 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3733 | const DexFile& GetDexFile() const { return dex_file_; } |
| 3734 | |
| 3735 | // Calls runtime so needs an environment. |
| 3736 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3737 | |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3738 | // Can throw errors when out-of-memory or if it's not instantiable/accessible. |
| 3739 | bool CanThrow() const OVERRIDE { return true; } |
| 3740 | |
| 3741 | // Needs to call into runtime to make sure it's instantiable/accessible. |
| 3742 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3743 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3744 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3745 | |
| 3746 | bool CanBeNull() const OVERRIDE { return false; } |
| 3747 | |
| 3748 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3749 | |
| 3750 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 3751 | entrypoint_ = entrypoint; |
| 3752 | } |
| 3753 | |
| 3754 | bool IsStringAlloc() const; |
| 3755 | |
| 3756 | DECLARE_INSTRUCTION(NewInstance); |
| 3757 | |
| 3758 | private: |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3759 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfExpressionPackedBits; |
| 3760 | static constexpr size_t kFlagFinalizable = kFlagNeedsAccessCheck + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3761 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagFinalizable + 1; |
| 3762 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 3763 | "Too many packed fields."); |
| 3764 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3765 | const dex::TypeIndex type_index_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3766 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3767 | QuickEntrypointEnum entrypoint_; |
| 3768 | |
| 3769 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3770 | }; |
| 3771 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3772 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3773 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3774 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3775 | }; |
| 3776 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3777 | enum IntrinsicSideEffects { |
| 3778 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 3779 | kReadSideEffects, // Intrinsic may read heap memory. |
| 3780 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 3781 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 3782 | }; |
| 3783 | |
| 3784 | enum IntrinsicExceptions { |
| 3785 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 3786 | kCanThrow // Intrinsic may throw exceptions. |
| 3787 | }; |
| 3788 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3789 | class HInvoke : public HInstruction { |
| 3790 | public: |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3791 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3792 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3793 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 3794 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 3795 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 3796 | } |
| 3797 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3798 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3799 | SetRawInputAt(index, argument); |
| 3800 | } |
| 3801 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3802 | // Return the number of arguments. This number can be lower than |
| 3803 | // the number of inputs returned by InputCount(), as some invoke |
| 3804 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3805 | // inputs at the end of their list of inputs. |
| 3806 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3807 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3808 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<ReturnTypeField>(); } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3809 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3810 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3811 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3812 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3813 | InvokeType GetInvokeType() const { |
| 3814 | return GetPackedField<InvokeTypeField>(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3815 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3816 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3817 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3818 | return intrinsic_; |
| 3819 | } |
| 3820 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3821 | void SetIntrinsic(Intrinsics intrinsic, |
| 3822 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 3823 | IntrinsicSideEffects side_effects, |
| 3824 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3825 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3826 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 3827 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3828 | } |
| 3829 | |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 3830 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
| 3831 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3832 | bool CanThrow() const OVERRIDE { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3833 | |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 3834 | bool CanBeMoved() const OVERRIDE { return IsIntrinsic() && !DoesAnyWrite(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3835 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3836 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3837 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 3838 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3839 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3840 | uint32_t* GetIntrinsicOptimizations() { |
| 3841 | return &intrinsic_optimizations_; |
| 3842 | } |
| 3843 | |
| 3844 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3845 | return &intrinsic_optimizations_; |
| 3846 | } |
| 3847 | |
| 3848 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3849 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3850 | ArtMethod* GetResolvedMethod() const { return resolved_method_; } |
| 3851 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3852 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3853 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3854 | protected: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3855 | static constexpr size_t kFieldInvokeType = kNumberOfGenericPackedBits; |
| 3856 | static constexpr size_t kFieldInvokeTypeSize = |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3857 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 3858 | static constexpr size_t kFieldReturnType = |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3859 | kFieldInvokeType + kFieldInvokeTypeSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3860 | static constexpr size_t kFieldReturnTypeSize = |
| 3861 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 3862 | static constexpr size_t kFlagCanThrow = kFieldReturnType + kFieldReturnTypeSize; |
| 3863 | static constexpr size_t kNumberOfInvokePackedBits = kFlagCanThrow + 1; |
| 3864 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3865 | using InvokeTypeField = BitField<InvokeType, kFieldInvokeType, kFieldInvokeTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3866 | using ReturnTypeField = BitField<Primitive::Type, kFieldReturnType, kFieldReturnTypeSize>; |
| 3867 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3868 | HInvoke(ArenaAllocator* arena, |
| 3869 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3870 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3871 | Primitive::Type return_type, |
| 3872 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3873 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3874 | ArtMethod* resolved_method, |
| 3875 | InvokeType invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3876 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3877 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3878 | number_of_arguments_(number_of_arguments), |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3879 | resolved_method_(resolved_method), |
Vladimir Marko | b7d8e8c | 2015-09-17 15:47:05 +0100 | [diff] [blame] | 3880 | inputs_(number_of_arguments + number_of_other_inputs, |
| 3881 | arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3882 | dex_method_index_(dex_method_index), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3883 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3884 | intrinsic_optimizations_(0) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3885 | SetPackedField<ReturnTypeField>(return_type); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3886 | SetPackedField<InvokeTypeField>(invoke_type); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3887 | SetPackedFlag<kFlagCanThrow>(true); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3888 | } |
| 3889 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3890 | uint32_t number_of_arguments_; |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3891 | ArtMethod* const resolved_method_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3892 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3893 | const uint32_t dex_method_index_; |
| 3894 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3895 | |
| 3896 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3897 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3898 | |
| 3899 | private: |
| 3900 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3901 | }; |
| 3902 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3903 | class HInvokeUnresolved FINAL : public HInvoke { |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3904 | public: |
| 3905 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3906 | uint32_t number_of_arguments, |
| 3907 | Primitive::Type return_type, |
| 3908 | uint32_t dex_pc, |
| 3909 | uint32_t dex_method_index, |
| 3910 | InvokeType invoke_type) |
| 3911 | : HInvoke(arena, |
| 3912 | number_of_arguments, |
| 3913 | 0u /* number_of_other_inputs */, |
| 3914 | return_type, |
| 3915 | dex_pc, |
| 3916 | dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3917 | nullptr, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3918 | invoke_type) { |
| 3919 | } |
| 3920 | |
| 3921 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3922 | |
| 3923 | private: |
| 3924 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3925 | }; |
| 3926 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3927 | class HInvokeStaticOrDirect FINAL : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3928 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3929 | // Requirements of this method call regarding the class |
| 3930 | // initialization (clinit) check of its declaring class. |
| 3931 | enum class ClinitCheckRequirement { |
| 3932 | kNone, // Class already initialized. |
| 3933 | kExplicit, // Static call having explicit clinit check as last input. |
| 3934 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3935 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3936 | }; |
| 3937 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3938 | // Determines how to load the target ArtMethod*. |
| 3939 | enum class MethodLoadKind { |
| 3940 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3941 | kStringInit, |
| 3942 | |
| 3943 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3944 | kRecursive, |
| 3945 | |
| 3946 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3947 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3948 | kDirectAddress, |
| 3949 | |
| 3950 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3951 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3952 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3953 | // the image relocatable or not. |
| 3954 | kDirectAddressWithFixup, |
| 3955 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3956 | // 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] | 3957 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3958 | // may cause class initialization (the entry may point to a resolution method), |
| 3959 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3960 | kDexCachePcRelative, |
| 3961 | |
| 3962 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3963 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3964 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3965 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3966 | kDexCacheViaMethod, |
| 3967 | }; |
| 3968 | |
| 3969 | // Determines the location of the code pointer. |
| 3970 | enum class CodePtrLocation { |
| 3971 | // Recursive call, use local PC-relative call instruction. |
| 3972 | kCallSelf, |
| 3973 | |
| 3974 | // Use PC-relative call instruction patched at link time. |
| 3975 | // Used for calls within an oat file, boot->boot or app->app. |
| 3976 | kCallPCRelative, |
| 3977 | |
| 3978 | // Call to a known target address, embed the direct address in code. |
| 3979 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3980 | kCallDirect, |
| 3981 | |
| 3982 | // Call to a target address that will be known at link time, embed the direct |
| 3983 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3984 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3985 | // the image relocatable or not. |
| 3986 | kCallDirectWithFixup, |
| 3987 | |
| 3988 | // Use code pointer from the ArtMethod*. |
| 3989 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3990 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3991 | kCallArtMethod, |
| 3992 | }; |
| 3993 | |
| 3994 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3995 | MethodLoadKind method_load_kind; |
| 3996 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3997 | // The method load data holds |
| 3998 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3999 | // Note that there are multiple string init methods, each having its own offset. |
| 4000 | // - the method address for kDirectAddress |
| 4001 | // - the dex cache arrays offset for kDexCachePcRel. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4002 | uint64_t method_load_data; |
| 4003 | uint64_t direct_code_ptr; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4004 | }; |
| 4005 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4006 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 4007 | uint32_t number_of_arguments, |
| 4008 | Primitive::Type return_type, |
| 4009 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4010 | uint32_t method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4011 | ArtMethod* resolved_method, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4012 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4013 | InvokeType invoke_type, |
| 4014 | MethodReference target_method, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4015 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4016 | : HInvoke(arena, |
| 4017 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4018 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 4019 | // potentially one other if the clinit check is explicit, and potentially |
| 4020 | // one other if the method is a string factory. |
| 4021 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 4022 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4023 | return_type, |
| 4024 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4025 | method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4026 | resolved_method, |
| 4027 | invoke_type), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4028 | target_method_(target_method), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4029 | dispatch_info_(dispatch_info) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4030 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 4031 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4032 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4033 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4034 | bool had_current_method_input = HasCurrentMethodInput(); |
| 4035 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 4036 | |
| 4037 | // Using the current method is the default and once we find a better |
| 4038 | // method load kind, we should not go back to using the current method. |
| 4039 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 4040 | |
| 4041 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4042 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 4043 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4044 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4045 | dispatch_info_ = dispatch_info; |
| 4046 | } |
| 4047 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4048 | void AddSpecialInput(HInstruction* input) { |
| 4049 | // We allow only one special input. |
| 4050 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 4051 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4052 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 4053 | InsertInputAt(GetSpecialInputIndex(), input); |
| 4054 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4055 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4056 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 4057 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 4058 | ArrayRef<HUserRecord<HInstruction*>> input_records = HInvoke::GetInputRecords(); |
| 4059 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck()) { |
| 4060 | DCHECK(!input_records.empty()); |
| 4061 | DCHECK_GT(input_records.size(), GetNumberOfArguments()); |
| 4062 | HInstruction* last_input = input_records.back().GetInstruction(); |
| 4063 | // Note: `last_input` may be null during arguments setup. |
| 4064 | if (last_input != nullptr) { |
| 4065 | // `last_input` is the last input of a static invoke marked as having |
| 4066 | // an explicit clinit check. It must either be: |
| 4067 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 4068 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 4069 | DCHECK(last_input->IsClinitCheck() || last_input->IsLoadClass()) << last_input->DebugName(); |
| 4070 | } |
| 4071 | } |
| 4072 | return input_records; |
| 4073 | } |
| 4074 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4075 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4076 | // We access the method via the dex cache so we can't do an implicit null check. |
| 4077 | // TODO: for intrinsics we can generate implicit null checks. |
| 4078 | return false; |
| 4079 | } |
| 4080 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4081 | bool CanBeNull() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4082 | return GetPackedField<ReturnTypeField>() == Primitive::kPrimNot && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4083 | } |
| 4084 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4085 | // Get the index of the special input, if any. |
| 4086 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4087 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 4088 | // method pointer; otherwise there may be one platform-specific special input, |
| 4089 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4090 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
Nicolas Geoffray | 9779307 | 2016-02-16 15:33:54 +0000 | [diff] [blame] | 4091 | bool HasSpecialInput() const { return GetNumberOfArguments() != InputCount(); } |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4092 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4093 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 4094 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 4095 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4096 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4097 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4098 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4099 | bool HasPcRelativeDexCache() const { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4100 | return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; |
| 4101 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4102 | bool HasCurrentMethodInput() const { |
| 4103 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 4104 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4105 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4106 | return true; |
| 4107 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4108 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4109 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4110 | return false; |
| 4111 | } |
| 4112 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4113 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4114 | |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4115 | QuickEntrypointEnum GetStringInitEntryPoint() const { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4116 | DCHECK(IsStringInit()); |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4117 | return static_cast<QuickEntrypointEnum>(dispatch_info_.method_load_data); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4118 | } |
| 4119 | |
| 4120 | uint64_t GetMethodAddress() const { |
| 4121 | DCHECK(HasMethodAddress()); |
| 4122 | return dispatch_info_.method_load_data; |
| 4123 | } |
| 4124 | |
| 4125 | uint32_t GetDexCacheArrayOffset() const { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4126 | DCHECK(HasPcRelativeDexCache()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4127 | return dispatch_info_.method_load_data; |
| 4128 | } |
| 4129 | |
| 4130 | uint64_t GetDirectCodePtr() const { |
| 4131 | DCHECK(HasDirectCodePtr()); |
| 4132 | return dispatch_info_.direct_code_ptr; |
| 4133 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4134 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4135 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 4136 | return GetPackedField<ClinitCheckRequirementField>(); |
| 4137 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 4138 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4139 | // Is this instruction a call to a static method? |
| 4140 | bool IsStatic() const { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4141 | return GetInvokeType() == kStatic; |
| 4142 | } |
| 4143 | |
| 4144 | MethodReference GetTargetMethod() const { |
| 4145 | return target_method_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4146 | } |
| 4147 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4148 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 4149 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 4150 | // instruction; only relevant for static calls with explicit clinit check. |
| 4151 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4152 | DCHECK(IsStaticWithExplicitClinitCheck()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4153 | size_t last_input_index = inputs_.size() - 1u; |
| 4154 | HInstruction* last_input = inputs_.back().GetInstruction(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4155 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4156 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4157 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4158 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4159 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4160 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4161 | } |
| 4162 | |
| 4163 | // 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] | 4164 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4165 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4166 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4167 | } |
| 4168 | |
| 4169 | // Is this a call to a static method whose declaring class has an |
| 4170 | // implicit intialization check requirement? |
| 4171 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4172 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4173 | } |
| 4174 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4175 | // Does this method load kind need the current method as an input? |
| 4176 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
| 4177 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kDexCacheViaMethod; |
| 4178 | } |
| 4179 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4180 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4181 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4182 | protected: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4183 | void InsertInputAt(size_t index, HInstruction* input); |
| 4184 | void RemoveInputAt(size_t index); |
| 4185 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4186 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4187 | static constexpr size_t kFieldClinitCheckRequirement = kNumberOfInvokePackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4188 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 4189 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 4190 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 4191 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 4192 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 4193 | "Too many packed fields."); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4194 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 4195 | kFieldClinitCheckRequirement, |
| 4196 | kFieldClinitCheckRequirementSize>; |
| 4197 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4198 | // Cached values of the resolved method, to avoid needing the mutator lock. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4199 | MethodReference target_method_; |
| 4200 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4201 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4202 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4203 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 4204 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4205 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4206 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4207 | class HInvokeVirtual FINAL : public HInvoke { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4208 | public: |
| 4209 | HInvokeVirtual(ArenaAllocator* arena, |
| 4210 | uint32_t number_of_arguments, |
| 4211 | Primitive::Type return_type, |
| 4212 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4213 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4214 | ArtMethod* resolved_method, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4215 | uint32_t vtable_index) |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4216 | : HInvoke(arena, |
| 4217 | number_of_arguments, |
| 4218 | 0u, |
| 4219 | return_type, |
| 4220 | dex_pc, |
| 4221 | dex_method_index, |
| 4222 | resolved_method, |
| 4223 | kVirtual), |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4224 | vtable_index_(vtable_index) {} |
| 4225 | |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 4226 | bool CanBeNull() const OVERRIDE { |
| 4227 | switch (GetIntrinsic()) { |
| 4228 | case Intrinsics::kThreadCurrentThread: |
| 4229 | case Intrinsics::kStringBufferAppend: |
| 4230 | case Intrinsics::kStringBufferToString: |
| 4231 | case Intrinsics::kStringBuilderAppend: |
| 4232 | case Intrinsics::kStringBuilderToString: |
| 4233 | return false; |
| 4234 | default: |
| 4235 | return HInvoke::CanBeNull(); |
| 4236 | } |
| 4237 | } |
| 4238 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4239 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4240 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4241 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4242 | } |
| 4243 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4244 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 4245 | |
| 4246 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 4247 | |
| 4248 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4249 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4250 | const uint32_t vtable_index_; |
| 4251 | |
| 4252 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 4253 | }; |
| 4254 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4255 | class HInvokeInterface FINAL : public HInvoke { |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4256 | public: |
| 4257 | HInvokeInterface(ArenaAllocator* arena, |
| 4258 | uint32_t number_of_arguments, |
| 4259 | Primitive::Type return_type, |
| 4260 | uint32_t dex_pc, |
| 4261 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4262 | ArtMethod* resolved_method, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4263 | uint32_t imt_index) |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4264 | : HInvoke(arena, |
| 4265 | number_of_arguments, |
| 4266 | 0u, |
| 4267 | return_type, |
| 4268 | dex_pc, |
| 4269 | dex_method_index, |
| 4270 | resolved_method, |
| 4271 | kInterface), |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4272 | imt_index_(imt_index) {} |
| 4273 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4274 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4275 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4276 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4277 | } |
| 4278 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4279 | uint32_t GetImtIndex() const { return imt_index_; } |
| 4280 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 4281 | |
| 4282 | DECLARE_INSTRUCTION(InvokeInterface); |
| 4283 | |
| 4284 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4285 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4286 | const uint32_t imt_index_; |
| 4287 | |
| 4288 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 4289 | }; |
| 4290 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4291 | class HNeg FINAL : public HUnaryOperation { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4292 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4293 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 937e6cd | 2016-03-22 11:54:37 +0000 | [diff] [blame] | 4294 | : HUnaryOperation(result_type, input, dex_pc) { |
| 4295 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(input->GetType())); |
| 4296 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4297 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4298 | template <typename T> static T Compute(T x) { return -x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4299 | |
| 4300 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4301 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4302 | } |
| 4303 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4304 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4305 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4306 | HConstant* Evaluate(HFloatConstant* x) const OVERRIDE { |
| 4307 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 4308 | } |
| 4309 | HConstant* Evaluate(HDoubleConstant* x) const OVERRIDE { |
| 4310 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 4311 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 4312 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4313 | DECLARE_INSTRUCTION(Neg); |
| 4314 | |
| 4315 | private: |
| 4316 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 4317 | }; |
| 4318 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4319 | class HNewArray FINAL : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4320 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4321 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4322 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4323 | uint32_t dex_pc, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4324 | dex::TypeIndex type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4325 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4326 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4327 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4328 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4329 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4330 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4331 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4332 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4333 | } |
| 4334 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4335 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4336 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4337 | |
| 4338 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4339 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4340 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4341 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 4342 | bool CanThrow() const OVERRIDE { return true; } |
| 4343 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4344 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4345 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4346 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 4347 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4348 | DECLARE_INSTRUCTION(NewArray); |
| 4349 | |
| 4350 | private: |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4351 | const dex::TypeIndex type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4352 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4353 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4354 | |
| 4355 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 4356 | }; |
| 4357 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4358 | class HAdd FINAL : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4359 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4360 | HAdd(Primitive::Type result_type, |
| 4361 | HInstruction* left, |
| 4362 | HInstruction* right, |
| 4363 | uint32_t dex_pc = kNoDexPc) |
| 4364 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4365 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4366 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4367 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4368 | template <typename T> static T Compute(T x, T y) { return x + y; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4369 | |
| 4370 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4371 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4372 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4373 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4374 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4375 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4376 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4377 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4378 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4379 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4380 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4381 | } |
| 4382 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4383 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4384 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4385 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4386 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4387 | DECLARE_INSTRUCTION(Add); |
| 4388 | |
| 4389 | private: |
| 4390 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 4391 | }; |
| 4392 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4393 | class HSub FINAL : public HBinaryOperation { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4394 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4395 | HSub(Primitive::Type result_type, |
| 4396 | HInstruction* left, |
| 4397 | HInstruction* right, |
| 4398 | uint32_t dex_pc = kNoDexPc) |
| 4399 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4400 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4401 | template <typename T> static T Compute(T x, T y) { return x - y; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4402 | |
| 4403 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4404 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4405 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4406 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4407 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4408 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4409 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4410 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4411 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4412 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4413 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4414 | } |
| 4415 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4416 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4417 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4418 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4419 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4420 | DECLARE_INSTRUCTION(Sub); |
| 4421 | |
| 4422 | private: |
| 4423 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 4424 | }; |
| 4425 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4426 | class HMul FINAL : public HBinaryOperation { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4427 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4428 | HMul(Primitive::Type result_type, |
| 4429 | HInstruction* left, |
| 4430 | HInstruction* right, |
| 4431 | uint32_t dex_pc = kNoDexPc) |
| 4432 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4433 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4434 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4435 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4436 | template <typename T> static T Compute(T x, T y) { return x * y; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4437 | |
| 4438 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4439 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4440 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4441 | } |
| 4442 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4443 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4444 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4445 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4446 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4447 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4448 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4449 | } |
| 4450 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4451 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4452 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4453 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4454 | |
| 4455 | DECLARE_INSTRUCTION(Mul); |
| 4456 | |
| 4457 | private: |
| 4458 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 4459 | }; |
| 4460 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4461 | class HDiv FINAL : public HBinaryOperation { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4462 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4463 | HDiv(Primitive::Type result_type, |
| 4464 | HInstruction* left, |
| 4465 | HInstruction* right, |
| 4466 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 4467 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4468 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4469 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4470 | T ComputeIntegral(T x, T y) const { |
| 4471 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4472 | // Our graph structure ensures we never have 0 for `y` during |
| 4473 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4474 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4475 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4476 | return (y == -1) ? -x : x / y; |
| 4477 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4478 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4479 | template <typename T> |
| 4480 | T ComputeFP(T x, T y) const { |
| 4481 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4482 | return x / y; |
| 4483 | } |
| 4484 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4485 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4486 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4487 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4488 | } |
| 4489 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4490 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4491 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4492 | } |
| 4493 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4494 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4495 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4496 | } |
| 4497 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4498 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4499 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4500 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4501 | |
| 4502 | DECLARE_INSTRUCTION(Div); |
| 4503 | |
| 4504 | private: |
| 4505 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 4506 | }; |
| 4507 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4508 | class HRem FINAL : public HBinaryOperation { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4509 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4510 | HRem(Primitive::Type result_type, |
| 4511 | HInstruction* left, |
| 4512 | HInstruction* right, |
| 4513 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 4514 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4515 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4516 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4517 | T ComputeIntegral(T x, T y) const { |
| 4518 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4519 | // Our graph structure ensures we never have 0 for `y` during |
| 4520 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4521 | DCHECK_NE(y, 0); |
| 4522 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 4523 | return (y == -1) ? 0 : x % y; |
| 4524 | } |
| 4525 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4526 | template <typename T> |
| 4527 | T ComputeFP(T x, T y) const { |
| 4528 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4529 | return std::fmod(x, y); |
| 4530 | } |
| 4531 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4532 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4533 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4534 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4535 | } |
| 4536 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4537 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4538 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4539 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4540 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4541 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4542 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4543 | } |
| 4544 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4545 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4546 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4547 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4548 | |
| 4549 | DECLARE_INSTRUCTION(Rem); |
| 4550 | |
| 4551 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4552 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 4553 | }; |
| 4554 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4555 | class HDivZeroCheck FINAL : public HExpression<1> { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4556 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4557 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
| 4558 | // constructor. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4559 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4560 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4561 | SetRawInputAt(0, value); |
| 4562 | } |
| 4563 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4564 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 4565 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4566 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4567 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4568 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4569 | return true; |
| 4570 | } |
| 4571 | |
| 4572 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4573 | bool CanThrow() const OVERRIDE { return true; } |
| 4574 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4575 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 4576 | |
| 4577 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4578 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 4579 | }; |
| 4580 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4581 | class HShl FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4582 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4583 | HShl(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4584 | HInstruction* value, |
| 4585 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4586 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4587 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4588 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4589 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4590 | } |
| 4591 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4592 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4593 | static T Compute(T value, int32_t distance, int32_t max_shift_distance) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4594 | return value << (distance & max_shift_distance); |
| 4595 | } |
| 4596 | |
| 4597 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4598 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4599 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4600 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4601 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4602 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4603 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4604 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4605 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4606 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4607 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4608 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4609 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4610 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4611 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4612 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4613 | UNREACHABLE(); |
| 4614 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4615 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4616 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4617 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4618 | UNREACHABLE(); |
| 4619 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4620 | |
| 4621 | DECLARE_INSTRUCTION(Shl); |
| 4622 | |
| 4623 | private: |
| 4624 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 4625 | }; |
| 4626 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4627 | class HShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4628 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4629 | HShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4630 | HInstruction* value, |
| 4631 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4632 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4633 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4634 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4635 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4636 | } |
| 4637 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4638 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4639 | static T Compute(T value, int32_t distance, int32_t max_shift_distance) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4640 | return value >> (distance & max_shift_distance); |
| 4641 | } |
| 4642 | |
| 4643 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4644 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4645 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4646 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4647 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4648 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4649 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4650 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4651 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4652 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4653 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4654 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4655 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4656 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4657 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4658 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4659 | UNREACHABLE(); |
| 4660 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4661 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4662 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4663 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4664 | UNREACHABLE(); |
| 4665 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4666 | |
| 4667 | DECLARE_INSTRUCTION(Shr); |
| 4668 | |
| 4669 | private: |
| 4670 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 4671 | }; |
| 4672 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4673 | class HUShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4674 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4675 | HUShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4676 | HInstruction* value, |
| 4677 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4678 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4679 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4680 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4681 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4682 | } |
| 4683 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4684 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4685 | static T Compute(T value, int32_t distance, int32_t max_shift_distance) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4686 | typedef typename std::make_unsigned<T>::type V; |
| 4687 | V ux = static_cast<V>(value); |
| 4688 | return static_cast<T>(ux >> (distance & max_shift_distance)); |
| 4689 | } |
| 4690 | |
| 4691 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4692 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4693 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4694 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4695 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4696 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4697 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4698 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4699 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4700 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4701 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4702 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4703 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4704 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4705 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4706 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4707 | UNREACHABLE(); |
| 4708 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4709 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4710 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4711 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4712 | UNREACHABLE(); |
| 4713 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4714 | |
| 4715 | DECLARE_INSTRUCTION(UShr); |
| 4716 | |
| 4717 | private: |
| 4718 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 4719 | }; |
| 4720 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4721 | class HAnd FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4722 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4723 | HAnd(Primitive::Type result_type, |
| 4724 | HInstruction* left, |
| 4725 | HInstruction* right, |
| 4726 | uint32_t dex_pc = kNoDexPc) |
| 4727 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4728 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4729 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4730 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4731 | template <typename T> static T Compute(T x, T y) { return x & y; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4732 | |
| 4733 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4734 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4735 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4736 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4737 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4738 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4739 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4740 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4741 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4742 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4743 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4744 | UNREACHABLE(); |
| 4745 | } |
| 4746 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4747 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4748 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4749 | UNREACHABLE(); |
| 4750 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4751 | |
| 4752 | DECLARE_INSTRUCTION(And); |
| 4753 | |
| 4754 | private: |
| 4755 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4756 | }; |
| 4757 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4758 | class HOr FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4759 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4760 | HOr(Primitive::Type result_type, |
| 4761 | HInstruction* left, |
| 4762 | HInstruction* right, |
| 4763 | uint32_t dex_pc = kNoDexPc) |
| 4764 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4765 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4766 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4767 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4768 | template <typename T> static T Compute(T x, T y) { return x | y; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4769 | |
| 4770 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4771 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4772 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4773 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4774 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4775 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4776 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4777 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4778 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4779 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4780 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4781 | UNREACHABLE(); |
| 4782 | } |
| 4783 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4784 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4785 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4786 | UNREACHABLE(); |
| 4787 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4788 | |
| 4789 | DECLARE_INSTRUCTION(Or); |
| 4790 | |
| 4791 | private: |
| 4792 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4793 | }; |
| 4794 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4795 | class HXor FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4796 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4797 | HXor(Primitive::Type result_type, |
| 4798 | HInstruction* left, |
| 4799 | HInstruction* right, |
| 4800 | uint32_t dex_pc = kNoDexPc) |
| 4801 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4802 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4803 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4804 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4805 | template <typename T> static T Compute(T x, T y) { return x ^ y; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4806 | |
| 4807 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4808 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4809 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4810 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4811 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4812 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4813 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4814 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4815 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4816 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4817 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4818 | UNREACHABLE(); |
| 4819 | } |
| 4820 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4821 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4822 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4823 | UNREACHABLE(); |
| 4824 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4825 | |
| 4826 | DECLARE_INSTRUCTION(Xor); |
| 4827 | |
| 4828 | private: |
| 4829 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 4830 | }; |
| 4831 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4832 | class HRor FINAL : public HBinaryOperation { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4833 | public: |
| 4834 | HRor(Primitive::Type result_type, HInstruction* value, HInstruction* distance) |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4835 | : HBinaryOperation(result_type, value, distance) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4836 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4837 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4838 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4839 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4840 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4841 | static T Compute(T value, int32_t distance, int32_t max_shift_value) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4842 | typedef typename std::make_unsigned<T>::type V; |
| 4843 | V ux = static_cast<V>(value); |
| 4844 | if ((distance & max_shift_value) == 0) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4845 | return static_cast<T>(ux); |
| 4846 | } else { |
| 4847 | const V reg_bits = sizeof(T) * 8; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4848 | return static_cast<T>(ux >> (distance & max_shift_value)) | |
| 4849 | (value << (reg_bits - (distance & max_shift_value))); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4850 | } |
| 4851 | } |
| 4852 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4853 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4854 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4855 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4856 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4857 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4858 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4859 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4860 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4861 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4862 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4863 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4864 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4865 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4866 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4867 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4868 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4869 | UNREACHABLE(); |
| 4870 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4871 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4872 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4873 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4874 | UNREACHABLE(); |
| 4875 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4876 | |
| 4877 | DECLARE_INSTRUCTION(Ror); |
| 4878 | |
| 4879 | private: |
| 4880 | DISALLOW_COPY_AND_ASSIGN(HRor); |
| 4881 | }; |
| 4882 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4883 | // The value of a parameter in this method. Its location depends on |
| 4884 | // the calling convention. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4885 | class HParameterValue FINAL : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4886 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4887 | HParameterValue(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4888 | dex::TypeIndex type_index, |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4889 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4890 | Primitive::Type parameter_type, |
| 4891 | bool is_this = false) |
| 4892 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4893 | dex_file_(dex_file), |
| 4894 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4895 | index_(index) { |
| 4896 | SetPackedFlag<kFlagIsThis>(is_this); |
| 4897 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 4898 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4899 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4900 | const DexFile& GetDexFile() const { return dex_file_; } |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4901 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4902 | uint8_t GetIndex() const { return index_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4903 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4904 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4905 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 4906 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4907 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4908 | DECLARE_INSTRUCTION(ParameterValue); |
| 4909 | |
| 4910 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4911 | // Whether or not the parameter value corresponds to 'this' argument. |
| 4912 | static constexpr size_t kFlagIsThis = kNumberOfExpressionPackedBits; |
| 4913 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 4914 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 4915 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 4916 | "Too many packed fields."); |
| 4917 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4918 | const DexFile& dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4919 | const dex::TypeIndex type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4920 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4921 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4922 | const uint8_t index_; |
| 4923 | |
| 4924 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 4925 | }; |
| 4926 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4927 | class HNot FINAL : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4928 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4929 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4930 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4931 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4932 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4933 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4934 | return true; |
| 4935 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4936 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4937 | template <typename T> static T Compute(T x) { return ~x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4938 | |
| 4939 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4940 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4941 | } |
| 4942 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4943 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4944 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4945 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4946 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4947 | UNREACHABLE(); |
| 4948 | } |
| 4949 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4950 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4951 | UNREACHABLE(); |
| 4952 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4953 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4954 | DECLARE_INSTRUCTION(Not); |
| 4955 | |
| 4956 | private: |
| 4957 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 4958 | }; |
| 4959 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4960 | class HBooleanNot FINAL : public HUnaryOperation { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4961 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4962 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4963 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4964 | |
| 4965 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4966 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4967 | return true; |
| 4968 | } |
| 4969 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4970 | template <typename T> static bool Compute(T x) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4971 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4972 | return !x; |
| 4973 | } |
| 4974 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4975 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4976 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4977 | } |
| 4978 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4979 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4980 | UNREACHABLE(); |
| 4981 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4982 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4983 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4984 | UNREACHABLE(); |
| 4985 | } |
| 4986 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4987 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4988 | UNREACHABLE(); |
| 4989 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4990 | |
| 4991 | DECLARE_INSTRUCTION(BooleanNot); |
| 4992 | |
| 4993 | private: |
| 4994 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 4995 | }; |
| 4996 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4997 | class HTypeConversion FINAL : public HExpression<1> { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4998 | public: |
| 4999 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 5000 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5001 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5002 | SetRawInputAt(0, input); |
Roland Levillain | f355c3f | 2016-03-30 19:09:03 +0100 | [diff] [blame] | 5003 | // Invariant: We should never generate a conversion to a Boolean value. |
| 5004 | DCHECK_NE(Primitive::kPrimBoolean, result_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5005 | } |
| 5006 | |
| 5007 | HInstruction* GetInput() const { return InputAt(0); } |
| 5008 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 5009 | Primitive::Type GetResultType() const { return GetType(); } |
| 5010 | |
| 5011 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5012 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5013 | return true; |
| 5014 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5015 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 5016 | // Try to statically evaluate the conversion and return a HConstant |
| 5017 | // containing the result. If the input cannot be converted, return nullptr. |
| 5018 | HConstant* TryStaticEvaluation() const; |
| 5019 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5020 | DECLARE_INSTRUCTION(TypeConversion); |
| 5021 | |
| 5022 | private: |
| 5023 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 5024 | }; |
| 5025 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 5026 | static constexpr uint32_t kNoRegNumber = -1; |
| 5027 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5028 | class HNullCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5029 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5030 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
| 5031 | // constructor. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5032 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5033 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5034 | SetRawInputAt(0, value); |
| 5035 | } |
| 5036 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5037 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5038 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5039 | return true; |
| 5040 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5041 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5042 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5043 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5044 | bool CanThrow() const OVERRIDE { return true; } |
| 5045 | |
| 5046 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5047 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5048 | |
| 5049 | DECLARE_INSTRUCTION(NullCheck); |
| 5050 | |
| 5051 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5052 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 5053 | }; |
| 5054 | |
| 5055 | class FieldInfo : public ValueObject { |
| 5056 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5057 | FieldInfo(MemberOffset field_offset, |
| 5058 | Primitive::Type field_type, |
| 5059 | bool is_volatile, |
| 5060 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5061 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5062 | const DexFile& dex_file, |
| 5063 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5064 | : field_offset_(field_offset), |
| 5065 | field_type_(field_type), |
| 5066 | is_volatile_(is_volatile), |
| 5067 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5068 | declaring_class_def_index_(declaring_class_def_index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5069 | dex_file_(dex_file), |
| 5070 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5071 | |
| 5072 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5073 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5074 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5075 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5076 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5077 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5078 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5079 | |
| 5080 | private: |
| 5081 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5082 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5083 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5084 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5085 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5086 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5087 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5088 | }; |
| 5089 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5090 | class HInstanceFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5091 | public: |
| 5092 | HInstanceFieldGet(HInstruction* value, |
| 5093 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5094 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5095 | bool is_volatile, |
| 5096 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5097 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5098 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5099 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5100 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5101 | : HExpression(field_type, SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5102 | field_info_(field_offset, |
| 5103 | field_type, |
| 5104 | is_volatile, |
| 5105 | field_idx, |
| 5106 | declaring_class_def_index, |
| 5107 | dex_file, |
| 5108 | dex_cache) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5109 | SetRawInputAt(0, value); |
| 5110 | } |
| 5111 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5112 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5113 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5114 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 5115 | const HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5116 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5117 | } |
| 5118 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5119 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5120 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5121 | } |
| 5122 | |
| 5123 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 5124 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5125 | } |
| 5126 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5127 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5128 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5129 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5130 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5131 | |
| 5132 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 5133 | |
| 5134 | private: |
| 5135 | const FieldInfo field_info_; |
| 5136 | |
| 5137 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 5138 | }; |
| 5139 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5140 | class HInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5141 | public: |
| 5142 | HInstanceFieldSet(HInstruction* object, |
| 5143 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5144 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5145 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5146 | bool is_volatile, |
| 5147 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5148 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5149 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5150 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5151 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5152 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5153 | field_info_(field_offset, |
| 5154 | field_type, |
| 5155 | is_volatile, |
| 5156 | field_idx, |
| 5157 | declaring_class_def_index, |
| 5158 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5159 | dex_cache) { |
| 5160 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5161 | SetRawInputAt(0, object); |
| 5162 | SetRawInputAt(1, value); |
| 5163 | } |
| 5164 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5165 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5166 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5167 | } |
| 5168 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5169 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5170 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5171 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5172 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5173 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5174 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5175 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5176 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5177 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 5178 | |
| 5179 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5180 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5181 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5182 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5183 | "Too many packed fields."); |
| 5184 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5185 | const FieldInfo field_info_; |
| 5186 | |
| 5187 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 5188 | }; |
| 5189 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5190 | class HArrayGet FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5191 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5192 | HArrayGet(HInstruction* array, |
| 5193 | HInstruction* index, |
| 5194 | Primitive::Type type, |
| 5195 | uint32_t dex_pc, |
| 5196 | bool is_string_char_at = false) |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5197 | : HExpression(type, SideEffects::ArrayReadOfType(type), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5198 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5199 | SetRawInputAt(0, array); |
| 5200 | SetRawInputAt(1, index); |
| 5201 | } |
| 5202 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5203 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5204 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5205 | return true; |
| 5206 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5207 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5208 | // TODO: We can be smarter here. |
| 5209 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 5210 | // which generates the implicit null check. There are cases when these can be removed |
| 5211 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 5212 | // implicit check here (as long as the address falls in the first page). |
| 5213 | return false; |
| 5214 | } |
| 5215 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5216 | bool IsEquivalentOf(HArrayGet* other) const { |
| 5217 | bool result = (GetDexPc() == other->GetDexPc()); |
| 5218 | if (kIsDebugBuild && result) { |
| 5219 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 5220 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 5221 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
| 5222 | if (Primitive::IsIntOrLongType(GetType())) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5223 | DCHECK(Primitive::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5224 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5225 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 5226 | DCHECK(Primitive::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5227 | } |
| 5228 | } |
| 5229 | return result; |
| 5230 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5231 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5232 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
| 5233 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5234 | HInstruction* GetArray() const { return InputAt(0); } |
| 5235 | HInstruction* GetIndex() const { return InputAt(1); } |
| 5236 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5237 | DECLARE_INSTRUCTION(ArrayGet); |
| 5238 | |
| 5239 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5240 | // We treat a String as an array, creating the HArrayGet from String.charAt() |
| 5241 | // intrinsic in the instruction simplifier. We can always determine whether |
| 5242 | // a particular HArrayGet is actually a String.charAt() by looking at the type |
| 5243 | // of the input but that requires holding the mutator lock, so we prefer to use |
| 5244 | // a flag, so that code generators don't need to do the locking. |
| 5245 | static constexpr size_t kFlagIsStringCharAt = kNumberOfExpressionPackedBits; |
| 5246 | static constexpr size_t kNumberOfArrayGetPackedBits = kFlagIsStringCharAt + 1; |
| 5247 | static_assert(kNumberOfArrayGetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5248 | "Too many packed fields."); |
| 5249 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5250 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 5251 | }; |
| 5252 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5253 | class HArraySet FINAL : public HTemplateInstruction<3> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5254 | public: |
| 5255 | HArraySet(HInstruction* array, |
| 5256 | HInstruction* index, |
| 5257 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5258 | Primitive::Type expected_component_type, |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5259 | uint32_t dex_pc) |
| 5260 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5261 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
| 5262 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == Primitive::kPrimNot); |
| 5263 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 5264 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5265 | SetRawInputAt(0, array); |
| 5266 | SetRawInputAt(1, index); |
| 5267 | SetRawInputAt(2, value); |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5268 | // Make a best guess now, may be refined during SSA building. |
| 5269 | ComputeSideEffects(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5270 | } |
| 5271 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5272 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5273 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5274 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5275 | } |
| 5276 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5277 | // Can throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5278 | bool CanThrow() const OVERRIDE { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5279 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5280 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5281 | // TODO: Same as for ArrayGet. |
| 5282 | return false; |
| 5283 | } |
| 5284 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5285 | void ClearNeedsTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5286 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5287 | } |
| 5288 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5289 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5290 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5291 | } |
| 5292 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5293 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5294 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5295 | } |
| 5296 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5297 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5298 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 5299 | bool StaticTypeOfArrayIsObjectArray() const { |
| 5300 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 5301 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5302 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5303 | HInstruction* GetArray() const { return InputAt(0); } |
| 5304 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5305 | HInstruction* GetValue() const { return InputAt(2); } |
| 5306 | |
| 5307 | Primitive::Type GetComponentType() const { |
| 5308 | // The Dex format does not type floating point index operations. Since the |
| 5309 | // `expected_component_type_` is set during building and can therefore not |
| 5310 | // be correct, we also check what is the value type. If it is a floating |
| 5311 | // point type, we must use that type. |
| 5312 | Primitive::Type value_type = GetValue()->GetType(); |
| 5313 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 5314 | ? value_type |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5315 | : GetRawExpectedComponentType(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5316 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5317 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5318 | Primitive::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5319 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5320 | } |
| 5321 | |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5322 | void ComputeSideEffects() { |
| 5323 | Primitive::Type type = GetComponentType(); |
| 5324 | SetSideEffects(SideEffects::ArrayWriteOfType(type).Union( |
| 5325 | SideEffectsForArchRuntimeCalls(type))); |
| 5326 | } |
| 5327 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5328 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 5329 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 5330 | } |
| 5331 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5332 | DECLARE_INSTRUCTION(ArraySet); |
| 5333 | |
| 5334 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5335 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 5336 | static constexpr size_t kFieldExpectedComponentTypeSize = |
| 5337 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5338 | static constexpr size_t kFlagNeedsTypeCheck = |
| 5339 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 5340 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5341 | // Cached information for the reference_type_info_ so that codegen |
| 5342 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5343 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 5344 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 5345 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 5346 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5347 | using ExpectedComponentTypeField = |
| 5348 | BitField<Primitive::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5349 | |
| 5350 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 5351 | }; |
| 5352 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5353 | class HArrayLength FINAL : public HExpression<1> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5354 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5355 | HArrayLength(HInstruction* array, uint32_t dex_pc, bool is_string_length = false) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5356 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5357 | SetPackedFlag<kFlagIsStringLength>(is_string_length); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5358 | // Note that arrays do not change length, so the instruction does not |
| 5359 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5360 | SetRawInputAt(0, array); |
| 5361 | } |
| 5362 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5363 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5364 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5365 | return true; |
| 5366 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5367 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5368 | return obj == InputAt(0); |
| 5369 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5370 | |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5371 | bool IsStringLength() const { return GetPackedFlag<kFlagIsStringLength>(); } |
| 5372 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5373 | DECLARE_INSTRUCTION(ArrayLength); |
| 5374 | |
| 5375 | private: |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5376 | // We treat a String as an array, creating the HArrayLength from String.length() |
| 5377 | // or String.isEmpty() intrinsic in the instruction simplifier. We can always |
| 5378 | // determine whether a particular HArrayLength is actually a String.length() by |
| 5379 | // looking at the type of the input but that requires holding the mutator lock, so |
| 5380 | // we prefer to use a flag, so that code generators don't need to do the locking. |
| 5381 | static constexpr size_t kFlagIsStringLength = kNumberOfExpressionPackedBits; |
| 5382 | static constexpr size_t kNumberOfArrayLengthPackedBits = kFlagIsStringLength + 1; |
| 5383 | static_assert(kNumberOfArrayLengthPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5384 | "Too many packed fields."); |
| 5385 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5386 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 5387 | }; |
| 5388 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5389 | class HBoundsCheck FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5390 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5391 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
| 5392 | // constructor. |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5393 | HBoundsCheck(HInstruction* index, |
| 5394 | HInstruction* length, |
| 5395 | uint32_t dex_pc, |
| 5396 | uint32_t string_char_at_method_index = DexFile::kDexNoIndex) |
| 5397 | : HExpression(index->GetType(), SideEffects::CanTriggerGC(), dex_pc), |
| 5398 | string_char_at_method_index_(string_char_at_method_index) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 5399 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(index->GetType())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5400 | SetRawInputAt(0, index); |
| 5401 | SetRawInputAt(1, length); |
| 5402 | } |
| 5403 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5404 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5405 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5406 | return true; |
| 5407 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5408 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5409 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5410 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5411 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5412 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5413 | bool IsStringCharAt() const { return GetStringCharAtMethodIndex() != DexFile::kDexNoIndex; } |
| 5414 | uint32_t GetStringCharAtMethodIndex() const { return string_char_at_method_index_; } |
| 5415 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5416 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5417 | |
| 5418 | DECLARE_INSTRUCTION(BoundsCheck); |
| 5419 | |
| 5420 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5421 | // We treat a String as an array, creating the HBoundsCheck from String.charAt() |
| 5422 | // intrinsic in the instruction simplifier. We want to include the String.charAt() |
| 5423 | // in the stack trace if we actually throw the StringIndexOutOfBoundsException, |
| 5424 | // so we need to create an HEnvironment which will be translated to an InlineInfo |
| 5425 | // indicating the extra stack frame. Since we add this HEnvironment quite late, |
| 5426 | // in the PrepareForRegisterAllocation pass, we need to remember the method index |
| 5427 | // from the invoke as we don't want to look again at the dex bytecode. |
| 5428 | uint32_t string_char_at_method_index_; // DexFile::kDexNoIndex if regular array. |
| 5429 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5430 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 5431 | }; |
| 5432 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5433 | class HSuspendCheck FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5434 | public: |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 5435 | explicit HSuspendCheck(uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5436 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5437 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5438 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5439 | return true; |
| 5440 | } |
| 5441 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5442 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 5443 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5444 | |
| 5445 | DECLARE_INSTRUCTION(SuspendCheck); |
| 5446 | |
| 5447 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5448 | // Only used for code generation, in order to share the same slow path between back edges |
| 5449 | // of a same loop. |
| 5450 | SlowPathCode* slow_path_; |
| 5451 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5452 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 5453 | }; |
| 5454 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 5455 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 5456 | // It ensures that we can generate line number and local variables at this point. |
| 5457 | class HNativeDebugInfo : public HTemplateInstruction<0> { |
| 5458 | public: |
| 5459 | explicit HNativeDebugInfo(uint32_t dex_pc) |
| 5460 | : HTemplateInstruction<0>(SideEffects::None(), dex_pc) {} |
| 5461 | |
| 5462 | bool NeedsEnvironment() const OVERRIDE { |
| 5463 | return true; |
| 5464 | } |
| 5465 | |
| 5466 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 5467 | |
| 5468 | private: |
| 5469 | DISALLOW_COPY_AND_ASSIGN(HNativeDebugInfo); |
| 5470 | }; |
| 5471 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5472 | /** |
| 5473 | * Instruction to load a Class object. |
| 5474 | */ |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5475 | class HLoadClass FINAL : public HInstruction { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5476 | public: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5477 | // Determines how to load the Class. |
| 5478 | enum class LoadKind { |
| 5479 | // Use the Class* from the method's own ArtMethod*. |
| 5480 | kReferrersClass, |
| 5481 | |
| 5482 | // Use boot image Class* address that will be known at link time. |
| 5483 | // Used for boot image classes referenced by boot image code in non-PIC mode. |
| 5484 | kBootImageLinkTimeAddress, |
| 5485 | |
| 5486 | // Use PC-relative boot image Class* address that will be known at link time. |
| 5487 | // Used for boot image classes referenced by boot image code in PIC mode. |
| 5488 | kBootImageLinkTimePcRelative, |
| 5489 | |
| 5490 | // Use a known boot image Class* address, embedded in the code by the codegen. |
| 5491 | // Used for boot image classes referenced by apps in AOT- and JIT-compiled code. |
| 5492 | // Note: codegen needs to emit a linker patch if indicated by compiler options' |
| 5493 | // GetIncludePatchInformation(). |
| 5494 | kBootImageAddress, |
| 5495 | |
| 5496 | // Load from the resolved types array at an absolute address. |
| 5497 | // Used for classes outside the boot image referenced by JIT-compiled code. |
| 5498 | kDexCacheAddress, |
| 5499 | |
| 5500 | // Load from resolved types array in the dex cache using a PC-relative load. |
| 5501 | // Used for classes outside boot image when we know that we can access |
| 5502 | // the dex cache arrays using a PC-relative load. |
| 5503 | kDexCachePcRelative, |
| 5504 | |
| 5505 | // Load from resolved types array accessed through the class loaded from |
| 5506 | // the compiled method's own ArtMethod*. This is the default access type when |
| 5507 | // all other types are unavailable. |
| 5508 | kDexCacheViaMethod, |
| 5509 | |
| 5510 | kLast = kDexCacheViaMethod |
| 5511 | }; |
| 5512 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5513 | HLoadClass(HCurrentMethod* current_method, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5514 | dex::TypeIndex type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5515 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5516 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5517 | uint32_t dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5518 | bool needs_access_check, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5519 | bool is_in_dex_cache, |
| 5520 | bool is_in_boot_image) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5521 | : HInstruction(SideEffectsForArchRuntimeCalls(), dex_pc), |
| 5522 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5523 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5524 | dex_file_(dex_file), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5525 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5526 | // Referrers class should not need access check. We never inline unverified |
| 5527 | // methods so we can't possibly end up in this situation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5528 | DCHECK(!is_referrers_class || !needs_access_check); |
| 5529 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5530 | SetPackedField<LoadKindField>( |
| 5531 | is_referrers_class ? LoadKind::kReferrersClass : LoadKind::kDexCacheViaMethod); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5532 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
| 5533 | SetPackedFlag<kFlagIsInDexCache>(is_in_dex_cache); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5534 | SetPackedFlag<kFlagIsInBootImage>(is_in_boot_image); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5535 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5536 | } |
| 5537 | |
| 5538 | void SetLoadKindWithAddress(LoadKind load_kind, uint64_t address) { |
| 5539 | DCHECK(HasAddress(load_kind)); |
| 5540 | load_data_.address = address; |
| 5541 | SetLoadKindInternal(load_kind); |
| 5542 | } |
| 5543 | |
| 5544 | void SetLoadKindWithTypeReference(LoadKind load_kind, |
| 5545 | const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5546 | dex::TypeIndex type_index) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5547 | DCHECK(HasTypeReference(load_kind)); |
| 5548 | DCHECK(IsSameDexFile(dex_file_, dex_file)); |
| 5549 | DCHECK_EQ(type_index_, type_index); |
| 5550 | SetLoadKindInternal(load_kind); |
| 5551 | } |
| 5552 | |
| 5553 | void SetLoadKindWithDexCacheReference(LoadKind load_kind, |
| 5554 | const DexFile& dex_file, |
| 5555 | uint32_t element_index) { |
| 5556 | DCHECK(HasDexCacheReference(load_kind)); |
| 5557 | DCHECK(IsSameDexFile(dex_file_, dex_file)); |
| 5558 | load_data_.dex_cache_element_index = element_index; |
| 5559 | SetLoadKindInternal(load_kind); |
| 5560 | } |
| 5561 | |
| 5562 | LoadKind GetLoadKind() const { |
| 5563 | return GetPackedField<LoadKindField>(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5564 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5565 | |
| 5566 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5567 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5568 | bool InstructionDataEquals(const HInstruction* other) const; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5569 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5570 | size_t ComputeHashCode() const OVERRIDE { return type_index_.index_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5571 | |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 5572 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5573 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5574 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5575 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5576 | } |
| 5577 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 5578 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 5579 | // The entrypoint the code generator is going to call does not do |
| 5580 | // clinit of the class. |
| 5581 | DCHECK(!NeedsAccessCheck()); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5582 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5583 | } |
| 5584 | |
| 5585 | bool CanCallRuntime() const { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5586 | return MustGenerateClinitCheck() || |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5587 | (!IsReferrersClass() && !IsInDexCache()) || |
| 5588 | NeedsAccessCheck(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5589 | } |
| 5590 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5591 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5592 | bool CanThrow() const OVERRIDE { |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 5593 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5594 | } |
| 5595 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5596 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 5597 | return loaded_class_rti_; |
| 5598 | } |
| 5599 | |
| 5600 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 5601 | // Make sure we only set exact types (the loaded class should never be merged). |
| 5602 | DCHECK(rti.IsExact()); |
| 5603 | loaded_class_rti_ = rti; |
| 5604 | } |
| 5605 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5606 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5607 | const DexFile& GetDexFile() const { return dex_file_; } |
| 5608 | |
| 5609 | uint32_t GetDexCacheElementOffset() const; |
| 5610 | |
| 5611 | uint64_t GetAddress() const { |
| 5612 | DCHECK(HasAddress(GetLoadKind())); |
| 5613 | return load_data_.address; |
| 5614 | } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5615 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5616 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return !IsReferrersClass(); } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 5617 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5618 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5619 | return SideEffects::CanTriggerGC(); |
| 5620 | } |
| 5621 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5622 | bool IsReferrersClass() const { return GetLoadKind() == LoadKind::kReferrersClass; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5623 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
| 5624 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5625 | bool IsInBootImage() const { return GetPackedFlag<kFlagIsInBootImage>(); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5626 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5627 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5628 | void MarkInDexCache() { |
| 5629 | SetPackedFlag<kFlagIsInDexCache>(true); |
| 5630 | DCHECK(!NeedsEnvironment()); |
| 5631 | RemoveEnvironment(); |
| 5632 | SetSideEffects(SideEffects::None()); |
| 5633 | } |
| 5634 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5635 | void MarkInBootImage() { |
| 5636 | SetPackedFlag<kFlagIsInBootImage>(true); |
| 5637 | } |
| 5638 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5639 | void AddSpecialInput(HInstruction* special_input); |
| 5640 | |
| 5641 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 5642 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 5643 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 5644 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 5645 | } |
| 5646 | |
| 5647 | Primitive::Type GetType() const OVERRIDE { |
| 5648 | return Primitive::kPrimNot; |
| 5649 | } |
| 5650 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5651 | DECLARE_INSTRUCTION(LoadClass); |
| 5652 | |
| 5653 | private: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5654 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5655 | static constexpr size_t kFlagIsInDexCache = kFlagNeedsAccessCheck + 1; |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5656 | static constexpr size_t kFlagIsInBootImage = kFlagIsInDexCache + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5657 | // Whether this instruction must generate the initialization check. |
| 5658 | // Used for code generation. |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5659 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInBootImage + 1; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5660 | static constexpr size_t kFieldLoadKind = kFlagGenerateClInitCheck + 1; |
| 5661 | static constexpr size_t kFieldLoadKindSize = |
| 5662 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 5663 | static constexpr size_t kNumberOfLoadClassPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5664 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5665 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
| 5666 | |
| 5667 | static bool HasTypeReference(LoadKind load_kind) { |
| 5668 | return load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5669 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
| 5670 | load_kind == LoadKind::kDexCacheViaMethod || |
| 5671 | load_kind == LoadKind::kReferrersClass; |
| 5672 | } |
| 5673 | |
| 5674 | static bool HasAddress(LoadKind load_kind) { |
| 5675 | return load_kind == LoadKind::kBootImageAddress || load_kind == LoadKind::kDexCacheAddress; |
| 5676 | } |
| 5677 | |
| 5678 | static bool HasDexCacheReference(LoadKind load_kind) { |
| 5679 | return load_kind == LoadKind::kDexCachePcRelative; |
| 5680 | } |
| 5681 | |
| 5682 | void SetLoadKindInternal(LoadKind load_kind); |
| 5683 | |
| 5684 | // The special input is the HCurrentMethod for kDexCacheViaMethod or kReferrersClass. |
| 5685 | // For other load kinds it's empty or possibly some architecture-specific instruction |
| 5686 | // for PC-relative loads, i.e. kDexCachePcRelative or kBootImageLinkTimePcRelative. |
| 5687 | HUserRecord<HInstruction*> special_input_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5688 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5689 | const dex::TypeIndex type_index_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5690 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5691 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5692 | union { |
| 5693 | uint32_t dex_cache_element_index; // Only for dex cache reference. |
| 5694 | uint64_t address; // Up to 64-bit, needed for kDexCacheAddress on 64-bit targets. |
| 5695 | } load_data_; |
| 5696 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5697 | ReferenceTypeInfo loaded_class_rti_; |
| 5698 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5699 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 5700 | }; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5701 | std::ostream& operator<<(std::ostream& os, HLoadClass::LoadKind rhs); |
| 5702 | |
| 5703 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
| 5704 | inline uint32_t HLoadClass::GetDexCacheElementOffset() const { |
| 5705 | DCHECK(HasDexCacheReference(GetLoadKind())) << GetLoadKind(); |
| 5706 | return load_data_.dex_cache_element_index; |
| 5707 | } |
| 5708 | |
| 5709 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
| 5710 | inline void HLoadClass::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5711 | // The special input is used for PC-relative loads on some architectures, |
| 5712 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5713 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5714 | GetLoadKind() == LoadKind::kDexCachePcRelative || |
| 5715 | GetLoadKind() == LoadKind::kBootImageLinkTimeAddress || |
| 5716 | GetLoadKind() == LoadKind::kBootImageAddress) << GetLoadKind(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5717 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 5718 | special_input_ = HUserRecord<HInstruction*>(special_input); |
| 5719 | special_input->AddUseAt(this, 0); |
| 5720 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5721 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5722 | class HLoadString FINAL : public HInstruction { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5723 | public: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5724 | // Determines how to load the String. |
| 5725 | enum class LoadKind { |
| 5726 | // Use boot image String* address that will be known at link time. |
| 5727 | // Used for boot image strings referenced by boot image code in non-PIC mode. |
| 5728 | kBootImageLinkTimeAddress, |
| 5729 | |
| 5730 | // Use PC-relative boot image String* address that will be known at link time. |
| 5731 | // Used for boot image strings referenced by boot image code in PIC mode. |
| 5732 | kBootImageLinkTimePcRelative, |
| 5733 | |
| 5734 | // Use a known boot image String* address, embedded in the code by the codegen. |
| 5735 | // Used for boot image strings referenced by apps in AOT- and JIT-compiled code. |
| 5736 | // Note: codegen needs to emit a linker patch if indicated by compiler options' |
| 5737 | // GetIncludePatchInformation(). |
| 5738 | kBootImageAddress, |
| 5739 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5740 | // Load from an entry in the .bss section using a PC-relative load. |
| 5741 | // Used for strings outside boot image when .bss is accessible with a PC-relative load. |
| 5742 | kBssEntry, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5743 | |
| 5744 | // Load from resolved strings array accessed through the class loaded from |
| 5745 | // the compiled method's own ArtMethod*. This is the default access type when |
| 5746 | // all other types are unavailable. |
| 5747 | kDexCacheViaMethod, |
| 5748 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5749 | // Load from the root table associated with the JIT compiled method. |
| 5750 | kJitTableAddress, |
| 5751 | |
| 5752 | kLast = kJitTableAddress, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5753 | }; |
| 5754 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5755 | HLoadString(HCurrentMethod* current_method, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5756 | dex::StringIndex string_index, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5757 | const DexFile& dex_file, |
| 5758 | uint32_t dex_pc) |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5759 | : HInstruction(SideEffectsForArchRuntimeCalls(), dex_pc), |
| 5760 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5761 | string_index_(string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5762 | SetPackedFlag<kFlagIsInDexCache>(false); |
| 5763 | SetPackedField<LoadKindField>(LoadKind::kDexCacheViaMethod); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5764 | load_data_.dex_file_ = &dex_file; |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5765 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5766 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5767 | void SetLoadKindWithAddress(LoadKind load_kind, uint64_t address) { |
| 5768 | DCHECK(HasAddress(load_kind)); |
| 5769 | load_data_.address = address; |
| 5770 | SetLoadKindInternal(load_kind); |
| 5771 | } |
| 5772 | |
| 5773 | void SetLoadKindWithStringReference(LoadKind load_kind, |
| 5774 | const DexFile& dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5775 | dex::StringIndex string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5776 | DCHECK(HasStringReference(load_kind)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5777 | load_data_.dex_file_ = &dex_file; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5778 | string_index_ = string_index; |
| 5779 | SetLoadKindInternal(load_kind); |
| 5780 | } |
| 5781 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5782 | LoadKind GetLoadKind() const { |
| 5783 | return GetPackedField<LoadKindField>(); |
| 5784 | } |
| 5785 | |
| 5786 | const DexFile& GetDexFile() const; |
| 5787 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5788 | dex::StringIndex GetStringIndex() const { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5789 | DCHECK(HasStringReference(GetLoadKind()) || /* For slow paths. */ !IsInDexCache()); |
| 5790 | return string_index_; |
| 5791 | } |
| 5792 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5793 | uint64_t GetAddress() const { |
| 5794 | DCHECK(HasAddress(GetLoadKind())); |
| 5795 | return load_data_.address; |
| 5796 | } |
| 5797 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5798 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5799 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5800 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5801 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5802 | size_t ComputeHashCode() const OVERRIDE { return string_index_.index_; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5803 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5804 | // Will call the runtime if we need to load the string through |
| 5805 | // the dex cache and the string is not guaranteed to be there yet. |
| 5806 | bool NeedsEnvironment() const OVERRIDE { |
| 5807 | LoadKind load_kind = GetLoadKind(); |
| 5808 | if (load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5809 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5810 | load_kind == LoadKind::kBootImageAddress || |
| 5811 | load_kind == LoadKind::kJitTableAddress) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5812 | return false; |
| 5813 | } |
| 5814 | return !IsInDexCache(); |
| 5815 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5816 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5817 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
| 5818 | return GetLoadKind() == LoadKind::kDexCacheViaMethod; |
| 5819 | } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5820 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 5821 | bool CanBeNull() const OVERRIDE { return false; } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5822 | bool CanThrow() const OVERRIDE { return NeedsEnvironment(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5823 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5824 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5825 | return SideEffects::CanTriggerGC(); |
| 5826 | } |
| 5827 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5828 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
| 5829 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5830 | void MarkInDexCache() { |
| 5831 | SetPackedFlag<kFlagIsInDexCache>(true); |
| 5832 | DCHECK(!NeedsEnvironment()); |
| 5833 | RemoveEnvironment(); |
Vladimir Marko | ace7a00 | 2016-04-05 11:18:49 +0100 | [diff] [blame] | 5834 | SetSideEffects(SideEffects::None()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5835 | } |
| 5836 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5837 | void AddSpecialInput(HInstruction* special_input); |
| 5838 | |
| 5839 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 5840 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 5841 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 5842 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5843 | } |
| 5844 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5845 | Primitive::Type GetType() const OVERRIDE { |
| 5846 | return Primitive::kPrimNot; |
| 5847 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5848 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5849 | DECLARE_INSTRUCTION(LoadString); |
| 5850 | |
| 5851 | private: |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5852 | static constexpr size_t kFlagIsInDexCache = kNumberOfGenericPackedBits; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5853 | static constexpr size_t kFieldLoadKind = kFlagIsInDexCache + 1; |
| 5854 | static constexpr size_t kFieldLoadKindSize = |
| 5855 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 5856 | static constexpr size_t kNumberOfLoadStringPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5857 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5858 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5859 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5860 | static bool HasStringReference(LoadKind load_kind) { |
| 5861 | return load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5862 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5863 | load_kind == LoadKind::kBssEntry || |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5864 | load_kind == LoadKind::kDexCacheViaMethod || |
| 5865 | load_kind == LoadKind::kJitTableAddress; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5866 | } |
| 5867 | |
| 5868 | static bool HasAddress(LoadKind load_kind) { |
Vladimir Marko | 54d6a20 | 2016-11-09 12:46:38 +0000 | [diff] [blame] | 5869 | return load_kind == LoadKind::kBootImageAddress; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5870 | } |
| 5871 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5872 | void SetLoadKindInternal(LoadKind load_kind); |
| 5873 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5874 | // The special input is the HCurrentMethod for kDexCacheViaMethod. |
| 5875 | // For other load kinds it's empty or possibly some architecture-specific instruction |
| 5876 | // for PC-relative loads, i.e. kDexCachePcRelative or kBootImageLinkTimePcRelative. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5877 | HUserRecord<HInstruction*> special_input_; |
| 5878 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5879 | // String index serves also as the hash code and it's also needed for slow-paths, |
| 5880 | // so it must not be overwritten with other load data. |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5881 | dex::StringIndex string_index_; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5882 | |
| 5883 | union { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5884 | const DexFile* dex_file_; // For string reference. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5885 | uint64_t address; // Up to 64-bit, needed for kDexCacheAddress on 64-bit targets. |
| 5886 | } load_data_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5887 | |
| 5888 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 5889 | }; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5890 | std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs); |
| 5891 | |
| 5892 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5893 | inline const DexFile& HLoadString::GetDexFile() const { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5894 | DCHECK(HasStringReference(GetLoadKind())) << GetLoadKind(); |
| 5895 | return *load_data_.dex_file_; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5896 | } |
| 5897 | |
| 5898 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5899 | inline void HLoadString::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5900 | // The special input is used for PC-relative loads on some architectures, |
| 5901 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5902 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5903 | GetLoadKind() == LoadKind::kBssEntry || |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5904 | GetLoadKind() == LoadKind::kBootImageLinkTimeAddress || |
| 5905 | GetLoadKind() == LoadKind::kBootImageAddress) << GetLoadKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5906 | // HLoadString::GetInputRecords() returns an empty array at this point, |
| 5907 | // so use the GetInputRecords() from the base class to set the input record. |
| 5908 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 5909 | special_input_ = HUserRecord<HInstruction*>(special_input); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5910 | special_input->AddUseAt(this, 0); |
| 5911 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5912 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5913 | /** |
| 5914 | * Performs an initialization check on its Class object input. |
| 5915 | */ |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5916 | class HClinitCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5917 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 5918 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 5919 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5920 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5921 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 5922 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5923 | SetRawInputAt(0, constant); |
| 5924 | } |
| 5925 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5926 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5927 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5928 | return true; |
| 5929 | } |
| 5930 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5931 | bool NeedsEnvironment() const OVERRIDE { |
| 5932 | // May call runtime to initialize the class. |
| 5933 | return true; |
| 5934 | } |
| 5935 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 5936 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5937 | |
| 5938 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 5939 | |
| 5940 | DECLARE_INSTRUCTION(ClinitCheck); |
| 5941 | |
| 5942 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5943 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 5944 | }; |
| 5945 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5946 | class HStaticFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5947 | public: |
| 5948 | HStaticFieldGet(HInstruction* cls, |
| 5949 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5950 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5951 | bool is_volatile, |
| 5952 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5953 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5954 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5955 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5956 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5957 | : HExpression(field_type, SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5958 | field_info_(field_offset, |
| 5959 | field_type, |
| 5960 | is_volatile, |
| 5961 | field_idx, |
| 5962 | declaring_class_def_index, |
| 5963 | dex_file, |
| 5964 | dex_cache) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5965 | SetRawInputAt(0, cls); |
| 5966 | } |
| 5967 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5968 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5969 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5970 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5971 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 5972 | const HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5973 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5974 | } |
| 5975 | |
| 5976 | size_t ComputeHashCode() const OVERRIDE { |
| 5977 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5978 | } |
| 5979 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5980 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5981 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5982 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5983 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5984 | |
| 5985 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 5986 | |
| 5987 | private: |
| 5988 | const FieldInfo field_info_; |
| 5989 | |
| 5990 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 5991 | }; |
| 5992 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5993 | class HStaticFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5994 | public: |
| 5995 | HStaticFieldSet(HInstruction* cls, |
| 5996 | HInstruction* value, |
| 5997 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5998 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5999 | bool is_volatile, |
| 6000 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6001 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6002 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6003 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6004 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 6005 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6006 | field_info_(field_offset, |
| 6007 | field_type, |
| 6008 | is_volatile, |
| 6009 | field_idx, |
| 6010 | declaring_class_def_index, |
| 6011 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6012 | dex_cache) { |
| 6013 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6014 | SetRawInputAt(0, cls); |
| 6015 | SetRawInputAt(1, value); |
| 6016 | } |
| 6017 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6018 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6019 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 6020 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6021 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6022 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6023 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6024 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 6025 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6026 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6027 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 6028 | |
| 6029 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6030 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 6031 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 6032 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 6033 | "Too many packed fields."); |
| 6034 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6035 | const FieldInfo field_info_; |
| 6036 | |
| 6037 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 6038 | }; |
| 6039 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6040 | class HUnresolvedInstanceFieldGet FINAL : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6041 | public: |
| 6042 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 6043 | Primitive::Type field_type, |
| 6044 | uint32_t field_index, |
| 6045 | uint32_t dex_pc) |
| 6046 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 6047 | field_index_(field_index) { |
| 6048 | SetRawInputAt(0, obj); |
| 6049 | } |
| 6050 | |
| 6051 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6052 | bool CanThrow() const OVERRIDE { return true; } |
| 6053 | |
| 6054 | Primitive::Type GetFieldType() const { return GetType(); } |
| 6055 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6056 | |
| 6057 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 6058 | |
| 6059 | private: |
| 6060 | const uint32_t field_index_; |
| 6061 | |
| 6062 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 6063 | }; |
| 6064 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6065 | class HUnresolvedInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6066 | public: |
| 6067 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 6068 | HInstruction* value, |
| 6069 | Primitive::Type field_type, |
| 6070 | uint32_t field_index, |
| 6071 | uint32_t dex_pc) |
| 6072 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6073 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6074 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 6075 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6076 | SetRawInputAt(0, obj); |
| 6077 | SetRawInputAt(1, value); |
| 6078 | } |
| 6079 | |
| 6080 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6081 | bool CanThrow() const OVERRIDE { return true; } |
| 6082 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6083 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6084 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6085 | |
| 6086 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 6087 | |
| 6088 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6089 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6090 | static constexpr size_t kFieldFieldTypeSize = |
| 6091 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 6092 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6093 | kFieldFieldType + kFieldFieldTypeSize; |
| 6094 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6095 | "Too many packed fields."); |
| 6096 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 6097 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6098 | const uint32_t field_index_; |
| 6099 | |
| 6100 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 6101 | }; |
| 6102 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6103 | class HUnresolvedStaticFieldGet FINAL : public HExpression<0> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6104 | public: |
| 6105 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 6106 | uint32_t field_index, |
| 6107 | uint32_t dex_pc) |
| 6108 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 6109 | field_index_(field_index) { |
| 6110 | } |
| 6111 | |
| 6112 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6113 | bool CanThrow() const OVERRIDE { return true; } |
| 6114 | |
| 6115 | Primitive::Type GetFieldType() const { return GetType(); } |
| 6116 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6117 | |
| 6118 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 6119 | |
| 6120 | private: |
| 6121 | const uint32_t field_index_; |
| 6122 | |
| 6123 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 6124 | }; |
| 6125 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6126 | class HUnresolvedStaticFieldSet FINAL : public HTemplateInstruction<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6127 | public: |
| 6128 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 6129 | Primitive::Type field_type, |
| 6130 | uint32_t field_index, |
| 6131 | uint32_t dex_pc) |
| 6132 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6133 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6134 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 6135 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6136 | SetRawInputAt(0, value); |
| 6137 | } |
| 6138 | |
| 6139 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6140 | bool CanThrow() const OVERRIDE { return true; } |
| 6141 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6142 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6143 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6144 | |
| 6145 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 6146 | |
| 6147 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6148 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6149 | static constexpr size_t kFieldFieldTypeSize = |
| 6150 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 6151 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6152 | kFieldFieldType + kFieldFieldTypeSize; |
| 6153 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6154 | "Too many packed fields."); |
| 6155 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 6156 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6157 | const uint32_t field_index_; |
| 6158 | |
| 6159 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 6160 | }; |
| 6161 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6162 | // Implement the move-exception DEX instruction. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6163 | class HLoadException FINAL : public HExpression<0> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6164 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6165 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 6166 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6167 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 6168 | bool CanBeNull() const OVERRIDE { return false; } |
| 6169 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6170 | DECLARE_INSTRUCTION(LoadException); |
| 6171 | |
| 6172 | private: |
| 6173 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 6174 | }; |
| 6175 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6176 | // Implicit part of move-exception which clears thread-local exception storage. |
| 6177 | // 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] | 6178 | class HClearException FINAL : public HTemplateInstruction<0> { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6179 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6180 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 6181 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6182 | |
| 6183 | DECLARE_INSTRUCTION(ClearException); |
| 6184 | |
| 6185 | private: |
| 6186 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 6187 | }; |
| 6188 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6189 | class HThrow FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6190 | public: |
| 6191 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6192 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6193 | SetRawInputAt(0, exception); |
| 6194 | } |
| 6195 | |
| 6196 | bool IsControlFlow() const OVERRIDE { return true; } |
| 6197 | |
| 6198 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6199 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6200 | bool CanThrow() const OVERRIDE { return true; } |
| 6201 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6202 | |
| 6203 | DECLARE_INSTRUCTION(Throw); |
| 6204 | |
| 6205 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6206 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 6207 | }; |
| 6208 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6209 | /** |
| 6210 | * Implementation strategies for the code generator of a HInstanceOf |
| 6211 | * or `HCheckCast`. |
| 6212 | */ |
| 6213 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6214 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6215 | kExactCheck, // Can do a single class compare. |
| 6216 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 6217 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 6218 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 6219 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6220 | kArrayCheck, // No optimization yet when checking against a generic array. |
| 6221 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6222 | }; |
| 6223 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6224 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 6225 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6226 | class HInstanceOf FINAL : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6227 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6228 | HInstanceOf(HInstruction* object, |
| 6229 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6230 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6231 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6232 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6233 | SideEffectsForArchRuntimeCalls(check_kind), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6234 | dex_pc) { |
| 6235 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6236 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6237 | SetRawInputAt(0, object); |
| 6238 | SetRawInputAt(1, constant); |
| 6239 | } |
| 6240 | |
| 6241 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6242 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6243 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6244 | return true; |
| 6245 | } |
| 6246 | |
| 6247 | bool NeedsEnvironment() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6248 | return CanCallRuntime(GetTypeCheckKind()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6249 | } |
| 6250 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6251 | // Used only in code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6252 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6253 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6254 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6255 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6256 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6257 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 6258 | // Mips currently does runtime calls for any other checks. |
| 6259 | return check_kind != TypeCheckKind::kExactCheck; |
| 6260 | } |
| 6261 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6262 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6263 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6264 | } |
| 6265 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6266 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6267 | |
| 6268 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6269 | static constexpr size_t kFieldTypeCheckKind = kNumberOfExpressionPackedBits; |
| 6270 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6271 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6272 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6273 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagMustDoNullCheck + 1; |
| 6274 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6275 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6276 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6277 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 6278 | }; |
| 6279 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6280 | class HBoundType FINAL : public HExpression<1> { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6281 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 6282 | explicit HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6283 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6284 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 6285 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 6286 | SetPackedFlag<kFlagCanBeNull>(true); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 6287 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6288 | SetRawInputAt(0, input); |
| 6289 | } |
| 6290 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6291 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6292 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6293 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6294 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6295 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6296 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6297 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 6298 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6299 | } |
| 6300 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6301 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6302 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6303 | DECLARE_INSTRUCTION(BoundType); |
| 6304 | |
| 6305 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6306 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 6307 | // is false then CanBeNull() cannot be true). |
| 6308 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfExpressionPackedBits; |
| 6309 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 6310 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 6311 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6312 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6313 | // 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] | 6314 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 6315 | // It is used to bound the type in cases like: |
| 6316 | // if (x instanceof ClassX) { |
| 6317 | // // uper_bound_ will be ClassX |
| 6318 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6319 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6320 | |
| 6321 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 6322 | }; |
| 6323 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6324 | class HCheckCast FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6325 | public: |
| 6326 | HCheckCast(HInstruction* object, |
| 6327 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6328 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6329 | uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6330 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
| 6331 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6332 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6333 | SetRawInputAt(0, object); |
| 6334 | SetRawInputAt(1, constant); |
| 6335 | } |
| 6336 | |
| 6337 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6338 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6339 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6340 | return true; |
| 6341 | } |
| 6342 | |
| 6343 | bool NeedsEnvironment() const OVERRIDE { |
| 6344 | // Instruction may throw a CheckCastError. |
| 6345 | return true; |
| 6346 | } |
| 6347 | |
| 6348 | bool CanThrow() const OVERRIDE { return true; } |
| 6349 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6350 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6351 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6352 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6353 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6354 | |
| 6355 | DECLARE_INSTRUCTION(CheckCast); |
| 6356 | |
| 6357 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6358 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 6359 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6360 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6361 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6362 | static constexpr size_t kNumberOfCheckCastPackedBits = kFlagMustDoNullCheck + 1; |
| 6363 | static_assert(kNumberOfCheckCastPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6364 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6365 | |
| 6366 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6367 | }; |
| 6368 | |
Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame] | 6369 | /** |
| 6370 | * @brief Memory barrier types (see "The JSR-133 Cookbook for Compiler Writers"). |
| 6371 | * @details We define the combined barrier types that are actually required |
| 6372 | * by the Java Memory Model, rather than using exactly the terminology from |
| 6373 | * the JSR-133 cookbook. These should, in many cases, be replaced by acquire/release |
| 6374 | * primitives. Note that the JSR-133 cookbook generally does not deal with |
| 6375 | * store atomicity issues, and the recipes there are not always entirely sufficient. |
| 6376 | * The current recipe is as follows: |
| 6377 | * -# Use AnyStore ~= (LoadStore | StoreStore) ~= release barrier before volatile store. |
| 6378 | * -# Use AnyAny barrier after volatile store. (StoreLoad is as expensive.) |
| 6379 | * -# Use LoadAny barrier ~= (LoadLoad | LoadStore) ~= acquire barrier after each volatile load. |
| 6380 | * -# Use StoreStore barrier after all stores but before return from any constructor whose |
| 6381 | * class has final fields. |
| 6382 | * -# Use NTStoreStore to order non-temporal stores with respect to all later |
| 6383 | * store-to-memory instructions. Only generated together with non-temporal stores. |
| 6384 | */ |
| 6385 | enum MemBarrierKind { |
| 6386 | kAnyStore, |
| 6387 | kLoadAny, |
| 6388 | kStoreStore, |
| 6389 | kAnyAny, |
| 6390 | kNTStoreStore, |
| 6391 | kLastBarrierKind = kNTStoreStore |
| 6392 | }; |
| 6393 | std::ostream& operator<<(std::ostream& os, const MemBarrierKind& kind); |
| 6394 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6395 | class HMemoryBarrier FINAL : public HTemplateInstruction<0> { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6396 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6397 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 6398 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6399 | SideEffects::AllWritesAndReads(), dex_pc) { // Assume write/read on all fields/arrays. |
| 6400 | SetPackedField<BarrierKindField>(barrier_kind); |
| 6401 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6402 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6403 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6404 | |
| 6405 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 6406 | |
| 6407 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6408 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 6409 | static constexpr size_t kFieldBarrierKindSize = |
| 6410 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 6411 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 6412 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 6413 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 6414 | "Too many packed fields."); |
| 6415 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6416 | |
| 6417 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 6418 | }; |
| 6419 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6420 | class HMonitorOperation FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6421 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6422 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6423 | kEnter, |
| 6424 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6425 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6426 | }; |
| 6427 | |
| 6428 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6429 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6430 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 6431 | dex_pc) { |
| 6432 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6433 | SetRawInputAt(0, object); |
| 6434 | } |
| 6435 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6436 | // Instruction may go into runtime, so we need an environment. |
| 6437 | bool NeedsEnvironment() const OVERRIDE { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 6438 | |
| 6439 | bool CanThrow() const OVERRIDE { |
| 6440 | // Verifier guarantees that monitor-exit cannot throw. |
| 6441 | // This is important because it allows the HGraphBuilder to remove |
| 6442 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 6443 | return IsEnter(); |
| 6444 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6445 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6446 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 6447 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6448 | |
| 6449 | DECLARE_INSTRUCTION(MonitorOperation); |
| 6450 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6451 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6452 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 6453 | static constexpr size_t kFieldOperationKindSize = |
| 6454 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 6455 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 6456 | kFieldOperationKind + kFieldOperationKindSize; |
| 6457 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6458 | "Too many packed fields."); |
| 6459 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6460 | |
| 6461 | private: |
| 6462 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 6463 | }; |
| 6464 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6465 | class HSelect FINAL : public HExpression<3> { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6466 | public: |
| 6467 | HSelect(HInstruction* condition, |
| 6468 | HInstruction* true_value, |
| 6469 | HInstruction* false_value, |
| 6470 | uint32_t dex_pc) |
| 6471 | : HExpression(HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
| 6472 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 6473 | |
| 6474 | // First input must be `true_value` or `false_value` to allow codegens to |
| 6475 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 6476 | // that architectures which implement HSelect as a conditional move also |
| 6477 | // will not need to invert the condition. |
| 6478 | SetRawInputAt(0, false_value); |
| 6479 | SetRawInputAt(1, true_value); |
| 6480 | SetRawInputAt(2, condition); |
| 6481 | } |
| 6482 | |
| 6483 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 6484 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 6485 | HInstruction* GetCondition() const { return InputAt(2); } |
| 6486 | |
| 6487 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6488 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 6489 | return true; |
| 6490 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6491 | |
| 6492 | bool CanBeNull() const OVERRIDE { |
| 6493 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 6494 | } |
| 6495 | |
| 6496 | DECLARE_INSTRUCTION(Select); |
| 6497 | |
| 6498 | private: |
| 6499 | DISALLOW_COPY_AND_ASSIGN(HSelect); |
| 6500 | }; |
| 6501 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 6502 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6503 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6504 | MoveOperands(Location source, |
| 6505 | Location destination, |
| 6506 | Primitive::Type type, |
| 6507 | HInstruction* instruction) |
| 6508 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6509 | |
| 6510 | Location GetSource() const { return source_; } |
| 6511 | Location GetDestination() const { return destination_; } |
| 6512 | |
| 6513 | void SetSource(Location value) { source_ = value; } |
| 6514 | void SetDestination(Location value) { destination_ = value; } |
| 6515 | |
| 6516 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 6517 | // destination (but not the source). |
| 6518 | Location MarkPending() { |
| 6519 | DCHECK(!IsPending()); |
| 6520 | Location dest = destination_; |
| 6521 | destination_ = Location::NoLocation(); |
| 6522 | return dest; |
| 6523 | } |
| 6524 | |
| 6525 | void ClearPending(Location dest) { |
| 6526 | DCHECK(IsPending()); |
| 6527 | destination_ = dest; |
| 6528 | } |
| 6529 | |
| 6530 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6531 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 6532 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6533 | } |
| 6534 | |
| 6535 | // True if this blocks a move from the given location. |
| 6536 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 6537 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6538 | } |
| 6539 | |
| 6540 | // A move is redundant if it's been eliminated, if its source and |
| 6541 | // destination are the same, or if its destination is unneeded. |
| 6542 | bool IsRedundant() const { |
| 6543 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 6544 | } |
| 6545 | |
| 6546 | // We clear both operands to indicate move that's been eliminated. |
| 6547 | void Eliminate() { |
| 6548 | source_ = destination_ = Location::NoLocation(); |
| 6549 | } |
| 6550 | |
| 6551 | bool IsEliminated() const { |
| 6552 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 6553 | return source_.IsInvalid(); |
| 6554 | } |
| 6555 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6556 | Primitive::Type GetType() const { return type_; } |
| 6557 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6558 | bool Is64BitMove() const { |
| 6559 | return Primitive::Is64BitType(type_); |
| 6560 | } |
| 6561 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6562 | HInstruction* GetInstruction() const { return instruction_; } |
| 6563 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6564 | private: |
| 6565 | Location source_; |
| 6566 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6567 | // The type this move is for. |
| 6568 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6569 | // The instruction this move is assocatied with. Null when this move is |
| 6570 | // for moving an input in the expected locations of user (including a phi user). |
| 6571 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 6572 | // in the same parallel move. |
| 6573 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6574 | }; |
| 6575 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6576 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 6577 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6578 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 6579 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6580 | class HParallelMove FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6581 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6582 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6583 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 6584 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 6585 | moves_.reserve(kDefaultNumberOfMoves); |
| 6586 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6587 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6588 | void AddMove(Location source, |
| 6589 | Location destination, |
| 6590 | Primitive::Type type, |
| 6591 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6592 | DCHECK(source.IsValid()); |
| 6593 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6594 | if (kIsDebugBuild) { |
| 6595 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6596 | for (const MoveOperands& move : moves_) { |
| 6597 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6598 | // Special case the situation where the move is for the spill slot |
| 6599 | // of the instruction. |
| 6600 | if ((GetPrevious() == instruction) |
| 6601 | || ((GetPrevious() == nullptr) |
| 6602 | && instruction->IsPhi() |
| 6603 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6604 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6605 | << "Doing parallel moves for the same instruction."; |
| 6606 | } else { |
| 6607 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 6608 | } |
| 6609 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 6610 | } |
| 6611 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6612 | for (const MoveOperands& move : moves_) { |
| 6613 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6614 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6615 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6616 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6617 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6618 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6619 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6620 | } |
| 6621 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6622 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6623 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6624 | } |
| 6625 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6626 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6627 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 6628 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6629 | |
| 6630 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6631 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6632 | |
| 6633 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 6634 | }; |
| 6635 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6636 | } // namespace art |
| 6637 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 6638 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 6639 | #include "nodes_shared.h" |
| 6640 | #endif |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6641 | #ifdef ART_ENABLE_CODEGEN_arm |
| 6642 | #include "nodes_arm.h" |
| 6643 | #endif |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6644 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| 6645 | #include "nodes_arm64.h" |
| 6646 | #endif |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6647 | #ifdef ART_ENABLE_CODEGEN_mips |
| 6648 | #include "nodes_mips.h" |
| 6649 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6650 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 6651 | #include "nodes_x86.h" |
| 6652 | #endif |
| 6653 | |
| 6654 | namespace art { |
| 6655 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6656 | class HGraphVisitor : public ValueObject { |
| 6657 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 6658 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 6659 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6660 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6661 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6662 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 6663 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6664 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6665 | void VisitInsertionOrder(); |
| 6666 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6667 | // Visit the graph following dominator tree reverse post-order. |
| 6668 | void VisitReversePostOrder(); |
| 6669 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 6670 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 6671 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6672 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6673 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6674 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 6675 | |
| 6676 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6677 | |
| 6678 | #undef DECLARE_VISIT_INSTRUCTION |
| 6679 | |
| 6680 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 6681 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6682 | |
| 6683 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 6684 | }; |
| 6685 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6686 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 6687 | public: |
| 6688 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 6689 | virtual ~HGraphDelegateVisitor() {} |
| 6690 | |
| 6691 | // Visit functions that delegate to to super class. |
| 6692 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6693 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6694 | |
| 6695 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6696 | |
| 6697 | #undef DECLARE_VISIT_INSTRUCTION |
| 6698 | |
| 6699 | private: |
| 6700 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 6701 | }; |
| 6702 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6703 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6704 | // of an inner loop. The order in which the blocks are iterated is on their |
| 6705 | // block id. |
| 6706 | class HBlocksInLoopIterator : public ValueObject { |
| 6707 | public: |
| 6708 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 6709 | : blocks_in_loop_(info.GetBlocks()), |
| 6710 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 6711 | index_(0) { |
| 6712 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 6713 | Advance(); |
| 6714 | } |
| 6715 | } |
| 6716 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6717 | bool Done() const { return index_ == blocks_.size(); } |
| 6718 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6719 | void Advance() { |
| 6720 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6721 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6722 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 6723 | break; |
| 6724 | } |
| 6725 | } |
| 6726 | } |
| 6727 | |
| 6728 | private: |
| 6729 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6730 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6731 | size_t index_; |
| 6732 | |
| 6733 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 6734 | }; |
| 6735 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6736 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6737 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 6738 | // post order. |
| 6739 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 6740 | public: |
| 6741 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 6742 | : blocks_in_loop_(info.GetBlocks()), |
| 6743 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 6744 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6745 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6746 | Advance(); |
| 6747 | } |
| 6748 | } |
| 6749 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6750 | bool Done() const { return index_ == blocks_.size(); } |
| 6751 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6752 | void Advance() { |
| 6753 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6754 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 6755 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6756 | break; |
| 6757 | } |
| 6758 | } |
| 6759 | } |
| 6760 | |
| 6761 | private: |
| 6762 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6763 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6764 | size_t index_; |
| 6765 | |
| 6766 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 6767 | }; |
| 6768 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6769 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6770 | if (constant->IsIntConstant()) { |
| 6771 | return constant->AsIntConstant()->GetValue(); |
| 6772 | } else if (constant->IsLongConstant()) { |
| 6773 | return constant->AsLongConstant()->GetValue(); |
| 6774 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6775 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6776 | return 0; |
| 6777 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6778 | } |
| 6779 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6780 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 6781 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } \ |
| 6782 | inline const H##type* HInstruction::As##type() const { \ |
| 6783 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 6784 | } \ |
| 6785 | inline H##type* HInstruction::As##type() { \ |
| 6786 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 6787 | } |
| 6788 | |
| 6789 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 6790 | #undef INSTRUCTION_TYPE_CHECK |
| 6791 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 6792 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 6793 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 6794 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 6795 | size_t number_of_new_blocks, |
| 6796 | size_t after) { |
| 6797 | DCHECK_LT(after, blocks->size()); |
| 6798 | size_t old_size = blocks->size(); |
| 6799 | size_t new_size = old_size + number_of_new_blocks; |
| 6800 | blocks->resize(new_size); |
| 6801 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 6802 | } |
| 6803 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6804 | } // namespace art |
| 6805 | |
| 6806 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |