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()), |
| 336 | osr_(osr) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 337 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 338 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 339 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 340 | // 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] | 341 | void InitializeInexactObjectRTI(VariableSizedHandleScope* handles); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 342 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 343 | ArenaAllocator* GetArena() const { return arena_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 344 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 345 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 346 | bool IsInSsaForm() const { return in_ssa_form_; } |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 347 | void SetInSsaForm() { in_ssa_form_ = true; } |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 348 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 349 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 350 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 351 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 352 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 353 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 354 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 355 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 356 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 357 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 358 | void ComputeDominanceInformation(); |
| 359 | void ClearDominanceInformation(); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 360 | void ClearLoopInformation(); |
| 361 | void FindBackEdges(ArenaBitVector* visited); |
| 362 | GraphAnalysisResult BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 363 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 364 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 365 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 366 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 367 | // 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] | 368 | // 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] | 369 | GraphAnalysisResult AnalyzeLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 370 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 371 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 372 | // order and loop information. |
| 373 | void ComputeTryBlockInformation(); |
| 374 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 375 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 376 | // Returns the instruction to replace the invoke expression or null if the |
| 377 | // invoke is for a void method. Note that the caller is responsible for replacing |
| 378 | // and removing the invoke instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 379 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 380 | |
Nicolas Geoffray | a1d8ddf | 2016-02-29 11:46:58 +0000 | [diff] [blame] | 381 | // Update the loop and try membership of `block`, which was spawned from `reference`. |
| 382 | // In case `reference` is a back edge, `replace_if_back_edge` notifies whether `block` |
| 383 | // should be the new back edge. |
| 384 | void UpdateLoopAndTryInformationOfNewBlock(HBasicBlock* block, |
| 385 | HBasicBlock* reference, |
| 386 | bool replace_if_back_edge); |
| 387 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 388 | // Need to add a couple of blocks to test if the loop body is entered and |
| 389 | // put deoptimization instructions, etc. |
| 390 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 391 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 392 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 393 | // other blocks and has no instructions or phis. |
| 394 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 395 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 396 | // Splits the edge between `block` and `successor` while preserving the |
| 397 | // indices in the predecessor/successor lists. If there are multiple edges |
| 398 | // between the blocks, the lowest indices are used. |
| 399 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 400 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 401 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 402 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 403 | void SimplifyLoop(HBasicBlock* header); |
| 404 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 405 | int32_t GetNextInstructionId() { |
| 406 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 407 | return current_instruction_id_++; |
| 408 | } |
| 409 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 410 | int32_t GetCurrentInstructionId() const { |
| 411 | return current_instruction_id_; |
| 412 | } |
| 413 | |
| 414 | void SetCurrentInstructionId(int32_t id) { |
David Brazdil | 3f52306 | 2016-02-29 16:53:33 +0000 | [diff] [blame] | 415 | DCHECK_GE(id, current_instruction_id_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 416 | current_instruction_id_ = id; |
| 417 | } |
| 418 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 419 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 420 | return maximum_number_of_out_vregs_; |
| 421 | } |
| 422 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 423 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 424 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 425 | } |
| 426 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 427 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 428 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 429 | } |
| 430 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 431 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 432 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 433 | } |
| 434 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 435 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 436 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 437 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 438 | } |
| 439 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 440 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 441 | number_of_vregs_ = number_of_vregs; |
| 442 | } |
| 443 | |
| 444 | uint16_t GetNumberOfVRegs() const { |
| 445 | return number_of_vregs_; |
| 446 | } |
| 447 | |
| 448 | void SetNumberOfInVRegs(uint16_t value) { |
| 449 | number_of_in_vregs_ = value; |
| 450 | } |
| 451 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 452 | uint16_t GetNumberOfInVRegs() const { |
| 453 | return number_of_in_vregs_; |
| 454 | } |
| 455 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 456 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 457 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 458 | return number_of_vregs_ - number_of_in_vregs_; |
| 459 | } |
| 460 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 461 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 462 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 463 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 464 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 465 | ArrayRef<HBasicBlock* const> GetReversePostOrderSkipEntryBlock() { |
| 466 | DCHECK(GetReversePostOrder()[0] == entry_block_); |
| 467 | return ArrayRef<HBasicBlock* const>(GetReversePostOrder()).SubArray(1); |
| 468 | } |
| 469 | |
| 470 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetPostOrder() const { |
| 471 | return ReverseRange(GetReversePostOrder()); |
| 472 | } |
| 473 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 474 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 475 | return linear_order_; |
| 476 | } |
| 477 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 478 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetLinearPostOrder() const { |
| 479 | return ReverseRange(GetLinearOrder()); |
| 480 | } |
| 481 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 482 | bool HasBoundsChecks() const { |
| 483 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 484 | } |
| 485 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 486 | void SetHasBoundsChecks(bool value) { |
| 487 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 488 | } |
| 489 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 490 | bool ShouldGenerateConstructorBarrier() const { |
| 491 | return should_generate_constructor_barrier_; |
| 492 | } |
| 493 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 494 | bool IsDebuggable() const { return debuggable_; } |
| 495 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 496 | // 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] | 497 | // already, it is created and inserted into the graph. This method is only for |
| 498 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 499 | 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] | 500 | |
| 501 | // TODO: This is problematic for the consistency of reference type propagation |
| 502 | // because it can be created anytime after the pass and thus it will be left |
| 503 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 504 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 505 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 506 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 507 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 508 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 509 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 510 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 511 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 512 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 513 | 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] | 514 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 515 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 516 | 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] | 517 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 518 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 519 | HCurrentMethod* GetCurrentMethod(); |
| 520 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 521 | const DexFile& GetDexFile() const { |
| 522 | return dex_file_; |
| 523 | } |
| 524 | |
| 525 | uint32_t GetMethodIdx() const { |
| 526 | return method_idx_; |
| 527 | } |
| 528 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 529 | InvokeType GetInvokeType() const { |
| 530 | return invoke_type_; |
| 531 | } |
| 532 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 533 | InstructionSet GetInstructionSet() const { |
| 534 | return instruction_set_; |
| 535 | } |
| 536 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 537 | bool IsCompilingOsr() const { return osr_; } |
| 538 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 539 | bool HasTryCatch() const { return has_try_catch_; } |
| 540 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 541 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 542 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 543 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 544 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 545 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 546 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 547 | |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 548 | // Returns an instruction with the opposite boolean value from 'cond'. |
| 549 | // The instruction has been inserted into the graph, either as a constant, or |
| 550 | // before cursor. |
| 551 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 552 | |
Nicolas Geoffray | 18401b7 | 2016-03-11 13:35:51 +0000 | [diff] [blame] | 553 | ReferenceTypeInfo GetInexactObjectRti() const { return inexact_object_rti_; } |
| 554 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 555 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 556 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 557 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 558 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 559 | template <class InstructionType, typename ValueType> |
| 560 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 561 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 562 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 563 | // Try to find an existing constant of the given value. |
| 564 | InstructionType* constant = nullptr; |
| 565 | auto cached_constant = cache->find(value); |
| 566 | if (cached_constant != cache->end()) { |
| 567 | constant = cached_constant->second; |
| 568 | } |
| 569 | |
| 570 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 571 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 572 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 573 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 574 | cache->Overwrite(value, constant); |
| 575 | InsertConstant(constant); |
| 576 | } |
| 577 | return constant; |
| 578 | } |
| 579 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 580 | void InsertConstant(HConstant* instruction); |
| 581 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 582 | // Cache a float constant into the graph. This method should only be |
| 583 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 584 | void CacheFloatConstant(HFloatConstant* constant); |
| 585 | |
| 586 | // See CacheFloatConstant comment. |
| 587 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 588 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 589 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 590 | |
| 591 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 592 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 593 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 594 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 595 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 596 | |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 597 | // List of blocks to perform a linear order tree traversal. Unlike the reverse |
| 598 | // post order, this order is not incrementally kept up-to-date. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 599 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 600 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 601 | HBasicBlock* entry_block_; |
| 602 | HBasicBlock* exit_block_; |
| 603 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 604 | // 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] | 605 | uint16_t maximum_number_of_out_vregs_; |
| 606 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 607 | // The number of virtual registers in this method. Contains the parameters. |
| 608 | uint16_t number_of_vregs_; |
| 609 | |
| 610 | // The number of virtual registers used by parameters of this method. |
| 611 | uint16_t number_of_in_vregs_; |
| 612 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 613 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 614 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 615 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 616 | // Has bounds checks. We can totally skip BCE if it's false. |
| 617 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 618 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 619 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 620 | // try/catch-related passes if false. |
| 621 | bool has_try_catch_; |
| 622 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 623 | // Flag whether there are any irreducible loops in the graph. |
| 624 | bool has_irreducible_loops_; |
| 625 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 626 | // Indicates whether the graph should be compiled in a way that |
| 627 | // ensures full debuggability. If false, we can apply more |
| 628 | // aggressive optimizations that may limit the level of debugging. |
| 629 | const bool debuggable_; |
| 630 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 631 | // 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] | 632 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 633 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 634 | // The dex file from which the method is from. |
| 635 | const DexFile& dex_file_; |
| 636 | |
| 637 | // The method index in the dex file. |
| 638 | const uint32_t method_idx_; |
| 639 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 640 | // If inlined, this encodes how the callee is being invoked. |
| 641 | const InvokeType invoke_type_; |
| 642 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 643 | // Whether the graph has been transformed to SSA form. Only used |
| 644 | // in debug mode to ensure we are not using properties only valid |
| 645 | // for non-SSA form (like the number of temporaries). |
| 646 | bool in_ssa_form_; |
| 647 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 648 | const bool should_generate_constructor_barrier_; |
| 649 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 650 | const InstructionSet instruction_set_; |
| 651 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 652 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 653 | HNullConstant* cached_null_constant_; |
| 654 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 655 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 656 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 657 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 658 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 659 | HCurrentMethod* cached_current_method_; |
| 660 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 661 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 662 | // for example for methods whose declaring class could not be resolved |
| 663 | // (such as when the superclass could not be found). |
| 664 | ArtMethod* art_method_; |
| 665 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 666 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 667 | // collection pointer to passes which may create NullConstant. |
| 668 | ReferenceTypeInfo inexact_object_rti_; |
| 669 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 670 | // Whether we are compiling this graph for on stack replacement: this will |
| 671 | // make all loops seen as irreducible and emit special stack maps to mark |
| 672 | // compiled code entries which the interpreter can directly jump to. |
| 673 | const bool osr_; |
| 674 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 675 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 676 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 677 | friend class HInliner; // For the reverse post order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 678 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 679 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 680 | }; |
| 681 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 682 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 683 | public: |
| 684 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 685 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 686 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 687 | irreducible_(false), |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 688 | contains_irreducible_loop_(false), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 689 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 690 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | f6a35de | 2016-03-21 12:01:50 +0000 | [diff] [blame] | 691 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true, kArenaAllocLoopInfoBackEdges) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 692 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 693 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 694 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 695 | bool IsIrreducible() const { return irreducible_; } |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 696 | bool ContainsIrreducibleLoop() const { return contains_irreducible_loop_; } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 697 | |
| 698 | void Dump(std::ostream& os); |
| 699 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 700 | HBasicBlock* GetHeader() const { |
| 701 | return header_; |
| 702 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 703 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 704 | void SetHeader(HBasicBlock* block) { |
| 705 | header_ = block; |
| 706 | } |
| 707 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 708 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 709 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 710 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 711 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 712 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 713 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 714 | } |
| 715 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 716 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 717 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 718 | } |
| 719 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 720 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 721 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 722 | } |
| 723 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 724 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 725 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 726 | } |
| 727 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 728 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 729 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 730 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 731 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 732 | } |
| 733 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 734 | // Returns the lifetime position of the back edge that has the |
| 735 | // greatest lifetime position. |
| 736 | size_t GetLifetimeEnd() const; |
| 737 | |
| 738 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 739 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 740 | } |
| 741 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 742 | // Finds blocks that are part of this loop. |
| 743 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 744 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 745 | // Returns whether this loop information contains `block`. |
| 746 | // Note that this loop information *must* be populated before entering this function. |
| 747 | bool Contains(const HBasicBlock& block) const; |
| 748 | |
| 749 | // Returns whether this loop information is an inner loop of `other`. |
| 750 | // Note that `other` *must* be populated before entering this function. |
| 751 | bool IsIn(const HLoopInformation& other) const; |
| 752 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 753 | // Returns true if instruction is not defined within this loop. |
| 754 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 755 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 756 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 757 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 758 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 759 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 760 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 761 | void ClearAllBlocks() { |
| 762 | blocks_.ClearAllBits(); |
| 763 | } |
| 764 | |
David Brazdil | 3f4a522 | 2016-05-06 12:46:21 +0100 | [diff] [blame] | 765 | bool HasBackEdgeNotDominatedByHeader() const; |
| 766 | |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 767 | bool IsPopulated() const { |
| 768 | return blocks_.GetHighestBitSet() != -1; |
| 769 | } |
| 770 | |
Anton Shamin | f89381f | 2016-05-16 16:44:13 +0600 | [diff] [blame] | 771 | bool DominatesAllBackEdges(HBasicBlock* block); |
| 772 | |
David Sehr | c757dec | 2016-11-04 15:48:34 -0700 | [diff] [blame] | 773 | bool HasExitEdge() const; |
| 774 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 775 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 776 | // Internal recursive implementation of `Populate`. |
| 777 | void PopulateRecursive(HBasicBlock* block); |
David Brazdil | c2e8af9 | 2016-04-05 17:15:19 +0100 | [diff] [blame] | 778 | void PopulateIrreducibleRecursive(HBasicBlock* block, ArenaBitVector* finalized); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 779 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 780 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 781 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 782 | bool irreducible_; |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 783 | bool contains_irreducible_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 784 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 785 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 786 | |
| 787 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 788 | }; |
| 789 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 790 | // Stores try/catch information for basic blocks. |
| 791 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 792 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 793 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 794 | public: |
| 795 | // Try block information constructor. |
| 796 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 797 | : try_entry_(&try_entry), |
| 798 | catch_dex_file_(nullptr), |
| 799 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 800 | DCHECK(try_entry_ != nullptr); |
| 801 | } |
| 802 | |
| 803 | // Catch block information constructor. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 804 | TryCatchInformation(dex::TypeIndex catch_type_index, const DexFile& dex_file) |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 805 | : try_entry_(nullptr), |
| 806 | catch_dex_file_(&dex_file), |
| 807 | catch_type_index_(catch_type_index) {} |
| 808 | |
| 809 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 810 | |
| 811 | const HTryBoundary& GetTryEntry() const { |
| 812 | DCHECK(IsTryBlock()); |
| 813 | return *try_entry_; |
| 814 | } |
| 815 | |
| 816 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 817 | |
| 818 | bool IsCatchAllTypeIndex() const { |
| 819 | DCHECK(IsCatchBlock()); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 820 | return !catch_type_index_.IsValid(); |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 821 | } |
| 822 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 823 | dex::TypeIndex GetCatchTypeIndex() const { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 824 | DCHECK(IsCatchBlock()); |
| 825 | return catch_type_index_; |
| 826 | } |
| 827 | |
| 828 | const DexFile& GetCatchDexFile() const { |
| 829 | DCHECK(IsCatchBlock()); |
| 830 | return *catch_dex_file_; |
| 831 | } |
| 832 | |
| 833 | private: |
| 834 | // One of possibly several TryBoundary instructions entering the block's try. |
| 835 | // Only set for try blocks. |
| 836 | const HTryBoundary* try_entry_; |
| 837 | |
| 838 | // Exception type information. Only set for catch blocks. |
| 839 | const DexFile* catch_dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 840 | const dex::TypeIndex catch_type_index_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 841 | }; |
| 842 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 843 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 844 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 845 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 846 | // A block in a method. Contains the list of instructions represented |
| 847 | // as a double linked list. Each block knows its predecessors and |
| 848 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 849 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 850 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 851 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 852 | explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 853 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 854 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 855 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 856 | loop_information_(nullptr), |
| 857 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 858 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 859 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 860 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 861 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 862 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 863 | try_catch_information_(nullptr) { |
| 864 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 865 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 866 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 867 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 868 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 869 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 870 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 871 | } |
| 872 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 873 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 874 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 875 | } |
| 876 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 877 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 878 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 879 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 880 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 881 | return ContainsElement(successors_, block, start_from); |
| 882 | } |
| 883 | |
| 884 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 885 | return dominated_blocks_; |
| 886 | } |
| 887 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 888 | bool IsEntryBlock() const { |
| 889 | return graph_->GetEntryBlock() == this; |
| 890 | } |
| 891 | |
| 892 | bool IsExitBlock() const { |
| 893 | return graph_->GetExitBlock() == this; |
| 894 | } |
| 895 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 896 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 897 | bool IsSingleTryBoundary() const; |
| 898 | |
| 899 | // Returns true if this block emits nothing but a jump. |
| 900 | bool IsSingleJump() const { |
| 901 | HLoopInformation* loop_info = GetLoopInformation(); |
| 902 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 903 | // Back edges generate a suspend check. |
| 904 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 905 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 906 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 907 | void AddBackEdge(HBasicBlock* back_edge) { |
| 908 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 909 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 910 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 911 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 912 | loop_information_->AddBackEdge(back_edge); |
| 913 | } |
| 914 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 915 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 916 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 917 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 918 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 919 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 920 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 921 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 922 | HBasicBlock* GetDominator() const { return dominator_; } |
| 923 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 924 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 925 | |
| 926 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 927 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 928 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 929 | |
| 930 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 931 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 932 | } |
| 933 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 934 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 935 | |
| 936 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 937 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 938 | } |
| 939 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 940 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 941 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 942 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 943 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 944 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 945 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 946 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 947 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 948 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 949 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 950 | successors_.push_back(block); |
| 951 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 952 | } |
| 953 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 954 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 955 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 956 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 957 | new_block->predecessors_.push_back(this); |
| 958 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 959 | } |
| 960 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 961 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 962 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 963 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 964 | new_block->successors_.push_back(this); |
| 965 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 966 | } |
| 967 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 968 | // Insert `this` between `predecessor` and `successor. This method |
| 969 | // preserves the indicies, and will update the first edge found between |
| 970 | // `predecessor` and `successor`. |
| 971 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 972 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 973 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 974 | successor->predecessors_[predecessor_index] = this; |
| 975 | predecessor->successors_[successor_index] = this; |
| 976 | successors_.push_back(successor); |
| 977 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 978 | } |
| 979 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 980 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 981 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 982 | } |
| 983 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 984 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 985 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 986 | } |
| 987 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 988 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 989 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 993 | predecessors_.push_back(block); |
| 994 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 995 | } |
| 996 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 997 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 998 | DCHECK_EQ(predecessors_.size(), 2u); |
| 999 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1000 | } |
| 1001 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1002 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1003 | DCHECK_EQ(successors_.size(), 2u); |
| 1004 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1005 | } |
| 1006 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1007 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1008 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1009 | } |
| 1010 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1011 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1012 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1013 | } |
| 1014 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1015 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1016 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1017 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1021 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1022 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | // Returns whether the first occurrence of `predecessor` in the list of |
| 1026 | // predecessors is at index `idx`. |
| 1027 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1028 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1029 | return GetPredecessorIndexOf(predecessor) == idx; |
| 1030 | } |
| 1031 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1032 | // Create a new block between this block and its predecessors. The new block |
| 1033 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 1034 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 1035 | // loop and try/catch information are not updated. |
| 1036 | HBasicBlock* CreateImmediateDominator(); |
| 1037 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1038 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 1039 | // created, latter block. Note that this method will add the block to the |
| 1040 | // graph, create a Goto at the end of the former block and will create an edge |
| 1041 | // 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] | 1042 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1043 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 1044 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1045 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1046 | // created block. Note that this method just updates raw block information, |
| 1047 | // like predecessors, successors, dominators, and instruction list. It does not |
| 1048 | // update the graph, reverse post order, loop information, nor make sure the |
| 1049 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1050 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 1051 | |
| 1052 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 1053 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1054 | |
| 1055 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1056 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1057 | // that this method does not update the graph, reverse post order, loop |
| 1058 | // information, nor make sure the blocks are consistent (for example ending |
| 1059 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1060 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1061 | |
| 1062 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1063 | // of `this` are moved to `other`. |
| 1064 | // Note that this method does not update the graph, reverse post order, loop |
| 1065 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1066 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1067 | void ReplaceWith(HBasicBlock* other); |
| 1068 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1069 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1070 | // order, links to predecessors, successors, dominators and deletes the block |
| 1071 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1072 | // predecessor of `other` and vice versa. |
| 1073 | void MergeWith(HBasicBlock* other); |
| 1074 | |
| 1075 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1076 | // removes it from all loops it is included in and eventually from the graph. |
| 1077 | // The block must not dominate any other block. Predecessors and successors |
| 1078 | // are safely updated. |
| 1079 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1080 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1081 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1082 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1083 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1084 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1085 | // Replace instruction `initial` with `replacement` within this block. |
| 1086 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1087 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1088 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1089 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1090 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1091 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1092 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1093 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1094 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1095 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1096 | |
| 1097 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1098 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1099 | } |
| 1100 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1101 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1102 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1103 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1104 | } |
| 1105 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1106 | bool IsFirstPredecessorBackEdge() const { |
| 1107 | DCHECK(IsLoopHeader()); |
| 1108 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1109 | } |
| 1110 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1111 | HLoopInformation* GetLoopInformation() const { |
| 1112 | return loop_information_; |
| 1113 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1114 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1115 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1116 | // 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] | 1117 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1118 | void SetInLoop(HLoopInformation* info) { |
| 1119 | if (IsLoopHeader()) { |
| 1120 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1121 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1122 | loop_information_ = info; |
| 1123 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1124 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1125 | // Note that a non loop header having a loop information means this loop information |
| 1126 | // has already been populated |
| 1127 | loop_information_ = info; |
| 1128 | } else { |
| 1129 | // Block is part of an inner loop. Do not update the loop information. |
| 1130 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1131 | // at this point, because this method is being called while populating `info`. |
| 1132 | } |
| 1133 | } |
| 1134 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1135 | // Raw update of the loop information. |
| 1136 | void SetLoopInformation(HLoopInformation* info) { |
| 1137 | loop_information_ = info; |
| 1138 | } |
| 1139 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1140 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1141 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1142 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1143 | |
| 1144 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1145 | try_catch_information_ = try_catch_information; |
| 1146 | } |
| 1147 | |
| 1148 | bool IsTryBlock() const { |
| 1149 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1150 | } |
| 1151 | |
| 1152 | bool IsCatchBlock() const { |
| 1153 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1154 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1155 | |
| 1156 | // Returns the try entry that this block's successors should have. They will |
| 1157 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1158 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1159 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1160 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1161 | bool HasThrowingInstructions() const; |
| 1162 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1163 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1164 | bool Dominates(HBasicBlock* block) const; |
| 1165 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1166 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1167 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1168 | |
| 1169 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1170 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1171 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1172 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1173 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1174 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1175 | bool HasSinglePhi() const; |
| 1176 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1177 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1178 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1179 | ArenaVector<HBasicBlock*> predecessors_; |
| 1180 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1181 | HInstructionList instructions_; |
| 1182 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1183 | HLoopInformation* loop_information_; |
| 1184 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1185 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1186 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1187 | // The dex program counter of the first instruction of this block. |
| 1188 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1189 | size_t lifetime_start_; |
| 1190 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1191 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1192 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1193 | friend class HGraph; |
| 1194 | friend class HInstruction; |
| 1195 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1196 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1197 | }; |
| 1198 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1199 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1200 | // from the innermost to the outermost. |
| 1201 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1202 | public: |
| 1203 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1204 | : current_(block.GetLoopInformation()) {} |
| 1205 | |
| 1206 | bool Done() const { return current_ == nullptr; } |
| 1207 | |
| 1208 | void Advance() { |
| 1209 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1210 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | HLoopInformation* Current() const { |
| 1214 | DCHECK(!Done()); |
| 1215 | return current_; |
| 1216 | } |
| 1217 | |
| 1218 | private: |
| 1219 | HLoopInformation* current_; |
| 1220 | |
| 1221 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1222 | }; |
| 1223 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1224 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1225 | M(Above, Condition) \ |
| 1226 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1227 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1228 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1229 | M(ArrayGet, Instruction) \ |
| 1230 | M(ArrayLength, Instruction) \ |
| 1231 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1232 | M(Below, Condition) \ |
| 1233 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1234 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1235 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1236 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1237 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1238 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1239 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1240 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1241 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1242 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1243 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1244 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1245 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1246 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1247 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1248 | M(Exit, Instruction) \ |
| 1249 | M(FloatConstant, Constant) \ |
| 1250 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1251 | M(GreaterThan, Condition) \ |
| 1252 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1253 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1254 | M(InstanceFieldGet, Instruction) \ |
| 1255 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1256 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1257 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1258 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1259 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1260 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1261 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1262 | M(LessThan, Condition) \ |
| 1263 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1264 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1265 | M(LoadException, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1266 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1267 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1268 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1269 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1270 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1271 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1272 | M(Neg, UnaryOperation) \ |
| 1273 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1274 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1275 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1276 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1277 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1278 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1279 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1280 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1281 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1282 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1283 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1284 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1285 | M(Return, Instruction) \ |
| 1286 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1287 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1288 | M(Shl, BinaryOperation) \ |
| 1289 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1290 | M(StaticFieldGet, Instruction) \ |
| 1291 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1292 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1293 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1294 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1295 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1296 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1297 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1298 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1299 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1300 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1301 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1302 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1303 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1304 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1305 | /* |
| 1306 | * Instructions, shared across several (not all) architectures. |
| 1307 | */ |
| 1308 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1309 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1310 | #else |
| 1311 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1312 | M(BitwiseNegatedRight, Instruction) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1313 | M(MultiplyAccumulate, Instruction) \ |
| 1314 | M(IntermediateAddress, Instruction) |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1315 | #endif |
| 1316 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1317 | #ifndef ART_ENABLE_CODEGEN_arm |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1318 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1319 | #else |
| 1320 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1321 | M(ArmDexCacheArraysBase, Instruction) |
| 1322 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1323 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1324 | #ifndef ART_ENABLE_CODEGEN_arm64 |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1325 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1326 | #else |
| 1327 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1328 | M(Arm64DataProcWithShifterOp, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1329 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1330 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1331 | #ifndef ART_ENABLE_CODEGEN_mips |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1332 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1333 | #else |
| 1334 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
| 1335 | M(MipsComputeBaseMethodAddress, Instruction) \ |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 1336 | M(MipsDexCacheArraysBase, Instruction) \ |
| 1337 | M(MipsPackedSwitch, Instruction) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1338 | #endif |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1339 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1340 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1341 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1342 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1343 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1344 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1345 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1346 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1347 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1348 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1349 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1350 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1351 | |
| 1352 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1353 | |
| 1354 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1355 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1356 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1357 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1358 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1359 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1360 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1361 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1362 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1363 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1364 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1365 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1366 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1367 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1368 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1369 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1370 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1371 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1372 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1373 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1374 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1375 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1376 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1377 | #undef FORWARD_DECLARATION |
| 1378 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1379 | #define DECLARE_INSTRUCTION(type) \ |
| 1380 | InstructionKind GetKindInternal() const OVERRIDE { return k##type; } \ |
| 1381 | const char* DebugName() const OVERRIDE { return #type; } \ |
| 1382 | bool InstructionTypeEquals(const HInstruction* other) const OVERRIDE { \ |
| 1383 | return other->Is##type(); \ |
| 1384 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1385 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1386 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1387 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
| 1388 | bool Is##type() const { return As##type() != nullptr; } \ |
| 1389 | const H##type* As##type() const { return this; } \ |
| 1390 | H##type* As##type() { return this; } |
| 1391 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1392 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1393 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1394 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1395 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1396 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1397 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1398 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1399 | // Hook for the IntrusiveForwardList<>. |
| 1400 | // TODO: Hide this better. |
| 1401 | IntrusiveForwardListHook hook; |
| 1402 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1403 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1404 | HUseListNode(T user, size_t index) |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1405 | : user_(user), index_(index) {} |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1406 | |
| 1407 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1408 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1409 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1410 | friend class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1411 | |
| 1412 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1413 | }; |
| 1414 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1415 | template <typename T> |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1416 | using HUseList = IntrusiveForwardList<HUseListNode<T>>; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1417 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1418 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1419 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1420 | // by the used instructions. |
| 1421 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1422 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1423 | public: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1424 | HUserRecord() : instruction_(nullptr), before_use_node_() {} |
| 1425 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), before_use_node_() {} |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1426 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1427 | HUserRecord(const HUserRecord<T>& old_record, typename HUseList<T>::iterator before_use_node) |
| 1428 | : HUserRecord(old_record.instruction_, before_use_node) {} |
| 1429 | HUserRecord(HInstruction* instruction, typename HUseList<T>::iterator before_use_node) |
| 1430 | : instruction_(instruction), before_use_node_(before_use_node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1431 | DCHECK(instruction_ != nullptr); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | HInstruction* GetInstruction() const { return instruction_; } |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1435 | typename HUseList<T>::iterator GetBeforeUseNode() const { return before_use_node_; } |
| 1436 | typename HUseList<T>::iterator GetUseNode() const { return ++GetBeforeUseNode(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1437 | |
| 1438 | private: |
| 1439 | // Instruction used by the user. |
| 1440 | HInstruction* instruction_; |
| 1441 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1442 | // Iterator before the corresponding entry in the use list kept by 'instruction_'. |
| 1443 | typename HUseList<T>::iterator before_use_node_; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1444 | }; |
| 1445 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1446 | // Helper class that extracts the input instruction from HUserRecord<HInstruction*>. |
| 1447 | // This is used for HInstruction::GetInputs() to return a container wrapper providing |
| 1448 | // HInstruction* values even though the underlying container has HUserRecord<>s. |
| 1449 | struct HInputExtractor { |
| 1450 | HInstruction* operator()(HUserRecord<HInstruction*>& record) const { |
| 1451 | return record.GetInstruction(); |
| 1452 | } |
| 1453 | const HInstruction* operator()(const HUserRecord<HInstruction*>& record) const { |
| 1454 | return record.GetInstruction(); |
| 1455 | } |
| 1456 | }; |
| 1457 | |
| 1458 | using HInputsRef = TransformArrayRef<HUserRecord<HInstruction*>, HInputExtractor>; |
| 1459 | using HConstInputsRef = TransformArrayRef<const HUserRecord<HInstruction*>, HInputExtractor>; |
| 1460 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1461 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1462 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1463 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1464 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1465 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1466 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1467 | * modify the value of a reference field read [although it may modify the |
| 1468 | * reference fetch prior to reading the field, which is represented by its own |
| 1469 | * write/read dependence]). The analysis makes conservative points-to |
| 1470 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1471 | * the same, and any reference read depends on any reference read without |
| 1472 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1473 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1474 | * The internal representation uses 38-bit and is described in the table below. |
| 1475 | * The first line indicates the side effect, and for field/array accesses the |
| 1476 | * second line indicates the type of the access (in the order of the |
| 1477 | * Primitive::Type enum). |
| 1478 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1479 | * vertically). |
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 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1482 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1483 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1484 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1485 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1486 | * |
| 1487 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1488 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1489 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1490 | class SideEffects : public ValueObject { |
| 1491 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1492 | SideEffects() : flags_(0) {} |
| 1493 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1494 | static SideEffects None() { |
| 1495 | return SideEffects(0); |
| 1496 | } |
| 1497 | |
| 1498 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1499 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1500 | } |
| 1501 | |
| 1502 | static SideEffects AllChanges() { |
| 1503 | return SideEffects(kAllChangeBits); |
| 1504 | } |
| 1505 | |
| 1506 | static SideEffects AllDependencies() { |
| 1507 | return SideEffects(kAllDependOnBits); |
| 1508 | } |
| 1509 | |
| 1510 | static SideEffects AllExceptGCDependency() { |
| 1511 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1512 | } |
| 1513 | |
| 1514 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1515 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1516 | } |
| 1517 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1518 | static SideEffects AllWrites() { |
| 1519 | return SideEffects(kAllWrites); |
| 1520 | } |
| 1521 | |
| 1522 | static SideEffects AllReads() { |
| 1523 | return SideEffects(kAllReads); |
| 1524 | } |
| 1525 | |
| 1526 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1527 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1528 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1529 | : SideEffects(TypeFlag(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1530 | } |
| 1531 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1532 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1533 | return SideEffects(TypeFlag(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1534 | } |
| 1535 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1536 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1537 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1538 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1539 | : SideEffects(TypeFlag(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1543 | return SideEffects(TypeFlag(type, kArrayReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1544 | } |
| 1545 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1546 | static SideEffects CanTriggerGC() { |
| 1547 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1548 | } |
| 1549 | |
| 1550 | static SideEffects DependsOnGC() { |
| 1551 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1552 | } |
| 1553 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1554 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1555 | SideEffects Union(SideEffects other) const { |
| 1556 | return SideEffects(flags_ | other.flags_); |
| 1557 | } |
| 1558 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1559 | SideEffects Exclusion(SideEffects other) const { |
| 1560 | return SideEffects(flags_ & ~other.flags_); |
| 1561 | } |
| 1562 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1563 | void Add(SideEffects other) { |
| 1564 | flags_ |= other.flags_; |
| 1565 | } |
| 1566 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1567 | bool Includes(SideEffects other) const { |
| 1568 | return (other.flags_ & flags_) == other.flags_; |
| 1569 | } |
| 1570 | |
| 1571 | bool HasSideEffects() const { |
| 1572 | return (flags_ & kAllChangeBits); |
| 1573 | } |
| 1574 | |
| 1575 | bool HasDependencies() const { |
| 1576 | return (flags_ & kAllDependOnBits); |
| 1577 | } |
| 1578 | |
| 1579 | // Returns true if there are no side effects or dependencies. |
| 1580 | bool DoesNothing() const { |
| 1581 | return flags_ == 0; |
| 1582 | } |
| 1583 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1584 | // Returns true if something is written. |
| 1585 | bool DoesAnyWrite() const { |
| 1586 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1587 | } |
| 1588 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1589 | // Returns true if something is read. |
| 1590 | bool DoesAnyRead() const { |
| 1591 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1592 | } |
| 1593 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1594 | // Returns true if potentially everything is written and read |
| 1595 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1596 | bool DoesAllReadWrite() const { |
| 1597 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1598 | } |
| 1599 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1600 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1601 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1602 | } |
| 1603 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1604 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1605 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1606 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1607 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1608 | } |
| 1609 | |
| 1610 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1611 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1612 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1613 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1614 | for (int s = kLastBit; s >= 0; s--) { |
| 1615 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1616 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1617 | // This is a bit for the GC side effect. |
| 1618 | if (current_bit_is_set) { |
| 1619 | flags += "GC"; |
| 1620 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1621 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1622 | } else { |
| 1623 | // This is a bit for the array/field analysis. |
| 1624 | // The underscore character stands for the 'can trigger GC' bit. |
| 1625 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1626 | if (current_bit_is_set) { |
| 1627 | flags += kDebug[s]; |
| 1628 | } |
| 1629 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1630 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1631 | flags += "|"; |
| 1632 | } |
| 1633 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1634 | } |
| 1635 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1636 | } |
| 1637 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1638 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1639 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1640 | private: |
| 1641 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1642 | |
| 1643 | static constexpr int kFieldWriteOffset = 0; |
| 1644 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1645 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1646 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1647 | |
| 1648 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1649 | |
| 1650 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1651 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1652 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1653 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1654 | |
| 1655 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1656 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1657 | |
| 1658 | // Aliases. |
| 1659 | |
| 1660 | static_assert(kChangeBits == kDependOnBits, |
| 1661 | "the 'change' bits should match the 'depend on' bits."); |
| 1662 | |
| 1663 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1664 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1665 | static constexpr uint64_t kAllWrites = |
| 1666 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1667 | static constexpr uint64_t kAllReads = |
| 1668 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1669 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1670 | // Translates type to bit flag. |
| 1671 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1672 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1673 | const uint64_t one = 1; |
| 1674 | const int shift = type; // 0-based consecutive enum |
| 1675 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1676 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1677 | return one << (type + offset); |
| 1678 | } |
| 1679 | |
| 1680 | // Private constructor on direct flags value. |
| 1681 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1682 | |
| 1683 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1684 | }; |
| 1685 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1686 | // 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] | 1687 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1688 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1689 | HEnvironment(ArenaAllocator* arena, |
| 1690 | size_t number_of_vregs, |
| 1691 | const DexFile& dex_file, |
| 1692 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1693 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1694 | InvokeType invoke_type, |
| 1695 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1696 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1697 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1698 | parent_(nullptr), |
| 1699 | dex_file_(dex_file), |
| 1700 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1701 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1702 | invoke_type_(invoke_type), |
| 1703 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1704 | } |
| 1705 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1706 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1707 | : HEnvironment(arena, |
| 1708 | to_copy.Size(), |
| 1709 | to_copy.GetDexFile(), |
| 1710 | to_copy.GetMethodIdx(), |
| 1711 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1712 | to_copy.GetInvokeType(), |
| 1713 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1714 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1715 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1716 | if (parent_ != nullptr) { |
| 1717 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1718 | } else { |
| 1719 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1720 | parent_->CopyFrom(parent); |
| 1721 | if (parent->GetParent() != nullptr) { |
| 1722 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1723 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1724 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1725 | } |
| 1726 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1727 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1728 | void CopyFrom(HEnvironment* environment); |
| 1729 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1730 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1731 | // input to the loop phi instead. This is for inserting instructions that |
| 1732 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1733 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1734 | |
| 1735 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1736 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1740 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1741 | } |
| 1742 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1743 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1744 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1745 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1746 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1747 | HEnvironment* GetParent() const { return parent_; } |
| 1748 | |
| 1749 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1750 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1754 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | uint32_t GetDexPc() const { |
| 1758 | return dex_pc_; |
| 1759 | } |
| 1760 | |
| 1761 | uint32_t GetMethodIdx() const { |
| 1762 | return method_idx_; |
| 1763 | } |
| 1764 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1765 | InvokeType GetInvokeType() const { |
| 1766 | return invoke_type_; |
| 1767 | } |
| 1768 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1769 | const DexFile& GetDexFile() const { |
| 1770 | return dex_file_; |
| 1771 | } |
| 1772 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1773 | HInstruction* GetHolder() const { |
| 1774 | return holder_; |
| 1775 | } |
| 1776 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1777 | |
| 1778 | bool IsFromInlinedInvoke() const { |
| 1779 | return GetParent() != nullptr; |
| 1780 | } |
| 1781 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1782 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1783 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1784 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1785 | HEnvironment* parent_; |
| 1786 | const DexFile& dex_file_; |
| 1787 | const uint32_t method_idx_; |
| 1788 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1789 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1790 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1791 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1792 | HInstruction* const holder_; |
| 1793 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1794 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1795 | |
| 1796 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1797 | }; |
| 1798 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1799 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1800 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1801 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1802 | : previous_(nullptr), |
| 1803 | next_(nullptr), |
| 1804 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1805 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1806 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1807 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1808 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1809 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1810 | locations_(nullptr), |
| 1811 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1812 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1813 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1814 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
| 1815 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 1816 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1817 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1818 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1819 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1820 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1821 | enum InstructionKind { |
| 1822 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1823 | }; |
| 1824 | #undef DECLARE_KIND |
| 1825 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1826 | HInstruction* GetNext() const { return next_; } |
| 1827 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1828 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1829 | HInstruction* GetNextDisregardingMoves() const; |
| 1830 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1831 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1832 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1833 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1834 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1835 | bool IsInBlock() const { return block_ != nullptr; } |
| 1836 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1837 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 1838 | bool IsIrreducibleLoopHeaderPhi() const { |
| 1839 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 1840 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1841 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1842 | virtual ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() = 0; |
| 1843 | |
| 1844 | ArrayRef<const HUserRecord<HInstruction*>> GetInputRecords() const { |
| 1845 | // One virtual method is enough, just const_cast<> and then re-add the const. |
| 1846 | return ArrayRef<const HUserRecord<HInstruction*>>( |
| 1847 | const_cast<HInstruction*>(this)->GetInputRecords()); |
| 1848 | } |
| 1849 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1850 | HInputsRef GetInputs() { |
| 1851 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1852 | } |
| 1853 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1854 | HConstInputsRef GetInputs() const { |
| 1855 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1856 | } |
| 1857 | |
| 1858 | size_t InputCount() const { return GetInputRecords().size(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1859 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1860 | |
Aart Bik | 2767f4b | 2016-10-28 15:03:53 -0700 | [diff] [blame] | 1861 | bool HasInput(HInstruction* input) const { |
| 1862 | for (const HInstruction* i : GetInputs()) { |
| 1863 | if (i == input) { |
| 1864 | return true; |
| 1865 | } |
| 1866 | } |
| 1867 | return false; |
| 1868 | } |
| 1869 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1870 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1871 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1872 | } |
| 1873 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1874 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1875 | virtual const char* DebugName() const = 0; |
| 1876 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1877 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
| 1878 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1879 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1880 | |
| 1881 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1882 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1883 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1884 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1885 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1886 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1887 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1888 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1889 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1890 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1891 | // Does not apply for all instructions, but having this at top level greatly |
| 1892 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1893 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1894 | virtual bool CanBeNull() const { |
| 1895 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1896 | return true; |
| 1897 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1898 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1899 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1900 | return false; |
| 1901 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1902 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 1903 | virtual bool IsActualObject() const { |
| 1904 | return GetType() == Primitive::kPrimNot; |
| 1905 | } |
| 1906 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1907 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1908 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1909 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1910 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1911 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 1912 | GetPackedFlag<kFlagReferenceTypeIsExact>()); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1913 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1914 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1915 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1916 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1917 | // Note: fixup_end remains valid across push_front(). |
| 1918 | auto fixup_end = uses_.empty() ? uses_.begin() : ++uses_.begin(); |
| 1919 | HUseListNode<HInstruction*>* new_node = |
| 1920 | new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HInstruction*>(user, index); |
| 1921 | uses_.push_front(*new_node); |
| 1922 | FixUpUserRecordsAfterUseInsertion(fixup_end); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1923 | } |
| 1924 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1925 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1926 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1927 | // Note: env_fixup_end remains valid across push_front(). |
| 1928 | auto env_fixup_end = env_uses_.empty() ? env_uses_.begin() : ++env_uses_.begin(); |
| 1929 | HUseListNode<HEnvironment*>* new_node = |
| 1930 | new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HEnvironment*>(user, index); |
| 1931 | env_uses_.push_front(*new_node); |
| 1932 | FixUpUserRecordsAfterEnvUseInsertion(env_fixup_end); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1933 | } |
| 1934 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1935 | void RemoveAsUserOfInput(size_t input) { |
| 1936 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1937 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 1938 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 1939 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1940 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1941 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1942 | void RemoveAsUserOfAllInputs() { |
| 1943 | for (const HUserRecord<HInstruction*>& input_use : GetInputRecords()) { |
| 1944 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 1945 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 1946 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
| 1947 | } |
| 1948 | } |
| 1949 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1950 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1951 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1952 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1953 | bool HasUses() const { return !uses_.empty() || !env_uses_.empty(); } |
| 1954 | bool HasEnvironmentUses() const { return !env_uses_.empty(); } |
| 1955 | bool HasNonEnvironmentUses() const { return !uses_.empty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1956 | bool HasOnlyOneNonEnvironmentUse() const { |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1957 | return !HasEnvironmentUses() && GetUses().HasExactlyOneElement(); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1958 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1959 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 1960 | bool IsRemovable() const { |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 1961 | return |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 1962 | !DoesAnyWrite() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 1963 | !CanThrow() && |
| 1964 | !IsSuspendCheck() && |
| 1965 | !IsControlFlow() && |
| 1966 | !IsNativeDebugInfo() && |
| 1967 | !IsParameterValue() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 1968 | // If we added an explicit barrier then we should keep it. |
| 1969 | !IsMemoryBarrier(); |
| 1970 | } |
| 1971 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 1972 | bool IsDeadAndRemovable() const { |
| 1973 | return IsRemovable() && !HasUses(); |
| 1974 | } |
| 1975 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1976 | // Does this instruction strictly dominate `other_instruction`? |
| 1977 | // Returns false if this instruction and `other_instruction` are the same. |
| 1978 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1979 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1980 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1981 | int GetId() const { return id_; } |
| 1982 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1983 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1984 | int GetSsaIndex() const { return ssa_index_; } |
| 1985 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 1986 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 1987 | |
| 1988 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 1989 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1990 | // Set the `environment_` field. Raw because this method does not |
| 1991 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1992 | void SetRawEnvironment(HEnvironment* environment) { |
| 1993 | DCHECK(environment_ == nullptr); |
| 1994 | DCHECK_EQ(environment->GetHolder(), this); |
| 1995 | environment_ = environment; |
| 1996 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1997 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 1998 | void InsertRawEnvironment(HEnvironment* environment) { |
| 1999 | DCHECK(environment_ != nullptr); |
| 2000 | DCHECK_EQ(environment->GetHolder(), this); |
| 2001 | DCHECK(environment->GetParent() == nullptr); |
| 2002 | environment->parent_ = environment_; |
| 2003 | environment_ = environment; |
| 2004 | } |
| 2005 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2006 | void RemoveEnvironment(); |
| 2007 | |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2008 | // Set the environment of this instruction, copying it from `environment`. While |
| 2009 | // copying, the uses lists are being updated. |
| 2010 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2011 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2012 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2013 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2014 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2015 | if (environment->GetParent() != nullptr) { |
| 2016 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2017 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2018 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2019 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2020 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 2021 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2022 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2023 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2024 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2025 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2026 | if (environment->GetParent() != nullptr) { |
| 2027 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2028 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2029 | } |
| 2030 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2031 | // Returns the number of entries in the environment. Typically, that is the |
| 2032 | // number of dex registers in a method. It could be more in case of inlining. |
| 2033 | size_t EnvironmentSize() const; |
| 2034 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2035 | LocationSummary* GetLocations() const { return locations_; } |
| 2036 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2037 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2038 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2039 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2040 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2041 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 2042 | // uses of this instruction by `other` are *not* updated. |
| 2043 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 2044 | ReplaceWith(other); |
| 2045 | other->ReplaceInput(this, use_index); |
| 2046 | } |
| 2047 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 2048 | // Move `this` instruction before `cursor`. |
| 2049 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2050 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2051 | // Move `this` before its first user and out of any loops. If there is no |
| 2052 | // out-of-loop user that dominates all other users, move the instruction |
| 2053 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2054 | // |
| 2055 | // This can be used only on non-throwing instructions with no side effects that |
| 2056 | // have at least one use but no environment uses. |
| 2057 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2058 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2059 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2060 | bool Is##type() const; \ |
| 2061 | const H##type* As##type() const; \ |
| 2062 | H##type* As##type(); |
| 2063 | |
| 2064 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2065 | #undef INSTRUCTION_TYPE_CHECK |
| 2066 | |
| 2067 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2068 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 2069 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2070 | virtual H##type* As##type() { return nullptr; } |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2071 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2072 | #undef INSTRUCTION_TYPE_CHECK |
| 2073 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2074 | // Returns whether the instruction can be moved within the graph. |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 2075 | // TODO: this method is used by LICM and GVN with possibly different |
| 2076 | // meanings? split and rename? |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2077 | virtual bool CanBeMoved() const { return false; } |
| 2078 | |
| 2079 | // Returns whether the two instructions are of the same kind. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2080 | virtual bool InstructionTypeEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2081 | return false; |
| 2082 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2083 | |
| 2084 | // Returns whether any data encoded in the two instructions is equal. |
| 2085 | // This method does not look at the inputs. Both instructions must be |
| 2086 | // of the same type, otherwise the method has undefined behavior. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2087 | virtual bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2088 | return false; |
| 2089 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2090 | |
| 2091 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2092 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2093 | // 2) Their inputs are identical. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2094 | bool Equals(const HInstruction* other) const; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2095 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2096 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2097 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2098 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2099 | // apply the strong requirement for virtual functions, preventing optimizations. |
| 2100 | InstructionKind GetKind() const PURE; |
| 2101 | virtual InstructionKind GetKindInternal() const = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2102 | |
| 2103 | virtual size_t ComputeHashCode() const { |
| 2104 | size_t result = GetKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2105 | for (const HInstruction* input : GetInputs()) { |
| 2106 | result = (result * 31) + input->GetId(); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2107 | } |
| 2108 | return result; |
| 2109 | } |
| 2110 | |
| 2111 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2112 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2113 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2114 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2115 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2116 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2117 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2118 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2119 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2120 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2121 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2122 | |
| 2123 | // Returns whether the code generation of the instruction will require to have access |
| 2124 | // to the current method. Such instructions are: |
| 2125 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2126 | // 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] | 2127 | // (2): HCurrentMethod, potentially used by HInvokeStaticOrDirect, HLoadString, or HLoadClass |
| 2128 | // to access the dex cache. |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2129 | bool NeedsCurrentMethod() const { |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2130 | return NeedsEnvironment() || IsCurrentMethod(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2131 | } |
| 2132 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2133 | // Returns whether the code generation of the instruction will require to have access |
| 2134 | // to the dex cache of the current method's declaring class via the current method. |
| 2135 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2136 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2137 | // Does this instruction have any use in an environment before |
| 2138 | // control flow hits 'other'? |
| 2139 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2140 | |
| 2141 | // Remove all references to environment uses of this instruction. |
| 2142 | // The caller must ensure that this is safe to do. |
| 2143 | void RemoveEnvironmentUsers(); |
| 2144 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2145 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2146 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2147 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2148 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2149 | // If set, the machine code for this instruction is assumed to be generated by |
| 2150 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2151 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2152 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
| 2153 | static constexpr size_t kNumberOfGenericPackedBits = kFlagReferenceTypeIsExact + 1; |
| 2154 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2155 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2156 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const { |
| 2157 | return GetInputRecords()[i]; |
| 2158 | } |
| 2159 | |
| 2160 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) { |
| 2161 | ArrayRef<HUserRecord<HInstruction*>> input_records = GetInputRecords(); |
| 2162 | input_records[index] = input; |
| 2163 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2164 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2165 | uint32_t GetPackedFields() const { |
| 2166 | return packed_fields_; |
| 2167 | } |
| 2168 | |
| 2169 | template <size_t flag> |
| 2170 | bool GetPackedFlag() const { |
| 2171 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2172 | } |
| 2173 | |
| 2174 | template <size_t flag> |
| 2175 | void SetPackedFlag(bool value = true) { |
| 2176 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2177 | } |
| 2178 | |
| 2179 | template <typename BitFieldType> |
| 2180 | typename BitFieldType::value_type GetPackedField() const { |
| 2181 | return BitFieldType::Decode(packed_fields_); |
| 2182 | } |
| 2183 | |
| 2184 | template <typename BitFieldType> |
| 2185 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2186 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2187 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2188 | } |
| 2189 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2190 | private: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2191 | void FixUpUserRecordsAfterUseInsertion(HUseList<HInstruction*>::iterator fixup_end) { |
| 2192 | auto before_use_node = uses_.before_begin(); |
| 2193 | for (auto use_node = uses_.begin(); use_node != fixup_end; ++use_node) { |
| 2194 | HInstruction* user = use_node->GetUser(); |
| 2195 | size_t input_index = use_node->GetIndex(); |
| 2196 | user->SetRawInputRecordAt(input_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2197 | before_use_node = use_node; |
| 2198 | } |
| 2199 | } |
| 2200 | |
| 2201 | void FixUpUserRecordsAfterUseRemoval(HUseList<HInstruction*>::iterator before_use_node) { |
| 2202 | auto next = ++HUseList<HInstruction*>::iterator(before_use_node); |
| 2203 | if (next != uses_.end()) { |
| 2204 | HInstruction* next_user = next->GetUser(); |
| 2205 | size_t next_index = next->GetIndex(); |
| 2206 | DCHECK(next_user->InputRecordAt(next_index).GetInstruction() == this); |
| 2207 | next_user->SetRawInputRecordAt(next_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2208 | } |
| 2209 | } |
| 2210 | |
| 2211 | void FixUpUserRecordsAfterEnvUseInsertion(HUseList<HEnvironment*>::iterator env_fixup_end) { |
| 2212 | auto before_env_use_node = env_uses_.before_begin(); |
| 2213 | for (auto env_use_node = env_uses_.begin(); env_use_node != env_fixup_end; ++env_use_node) { |
| 2214 | HEnvironment* user = env_use_node->GetUser(); |
| 2215 | size_t input_index = env_use_node->GetIndex(); |
| 2216 | user->vregs_[input_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2217 | before_env_use_node = env_use_node; |
| 2218 | } |
| 2219 | } |
| 2220 | |
| 2221 | void FixUpUserRecordsAfterEnvUseRemoval(HUseList<HEnvironment*>::iterator before_env_use_node) { |
| 2222 | auto next = ++HUseList<HEnvironment*>::iterator(before_env_use_node); |
| 2223 | if (next != env_uses_.end()) { |
| 2224 | HEnvironment* next_user = next->GetUser(); |
| 2225 | size_t next_index = next->GetIndex(); |
| 2226 | DCHECK(next_user->vregs_[next_index].GetInstruction() == this); |
| 2227 | next_user->vregs_[next_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2228 | } |
| 2229 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2230 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2231 | HInstruction* previous_; |
| 2232 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2233 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2234 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2235 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2236 | // An instruction gets an id when it is added to the graph. |
| 2237 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2238 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2239 | int id_; |
| 2240 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2241 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2242 | int ssa_index_; |
| 2243 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2244 | // Packed fields. |
| 2245 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2246 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2247 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2248 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2249 | |
| 2250 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2251 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2252 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2253 | // The environment associated with this instruction. Not null if the instruction |
| 2254 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2255 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2256 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2257 | // Set by the code generator. |
| 2258 | LocationSummary* locations_; |
| 2259 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2260 | // Set by the liveness analysis. |
| 2261 | LiveInterval* live_interval_; |
| 2262 | |
| 2263 | // Set by the liveness analysis, this is the position in a linear |
| 2264 | // order of blocks where this instruction's live interval start. |
| 2265 | size_t lifetime_position_; |
| 2266 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2267 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2268 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2269 | // The reference handle part of the reference type info. |
| 2270 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2271 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2272 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2273 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2274 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2275 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2276 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2277 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2278 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2279 | |
| 2280 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2281 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2282 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2283 | |
| 2284 | class HInstructionIterator : public ValueObject { |
| 2285 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2286 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2287 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2288 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2289 | } |
| 2290 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2291 | bool Done() const { return instruction_ == nullptr; } |
| 2292 | HInstruction* Current() const { return instruction_; } |
| 2293 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2294 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2295 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2296 | } |
| 2297 | |
| 2298 | private: |
| 2299 | HInstruction* instruction_; |
| 2300 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2301 | |
| 2302 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2303 | }; |
| 2304 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2305 | class HBackwardInstructionIterator : public ValueObject { |
| 2306 | public: |
| 2307 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2308 | : instruction_(instructions.last_instruction_) { |
| 2309 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2310 | } |
| 2311 | |
| 2312 | bool Done() const { return instruction_ == nullptr; } |
| 2313 | HInstruction* Current() const { return instruction_; } |
| 2314 | void Advance() { |
| 2315 | instruction_ = next_; |
| 2316 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2317 | } |
| 2318 | |
| 2319 | private: |
| 2320 | HInstruction* instruction_; |
| 2321 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2322 | |
| 2323 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2324 | }; |
| 2325 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2326 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2327 | class HTemplateInstruction: public HInstruction { |
| 2328 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2329 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2330 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2331 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2332 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2333 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2334 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2335 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2336 | } |
| 2337 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2338 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2339 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2340 | |
| 2341 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2342 | }; |
| 2343 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2344 | // HTemplateInstruction specialization for N=0. |
| 2345 | template<> |
| 2346 | class HTemplateInstruction<0>: public HInstruction { |
| 2347 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2348 | explicit HTemplateInstruction<0>(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) {} |
| 2350 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2351 | virtual ~HTemplateInstruction() {} |
| 2352 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2353 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2354 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2355 | return ArrayRef<HUserRecord<HInstruction*>>(); |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2356 | } |
| 2357 | |
| 2358 | private: |
| 2359 | friend class SsaBuilder; |
| 2360 | }; |
| 2361 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2362 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2363 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2364 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2365 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2366 | : HTemplateInstruction<N>(side_effects, dex_pc) { |
| 2367 | this->template SetPackedField<TypeField>(type); |
| 2368 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2369 | virtual ~HExpression() {} |
| 2370 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2371 | Primitive::Type GetType() const OVERRIDE { |
| 2372 | return TypeField::Decode(this->GetPackedFields()); |
| 2373 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2374 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2375 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2376 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2377 | static constexpr size_t kFieldTypeSize = |
| 2378 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2379 | static constexpr size_t kNumberOfExpressionPackedBits = kFieldType + kFieldTypeSize; |
| 2380 | static_assert(kNumberOfExpressionPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 2381 | "Too many packed fields."); |
| 2382 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2383 | }; |
| 2384 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2385 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2386 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2387 | class HReturnVoid FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2388 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2389 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2390 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2391 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2392 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2393 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2394 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2395 | |
| 2396 | private: |
| 2397 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2398 | }; |
| 2399 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2400 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2401 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2402 | class HReturn FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2403 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2404 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2405 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2406 | SetRawInputAt(0, value); |
| 2407 | } |
| 2408 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2409 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2410 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2411 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2412 | |
| 2413 | private: |
| 2414 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2415 | }; |
| 2416 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2417 | class HPhi FINAL : public HInstruction { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2418 | public: |
| 2419 | HPhi(ArenaAllocator* arena, |
| 2420 | uint32_t reg_number, |
| 2421 | size_t number_of_inputs, |
| 2422 | Primitive::Type type, |
| 2423 | uint32_t dex_pc = kNoDexPc) |
| 2424 | : HInstruction(SideEffects::None(), dex_pc), |
| 2425 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
| 2426 | reg_number_(reg_number) { |
| 2427 | SetPackedField<TypeField>(ToPhiType(type)); |
| 2428 | DCHECK_NE(GetType(), Primitive::kPrimVoid); |
| 2429 | // Phis are constructed live and marked dead if conflicting or unused. |
| 2430 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 2431 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 2432 | SetPackedFlag<kFlagIsLive>(true); |
| 2433 | SetPackedFlag<kFlagCanBeNull>(true); |
| 2434 | } |
| 2435 | |
| 2436 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 2437 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 2438 | return Primitive::PrimitiveKind(type); |
| 2439 | } |
| 2440 | |
| 2441 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 2442 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2443 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2444 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2445 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 2446 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2447 | |
| 2448 | void AddInput(HInstruction* input); |
| 2449 | void RemoveInputAt(size_t index); |
| 2450 | |
| 2451 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<TypeField>(); } |
| 2452 | void SetType(Primitive::Type new_type) { |
| 2453 | // Make sure that only valid type changes occur. The following are allowed: |
| 2454 | // (1) int -> float/ref (primitive type propagation), |
| 2455 | // (2) long -> double (primitive type propagation). |
| 2456 | DCHECK(GetType() == new_type || |
| 2457 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimFloat) || |
| 2458 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimNot) || |
| 2459 | (GetType() == Primitive::kPrimLong && new_type == Primitive::kPrimDouble)); |
| 2460 | SetPackedField<TypeField>(new_type); |
| 2461 | } |
| 2462 | |
| 2463 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 2464 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
| 2465 | |
| 2466 | uint32_t GetRegNumber() const { return reg_number_; } |
| 2467 | |
| 2468 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 2469 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 2470 | bool IsDead() const { return !IsLive(); } |
| 2471 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
| 2472 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2473 | bool IsVRegEquivalentOf(const HInstruction* other) const { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2474 | return other != nullptr |
| 2475 | && other->IsPhi() |
| 2476 | && other->AsPhi()->GetBlock() == GetBlock() |
| 2477 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 2478 | } |
| 2479 | |
| 2480 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 2481 | // An equivalent phi is a phi having the same dex register and type. |
| 2482 | // It assumes that phis with the same dex register are adjacent. |
| 2483 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 2484 | HInstruction* next = GetNext(); |
| 2485 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 2486 | if (next->GetType() == GetType()) { |
| 2487 | return next->AsPhi(); |
| 2488 | } |
| 2489 | next = next->GetNext(); |
| 2490 | } |
| 2491 | return nullptr; |
| 2492 | } |
| 2493 | |
| 2494 | DECLARE_INSTRUCTION(Phi); |
| 2495 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2496 | private: |
| 2497 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2498 | static constexpr size_t kFieldTypeSize = |
| 2499 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2500 | static constexpr size_t kFlagIsLive = kFieldType + kFieldTypeSize; |
| 2501 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 2502 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 2503 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 2504 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
| 2505 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2506 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2507 | const uint32_t reg_number_; |
| 2508 | |
| 2509 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 2510 | }; |
| 2511 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2512 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2513 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2514 | // exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2515 | class HExit FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2516 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2517 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2518 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2519 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2520 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2521 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2522 | |
| 2523 | private: |
| 2524 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2525 | }; |
| 2526 | |
| 2527 | // Jumps from one block to another. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2528 | class HGoto FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2529 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2530 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2531 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2532 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2533 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2534 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2535 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2536 | } |
| 2537 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2538 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2539 | |
| 2540 | private: |
| 2541 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2542 | }; |
| 2543 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2544 | class HConstant : public HExpression<0> { |
| 2545 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2546 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2547 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2548 | |
| 2549 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2550 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2551 | // Is this constant -1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2552 | virtual bool IsMinusOne() const { return false; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2553 | // Is this constant 0 in the arithmetic sense? |
| 2554 | virtual bool IsArithmeticZero() const { return false; } |
| 2555 | // Is this constant a 0-bit pattern? |
| 2556 | virtual bool IsZeroBitPattern() const { return false; } |
| 2557 | // Is this constant 1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2558 | virtual bool IsOne() const { return false; } |
| 2559 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2560 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2561 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2562 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2563 | |
| 2564 | private: |
| 2565 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2566 | }; |
| 2567 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2568 | class HNullConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2569 | public: |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2570 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2571 | return true; |
| 2572 | } |
| 2573 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2574 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2575 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2576 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2577 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2578 | // The null constant representation is a 0-bit pattern. |
| 2579 | virtual bool IsZeroBitPattern() const { return true; } |
| 2580 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2581 | DECLARE_INSTRUCTION(NullConstant); |
| 2582 | |
| 2583 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2584 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2585 | |
| 2586 | friend class HGraph; |
| 2587 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2588 | }; |
| 2589 | |
| 2590 | // Constants of the type int. Those can be from Dex instructions, or |
| 2591 | // synthesized (for example with the if-eqz instruction). |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2592 | class HIntConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2593 | public: |
| 2594 | int32_t GetValue() const { return value_; } |
| 2595 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2596 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2597 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2598 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2599 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2600 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2601 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2602 | return other->AsIntConstant()->value_ == value_; |
| 2603 | } |
| 2604 | |
| 2605 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2606 | |
| 2607 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2608 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2609 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2610 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2611 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2612 | // Integer constants are used to encode Boolean values as well, |
| 2613 | // where 1 means true and 0 means false. |
| 2614 | bool IsTrue() const { return GetValue() == 1; } |
| 2615 | bool IsFalse() const { return GetValue() == 0; } |
| 2616 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2617 | DECLARE_INSTRUCTION(IntConstant); |
| 2618 | |
| 2619 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2620 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2621 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2622 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2623 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2624 | |
| 2625 | const int32_t value_; |
| 2626 | |
| 2627 | friend class HGraph; |
| 2628 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2629 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2630 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2631 | }; |
| 2632 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2633 | class HLongConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2634 | public: |
| 2635 | int64_t GetValue() const { return value_; } |
| 2636 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2637 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2638 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2639 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2640 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2641 | return other->AsLongConstant()->value_ == value_; |
| 2642 | } |
| 2643 | |
| 2644 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2645 | |
| 2646 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2647 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2648 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2649 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2650 | |
| 2651 | DECLARE_INSTRUCTION(LongConstant); |
| 2652 | |
| 2653 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2654 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2655 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2656 | |
| 2657 | const int64_t value_; |
| 2658 | |
| 2659 | friend class HGraph; |
| 2660 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2661 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2662 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2663 | class HFloatConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2664 | public: |
| 2665 | float GetValue() const { return value_; } |
| 2666 | |
| 2667 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2668 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2669 | } |
| 2670 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2671 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2672 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 2673 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2674 | } |
| 2675 | |
| 2676 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2677 | |
| 2678 | bool IsMinusOne() const OVERRIDE { |
| 2679 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 2680 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2681 | bool IsArithmeticZero() const OVERRIDE { |
| 2682 | return std::fpclassify(value_) == FP_ZERO; |
| 2683 | } |
| 2684 | bool IsArithmeticPositiveZero() const { |
| 2685 | return IsArithmeticZero() && !std::signbit(value_); |
| 2686 | } |
| 2687 | bool IsArithmeticNegativeZero() const { |
| 2688 | return IsArithmeticZero() && std::signbit(value_); |
| 2689 | } |
| 2690 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2691 | 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] | 2692 | } |
| 2693 | bool IsOne() const OVERRIDE { |
| 2694 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 2695 | } |
| 2696 | bool IsNaN() const { |
| 2697 | return std::isnan(value_); |
| 2698 | } |
| 2699 | |
| 2700 | DECLARE_INSTRUCTION(FloatConstant); |
| 2701 | |
| 2702 | private: |
| 2703 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 2704 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 2705 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2706 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
| 2707 | |
| 2708 | const float value_; |
| 2709 | |
| 2710 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2711 | friend class SsaBuilder; |
| 2712 | friend class HGraph; |
| 2713 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 2714 | }; |
| 2715 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2716 | class HDoubleConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2717 | public: |
| 2718 | double GetValue() const { return value_; } |
| 2719 | |
| 2720 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 2721 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2722 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2723 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 2724 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2725 | } |
| 2726 | |
| 2727 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2728 | |
| 2729 | bool IsMinusOne() const OVERRIDE { |
| 2730 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 2731 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2732 | bool IsArithmeticZero() const OVERRIDE { |
| 2733 | return std::fpclassify(value_) == FP_ZERO; |
| 2734 | } |
| 2735 | bool IsArithmeticPositiveZero() const { |
| 2736 | return IsArithmeticZero() && !std::signbit(value_); |
| 2737 | } |
| 2738 | bool IsArithmeticNegativeZero() const { |
| 2739 | return IsArithmeticZero() && std::signbit(value_); |
| 2740 | } |
| 2741 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2742 | 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] | 2743 | } |
| 2744 | bool IsOne() const OVERRIDE { |
| 2745 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 2746 | } |
| 2747 | bool IsNaN() const { |
| 2748 | return std::isnan(value_); |
| 2749 | } |
| 2750 | |
| 2751 | DECLARE_INSTRUCTION(DoubleConstant); |
| 2752 | |
| 2753 | private: |
| 2754 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 2755 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 2756 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2757 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
| 2758 | |
| 2759 | const double value_; |
| 2760 | |
| 2761 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2762 | friend class SsaBuilder; |
| 2763 | friend class HGraph; |
| 2764 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 2765 | }; |
| 2766 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2767 | // Conditional branch. A block ending with an HIf instruction must have |
| 2768 | // two successors. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2769 | class HIf FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2770 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2771 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2772 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2773 | SetRawInputAt(0, input); |
| 2774 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2775 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2776 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2777 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2778 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2779 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2780 | } |
| 2781 | |
| 2782 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2783 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2784 | } |
| 2785 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2786 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2787 | |
| 2788 | private: |
| 2789 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2790 | }; |
| 2791 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2792 | |
| 2793 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2794 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2795 | // non-exceptional control flow. |
| 2796 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2797 | // higher indices in no particular order. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2798 | class HTryBoundary FINAL : public HTemplateInstruction<0> { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2799 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2800 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2801 | kEntry, |
| 2802 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2803 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2804 | }; |
| 2805 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2806 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2807 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
| 2808 | SetPackedField<BoundaryKindField>(kind); |
| 2809 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2810 | |
| 2811 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2812 | |
| 2813 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2814 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2815 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 2816 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 2817 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 2818 | } |
| 2819 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2820 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2821 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2822 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2823 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2824 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2825 | } |
| 2826 | |
| 2827 | // If not present already, adds `handler` to its block's list of exception |
| 2828 | // handlers. |
| 2829 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2830 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2831 | GetBlock()->AddSuccessor(handler); |
| 2832 | } |
| 2833 | } |
| 2834 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2835 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 2836 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2837 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2838 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2839 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2840 | DECLARE_INSTRUCTION(TryBoundary); |
| 2841 | |
| 2842 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2843 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 2844 | static constexpr size_t kFieldBoundaryKindSize = |
| 2845 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 2846 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 2847 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 2848 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 2849 | "Too many packed fields."); |
| 2850 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2851 | |
| 2852 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2853 | }; |
| 2854 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2855 | // Deoptimize to interpreter, upon checking a condition. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2856 | class HDeoptimize FINAL : public HTemplateInstruction<1> { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2857 | public: |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2858 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 2859 | // at the point of the `HDeoptimize`. |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2860 | HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2861 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2862 | SetRawInputAt(0, cond); |
| 2863 | } |
| 2864 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2865 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2866 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2867 | return true; |
| 2868 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2869 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2870 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2871 | |
| 2872 | DECLARE_INSTRUCTION(Deoptimize); |
| 2873 | |
| 2874 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2875 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2876 | }; |
| 2877 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2878 | // Represents the ArtMethod that was passed as a first argument to |
| 2879 | // the method. It is used by instructions that depend on it, like |
| 2880 | // instructions that work with the dex cache. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2881 | class HCurrentMethod FINAL : public HExpression<0> { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2882 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2883 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2884 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2885 | |
| 2886 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2887 | |
| 2888 | private: |
| 2889 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2890 | }; |
| 2891 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2892 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 2893 | // of a class. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2894 | class HClassTableGet FINAL : public HExpression<1> { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2895 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2896 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2897 | kVTable, |
| 2898 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2899 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2900 | }; |
| 2901 | HClassTableGet(HInstruction* cls, |
| 2902 | Primitive::Type type, |
| 2903 | TableKind kind, |
| 2904 | size_t index, |
| 2905 | uint32_t dex_pc) |
| 2906 | : HExpression(type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2907 | index_(index) { |
| 2908 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2909 | SetRawInputAt(0, cls); |
| 2910 | } |
| 2911 | |
| 2912 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2913 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2914 | return other->AsClassTableGet()->GetIndex() == index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2915 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2916 | } |
| 2917 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2918 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2919 | size_t GetIndex() const { return index_; } |
| 2920 | |
| 2921 | DECLARE_INSTRUCTION(ClassTableGet); |
| 2922 | |
| 2923 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2924 | static constexpr size_t kFieldTableKind = kNumberOfExpressionPackedBits; |
| 2925 | static constexpr size_t kFieldTableKindSize = |
| 2926 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 2927 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 2928 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 2929 | "Too many packed fields."); |
| 2930 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 2931 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2932 | // The index of the ArtMethod in the table. |
| 2933 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2934 | |
| 2935 | DISALLOW_COPY_AND_ASSIGN(HClassTableGet); |
| 2936 | }; |
| 2937 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2938 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 2939 | // have one successor for each entry in the switch table, and the final successor |
| 2940 | // will be the block containing the next Dex opcode. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2941 | class HPackedSwitch FINAL : public HTemplateInstruction<1> { |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2942 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2943 | HPackedSwitch(int32_t start_value, |
| 2944 | uint32_t num_entries, |
| 2945 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2946 | uint32_t dex_pc = kNoDexPc) |
| 2947 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 2948 | start_value_(start_value), |
| 2949 | num_entries_(num_entries) { |
| 2950 | SetRawInputAt(0, input); |
| 2951 | } |
| 2952 | |
| 2953 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2954 | |
| 2955 | int32_t GetStartValue() const { return start_value_; } |
| 2956 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 2957 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2958 | |
| 2959 | HBasicBlock* GetDefaultBlock() const { |
| 2960 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2961 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2962 | } |
| 2963 | DECLARE_INSTRUCTION(PackedSwitch); |
| 2964 | |
| 2965 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2966 | const int32_t start_value_; |
| 2967 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2968 | |
| 2969 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 2970 | }; |
| 2971 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2972 | class HUnaryOperation : public HExpression<1> { |
| 2973 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2974 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2975 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2976 | SetRawInputAt(0, input); |
| 2977 | } |
| 2978 | |
| 2979 | HInstruction* GetInput() const { return InputAt(0); } |
| 2980 | Primitive::Type GetResultType() const { return GetType(); } |
| 2981 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2982 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2983 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2984 | return true; |
| 2985 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2986 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2987 | // Try to statically evaluate `this` and return a HConstant |
| 2988 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2989 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2990 | HConstant* TryStaticEvaluation() const; |
| 2991 | |
| 2992 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2993 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 2994 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2995 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 2996 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2997 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2998 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2999 | |
| 3000 | private: |
| 3001 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 3002 | }; |
| 3003 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3004 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3005 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3006 | HBinaryOperation(Primitive::Type result_type, |
| 3007 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3008 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3009 | SideEffects side_effects = SideEffects::None(), |
| 3010 | uint32_t dex_pc = kNoDexPc) |
| 3011 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3012 | SetRawInputAt(0, left); |
| 3013 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3014 | } |
| 3015 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3016 | HInstruction* GetLeft() const { return InputAt(0); } |
| 3017 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3018 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3019 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3020 | virtual bool IsCommutative() const { return false; } |
| 3021 | |
| 3022 | // Put constant on the right. |
| 3023 | // Returns whether order is changed. |
| 3024 | bool OrderInputsWithConstantOnTheRight() { |
| 3025 | HInstruction* left = InputAt(0); |
| 3026 | HInstruction* right = InputAt(1); |
| 3027 | if (left->IsConstant() && !right->IsConstant()) { |
| 3028 | ReplaceInput(right, 0); |
| 3029 | ReplaceInput(left, 1); |
| 3030 | return true; |
| 3031 | } |
| 3032 | return false; |
| 3033 | } |
| 3034 | |
| 3035 | // Order inputs by instruction id, but favor constant on the right side. |
| 3036 | // This helps GVN for commutative ops. |
| 3037 | void OrderInputs() { |
| 3038 | DCHECK(IsCommutative()); |
| 3039 | HInstruction* left = InputAt(0); |
| 3040 | HInstruction* right = InputAt(1); |
| 3041 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 3042 | return; |
| 3043 | } |
| 3044 | if (OrderInputsWithConstantOnTheRight()) { |
| 3045 | return; |
| 3046 | } |
| 3047 | // Order according to instruction id. |
| 3048 | if (left->GetId() > right->GetId()) { |
| 3049 | ReplaceInput(right, 0); |
| 3050 | ReplaceInput(left, 1); |
| 3051 | } |
| 3052 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3053 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3054 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3055 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3056 | return true; |
| 3057 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3058 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3059 | // Try to statically evaluate `this` and return a HConstant |
| 3060 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3061 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3062 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3063 | |
| 3064 | // Apply this operation to `x` and `y`. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3065 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3066 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3067 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 3068 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3069 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3070 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 3071 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3072 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 3073 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3074 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 3075 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3076 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3077 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 3078 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3079 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3080 | // 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] | 3081 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3082 | HConstant* GetConstantRight() const; |
| 3083 | |
| 3084 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3085 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3086 | HInstruction* GetLeastConstantLeft() const; |
| 3087 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3088 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 3089 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3090 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3091 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 3092 | }; |
| 3093 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3094 | // The comparison bias applies for floating point operations and indicates how NaN |
| 3095 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3096 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3097 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 3098 | kGtBias, // return 1 for NaN comparisons |
| 3099 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3100 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3101 | }; |
| 3102 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3103 | std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs); |
| 3104 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3105 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3106 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3107 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3108 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc) { |
| 3109 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 3110 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3111 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3112 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3113 | // `instruction`, and disregard moves in between. |
| 3114 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3115 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3116 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3117 | |
| 3118 | virtual IfCondition GetCondition() const = 0; |
| 3119 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3120 | virtual IfCondition GetOppositeCondition() const = 0; |
| 3121 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3122 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3123 | bool IsLtBias() const { return GetBias() == ComparisonBias::kLtBias; } |
| 3124 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3125 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 3126 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3127 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3128 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3129 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3130 | } |
| 3131 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3132 | bool IsFPConditionTrueIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3133 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3134 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3135 | if (if_cond == kCondNE) { |
| 3136 | return true; |
| 3137 | } else if (if_cond == kCondEQ) { |
| 3138 | return false; |
| 3139 | } |
| 3140 | return ((if_cond == kCondGT) || (if_cond == kCondGE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3141 | } |
| 3142 | |
| 3143 | bool IsFPConditionFalseIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3144 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3145 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3146 | if (if_cond == kCondEQ) { |
| 3147 | return true; |
| 3148 | } else if (if_cond == kCondNE) { |
| 3149 | return false; |
| 3150 | } |
| 3151 | return ((if_cond == kCondLT) || (if_cond == kCondLE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3152 | } |
| 3153 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3154 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3155 | // Needed if we merge a HCompare into a HCondition. |
| 3156 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3157 | static constexpr size_t kFieldComparisonBiasSize = |
| 3158 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3159 | static constexpr size_t kNumberOfConditionPackedBits = |
| 3160 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3161 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3162 | using ComparisonBiasField = |
| 3163 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3164 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3165 | template <typename T> |
| 3166 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3167 | |
| 3168 | template <typename T> |
| 3169 | int32_t CompareFP(T x, T y) const { |
| 3170 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3171 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3172 | // Handle the bias. |
| 3173 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 3174 | } |
| 3175 | |
| 3176 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3177 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3178 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3179 | } |
| 3180 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3181 | private: |
| 3182 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 3183 | }; |
| 3184 | |
| 3185 | // Instruction to check if two inputs are equal to each other. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3186 | class HEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3187 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3188 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3189 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3190 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3191 | bool IsCommutative() const OVERRIDE { return true; } |
| 3192 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3193 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3194 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3195 | return MakeConstantCondition(true, GetDexPc()); |
| 3196 | } |
| 3197 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3198 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3199 | } |
| 3200 | // In the following Evaluate methods, a HCompare instruction has |
| 3201 | // been merged into this HEqual instruction; evaluate it as |
| 3202 | // `Compare(x, y) == 0`. |
| 3203 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3204 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3205 | GetDexPc()); |
| 3206 | } |
| 3207 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3208 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3209 | } |
| 3210 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3211 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3212 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3213 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3214 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3215 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3216 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3217 | return kCondEQ; |
| 3218 | } |
| 3219 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3220 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3221 | return kCondNE; |
| 3222 | } |
| 3223 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3224 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3225 | 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] | 3226 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3227 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 3228 | }; |
| 3229 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3230 | class HNotEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3231 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3232 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3233 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3234 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3235 | bool IsCommutative() const OVERRIDE { return true; } |
| 3236 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3237 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3238 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3239 | return MakeConstantCondition(false, GetDexPc()); |
| 3240 | } |
| 3241 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3242 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3243 | } |
| 3244 | // In the following Evaluate methods, a HCompare instruction has |
| 3245 | // been merged into this HNotEqual instruction; evaluate it as |
| 3246 | // `Compare(x, y) != 0`. |
| 3247 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3248 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3249 | } |
| 3250 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3251 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3252 | } |
| 3253 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3254 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3255 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3256 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3257 | DECLARE_INSTRUCTION(NotEqual); |
| 3258 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3259 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3260 | return kCondNE; |
| 3261 | } |
| 3262 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3263 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3264 | return kCondEQ; |
| 3265 | } |
| 3266 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3267 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3268 | 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] | 3269 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3270 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 3271 | }; |
| 3272 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3273 | class HLessThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3274 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3275 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3276 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3277 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3278 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3279 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3280 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3281 | // In the following Evaluate methods, a HCompare instruction has |
| 3282 | // been merged into this HLessThan instruction; evaluate it as |
| 3283 | // `Compare(x, y) < 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3284 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3285 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3286 | } |
| 3287 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3288 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3289 | } |
| 3290 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3291 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3292 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3293 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3294 | DECLARE_INSTRUCTION(LessThan); |
| 3295 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3296 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3297 | return kCondLT; |
| 3298 | } |
| 3299 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3300 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3301 | return kCondGE; |
| 3302 | } |
| 3303 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3304 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3305 | 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] | 3306 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3307 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 3308 | }; |
| 3309 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3310 | class HLessThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3311 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3312 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3313 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3314 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3315 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3316 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3317 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3318 | // In the following Evaluate methods, a HCompare instruction has |
| 3319 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 3320 | // `Compare(x, y) <= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3321 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3322 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3323 | } |
| 3324 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3325 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3326 | } |
| 3327 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3328 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3329 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3330 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3331 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 3332 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3333 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3334 | return kCondLE; |
| 3335 | } |
| 3336 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3337 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3338 | return kCondGT; |
| 3339 | } |
| 3340 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3341 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3342 | 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] | 3343 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3344 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 3345 | }; |
| 3346 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3347 | class HGreaterThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3348 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3349 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3350 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3351 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3352 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3353 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3354 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3355 | // In the following Evaluate methods, a HCompare instruction has |
| 3356 | // been merged into this HGreaterThan instruction; evaluate it as |
| 3357 | // `Compare(x, y) > 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3358 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3359 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3360 | } |
| 3361 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3362 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3363 | } |
| 3364 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3365 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3366 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3367 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3368 | DECLARE_INSTRUCTION(GreaterThan); |
| 3369 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3370 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3371 | return kCondGT; |
| 3372 | } |
| 3373 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3374 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3375 | return kCondLE; |
| 3376 | } |
| 3377 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3378 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3379 | 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] | 3380 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3381 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 3382 | }; |
| 3383 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3384 | class HGreaterThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3385 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3386 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3387 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3388 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3389 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3390 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3391 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3392 | // In the following Evaluate methods, a HCompare instruction has |
| 3393 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 3394 | // `Compare(x, y) >= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3395 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3396 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3397 | } |
| 3398 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3399 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3400 | } |
| 3401 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3402 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3403 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3404 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3405 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 3406 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3407 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3408 | return kCondGE; |
| 3409 | } |
| 3410 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3411 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3412 | return kCondLT; |
| 3413 | } |
| 3414 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3415 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3416 | 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] | 3417 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3418 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 3419 | }; |
| 3420 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3421 | class HBelow FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3422 | public: |
| 3423 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3424 | : HCondition(first, second, dex_pc) {} |
| 3425 | |
| 3426 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3427 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3428 | } |
| 3429 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3430 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3431 | } |
| 3432 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3433 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3434 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3435 | UNREACHABLE(); |
| 3436 | } |
| 3437 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3438 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3439 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3440 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3441 | } |
| 3442 | |
| 3443 | DECLARE_INSTRUCTION(Below); |
| 3444 | |
| 3445 | IfCondition GetCondition() const OVERRIDE { |
| 3446 | return kCondB; |
| 3447 | } |
| 3448 | |
| 3449 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3450 | return kCondAE; |
| 3451 | } |
| 3452 | |
| 3453 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3454 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3455 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 3456 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3457 | |
| 3458 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 3459 | }; |
| 3460 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3461 | class HBelowOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3462 | public: |
| 3463 | HBelowOrEqual(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(BelowOrEqual); |
| 3484 | |
| 3485 | IfCondition GetCondition() const OVERRIDE { |
| 3486 | return kCondBE; |
| 3487 | } |
| 3488 | |
| 3489 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3490 | return kCondA; |
| 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(HBelowOrEqual); |
| 3499 | }; |
| 3500 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3501 | class HAbove FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3502 | public: |
| 3503 | HAbove(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(Above); |
| 3524 | |
| 3525 | IfCondition GetCondition() const OVERRIDE { |
| 3526 | return kCondA; |
| 3527 | } |
| 3528 | |
| 3529 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3530 | return kCondBE; |
| 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(HAbove); |
| 3539 | }; |
| 3540 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3541 | class HAboveOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3542 | public: |
| 3543 | HAboveOrEqual(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(AboveOrEqual); |
| 3564 | |
| 3565 | IfCondition GetCondition() const OVERRIDE { |
| 3566 | return kCondAE; |
| 3567 | } |
| 3568 | |
| 3569 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3570 | return kCondB; |
| 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(HAboveOrEqual); |
| 3579 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3580 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3581 | // Instruction to check how two inputs compare to each other. |
| 3582 | // 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] | 3583 | class HCompare FINAL : public HBinaryOperation { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3584 | public: |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3585 | // Note that `comparison_type` is the type of comparison performed |
| 3586 | // between the comparison's inputs, not the type of the instantiated |
| 3587 | // HCompare instruction (which is always Primitive::kPrimInt). |
| 3588 | HCompare(Primitive::Type comparison_type, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3589 | HInstruction* first, |
| 3590 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3591 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3592 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3593 | : HBinaryOperation(Primitive::kPrimInt, |
| 3594 | first, |
| 3595 | second, |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3596 | SideEffectsForArchRuntimeCalls(comparison_type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3597 | dex_pc) { |
| 3598 | SetPackedField<ComparisonBiasField>(bias); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3599 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(first->GetType())); |
| 3600 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(second->GetType())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3601 | } |
| 3602 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3603 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3604 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3605 | |
| 3606 | template <typename T> |
| 3607 | int32_t ComputeFP(T x, T y) const { |
| 3608 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3609 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3610 | // Handle the bias. |
| 3611 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 3612 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3613 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3614 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3615 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 3616 | // reach this code path when processing a freshly built HIR |
| 3617 | // graph. However HCompare integer instructions can be synthesized |
| 3618 | // by the instruction simplifier to implement IntegerCompare and |
| 3619 | // IntegerSignum intrinsics, so we have to handle this case. |
| 3620 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3621 | } |
| 3622 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3623 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3624 | } |
| 3625 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3626 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3627 | } |
| 3628 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3629 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3630 | } |
| 3631 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3632 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3633 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3634 | } |
| 3635 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3636 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3637 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3638 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3639 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3640 | bool IsGtBias() const { |
| 3641 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3642 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3643 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3644 | |
Roland Levillain | 1693a1f | 2016-03-15 14:57:31 +0000 | [diff] [blame] | 3645 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type ATTRIBUTE_UNUSED) { |
| 3646 | // Comparisons do not require a runtime call in any back end. |
| 3647 | return SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3648 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3649 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3650 | DECLARE_INSTRUCTION(Compare); |
| 3651 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3652 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3653 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3654 | static constexpr size_t kFieldComparisonBiasSize = |
| 3655 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3656 | static constexpr size_t kNumberOfComparePackedBits = |
| 3657 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3658 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3659 | using ComparisonBiasField = |
| 3660 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3661 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3662 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 3663 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 3664 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 3665 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3666 | } |
| 3667 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3668 | private: |
| 3669 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3670 | }; |
| 3671 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3672 | class HNewInstance FINAL : public HExpression<2> { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3673 | public: |
| 3674 | HNewInstance(HInstruction* cls, |
| 3675 | HCurrentMethod* current_method, |
| 3676 | uint32_t dex_pc, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3677 | dex::TypeIndex type_index, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3678 | const DexFile& dex_file, |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3679 | bool needs_access_check, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3680 | bool finalizable, |
| 3681 | QuickEntrypointEnum entrypoint) |
| 3682 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
| 3683 | type_index_(type_index), |
| 3684 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3685 | entrypoint_(entrypoint) { |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3686 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3687 | SetPackedFlag<kFlagFinalizable>(finalizable); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3688 | SetRawInputAt(0, cls); |
| 3689 | SetRawInputAt(1, current_method); |
| 3690 | } |
| 3691 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3692 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3693 | const DexFile& GetDexFile() const { return dex_file_; } |
| 3694 | |
| 3695 | // Calls runtime so needs an environment. |
| 3696 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3697 | |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3698 | // Can throw errors when out-of-memory or if it's not instantiable/accessible. |
| 3699 | bool CanThrow() const OVERRIDE { return true; } |
| 3700 | |
| 3701 | // Needs to call into runtime to make sure it's instantiable/accessible. |
| 3702 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3703 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3704 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3705 | |
| 3706 | bool CanBeNull() const OVERRIDE { return false; } |
| 3707 | |
| 3708 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3709 | |
| 3710 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 3711 | entrypoint_ = entrypoint; |
| 3712 | } |
| 3713 | |
| 3714 | bool IsStringAlloc() const; |
| 3715 | |
| 3716 | DECLARE_INSTRUCTION(NewInstance); |
| 3717 | |
| 3718 | private: |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3719 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfExpressionPackedBits; |
| 3720 | static constexpr size_t kFlagFinalizable = kFlagNeedsAccessCheck + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3721 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagFinalizable + 1; |
| 3722 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 3723 | "Too many packed fields."); |
| 3724 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3725 | const dex::TypeIndex type_index_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3726 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3727 | QuickEntrypointEnum entrypoint_; |
| 3728 | |
| 3729 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3730 | }; |
| 3731 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3732 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3733 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3734 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3735 | }; |
| 3736 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3737 | enum IntrinsicSideEffects { |
| 3738 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 3739 | kReadSideEffects, // Intrinsic may read heap memory. |
| 3740 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 3741 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 3742 | }; |
| 3743 | |
| 3744 | enum IntrinsicExceptions { |
| 3745 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 3746 | kCanThrow // Intrinsic may throw exceptions. |
| 3747 | }; |
| 3748 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3749 | class HInvoke : public HInstruction { |
| 3750 | public: |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3751 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3752 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3753 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 3754 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 3755 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 3756 | } |
| 3757 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3758 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3759 | SetRawInputAt(index, argument); |
| 3760 | } |
| 3761 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3762 | // Return the number of arguments. This number can be lower than |
| 3763 | // the number of inputs returned by InputCount(), as some invoke |
| 3764 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3765 | // inputs at the end of their list of inputs. |
| 3766 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3767 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3768 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<ReturnTypeField>(); } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3769 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3770 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3771 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3772 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3773 | InvokeType GetInvokeType() const { |
| 3774 | return GetPackedField<InvokeTypeField>(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3775 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3776 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3777 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3778 | return intrinsic_; |
| 3779 | } |
| 3780 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3781 | void SetIntrinsic(Intrinsics intrinsic, |
| 3782 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 3783 | IntrinsicSideEffects side_effects, |
| 3784 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3785 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3786 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 3787 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3788 | } |
| 3789 | |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 3790 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
| 3791 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3792 | bool CanThrow() const OVERRIDE { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3793 | |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 3794 | bool CanBeMoved() const OVERRIDE { return IsIntrinsic() && !DoesAnyWrite(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3795 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3796 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3797 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 3798 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3799 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3800 | uint32_t* GetIntrinsicOptimizations() { |
| 3801 | return &intrinsic_optimizations_; |
| 3802 | } |
| 3803 | |
| 3804 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3805 | return &intrinsic_optimizations_; |
| 3806 | } |
| 3807 | |
| 3808 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3809 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3810 | ArtMethod* GetResolvedMethod() const { return resolved_method_; } |
| 3811 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3812 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3813 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3814 | protected: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3815 | static constexpr size_t kFieldInvokeType = kNumberOfGenericPackedBits; |
| 3816 | static constexpr size_t kFieldInvokeTypeSize = |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3817 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 3818 | static constexpr size_t kFieldReturnType = |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3819 | kFieldInvokeType + kFieldInvokeTypeSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3820 | static constexpr size_t kFieldReturnTypeSize = |
| 3821 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 3822 | static constexpr size_t kFlagCanThrow = kFieldReturnType + kFieldReturnTypeSize; |
| 3823 | static constexpr size_t kNumberOfInvokePackedBits = kFlagCanThrow + 1; |
| 3824 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3825 | using InvokeTypeField = BitField<InvokeType, kFieldInvokeType, kFieldInvokeTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3826 | using ReturnTypeField = BitField<Primitive::Type, kFieldReturnType, kFieldReturnTypeSize>; |
| 3827 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3828 | HInvoke(ArenaAllocator* arena, |
| 3829 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3830 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3831 | Primitive::Type return_type, |
| 3832 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3833 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3834 | ArtMethod* resolved_method, |
| 3835 | InvokeType invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3836 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3837 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3838 | number_of_arguments_(number_of_arguments), |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3839 | resolved_method_(resolved_method), |
Vladimir Marko | b7d8e8c | 2015-09-17 15:47:05 +0100 | [diff] [blame] | 3840 | inputs_(number_of_arguments + number_of_other_inputs, |
| 3841 | arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3842 | dex_method_index_(dex_method_index), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3843 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3844 | intrinsic_optimizations_(0) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3845 | SetPackedField<ReturnTypeField>(return_type); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3846 | SetPackedField<InvokeTypeField>(invoke_type); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3847 | SetPackedFlag<kFlagCanThrow>(true); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3848 | } |
| 3849 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3850 | uint32_t number_of_arguments_; |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3851 | ArtMethod* const resolved_method_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3852 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3853 | const uint32_t dex_method_index_; |
| 3854 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3855 | |
| 3856 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3857 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3858 | |
| 3859 | private: |
| 3860 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3861 | }; |
| 3862 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3863 | class HInvokeUnresolved FINAL : public HInvoke { |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3864 | public: |
| 3865 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3866 | uint32_t number_of_arguments, |
| 3867 | Primitive::Type return_type, |
| 3868 | uint32_t dex_pc, |
| 3869 | uint32_t dex_method_index, |
| 3870 | InvokeType invoke_type) |
| 3871 | : HInvoke(arena, |
| 3872 | number_of_arguments, |
| 3873 | 0u /* number_of_other_inputs */, |
| 3874 | return_type, |
| 3875 | dex_pc, |
| 3876 | dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3877 | nullptr, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3878 | invoke_type) { |
| 3879 | } |
| 3880 | |
| 3881 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3882 | |
| 3883 | private: |
| 3884 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3885 | }; |
| 3886 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3887 | class HInvokeStaticOrDirect FINAL : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3888 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3889 | // Requirements of this method call regarding the class |
| 3890 | // initialization (clinit) check of its declaring class. |
| 3891 | enum class ClinitCheckRequirement { |
| 3892 | kNone, // Class already initialized. |
| 3893 | kExplicit, // Static call having explicit clinit check as last input. |
| 3894 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3895 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3896 | }; |
| 3897 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3898 | // Determines how to load the target ArtMethod*. |
| 3899 | enum class MethodLoadKind { |
| 3900 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3901 | kStringInit, |
| 3902 | |
| 3903 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3904 | kRecursive, |
| 3905 | |
| 3906 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3907 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3908 | kDirectAddress, |
| 3909 | |
| 3910 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3911 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3912 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3913 | // the image relocatable or not. |
| 3914 | kDirectAddressWithFixup, |
| 3915 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3916 | // 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] | 3917 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3918 | // may cause class initialization (the entry may point to a resolution method), |
| 3919 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3920 | kDexCachePcRelative, |
| 3921 | |
| 3922 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3923 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3924 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3925 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3926 | kDexCacheViaMethod, |
| 3927 | }; |
| 3928 | |
| 3929 | // Determines the location of the code pointer. |
| 3930 | enum class CodePtrLocation { |
| 3931 | // Recursive call, use local PC-relative call instruction. |
| 3932 | kCallSelf, |
| 3933 | |
| 3934 | // Use PC-relative call instruction patched at link time. |
| 3935 | // Used for calls within an oat file, boot->boot or app->app. |
| 3936 | kCallPCRelative, |
| 3937 | |
| 3938 | // Call to a known target address, embed the direct address in code. |
| 3939 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3940 | kCallDirect, |
| 3941 | |
| 3942 | // Call to a target address that will be known at link time, embed the direct |
| 3943 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3944 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3945 | // the image relocatable or not. |
| 3946 | kCallDirectWithFixup, |
| 3947 | |
| 3948 | // Use code pointer from the ArtMethod*. |
| 3949 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3950 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3951 | kCallArtMethod, |
| 3952 | }; |
| 3953 | |
| 3954 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3955 | MethodLoadKind method_load_kind; |
| 3956 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3957 | // The method load data holds |
| 3958 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3959 | // Note that there are multiple string init methods, each having its own offset. |
| 3960 | // - the method address for kDirectAddress |
| 3961 | // - the dex cache arrays offset for kDexCachePcRel. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3962 | uint64_t method_load_data; |
| 3963 | uint64_t direct_code_ptr; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3964 | }; |
| 3965 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3966 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 3967 | uint32_t number_of_arguments, |
| 3968 | Primitive::Type return_type, |
| 3969 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3970 | uint32_t method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3971 | ArtMethod* resolved_method, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3972 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3973 | InvokeType invoke_type, |
| 3974 | MethodReference target_method, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3975 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3976 | : HInvoke(arena, |
| 3977 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3978 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 3979 | // potentially one other if the clinit check is explicit, and potentially |
| 3980 | // one other if the method is a string factory. |
| 3981 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3982 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3983 | return_type, |
| 3984 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3985 | method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3986 | resolved_method, |
| 3987 | invoke_type), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3988 | target_method_(target_method), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3989 | dispatch_info_(dispatch_info) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3990 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 3991 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3992 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3993 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3994 | bool had_current_method_input = HasCurrentMethodInput(); |
| 3995 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 3996 | |
| 3997 | // Using the current method is the default and once we find a better |
| 3998 | // method load kind, we should not go back to using the current method. |
| 3999 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 4000 | |
| 4001 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4002 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 4003 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4004 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4005 | dispatch_info_ = dispatch_info; |
| 4006 | } |
| 4007 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4008 | void AddSpecialInput(HInstruction* input) { |
| 4009 | // We allow only one special input. |
| 4010 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 4011 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4012 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 4013 | InsertInputAt(GetSpecialInputIndex(), input); |
| 4014 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4015 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4016 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 4017 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 4018 | ArrayRef<HUserRecord<HInstruction*>> input_records = HInvoke::GetInputRecords(); |
| 4019 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck()) { |
| 4020 | DCHECK(!input_records.empty()); |
| 4021 | DCHECK_GT(input_records.size(), GetNumberOfArguments()); |
| 4022 | HInstruction* last_input = input_records.back().GetInstruction(); |
| 4023 | // Note: `last_input` may be null during arguments setup. |
| 4024 | if (last_input != nullptr) { |
| 4025 | // `last_input` is the last input of a static invoke marked as having |
| 4026 | // an explicit clinit check. It must either be: |
| 4027 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 4028 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 4029 | DCHECK(last_input->IsClinitCheck() || last_input->IsLoadClass()) << last_input->DebugName(); |
| 4030 | } |
| 4031 | } |
| 4032 | return input_records; |
| 4033 | } |
| 4034 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4035 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4036 | // We access the method via the dex cache so we can't do an implicit null check. |
| 4037 | // TODO: for intrinsics we can generate implicit null checks. |
| 4038 | return false; |
| 4039 | } |
| 4040 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4041 | bool CanBeNull() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4042 | return GetPackedField<ReturnTypeField>() == Primitive::kPrimNot && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4043 | } |
| 4044 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4045 | // Get the index of the special input, if any. |
| 4046 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4047 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 4048 | // method pointer; otherwise there may be one platform-specific special input, |
| 4049 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4050 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
Nicolas Geoffray | 9779307 | 2016-02-16 15:33:54 +0000 | [diff] [blame] | 4051 | bool HasSpecialInput() const { return GetNumberOfArguments() != InputCount(); } |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4052 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4053 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 4054 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 4055 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4056 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4057 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4058 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4059 | bool HasPcRelativeDexCache() const { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4060 | return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; |
| 4061 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4062 | bool HasCurrentMethodInput() const { |
| 4063 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 4064 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4065 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4066 | return true; |
| 4067 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4068 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4069 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4070 | return false; |
| 4071 | } |
| 4072 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4073 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4074 | |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4075 | QuickEntrypointEnum GetStringInitEntryPoint() const { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4076 | DCHECK(IsStringInit()); |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4077 | return static_cast<QuickEntrypointEnum>(dispatch_info_.method_load_data); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4078 | } |
| 4079 | |
| 4080 | uint64_t GetMethodAddress() const { |
| 4081 | DCHECK(HasMethodAddress()); |
| 4082 | return dispatch_info_.method_load_data; |
| 4083 | } |
| 4084 | |
| 4085 | uint32_t GetDexCacheArrayOffset() const { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4086 | DCHECK(HasPcRelativeDexCache()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4087 | return dispatch_info_.method_load_data; |
| 4088 | } |
| 4089 | |
| 4090 | uint64_t GetDirectCodePtr() const { |
| 4091 | DCHECK(HasDirectCodePtr()); |
| 4092 | return dispatch_info_.direct_code_ptr; |
| 4093 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4094 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4095 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 4096 | return GetPackedField<ClinitCheckRequirementField>(); |
| 4097 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 4098 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4099 | // Is this instruction a call to a static method? |
| 4100 | bool IsStatic() const { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4101 | return GetInvokeType() == kStatic; |
| 4102 | } |
| 4103 | |
| 4104 | MethodReference GetTargetMethod() const { |
| 4105 | return target_method_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4106 | } |
| 4107 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4108 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 4109 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 4110 | // instruction; only relevant for static calls with explicit clinit check. |
| 4111 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4112 | DCHECK(IsStaticWithExplicitClinitCheck()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4113 | size_t last_input_index = inputs_.size() - 1u; |
| 4114 | HInstruction* last_input = inputs_.back().GetInstruction(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4115 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4116 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4117 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4118 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4119 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4120 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4121 | } |
| 4122 | |
| 4123 | // 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] | 4124 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4125 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4126 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4127 | } |
| 4128 | |
| 4129 | // Is this a call to a static method whose declaring class has an |
| 4130 | // implicit intialization check requirement? |
| 4131 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4132 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4133 | } |
| 4134 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4135 | // Does this method load kind need the current method as an input? |
| 4136 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
| 4137 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kDexCacheViaMethod; |
| 4138 | } |
| 4139 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4140 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4141 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4142 | protected: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4143 | void InsertInputAt(size_t index, HInstruction* input); |
| 4144 | void RemoveInputAt(size_t index); |
| 4145 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4146 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4147 | static constexpr size_t kFieldClinitCheckRequirement = kNumberOfInvokePackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4148 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 4149 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 4150 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 4151 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 4152 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 4153 | "Too many packed fields."); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4154 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 4155 | kFieldClinitCheckRequirement, |
| 4156 | kFieldClinitCheckRequirementSize>; |
| 4157 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4158 | // Cached values of the resolved method, to avoid needing the mutator lock. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4159 | MethodReference target_method_; |
| 4160 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4161 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4162 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4163 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 4164 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4165 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4166 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4167 | class HInvokeVirtual FINAL : public HInvoke { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4168 | public: |
| 4169 | HInvokeVirtual(ArenaAllocator* arena, |
| 4170 | uint32_t number_of_arguments, |
| 4171 | Primitive::Type return_type, |
| 4172 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4173 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4174 | ArtMethod* resolved_method, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4175 | uint32_t vtable_index) |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4176 | : HInvoke(arena, |
| 4177 | number_of_arguments, |
| 4178 | 0u, |
| 4179 | return_type, |
| 4180 | dex_pc, |
| 4181 | dex_method_index, |
| 4182 | resolved_method, |
| 4183 | kVirtual), |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4184 | vtable_index_(vtable_index) {} |
| 4185 | |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 4186 | bool CanBeNull() const OVERRIDE { |
| 4187 | switch (GetIntrinsic()) { |
| 4188 | case Intrinsics::kThreadCurrentThread: |
| 4189 | case Intrinsics::kStringBufferAppend: |
| 4190 | case Intrinsics::kStringBufferToString: |
| 4191 | case Intrinsics::kStringBuilderAppend: |
| 4192 | case Intrinsics::kStringBuilderToString: |
| 4193 | return false; |
| 4194 | default: |
| 4195 | return HInvoke::CanBeNull(); |
| 4196 | } |
| 4197 | } |
| 4198 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4199 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4200 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4201 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4202 | } |
| 4203 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4204 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 4205 | |
| 4206 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 4207 | |
| 4208 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4209 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4210 | const uint32_t vtable_index_; |
| 4211 | |
| 4212 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 4213 | }; |
| 4214 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4215 | class HInvokeInterface FINAL : public HInvoke { |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4216 | public: |
| 4217 | HInvokeInterface(ArenaAllocator* arena, |
| 4218 | uint32_t number_of_arguments, |
| 4219 | Primitive::Type return_type, |
| 4220 | uint32_t dex_pc, |
| 4221 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4222 | ArtMethod* resolved_method, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4223 | uint32_t imt_index) |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4224 | : HInvoke(arena, |
| 4225 | number_of_arguments, |
| 4226 | 0u, |
| 4227 | return_type, |
| 4228 | dex_pc, |
| 4229 | dex_method_index, |
| 4230 | resolved_method, |
| 4231 | kInterface), |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4232 | imt_index_(imt_index) {} |
| 4233 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4234 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4235 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4236 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4237 | } |
| 4238 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4239 | uint32_t GetImtIndex() const { return imt_index_; } |
| 4240 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 4241 | |
| 4242 | DECLARE_INSTRUCTION(InvokeInterface); |
| 4243 | |
| 4244 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4245 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4246 | const uint32_t imt_index_; |
| 4247 | |
| 4248 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 4249 | }; |
| 4250 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4251 | class HNeg FINAL : public HUnaryOperation { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4252 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4253 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 937e6cd | 2016-03-22 11:54:37 +0000 | [diff] [blame] | 4254 | : HUnaryOperation(result_type, input, dex_pc) { |
| 4255 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(input->GetType())); |
| 4256 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4257 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4258 | template <typename T> static T Compute(T x) { return -x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4259 | |
| 4260 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4261 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4262 | } |
| 4263 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4264 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4265 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4266 | HConstant* Evaluate(HFloatConstant* x) const OVERRIDE { |
| 4267 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 4268 | } |
| 4269 | HConstant* Evaluate(HDoubleConstant* x) const OVERRIDE { |
| 4270 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 4271 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 4272 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4273 | DECLARE_INSTRUCTION(Neg); |
| 4274 | |
| 4275 | private: |
| 4276 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 4277 | }; |
| 4278 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4279 | class HNewArray FINAL : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4280 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4281 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4282 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4283 | uint32_t dex_pc, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4284 | dex::TypeIndex type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4285 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4286 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4287 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4288 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4289 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4290 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4291 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4292 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4293 | } |
| 4294 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4295 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4296 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4297 | |
| 4298 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4299 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4300 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4301 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 4302 | bool CanThrow() const OVERRIDE { return true; } |
| 4303 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4304 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4305 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4306 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 4307 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4308 | DECLARE_INSTRUCTION(NewArray); |
| 4309 | |
| 4310 | private: |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4311 | const dex::TypeIndex type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4312 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4313 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4314 | |
| 4315 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 4316 | }; |
| 4317 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4318 | class HAdd FINAL : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4319 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4320 | HAdd(Primitive::Type result_type, |
| 4321 | HInstruction* left, |
| 4322 | HInstruction* right, |
| 4323 | uint32_t dex_pc = kNoDexPc) |
| 4324 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4325 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4326 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4327 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4328 | 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] | 4329 | |
| 4330 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4331 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4332 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4333 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4334 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4335 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4336 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4337 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4338 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4339 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4340 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4341 | } |
| 4342 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4343 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4344 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4345 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4346 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4347 | DECLARE_INSTRUCTION(Add); |
| 4348 | |
| 4349 | private: |
| 4350 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 4351 | }; |
| 4352 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4353 | class HSub FINAL : public HBinaryOperation { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4354 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4355 | HSub(Primitive::Type result_type, |
| 4356 | HInstruction* left, |
| 4357 | HInstruction* right, |
| 4358 | uint32_t dex_pc = kNoDexPc) |
| 4359 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4360 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4361 | 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] | 4362 | |
| 4363 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4364 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4365 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4366 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4367 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4368 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4369 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4370 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4371 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4372 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4373 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4374 | } |
| 4375 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4376 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4377 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4378 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4379 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4380 | DECLARE_INSTRUCTION(Sub); |
| 4381 | |
| 4382 | private: |
| 4383 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 4384 | }; |
| 4385 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4386 | class HMul FINAL : public HBinaryOperation { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4387 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4388 | HMul(Primitive::Type result_type, |
| 4389 | HInstruction* left, |
| 4390 | HInstruction* right, |
| 4391 | uint32_t dex_pc = kNoDexPc) |
| 4392 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4393 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4394 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4395 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4396 | 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] | 4397 | |
| 4398 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4399 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4400 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4401 | } |
| 4402 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4403 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4404 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4405 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4406 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4407 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4408 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4409 | } |
| 4410 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4411 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4412 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4413 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4414 | |
| 4415 | DECLARE_INSTRUCTION(Mul); |
| 4416 | |
| 4417 | private: |
| 4418 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 4419 | }; |
| 4420 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4421 | class HDiv FINAL : public HBinaryOperation { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4422 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4423 | HDiv(Primitive::Type result_type, |
| 4424 | HInstruction* left, |
| 4425 | HInstruction* right, |
| 4426 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 4427 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4428 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4429 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4430 | T ComputeIntegral(T x, T y) const { |
| 4431 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4432 | // Our graph structure ensures we never have 0 for `y` during |
| 4433 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4434 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4435 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4436 | return (y == -1) ? -x : x / y; |
| 4437 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4438 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4439 | template <typename T> |
| 4440 | T ComputeFP(T x, T y) const { |
| 4441 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4442 | return x / y; |
| 4443 | } |
| 4444 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4445 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4446 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4447 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4448 | } |
| 4449 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4450 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4451 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4452 | } |
| 4453 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4454 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4455 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4456 | } |
| 4457 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4458 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4459 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4460 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4461 | |
| 4462 | DECLARE_INSTRUCTION(Div); |
| 4463 | |
| 4464 | private: |
| 4465 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 4466 | }; |
| 4467 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4468 | class HRem FINAL : public HBinaryOperation { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4469 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4470 | HRem(Primitive::Type result_type, |
| 4471 | HInstruction* left, |
| 4472 | HInstruction* right, |
| 4473 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 4474 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4475 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4476 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4477 | T ComputeIntegral(T x, T y) const { |
| 4478 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4479 | // Our graph structure ensures we never have 0 for `y` during |
| 4480 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4481 | DCHECK_NE(y, 0); |
| 4482 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 4483 | return (y == -1) ? 0 : x % y; |
| 4484 | } |
| 4485 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4486 | template <typename T> |
| 4487 | T ComputeFP(T x, T y) const { |
| 4488 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4489 | return std::fmod(x, y); |
| 4490 | } |
| 4491 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4492 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4493 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4494 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4495 | } |
| 4496 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4497 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4498 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4499 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4500 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4501 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4502 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4503 | } |
| 4504 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4505 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4506 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4507 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4508 | |
| 4509 | DECLARE_INSTRUCTION(Rem); |
| 4510 | |
| 4511 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4512 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 4513 | }; |
| 4514 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4515 | class HDivZeroCheck FINAL : public HExpression<1> { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4516 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4517 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
| 4518 | // constructor. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4519 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4520 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4521 | SetRawInputAt(0, value); |
| 4522 | } |
| 4523 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4524 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 4525 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4526 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4527 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4528 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4529 | return true; |
| 4530 | } |
| 4531 | |
| 4532 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4533 | bool CanThrow() const OVERRIDE { return true; } |
| 4534 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4535 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 4536 | |
| 4537 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4538 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 4539 | }; |
| 4540 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4541 | class HShl FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4542 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4543 | HShl(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4544 | HInstruction* value, |
| 4545 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4546 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4547 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4548 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4549 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4550 | } |
| 4551 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4552 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4553 | 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] | 4554 | return value << (distance & max_shift_distance); |
| 4555 | } |
| 4556 | |
| 4557 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4558 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4559 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4560 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4561 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4562 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4563 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4564 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4565 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4566 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4567 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4568 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4569 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4570 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4571 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4572 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4573 | UNREACHABLE(); |
| 4574 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4575 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4576 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4577 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4578 | UNREACHABLE(); |
| 4579 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4580 | |
| 4581 | DECLARE_INSTRUCTION(Shl); |
| 4582 | |
| 4583 | private: |
| 4584 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 4585 | }; |
| 4586 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4587 | class HShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4588 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4589 | HShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4590 | HInstruction* value, |
| 4591 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4592 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4593 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4594 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4595 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4596 | } |
| 4597 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4598 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4599 | 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] | 4600 | return value >> (distance & max_shift_distance); |
| 4601 | } |
| 4602 | |
| 4603 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4604 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4605 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4606 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4607 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4608 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4609 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4610 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4611 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4612 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4613 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4614 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4615 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4616 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4617 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4618 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4619 | UNREACHABLE(); |
| 4620 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4621 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4622 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4623 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4624 | UNREACHABLE(); |
| 4625 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4626 | |
| 4627 | DECLARE_INSTRUCTION(Shr); |
| 4628 | |
| 4629 | private: |
| 4630 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 4631 | }; |
| 4632 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4633 | class HUShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4634 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4635 | HUShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4636 | HInstruction* value, |
| 4637 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4638 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4639 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4640 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4641 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4642 | } |
| 4643 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4644 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4645 | 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] | 4646 | typedef typename std::make_unsigned<T>::type V; |
| 4647 | V ux = static_cast<V>(value); |
| 4648 | return static_cast<T>(ux >> (distance & max_shift_distance)); |
| 4649 | } |
| 4650 | |
| 4651 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4652 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4653 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4654 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4655 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4656 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4657 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4658 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4659 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4660 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4661 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4662 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4663 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4664 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4665 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4666 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4667 | UNREACHABLE(); |
| 4668 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4669 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4670 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4671 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4672 | UNREACHABLE(); |
| 4673 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4674 | |
| 4675 | DECLARE_INSTRUCTION(UShr); |
| 4676 | |
| 4677 | private: |
| 4678 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 4679 | }; |
| 4680 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4681 | class HAnd FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4682 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4683 | HAnd(Primitive::Type result_type, |
| 4684 | HInstruction* left, |
| 4685 | HInstruction* right, |
| 4686 | uint32_t dex_pc = kNoDexPc) |
| 4687 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4688 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4689 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4690 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4691 | 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] | 4692 | |
| 4693 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4694 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4695 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4696 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4697 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4698 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4699 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4700 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4701 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4702 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4703 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4704 | UNREACHABLE(); |
| 4705 | } |
| 4706 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4707 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4708 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4709 | UNREACHABLE(); |
| 4710 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4711 | |
| 4712 | DECLARE_INSTRUCTION(And); |
| 4713 | |
| 4714 | private: |
| 4715 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4716 | }; |
| 4717 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4718 | class HOr FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4719 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4720 | HOr(Primitive::Type result_type, |
| 4721 | HInstruction* left, |
| 4722 | HInstruction* right, |
| 4723 | uint32_t dex_pc = kNoDexPc) |
| 4724 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4725 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4726 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4727 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4728 | 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] | 4729 | |
| 4730 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4731 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4732 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4733 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4734 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4735 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4736 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4737 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4738 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4739 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4740 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4741 | UNREACHABLE(); |
| 4742 | } |
| 4743 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4744 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4745 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4746 | UNREACHABLE(); |
| 4747 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4748 | |
| 4749 | DECLARE_INSTRUCTION(Or); |
| 4750 | |
| 4751 | private: |
| 4752 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4753 | }; |
| 4754 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4755 | class HXor FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4756 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4757 | HXor(Primitive::Type result_type, |
| 4758 | HInstruction* left, |
| 4759 | HInstruction* right, |
| 4760 | uint32_t dex_pc = kNoDexPc) |
| 4761 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4762 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4763 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4764 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4765 | 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] | 4766 | |
| 4767 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4768 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4769 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4770 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4771 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4772 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4773 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4774 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4775 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4776 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4777 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4778 | UNREACHABLE(); |
| 4779 | } |
| 4780 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4781 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4782 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4783 | UNREACHABLE(); |
| 4784 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4785 | |
| 4786 | DECLARE_INSTRUCTION(Xor); |
| 4787 | |
| 4788 | private: |
| 4789 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 4790 | }; |
| 4791 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4792 | class HRor FINAL : public HBinaryOperation { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4793 | public: |
| 4794 | HRor(Primitive::Type result_type, HInstruction* value, HInstruction* distance) |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4795 | : HBinaryOperation(result_type, value, distance) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4796 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4797 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4798 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4799 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4800 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4801 | 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] | 4802 | typedef typename std::make_unsigned<T>::type V; |
| 4803 | V ux = static_cast<V>(value); |
| 4804 | if ((distance & max_shift_value) == 0) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4805 | return static_cast<T>(ux); |
| 4806 | } else { |
| 4807 | const V reg_bits = sizeof(T) * 8; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4808 | return static_cast<T>(ux >> (distance & max_shift_value)) | |
| 4809 | (value << (reg_bits - (distance & max_shift_value))); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4810 | } |
| 4811 | } |
| 4812 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4813 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4814 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4815 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4816 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4817 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4818 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4819 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4820 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4821 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4822 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4823 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4824 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4825 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4826 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4827 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4828 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4829 | UNREACHABLE(); |
| 4830 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4831 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4832 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4833 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4834 | UNREACHABLE(); |
| 4835 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4836 | |
| 4837 | DECLARE_INSTRUCTION(Ror); |
| 4838 | |
| 4839 | private: |
| 4840 | DISALLOW_COPY_AND_ASSIGN(HRor); |
| 4841 | }; |
| 4842 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4843 | // The value of a parameter in this method. Its location depends on |
| 4844 | // the calling convention. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4845 | class HParameterValue FINAL : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4846 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4847 | HParameterValue(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4848 | dex::TypeIndex type_index, |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4849 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4850 | Primitive::Type parameter_type, |
| 4851 | bool is_this = false) |
| 4852 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4853 | dex_file_(dex_file), |
| 4854 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4855 | index_(index) { |
| 4856 | SetPackedFlag<kFlagIsThis>(is_this); |
| 4857 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 4858 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4859 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4860 | const DexFile& GetDexFile() const { return dex_file_; } |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4861 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4862 | uint8_t GetIndex() const { return index_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4863 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4864 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4865 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 4866 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4867 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4868 | DECLARE_INSTRUCTION(ParameterValue); |
| 4869 | |
| 4870 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4871 | // Whether or not the parameter value corresponds to 'this' argument. |
| 4872 | static constexpr size_t kFlagIsThis = kNumberOfExpressionPackedBits; |
| 4873 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 4874 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 4875 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 4876 | "Too many packed fields."); |
| 4877 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4878 | const DexFile& dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4879 | const dex::TypeIndex type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4880 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4881 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4882 | const uint8_t index_; |
| 4883 | |
| 4884 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 4885 | }; |
| 4886 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4887 | class HNot FINAL : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4888 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4889 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4890 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4891 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4892 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4893 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4894 | return true; |
| 4895 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4896 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4897 | template <typename T> static T Compute(T x) { return ~x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4898 | |
| 4899 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4900 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4901 | } |
| 4902 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4903 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4904 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4905 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4906 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4907 | UNREACHABLE(); |
| 4908 | } |
| 4909 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4910 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4911 | UNREACHABLE(); |
| 4912 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4913 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4914 | DECLARE_INSTRUCTION(Not); |
| 4915 | |
| 4916 | private: |
| 4917 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 4918 | }; |
| 4919 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4920 | class HBooleanNot FINAL : public HUnaryOperation { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4921 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4922 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4923 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4924 | |
| 4925 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4926 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4927 | return true; |
| 4928 | } |
| 4929 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4930 | template <typename T> static bool Compute(T x) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4931 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4932 | return !x; |
| 4933 | } |
| 4934 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4935 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4936 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4937 | } |
| 4938 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4939 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4940 | UNREACHABLE(); |
| 4941 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4942 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4943 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4944 | UNREACHABLE(); |
| 4945 | } |
| 4946 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4947 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4948 | UNREACHABLE(); |
| 4949 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4950 | |
| 4951 | DECLARE_INSTRUCTION(BooleanNot); |
| 4952 | |
| 4953 | private: |
| 4954 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 4955 | }; |
| 4956 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4957 | class HTypeConversion FINAL : public HExpression<1> { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4958 | public: |
| 4959 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4960 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 4961 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4962 | SetRawInputAt(0, input); |
Roland Levillain | f355c3f | 2016-03-30 19:09:03 +0100 | [diff] [blame] | 4963 | // Invariant: We should never generate a conversion to a Boolean value. |
| 4964 | DCHECK_NE(Primitive::kPrimBoolean, result_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4965 | } |
| 4966 | |
| 4967 | HInstruction* GetInput() const { return InputAt(0); } |
| 4968 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 4969 | Primitive::Type GetResultType() const { return GetType(); } |
| 4970 | |
| 4971 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4972 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4973 | return true; |
| 4974 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4975 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 4976 | // Try to statically evaluate the conversion and return a HConstant |
| 4977 | // containing the result. If the input cannot be converted, return nullptr. |
| 4978 | HConstant* TryStaticEvaluation() const; |
| 4979 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4980 | DECLARE_INSTRUCTION(TypeConversion); |
| 4981 | |
| 4982 | private: |
| 4983 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 4984 | }; |
| 4985 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 4986 | static constexpr uint32_t kNoRegNumber = -1; |
| 4987 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4988 | class HNullCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4989 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4990 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
| 4991 | // constructor. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4992 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4993 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4994 | SetRawInputAt(0, value); |
| 4995 | } |
| 4996 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4997 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4998 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4999 | return true; |
| 5000 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5001 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5002 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5003 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5004 | bool CanThrow() const OVERRIDE { return true; } |
| 5005 | |
| 5006 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5007 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5008 | |
| 5009 | DECLARE_INSTRUCTION(NullCheck); |
| 5010 | |
| 5011 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5012 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 5013 | }; |
| 5014 | |
| 5015 | class FieldInfo : public ValueObject { |
| 5016 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5017 | FieldInfo(MemberOffset field_offset, |
| 5018 | Primitive::Type field_type, |
| 5019 | bool is_volatile, |
| 5020 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5021 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5022 | const DexFile& dex_file, |
| 5023 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5024 | : field_offset_(field_offset), |
| 5025 | field_type_(field_type), |
| 5026 | is_volatile_(is_volatile), |
| 5027 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5028 | declaring_class_def_index_(declaring_class_def_index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5029 | dex_file_(dex_file), |
| 5030 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5031 | |
| 5032 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5033 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5034 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5035 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5036 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5037 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5038 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5039 | |
| 5040 | private: |
| 5041 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5042 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5043 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5044 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5045 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5046 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5047 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5048 | }; |
| 5049 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5050 | class HInstanceFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5051 | public: |
| 5052 | HInstanceFieldGet(HInstruction* value, |
| 5053 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5054 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5055 | bool is_volatile, |
| 5056 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5057 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5058 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5059 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5060 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5061 | : HExpression(field_type, SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5062 | field_info_(field_offset, |
| 5063 | field_type, |
| 5064 | is_volatile, |
| 5065 | field_idx, |
| 5066 | declaring_class_def_index, |
| 5067 | dex_file, |
| 5068 | dex_cache) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5069 | SetRawInputAt(0, value); |
| 5070 | } |
| 5071 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5072 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5073 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5074 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 5075 | const HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5076 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5077 | } |
| 5078 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5079 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5080 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5081 | } |
| 5082 | |
| 5083 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 5084 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5085 | } |
| 5086 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5087 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5088 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5089 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5090 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5091 | |
| 5092 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 5093 | |
| 5094 | private: |
| 5095 | const FieldInfo field_info_; |
| 5096 | |
| 5097 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 5098 | }; |
| 5099 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5100 | class HInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5101 | public: |
| 5102 | HInstanceFieldSet(HInstruction* object, |
| 5103 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5104 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5105 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5106 | bool is_volatile, |
| 5107 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5108 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5109 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5110 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5111 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5112 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5113 | field_info_(field_offset, |
| 5114 | field_type, |
| 5115 | is_volatile, |
| 5116 | field_idx, |
| 5117 | declaring_class_def_index, |
| 5118 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5119 | dex_cache) { |
| 5120 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5121 | SetRawInputAt(0, object); |
| 5122 | SetRawInputAt(1, value); |
| 5123 | } |
| 5124 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5125 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5126 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5127 | } |
| 5128 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5129 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5130 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5131 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5132 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5133 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5134 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5135 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5136 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5137 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 5138 | |
| 5139 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5140 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5141 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5142 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5143 | "Too many packed fields."); |
| 5144 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5145 | const FieldInfo field_info_; |
| 5146 | |
| 5147 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 5148 | }; |
| 5149 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5150 | class HArrayGet FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5151 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5152 | HArrayGet(HInstruction* array, |
| 5153 | HInstruction* index, |
| 5154 | Primitive::Type type, |
| 5155 | uint32_t dex_pc, |
| 5156 | bool is_string_char_at = false) |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5157 | : HExpression(type, SideEffects::ArrayReadOfType(type), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5158 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5159 | SetRawInputAt(0, array); |
| 5160 | SetRawInputAt(1, index); |
| 5161 | } |
| 5162 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5163 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5164 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5165 | return true; |
| 5166 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5167 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5168 | // TODO: We can be smarter here. |
| 5169 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 5170 | // which generates the implicit null check. There are cases when these can be removed |
| 5171 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 5172 | // implicit check here (as long as the address falls in the first page). |
| 5173 | return false; |
| 5174 | } |
| 5175 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5176 | bool IsEquivalentOf(HArrayGet* other) const { |
| 5177 | bool result = (GetDexPc() == other->GetDexPc()); |
| 5178 | if (kIsDebugBuild && result) { |
| 5179 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 5180 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 5181 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
| 5182 | if (Primitive::IsIntOrLongType(GetType())) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5183 | DCHECK(Primitive::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5184 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5185 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 5186 | DCHECK(Primitive::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5187 | } |
| 5188 | } |
| 5189 | return result; |
| 5190 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5191 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5192 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
| 5193 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5194 | HInstruction* GetArray() const { return InputAt(0); } |
| 5195 | HInstruction* GetIndex() const { return InputAt(1); } |
| 5196 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5197 | DECLARE_INSTRUCTION(ArrayGet); |
| 5198 | |
| 5199 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5200 | // We treat a String as an array, creating the HArrayGet from String.charAt() |
| 5201 | // intrinsic in the instruction simplifier. We can always determine whether |
| 5202 | // a particular HArrayGet is actually a String.charAt() by looking at the type |
| 5203 | // of the input but that requires holding the mutator lock, so we prefer to use |
| 5204 | // a flag, so that code generators don't need to do the locking. |
| 5205 | static constexpr size_t kFlagIsStringCharAt = kNumberOfExpressionPackedBits; |
| 5206 | static constexpr size_t kNumberOfArrayGetPackedBits = kFlagIsStringCharAt + 1; |
| 5207 | static_assert(kNumberOfArrayGetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5208 | "Too many packed fields."); |
| 5209 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5210 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 5211 | }; |
| 5212 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5213 | class HArraySet FINAL : public HTemplateInstruction<3> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5214 | public: |
| 5215 | HArraySet(HInstruction* array, |
| 5216 | HInstruction* index, |
| 5217 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5218 | Primitive::Type expected_component_type, |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5219 | uint32_t dex_pc) |
| 5220 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5221 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
| 5222 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == Primitive::kPrimNot); |
| 5223 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 5224 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5225 | SetRawInputAt(0, array); |
| 5226 | SetRawInputAt(1, index); |
| 5227 | SetRawInputAt(2, value); |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5228 | // Make a best guess now, may be refined during SSA building. |
| 5229 | ComputeSideEffects(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5230 | } |
| 5231 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5232 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5233 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5234 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5235 | } |
| 5236 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5237 | // Can throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5238 | bool CanThrow() const OVERRIDE { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5239 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5240 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5241 | // TODO: Same as for ArrayGet. |
| 5242 | return false; |
| 5243 | } |
| 5244 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5245 | void ClearNeedsTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5246 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5247 | } |
| 5248 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5249 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5250 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5251 | } |
| 5252 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5253 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5254 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5255 | } |
| 5256 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5257 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5258 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 5259 | bool StaticTypeOfArrayIsObjectArray() const { |
| 5260 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 5261 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5262 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5263 | HInstruction* GetArray() const { return InputAt(0); } |
| 5264 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5265 | HInstruction* GetValue() const { return InputAt(2); } |
| 5266 | |
| 5267 | Primitive::Type GetComponentType() const { |
| 5268 | // The Dex format does not type floating point index operations. Since the |
| 5269 | // `expected_component_type_` is set during building and can therefore not |
| 5270 | // be correct, we also check what is the value type. If it is a floating |
| 5271 | // point type, we must use that type. |
| 5272 | Primitive::Type value_type = GetValue()->GetType(); |
| 5273 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 5274 | ? value_type |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5275 | : GetRawExpectedComponentType(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5276 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5277 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5278 | Primitive::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5279 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5280 | } |
| 5281 | |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5282 | void ComputeSideEffects() { |
| 5283 | Primitive::Type type = GetComponentType(); |
| 5284 | SetSideEffects(SideEffects::ArrayWriteOfType(type).Union( |
| 5285 | SideEffectsForArchRuntimeCalls(type))); |
| 5286 | } |
| 5287 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5288 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 5289 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 5290 | } |
| 5291 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5292 | DECLARE_INSTRUCTION(ArraySet); |
| 5293 | |
| 5294 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5295 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 5296 | static constexpr size_t kFieldExpectedComponentTypeSize = |
| 5297 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5298 | static constexpr size_t kFlagNeedsTypeCheck = |
| 5299 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 5300 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5301 | // Cached information for the reference_type_info_ so that codegen |
| 5302 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5303 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 5304 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 5305 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 5306 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5307 | using ExpectedComponentTypeField = |
| 5308 | BitField<Primitive::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5309 | |
| 5310 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 5311 | }; |
| 5312 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5313 | class HArrayLength FINAL : public HExpression<1> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5314 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5315 | HArrayLength(HInstruction* array, uint32_t dex_pc, bool is_string_length = false) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5316 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5317 | SetPackedFlag<kFlagIsStringLength>(is_string_length); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5318 | // Note that arrays do not change length, so the instruction does not |
| 5319 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5320 | SetRawInputAt(0, array); |
| 5321 | } |
| 5322 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5323 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5324 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5325 | return true; |
| 5326 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5327 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5328 | return obj == InputAt(0); |
| 5329 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5330 | |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5331 | bool IsStringLength() const { return GetPackedFlag<kFlagIsStringLength>(); } |
| 5332 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5333 | DECLARE_INSTRUCTION(ArrayLength); |
| 5334 | |
| 5335 | private: |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5336 | // We treat a String as an array, creating the HArrayLength from String.length() |
| 5337 | // or String.isEmpty() intrinsic in the instruction simplifier. We can always |
| 5338 | // determine whether a particular HArrayLength is actually a String.length() by |
| 5339 | // looking at the type of the input but that requires holding the mutator lock, so |
| 5340 | // we prefer to use a flag, so that code generators don't need to do the locking. |
| 5341 | static constexpr size_t kFlagIsStringLength = kNumberOfExpressionPackedBits; |
| 5342 | static constexpr size_t kNumberOfArrayLengthPackedBits = kFlagIsStringLength + 1; |
| 5343 | static_assert(kNumberOfArrayLengthPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5344 | "Too many packed fields."); |
| 5345 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5346 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 5347 | }; |
| 5348 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5349 | class HBoundsCheck FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5350 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5351 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
| 5352 | // constructor. |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5353 | HBoundsCheck(HInstruction* index, |
| 5354 | HInstruction* length, |
| 5355 | uint32_t dex_pc, |
| 5356 | uint32_t string_char_at_method_index = DexFile::kDexNoIndex) |
| 5357 | : HExpression(index->GetType(), SideEffects::CanTriggerGC(), dex_pc), |
| 5358 | string_char_at_method_index_(string_char_at_method_index) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 5359 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(index->GetType())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5360 | SetRawInputAt(0, index); |
| 5361 | SetRawInputAt(1, length); |
| 5362 | } |
| 5363 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5364 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5365 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5366 | return true; |
| 5367 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5368 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5369 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5370 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5371 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5372 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5373 | bool IsStringCharAt() const { return GetStringCharAtMethodIndex() != DexFile::kDexNoIndex; } |
| 5374 | uint32_t GetStringCharAtMethodIndex() const { return string_char_at_method_index_; } |
| 5375 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5376 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5377 | |
| 5378 | DECLARE_INSTRUCTION(BoundsCheck); |
| 5379 | |
| 5380 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5381 | // We treat a String as an array, creating the HBoundsCheck from String.charAt() |
| 5382 | // intrinsic in the instruction simplifier. We want to include the String.charAt() |
| 5383 | // in the stack trace if we actually throw the StringIndexOutOfBoundsException, |
| 5384 | // so we need to create an HEnvironment which will be translated to an InlineInfo |
| 5385 | // indicating the extra stack frame. Since we add this HEnvironment quite late, |
| 5386 | // in the PrepareForRegisterAllocation pass, we need to remember the method index |
| 5387 | // from the invoke as we don't want to look again at the dex bytecode. |
| 5388 | uint32_t string_char_at_method_index_; // DexFile::kDexNoIndex if regular array. |
| 5389 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5390 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 5391 | }; |
| 5392 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5393 | class HSuspendCheck FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5394 | public: |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 5395 | explicit HSuspendCheck(uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5396 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5397 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5398 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5399 | return true; |
| 5400 | } |
| 5401 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5402 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 5403 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5404 | |
| 5405 | DECLARE_INSTRUCTION(SuspendCheck); |
| 5406 | |
| 5407 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5408 | // Only used for code generation, in order to share the same slow path between back edges |
| 5409 | // of a same loop. |
| 5410 | SlowPathCode* slow_path_; |
| 5411 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5412 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 5413 | }; |
| 5414 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 5415 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 5416 | // It ensures that we can generate line number and local variables at this point. |
| 5417 | class HNativeDebugInfo : public HTemplateInstruction<0> { |
| 5418 | public: |
| 5419 | explicit HNativeDebugInfo(uint32_t dex_pc) |
| 5420 | : HTemplateInstruction<0>(SideEffects::None(), dex_pc) {} |
| 5421 | |
| 5422 | bool NeedsEnvironment() const OVERRIDE { |
| 5423 | return true; |
| 5424 | } |
| 5425 | |
| 5426 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 5427 | |
| 5428 | private: |
| 5429 | DISALLOW_COPY_AND_ASSIGN(HNativeDebugInfo); |
| 5430 | }; |
| 5431 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5432 | /** |
| 5433 | * Instruction to load a Class object. |
| 5434 | */ |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5435 | class HLoadClass FINAL : public HInstruction { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5436 | public: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5437 | // Determines how to load the Class. |
| 5438 | enum class LoadKind { |
| 5439 | // Use the Class* from the method's own ArtMethod*. |
| 5440 | kReferrersClass, |
| 5441 | |
| 5442 | // Use boot image Class* address that will be known at link time. |
| 5443 | // Used for boot image classes referenced by boot image code in non-PIC mode. |
| 5444 | kBootImageLinkTimeAddress, |
| 5445 | |
| 5446 | // Use PC-relative boot image Class* address that will be known at link time. |
| 5447 | // Used for boot image classes referenced by boot image code in PIC mode. |
| 5448 | kBootImageLinkTimePcRelative, |
| 5449 | |
| 5450 | // Use a known boot image Class* address, embedded in the code by the codegen. |
| 5451 | // Used for boot image classes referenced by apps in AOT- and JIT-compiled code. |
| 5452 | // Note: codegen needs to emit a linker patch if indicated by compiler options' |
| 5453 | // GetIncludePatchInformation(). |
| 5454 | kBootImageAddress, |
| 5455 | |
| 5456 | // Load from the resolved types array at an absolute address. |
| 5457 | // Used for classes outside the boot image referenced by JIT-compiled code. |
| 5458 | kDexCacheAddress, |
| 5459 | |
| 5460 | // Load from resolved types array in the dex cache using a PC-relative load. |
| 5461 | // Used for classes outside boot image when we know that we can access |
| 5462 | // the dex cache arrays using a PC-relative load. |
| 5463 | kDexCachePcRelative, |
| 5464 | |
| 5465 | // Load from resolved types array accessed through the class loaded from |
| 5466 | // the compiled method's own ArtMethod*. This is the default access type when |
| 5467 | // all other types are unavailable. |
| 5468 | kDexCacheViaMethod, |
| 5469 | |
| 5470 | kLast = kDexCacheViaMethod |
| 5471 | }; |
| 5472 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5473 | HLoadClass(HCurrentMethod* current_method, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5474 | dex::TypeIndex type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5475 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5476 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5477 | uint32_t dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5478 | bool needs_access_check, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5479 | bool is_in_dex_cache, |
| 5480 | bool is_in_boot_image) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5481 | : HInstruction(SideEffectsForArchRuntimeCalls(), dex_pc), |
| 5482 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5483 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5484 | dex_file_(dex_file), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5485 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5486 | // Referrers class should not need access check. We never inline unverified |
| 5487 | // methods so we can't possibly end up in this situation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5488 | DCHECK(!is_referrers_class || !needs_access_check); |
| 5489 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5490 | SetPackedField<LoadKindField>( |
| 5491 | is_referrers_class ? LoadKind::kReferrersClass : LoadKind::kDexCacheViaMethod); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5492 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
| 5493 | SetPackedFlag<kFlagIsInDexCache>(is_in_dex_cache); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5494 | SetPackedFlag<kFlagIsInBootImage>(is_in_boot_image); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5495 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5496 | } |
| 5497 | |
| 5498 | void SetLoadKindWithAddress(LoadKind load_kind, uint64_t address) { |
| 5499 | DCHECK(HasAddress(load_kind)); |
| 5500 | load_data_.address = address; |
| 5501 | SetLoadKindInternal(load_kind); |
| 5502 | } |
| 5503 | |
| 5504 | void SetLoadKindWithTypeReference(LoadKind load_kind, |
| 5505 | const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5506 | dex::TypeIndex type_index) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5507 | DCHECK(HasTypeReference(load_kind)); |
| 5508 | DCHECK(IsSameDexFile(dex_file_, dex_file)); |
| 5509 | DCHECK_EQ(type_index_, type_index); |
| 5510 | SetLoadKindInternal(load_kind); |
| 5511 | } |
| 5512 | |
| 5513 | void SetLoadKindWithDexCacheReference(LoadKind load_kind, |
| 5514 | const DexFile& dex_file, |
| 5515 | uint32_t element_index) { |
| 5516 | DCHECK(HasDexCacheReference(load_kind)); |
| 5517 | DCHECK(IsSameDexFile(dex_file_, dex_file)); |
| 5518 | load_data_.dex_cache_element_index = element_index; |
| 5519 | SetLoadKindInternal(load_kind); |
| 5520 | } |
| 5521 | |
| 5522 | LoadKind GetLoadKind() const { |
| 5523 | return GetPackedField<LoadKindField>(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5524 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5525 | |
| 5526 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5527 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5528 | bool InstructionDataEquals(const HInstruction* other) const; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5529 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5530 | size_t ComputeHashCode() const OVERRIDE { return type_index_.index_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5531 | |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 5532 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5533 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5534 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5535 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5536 | } |
| 5537 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 5538 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 5539 | // The entrypoint the code generator is going to call does not do |
| 5540 | // clinit of the class. |
| 5541 | DCHECK(!NeedsAccessCheck()); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5542 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5543 | } |
| 5544 | |
| 5545 | bool CanCallRuntime() const { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5546 | return MustGenerateClinitCheck() || |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5547 | (!IsReferrersClass() && !IsInDexCache()) || |
| 5548 | NeedsAccessCheck(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5549 | } |
| 5550 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5551 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5552 | bool CanThrow() const OVERRIDE { |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 5553 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5554 | } |
| 5555 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5556 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 5557 | return loaded_class_rti_; |
| 5558 | } |
| 5559 | |
| 5560 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 5561 | // Make sure we only set exact types (the loaded class should never be merged). |
| 5562 | DCHECK(rti.IsExact()); |
| 5563 | loaded_class_rti_ = rti; |
| 5564 | } |
| 5565 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5566 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5567 | const DexFile& GetDexFile() const { return dex_file_; } |
| 5568 | |
| 5569 | uint32_t GetDexCacheElementOffset() const; |
| 5570 | |
| 5571 | uint64_t GetAddress() const { |
| 5572 | DCHECK(HasAddress(GetLoadKind())); |
| 5573 | return load_data_.address; |
| 5574 | } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5575 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5576 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return !IsReferrersClass(); } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 5577 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5578 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5579 | return SideEffects::CanTriggerGC(); |
| 5580 | } |
| 5581 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5582 | bool IsReferrersClass() const { return GetLoadKind() == LoadKind::kReferrersClass; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5583 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
| 5584 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5585 | bool IsInBootImage() const { return GetPackedFlag<kFlagIsInBootImage>(); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5586 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5587 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5588 | void MarkInDexCache() { |
| 5589 | SetPackedFlag<kFlagIsInDexCache>(true); |
| 5590 | DCHECK(!NeedsEnvironment()); |
| 5591 | RemoveEnvironment(); |
| 5592 | SetSideEffects(SideEffects::None()); |
| 5593 | } |
| 5594 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5595 | void MarkInBootImage() { |
| 5596 | SetPackedFlag<kFlagIsInBootImage>(true); |
| 5597 | } |
| 5598 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5599 | void AddSpecialInput(HInstruction* special_input); |
| 5600 | |
| 5601 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 5602 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 5603 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 5604 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 5605 | } |
| 5606 | |
| 5607 | Primitive::Type GetType() const OVERRIDE { |
| 5608 | return Primitive::kPrimNot; |
| 5609 | } |
| 5610 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5611 | DECLARE_INSTRUCTION(LoadClass); |
| 5612 | |
| 5613 | private: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5614 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5615 | static constexpr size_t kFlagIsInDexCache = kFlagNeedsAccessCheck + 1; |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5616 | static constexpr size_t kFlagIsInBootImage = kFlagIsInDexCache + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5617 | // Whether this instruction must generate the initialization check. |
| 5618 | // Used for code generation. |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5619 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInBootImage + 1; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5620 | static constexpr size_t kFieldLoadKind = kFlagGenerateClInitCheck + 1; |
| 5621 | static constexpr size_t kFieldLoadKindSize = |
| 5622 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 5623 | static constexpr size_t kNumberOfLoadClassPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5624 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5625 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
| 5626 | |
| 5627 | static bool HasTypeReference(LoadKind load_kind) { |
| 5628 | return load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5629 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
| 5630 | load_kind == LoadKind::kDexCacheViaMethod || |
| 5631 | load_kind == LoadKind::kReferrersClass; |
| 5632 | } |
| 5633 | |
| 5634 | static bool HasAddress(LoadKind load_kind) { |
| 5635 | return load_kind == LoadKind::kBootImageAddress || load_kind == LoadKind::kDexCacheAddress; |
| 5636 | } |
| 5637 | |
| 5638 | static bool HasDexCacheReference(LoadKind load_kind) { |
| 5639 | return load_kind == LoadKind::kDexCachePcRelative; |
| 5640 | } |
| 5641 | |
| 5642 | void SetLoadKindInternal(LoadKind load_kind); |
| 5643 | |
| 5644 | // The special input is the HCurrentMethod for kDexCacheViaMethod or kReferrersClass. |
| 5645 | // For other load kinds it's empty or possibly some architecture-specific instruction |
| 5646 | // for PC-relative loads, i.e. kDexCachePcRelative or kBootImageLinkTimePcRelative. |
| 5647 | HUserRecord<HInstruction*> special_input_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5648 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5649 | const dex::TypeIndex type_index_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5650 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5651 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5652 | union { |
| 5653 | uint32_t dex_cache_element_index; // Only for dex cache reference. |
| 5654 | uint64_t address; // Up to 64-bit, needed for kDexCacheAddress on 64-bit targets. |
| 5655 | } load_data_; |
| 5656 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5657 | ReferenceTypeInfo loaded_class_rti_; |
| 5658 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5659 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 5660 | }; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5661 | std::ostream& operator<<(std::ostream& os, HLoadClass::LoadKind rhs); |
| 5662 | |
| 5663 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
| 5664 | inline uint32_t HLoadClass::GetDexCacheElementOffset() const { |
| 5665 | DCHECK(HasDexCacheReference(GetLoadKind())) << GetLoadKind(); |
| 5666 | return load_data_.dex_cache_element_index; |
| 5667 | } |
| 5668 | |
| 5669 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
| 5670 | inline void HLoadClass::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5671 | // The special input is used for PC-relative loads on some architectures, |
| 5672 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5673 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5674 | GetLoadKind() == LoadKind::kDexCachePcRelative || |
| 5675 | GetLoadKind() == LoadKind::kBootImageLinkTimeAddress || |
| 5676 | GetLoadKind() == LoadKind::kBootImageAddress) << GetLoadKind(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5677 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 5678 | special_input_ = HUserRecord<HInstruction*>(special_input); |
| 5679 | special_input->AddUseAt(this, 0); |
| 5680 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5681 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5682 | class HLoadString FINAL : public HInstruction { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5683 | public: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5684 | // Determines how to load the String. |
| 5685 | enum class LoadKind { |
| 5686 | // Use boot image String* address that will be known at link time. |
| 5687 | // Used for boot image strings referenced by boot image code in non-PIC mode. |
| 5688 | kBootImageLinkTimeAddress, |
| 5689 | |
| 5690 | // Use PC-relative boot image String* address that will be known at link time. |
| 5691 | // Used for boot image strings referenced by boot image code in PIC mode. |
| 5692 | kBootImageLinkTimePcRelative, |
| 5693 | |
| 5694 | // Use a known boot image String* address, embedded in the code by the codegen. |
| 5695 | // Used for boot image strings referenced by apps in AOT- and JIT-compiled code. |
| 5696 | // Note: codegen needs to emit a linker patch if indicated by compiler options' |
| 5697 | // GetIncludePatchInformation(). |
| 5698 | kBootImageAddress, |
| 5699 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5700 | // Load from an entry in the .bss section using a PC-relative load. |
| 5701 | // Used for strings outside boot image when .bss is accessible with a PC-relative load. |
| 5702 | kBssEntry, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5703 | |
| 5704 | // Load from resolved strings array accessed through the class loaded from |
| 5705 | // the compiled method's own ArtMethod*. This is the default access type when |
| 5706 | // all other types are unavailable. |
| 5707 | kDexCacheViaMethod, |
| 5708 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5709 | // Load from the root table associated with the JIT compiled method. |
| 5710 | kJitTableAddress, |
| 5711 | |
| 5712 | kLast = kJitTableAddress, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5713 | }; |
| 5714 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5715 | HLoadString(HCurrentMethod* current_method, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5716 | dex::StringIndex string_index, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5717 | const DexFile& dex_file, |
| 5718 | uint32_t dex_pc) |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5719 | : HInstruction(SideEffectsForArchRuntimeCalls(), dex_pc), |
| 5720 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5721 | string_index_(string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5722 | SetPackedFlag<kFlagIsInDexCache>(false); |
| 5723 | SetPackedField<LoadKindField>(LoadKind::kDexCacheViaMethod); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5724 | load_data_.dex_file_ = &dex_file; |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5725 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5726 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5727 | void SetLoadKindWithAddress(LoadKind load_kind, uint64_t address) { |
| 5728 | DCHECK(HasAddress(load_kind)); |
| 5729 | load_data_.address = address; |
| 5730 | SetLoadKindInternal(load_kind); |
| 5731 | } |
| 5732 | |
| 5733 | void SetLoadKindWithStringReference(LoadKind load_kind, |
| 5734 | const DexFile& dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5735 | dex::StringIndex string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5736 | DCHECK(HasStringReference(load_kind)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5737 | load_data_.dex_file_ = &dex_file; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5738 | string_index_ = string_index; |
| 5739 | SetLoadKindInternal(load_kind); |
| 5740 | } |
| 5741 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5742 | LoadKind GetLoadKind() const { |
| 5743 | return GetPackedField<LoadKindField>(); |
| 5744 | } |
| 5745 | |
| 5746 | const DexFile& GetDexFile() const; |
| 5747 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5748 | dex::StringIndex GetStringIndex() const { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5749 | DCHECK(HasStringReference(GetLoadKind()) || /* For slow paths. */ !IsInDexCache()); |
| 5750 | return string_index_; |
| 5751 | } |
| 5752 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5753 | uint64_t GetAddress() const { |
| 5754 | DCHECK(HasAddress(GetLoadKind())); |
| 5755 | return load_data_.address; |
| 5756 | } |
| 5757 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5758 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5759 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5760 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5761 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5762 | size_t ComputeHashCode() const OVERRIDE { return string_index_.index_; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5763 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5764 | // Will call the runtime if we need to load the string through |
| 5765 | // the dex cache and the string is not guaranteed to be there yet. |
| 5766 | bool NeedsEnvironment() const OVERRIDE { |
| 5767 | LoadKind load_kind = GetLoadKind(); |
| 5768 | if (load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5769 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5770 | load_kind == LoadKind::kBootImageAddress || |
| 5771 | load_kind == LoadKind::kJitTableAddress) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5772 | return false; |
| 5773 | } |
| 5774 | return !IsInDexCache(); |
| 5775 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5776 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5777 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
| 5778 | return GetLoadKind() == LoadKind::kDexCacheViaMethod; |
| 5779 | } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5780 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 5781 | bool CanBeNull() const OVERRIDE { return false; } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5782 | bool CanThrow() const OVERRIDE { return NeedsEnvironment(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5783 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5784 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5785 | return SideEffects::CanTriggerGC(); |
| 5786 | } |
| 5787 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5788 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
| 5789 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5790 | void MarkInDexCache() { |
| 5791 | SetPackedFlag<kFlagIsInDexCache>(true); |
| 5792 | DCHECK(!NeedsEnvironment()); |
| 5793 | RemoveEnvironment(); |
Vladimir Marko | ace7a00 | 2016-04-05 11:18:49 +0100 | [diff] [blame] | 5794 | SetSideEffects(SideEffects::None()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5795 | } |
| 5796 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5797 | void AddSpecialInput(HInstruction* special_input); |
| 5798 | |
| 5799 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 5800 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 5801 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 5802 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5803 | } |
| 5804 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5805 | Primitive::Type GetType() const OVERRIDE { |
| 5806 | return Primitive::kPrimNot; |
| 5807 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5808 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5809 | DECLARE_INSTRUCTION(LoadString); |
| 5810 | |
| 5811 | private: |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5812 | static constexpr size_t kFlagIsInDexCache = kNumberOfGenericPackedBits; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5813 | static constexpr size_t kFieldLoadKind = kFlagIsInDexCache + 1; |
| 5814 | static constexpr size_t kFieldLoadKindSize = |
| 5815 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 5816 | static constexpr size_t kNumberOfLoadStringPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5817 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5818 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5819 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5820 | static bool HasStringReference(LoadKind load_kind) { |
| 5821 | return load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5822 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5823 | load_kind == LoadKind::kBssEntry || |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5824 | load_kind == LoadKind::kDexCacheViaMethod || |
| 5825 | load_kind == LoadKind::kJitTableAddress; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5826 | } |
| 5827 | |
| 5828 | static bool HasAddress(LoadKind load_kind) { |
Vladimir Marko | 54d6a20 | 2016-11-09 12:46:38 +0000 | [diff] [blame] | 5829 | return load_kind == LoadKind::kBootImageAddress; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5830 | } |
| 5831 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5832 | void SetLoadKindInternal(LoadKind load_kind); |
| 5833 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5834 | // The special input is the HCurrentMethod for kDexCacheViaMethod. |
| 5835 | // For other load kinds it's empty or possibly some architecture-specific instruction |
| 5836 | // for PC-relative loads, i.e. kDexCachePcRelative or kBootImageLinkTimePcRelative. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5837 | HUserRecord<HInstruction*> special_input_; |
| 5838 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5839 | // String index serves also as the hash code and it's also needed for slow-paths, |
| 5840 | // so it must not be overwritten with other load data. |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5841 | dex::StringIndex string_index_; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5842 | |
| 5843 | union { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5844 | const DexFile* dex_file_; // For string reference. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5845 | uint64_t address; // Up to 64-bit, needed for kDexCacheAddress on 64-bit targets. |
| 5846 | } load_data_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5847 | |
| 5848 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 5849 | }; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5850 | std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs); |
| 5851 | |
| 5852 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5853 | inline const DexFile& HLoadString::GetDexFile() const { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5854 | DCHECK(HasStringReference(GetLoadKind())) << GetLoadKind(); |
| 5855 | return *load_data_.dex_file_; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5856 | } |
| 5857 | |
| 5858 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5859 | inline void HLoadString::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5860 | // The special input is used for PC-relative loads on some architectures, |
| 5861 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5862 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5863 | GetLoadKind() == LoadKind::kBssEntry || |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5864 | GetLoadKind() == LoadKind::kBootImageLinkTimeAddress || |
| 5865 | GetLoadKind() == LoadKind::kBootImageAddress) << GetLoadKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5866 | // HLoadString::GetInputRecords() returns an empty array at this point, |
| 5867 | // so use the GetInputRecords() from the base class to set the input record. |
| 5868 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 5869 | special_input_ = HUserRecord<HInstruction*>(special_input); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5870 | special_input->AddUseAt(this, 0); |
| 5871 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5872 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5873 | /** |
| 5874 | * Performs an initialization check on its Class object input. |
| 5875 | */ |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5876 | class HClinitCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5877 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 5878 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 5879 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5880 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5881 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 5882 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5883 | SetRawInputAt(0, constant); |
| 5884 | } |
| 5885 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5886 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5887 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5888 | return true; |
| 5889 | } |
| 5890 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5891 | bool NeedsEnvironment() const OVERRIDE { |
| 5892 | // May call runtime to initialize the class. |
| 5893 | return true; |
| 5894 | } |
| 5895 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 5896 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5897 | |
| 5898 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 5899 | |
| 5900 | DECLARE_INSTRUCTION(ClinitCheck); |
| 5901 | |
| 5902 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5903 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 5904 | }; |
| 5905 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5906 | class HStaticFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5907 | public: |
| 5908 | HStaticFieldGet(HInstruction* cls, |
| 5909 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5910 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5911 | bool is_volatile, |
| 5912 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5913 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5914 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5915 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5916 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5917 | : HExpression(field_type, SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5918 | field_info_(field_offset, |
| 5919 | field_type, |
| 5920 | is_volatile, |
| 5921 | field_idx, |
| 5922 | declaring_class_def_index, |
| 5923 | dex_file, |
| 5924 | dex_cache) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5925 | SetRawInputAt(0, cls); |
| 5926 | } |
| 5927 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5928 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5929 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5930 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5931 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 5932 | const HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5933 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5934 | } |
| 5935 | |
| 5936 | size_t ComputeHashCode() const OVERRIDE { |
| 5937 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5938 | } |
| 5939 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5940 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5941 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5942 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5943 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5944 | |
| 5945 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 5946 | |
| 5947 | private: |
| 5948 | const FieldInfo field_info_; |
| 5949 | |
| 5950 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 5951 | }; |
| 5952 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5953 | class HStaticFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5954 | public: |
| 5955 | HStaticFieldSet(HInstruction* cls, |
| 5956 | HInstruction* value, |
| 5957 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5958 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5959 | bool is_volatile, |
| 5960 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5961 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5962 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5963 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5964 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5965 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5966 | field_info_(field_offset, |
| 5967 | field_type, |
| 5968 | is_volatile, |
| 5969 | field_idx, |
| 5970 | declaring_class_def_index, |
| 5971 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5972 | dex_cache) { |
| 5973 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5974 | SetRawInputAt(0, cls); |
| 5975 | SetRawInputAt(1, value); |
| 5976 | } |
| 5977 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5978 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5979 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5980 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5981 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5982 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5983 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5984 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5985 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5986 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5987 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 5988 | |
| 5989 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5990 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5991 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5992 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5993 | "Too many packed fields."); |
| 5994 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5995 | const FieldInfo field_info_; |
| 5996 | |
| 5997 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 5998 | }; |
| 5999 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6000 | class HUnresolvedInstanceFieldGet FINAL : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6001 | public: |
| 6002 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 6003 | Primitive::Type field_type, |
| 6004 | uint32_t field_index, |
| 6005 | uint32_t dex_pc) |
| 6006 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 6007 | field_index_(field_index) { |
| 6008 | SetRawInputAt(0, obj); |
| 6009 | } |
| 6010 | |
| 6011 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6012 | bool CanThrow() const OVERRIDE { return true; } |
| 6013 | |
| 6014 | Primitive::Type GetFieldType() const { return GetType(); } |
| 6015 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6016 | |
| 6017 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 6018 | |
| 6019 | private: |
| 6020 | const uint32_t field_index_; |
| 6021 | |
| 6022 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 6023 | }; |
| 6024 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6025 | class HUnresolvedInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6026 | public: |
| 6027 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 6028 | HInstruction* value, |
| 6029 | Primitive::Type field_type, |
| 6030 | uint32_t field_index, |
| 6031 | uint32_t dex_pc) |
| 6032 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6033 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6034 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 6035 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6036 | SetRawInputAt(0, obj); |
| 6037 | SetRawInputAt(1, value); |
| 6038 | } |
| 6039 | |
| 6040 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6041 | bool CanThrow() const OVERRIDE { return true; } |
| 6042 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6043 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6044 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6045 | |
| 6046 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 6047 | |
| 6048 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6049 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6050 | static constexpr size_t kFieldFieldTypeSize = |
| 6051 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 6052 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6053 | kFieldFieldType + kFieldFieldTypeSize; |
| 6054 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6055 | "Too many packed fields."); |
| 6056 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 6057 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6058 | const uint32_t field_index_; |
| 6059 | |
| 6060 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 6061 | }; |
| 6062 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6063 | class HUnresolvedStaticFieldGet FINAL : public HExpression<0> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6064 | public: |
| 6065 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 6066 | uint32_t field_index, |
| 6067 | uint32_t dex_pc) |
| 6068 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 6069 | field_index_(field_index) { |
| 6070 | } |
| 6071 | |
| 6072 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6073 | bool CanThrow() const OVERRIDE { return true; } |
| 6074 | |
| 6075 | Primitive::Type GetFieldType() const { return GetType(); } |
| 6076 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6077 | |
| 6078 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 6079 | |
| 6080 | private: |
| 6081 | const uint32_t field_index_; |
| 6082 | |
| 6083 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 6084 | }; |
| 6085 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6086 | class HUnresolvedStaticFieldSet FINAL : public HTemplateInstruction<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6087 | public: |
| 6088 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 6089 | Primitive::Type field_type, |
| 6090 | uint32_t field_index, |
| 6091 | uint32_t dex_pc) |
| 6092 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6093 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6094 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 6095 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6096 | SetRawInputAt(0, value); |
| 6097 | } |
| 6098 | |
| 6099 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6100 | bool CanThrow() const OVERRIDE { return true; } |
| 6101 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6102 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6103 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6104 | |
| 6105 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 6106 | |
| 6107 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6108 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6109 | static constexpr size_t kFieldFieldTypeSize = |
| 6110 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 6111 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6112 | kFieldFieldType + kFieldFieldTypeSize; |
| 6113 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6114 | "Too many packed fields."); |
| 6115 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 6116 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6117 | const uint32_t field_index_; |
| 6118 | |
| 6119 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 6120 | }; |
| 6121 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6122 | // Implement the move-exception DEX instruction. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6123 | class HLoadException FINAL : public HExpression<0> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6124 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6125 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 6126 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6127 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 6128 | bool CanBeNull() const OVERRIDE { return false; } |
| 6129 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6130 | DECLARE_INSTRUCTION(LoadException); |
| 6131 | |
| 6132 | private: |
| 6133 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 6134 | }; |
| 6135 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6136 | // Implicit part of move-exception which clears thread-local exception storage. |
| 6137 | // 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] | 6138 | class HClearException FINAL : public HTemplateInstruction<0> { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6139 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6140 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 6141 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6142 | |
| 6143 | DECLARE_INSTRUCTION(ClearException); |
| 6144 | |
| 6145 | private: |
| 6146 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 6147 | }; |
| 6148 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6149 | class HThrow FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6150 | public: |
| 6151 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6152 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6153 | SetRawInputAt(0, exception); |
| 6154 | } |
| 6155 | |
| 6156 | bool IsControlFlow() const OVERRIDE { return true; } |
| 6157 | |
| 6158 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6159 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6160 | bool CanThrow() const OVERRIDE { return true; } |
| 6161 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6162 | |
| 6163 | DECLARE_INSTRUCTION(Throw); |
| 6164 | |
| 6165 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6166 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 6167 | }; |
| 6168 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6169 | /** |
| 6170 | * Implementation strategies for the code generator of a HInstanceOf |
| 6171 | * or `HCheckCast`. |
| 6172 | */ |
| 6173 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6174 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6175 | kExactCheck, // Can do a single class compare. |
| 6176 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 6177 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 6178 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 6179 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6180 | kArrayCheck, // No optimization yet when checking against a generic array. |
| 6181 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6182 | }; |
| 6183 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6184 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 6185 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6186 | class HInstanceOf FINAL : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6187 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6188 | HInstanceOf(HInstruction* object, |
| 6189 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6190 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6191 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6192 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6193 | SideEffectsForArchRuntimeCalls(check_kind), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6194 | dex_pc) { |
| 6195 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6196 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6197 | SetRawInputAt(0, object); |
| 6198 | SetRawInputAt(1, constant); |
| 6199 | } |
| 6200 | |
| 6201 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6202 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6203 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6204 | return true; |
| 6205 | } |
| 6206 | |
| 6207 | bool NeedsEnvironment() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6208 | return CanCallRuntime(GetTypeCheckKind()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6209 | } |
| 6210 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6211 | // Used only in code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6212 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6213 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6214 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6215 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6216 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6217 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 6218 | // Mips currently does runtime calls for any other checks. |
| 6219 | return check_kind != TypeCheckKind::kExactCheck; |
| 6220 | } |
| 6221 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6222 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6223 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6224 | } |
| 6225 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6226 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6227 | |
| 6228 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6229 | static constexpr size_t kFieldTypeCheckKind = kNumberOfExpressionPackedBits; |
| 6230 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6231 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6232 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6233 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagMustDoNullCheck + 1; |
| 6234 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6235 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6236 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6237 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 6238 | }; |
| 6239 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6240 | class HBoundType FINAL : public HExpression<1> { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6241 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 6242 | explicit HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6243 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6244 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 6245 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 6246 | SetPackedFlag<kFlagCanBeNull>(true); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 6247 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6248 | SetRawInputAt(0, input); |
| 6249 | } |
| 6250 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6251 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6252 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6253 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6254 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6255 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6256 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6257 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 6258 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6259 | } |
| 6260 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6261 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6262 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6263 | DECLARE_INSTRUCTION(BoundType); |
| 6264 | |
| 6265 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6266 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 6267 | // is false then CanBeNull() cannot be true). |
| 6268 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfExpressionPackedBits; |
| 6269 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 6270 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 6271 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6272 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6273 | // 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] | 6274 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 6275 | // It is used to bound the type in cases like: |
| 6276 | // if (x instanceof ClassX) { |
| 6277 | // // uper_bound_ will be ClassX |
| 6278 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6279 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6280 | |
| 6281 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 6282 | }; |
| 6283 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6284 | class HCheckCast FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6285 | public: |
| 6286 | HCheckCast(HInstruction* object, |
| 6287 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6288 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6289 | uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6290 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
| 6291 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6292 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6293 | SetRawInputAt(0, object); |
| 6294 | SetRawInputAt(1, constant); |
| 6295 | } |
| 6296 | |
| 6297 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6298 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6299 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6300 | return true; |
| 6301 | } |
| 6302 | |
| 6303 | bool NeedsEnvironment() const OVERRIDE { |
| 6304 | // Instruction may throw a CheckCastError. |
| 6305 | return true; |
| 6306 | } |
| 6307 | |
| 6308 | bool CanThrow() const OVERRIDE { return true; } |
| 6309 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6310 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6311 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6312 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6313 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6314 | |
| 6315 | DECLARE_INSTRUCTION(CheckCast); |
| 6316 | |
| 6317 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6318 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 6319 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6320 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6321 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6322 | static constexpr size_t kNumberOfCheckCastPackedBits = kFlagMustDoNullCheck + 1; |
| 6323 | static_assert(kNumberOfCheckCastPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6324 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6325 | |
| 6326 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6327 | }; |
| 6328 | |
Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame] | 6329 | /** |
| 6330 | * @brief Memory barrier types (see "The JSR-133 Cookbook for Compiler Writers"). |
| 6331 | * @details We define the combined barrier types that are actually required |
| 6332 | * by the Java Memory Model, rather than using exactly the terminology from |
| 6333 | * the JSR-133 cookbook. These should, in many cases, be replaced by acquire/release |
| 6334 | * primitives. Note that the JSR-133 cookbook generally does not deal with |
| 6335 | * store atomicity issues, and the recipes there are not always entirely sufficient. |
| 6336 | * The current recipe is as follows: |
| 6337 | * -# Use AnyStore ~= (LoadStore | StoreStore) ~= release barrier before volatile store. |
| 6338 | * -# Use AnyAny barrier after volatile store. (StoreLoad is as expensive.) |
| 6339 | * -# Use LoadAny barrier ~= (LoadLoad | LoadStore) ~= acquire barrier after each volatile load. |
| 6340 | * -# Use StoreStore barrier after all stores but before return from any constructor whose |
| 6341 | * class has final fields. |
| 6342 | * -# Use NTStoreStore to order non-temporal stores with respect to all later |
| 6343 | * store-to-memory instructions. Only generated together with non-temporal stores. |
| 6344 | */ |
| 6345 | enum MemBarrierKind { |
| 6346 | kAnyStore, |
| 6347 | kLoadAny, |
| 6348 | kStoreStore, |
| 6349 | kAnyAny, |
| 6350 | kNTStoreStore, |
| 6351 | kLastBarrierKind = kNTStoreStore |
| 6352 | }; |
| 6353 | std::ostream& operator<<(std::ostream& os, const MemBarrierKind& kind); |
| 6354 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6355 | class HMemoryBarrier FINAL : public HTemplateInstruction<0> { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6356 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6357 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 6358 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6359 | SideEffects::AllWritesAndReads(), dex_pc) { // Assume write/read on all fields/arrays. |
| 6360 | SetPackedField<BarrierKindField>(barrier_kind); |
| 6361 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6362 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6363 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6364 | |
| 6365 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 6366 | |
| 6367 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6368 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 6369 | static constexpr size_t kFieldBarrierKindSize = |
| 6370 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 6371 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 6372 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 6373 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 6374 | "Too many packed fields."); |
| 6375 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6376 | |
| 6377 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 6378 | }; |
| 6379 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6380 | class HMonitorOperation FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6381 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6382 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6383 | kEnter, |
| 6384 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6385 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6386 | }; |
| 6387 | |
| 6388 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6389 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6390 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 6391 | dex_pc) { |
| 6392 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6393 | SetRawInputAt(0, object); |
| 6394 | } |
| 6395 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6396 | // Instruction may go into runtime, so we need an environment. |
| 6397 | bool NeedsEnvironment() const OVERRIDE { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 6398 | |
| 6399 | bool CanThrow() const OVERRIDE { |
| 6400 | // Verifier guarantees that monitor-exit cannot throw. |
| 6401 | // This is important because it allows the HGraphBuilder to remove |
| 6402 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 6403 | return IsEnter(); |
| 6404 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6405 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6406 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 6407 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6408 | |
| 6409 | DECLARE_INSTRUCTION(MonitorOperation); |
| 6410 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6411 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6412 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 6413 | static constexpr size_t kFieldOperationKindSize = |
| 6414 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 6415 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 6416 | kFieldOperationKind + kFieldOperationKindSize; |
| 6417 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6418 | "Too many packed fields."); |
| 6419 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6420 | |
| 6421 | private: |
| 6422 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 6423 | }; |
| 6424 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6425 | class HSelect FINAL : public HExpression<3> { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6426 | public: |
| 6427 | HSelect(HInstruction* condition, |
| 6428 | HInstruction* true_value, |
| 6429 | HInstruction* false_value, |
| 6430 | uint32_t dex_pc) |
| 6431 | : HExpression(HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
| 6432 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 6433 | |
| 6434 | // First input must be `true_value` or `false_value` to allow codegens to |
| 6435 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 6436 | // that architectures which implement HSelect as a conditional move also |
| 6437 | // will not need to invert the condition. |
| 6438 | SetRawInputAt(0, false_value); |
| 6439 | SetRawInputAt(1, true_value); |
| 6440 | SetRawInputAt(2, condition); |
| 6441 | } |
| 6442 | |
| 6443 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 6444 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 6445 | HInstruction* GetCondition() const { return InputAt(2); } |
| 6446 | |
| 6447 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6448 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 6449 | return true; |
| 6450 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6451 | |
| 6452 | bool CanBeNull() const OVERRIDE { |
| 6453 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 6454 | } |
| 6455 | |
| 6456 | DECLARE_INSTRUCTION(Select); |
| 6457 | |
| 6458 | private: |
| 6459 | DISALLOW_COPY_AND_ASSIGN(HSelect); |
| 6460 | }; |
| 6461 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 6462 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6463 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6464 | MoveOperands(Location source, |
| 6465 | Location destination, |
| 6466 | Primitive::Type type, |
| 6467 | HInstruction* instruction) |
| 6468 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6469 | |
| 6470 | Location GetSource() const { return source_; } |
| 6471 | Location GetDestination() const { return destination_; } |
| 6472 | |
| 6473 | void SetSource(Location value) { source_ = value; } |
| 6474 | void SetDestination(Location value) { destination_ = value; } |
| 6475 | |
| 6476 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 6477 | // destination (but not the source). |
| 6478 | Location MarkPending() { |
| 6479 | DCHECK(!IsPending()); |
| 6480 | Location dest = destination_; |
| 6481 | destination_ = Location::NoLocation(); |
| 6482 | return dest; |
| 6483 | } |
| 6484 | |
| 6485 | void ClearPending(Location dest) { |
| 6486 | DCHECK(IsPending()); |
| 6487 | destination_ = dest; |
| 6488 | } |
| 6489 | |
| 6490 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6491 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 6492 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6493 | } |
| 6494 | |
| 6495 | // True if this blocks a move from the given location. |
| 6496 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 6497 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6498 | } |
| 6499 | |
| 6500 | // A move is redundant if it's been eliminated, if its source and |
| 6501 | // destination are the same, or if its destination is unneeded. |
| 6502 | bool IsRedundant() const { |
| 6503 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 6504 | } |
| 6505 | |
| 6506 | // We clear both operands to indicate move that's been eliminated. |
| 6507 | void Eliminate() { |
| 6508 | source_ = destination_ = Location::NoLocation(); |
| 6509 | } |
| 6510 | |
| 6511 | bool IsEliminated() const { |
| 6512 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 6513 | return source_.IsInvalid(); |
| 6514 | } |
| 6515 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6516 | Primitive::Type GetType() const { return type_; } |
| 6517 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6518 | bool Is64BitMove() const { |
| 6519 | return Primitive::Is64BitType(type_); |
| 6520 | } |
| 6521 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6522 | HInstruction* GetInstruction() const { return instruction_; } |
| 6523 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6524 | private: |
| 6525 | Location source_; |
| 6526 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6527 | // The type this move is for. |
| 6528 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6529 | // The instruction this move is assocatied with. Null when this move is |
| 6530 | // for moving an input in the expected locations of user (including a phi user). |
| 6531 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 6532 | // in the same parallel move. |
| 6533 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6534 | }; |
| 6535 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6536 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 6537 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6538 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 6539 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6540 | class HParallelMove FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6541 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6542 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6543 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 6544 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 6545 | moves_.reserve(kDefaultNumberOfMoves); |
| 6546 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6547 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6548 | void AddMove(Location source, |
| 6549 | Location destination, |
| 6550 | Primitive::Type type, |
| 6551 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6552 | DCHECK(source.IsValid()); |
| 6553 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6554 | if (kIsDebugBuild) { |
| 6555 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6556 | for (const MoveOperands& move : moves_) { |
| 6557 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6558 | // Special case the situation where the move is for the spill slot |
| 6559 | // of the instruction. |
| 6560 | if ((GetPrevious() == instruction) |
| 6561 | || ((GetPrevious() == nullptr) |
| 6562 | && instruction->IsPhi() |
| 6563 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6564 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6565 | << "Doing parallel moves for the same instruction."; |
| 6566 | } else { |
| 6567 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 6568 | } |
| 6569 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 6570 | } |
| 6571 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6572 | for (const MoveOperands& move : moves_) { |
| 6573 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6574 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6575 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6576 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6577 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6578 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6579 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6580 | } |
| 6581 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6582 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6583 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6584 | } |
| 6585 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6586 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6587 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 6588 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6589 | |
| 6590 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6591 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6592 | |
| 6593 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 6594 | }; |
| 6595 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6596 | } // namespace art |
| 6597 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 6598 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 6599 | #include "nodes_shared.h" |
| 6600 | #endif |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6601 | #ifdef ART_ENABLE_CODEGEN_arm |
| 6602 | #include "nodes_arm.h" |
| 6603 | #endif |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6604 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| 6605 | #include "nodes_arm64.h" |
| 6606 | #endif |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6607 | #ifdef ART_ENABLE_CODEGEN_mips |
| 6608 | #include "nodes_mips.h" |
| 6609 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6610 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 6611 | #include "nodes_x86.h" |
| 6612 | #endif |
| 6613 | |
| 6614 | namespace art { |
| 6615 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6616 | class HGraphVisitor : public ValueObject { |
| 6617 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 6618 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 6619 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6620 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6621 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6622 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 6623 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6624 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6625 | void VisitInsertionOrder(); |
| 6626 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6627 | // Visit the graph following dominator tree reverse post-order. |
| 6628 | void VisitReversePostOrder(); |
| 6629 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 6630 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 6631 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6632 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6633 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6634 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 6635 | |
| 6636 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6637 | |
| 6638 | #undef DECLARE_VISIT_INSTRUCTION |
| 6639 | |
| 6640 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 6641 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6642 | |
| 6643 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 6644 | }; |
| 6645 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6646 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 6647 | public: |
| 6648 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 6649 | virtual ~HGraphDelegateVisitor() {} |
| 6650 | |
| 6651 | // Visit functions that delegate to to super class. |
| 6652 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6653 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6654 | |
| 6655 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6656 | |
| 6657 | #undef DECLARE_VISIT_INSTRUCTION |
| 6658 | |
| 6659 | private: |
| 6660 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 6661 | }; |
| 6662 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6663 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6664 | // of an inner loop. The order in which the blocks are iterated is on their |
| 6665 | // block id. |
| 6666 | class HBlocksInLoopIterator : public ValueObject { |
| 6667 | public: |
| 6668 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 6669 | : blocks_in_loop_(info.GetBlocks()), |
| 6670 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 6671 | index_(0) { |
| 6672 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 6673 | Advance(); |
| 6674 | } |
| 6675 | } |
| 6676 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6677 | bool Done() const { return index_ == blocks_.size(); } |
| 6678 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6679 | void Advance() { |
| 6680 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6681 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6682 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 6683 | break; |
| 6684 | } |
| 6685 | } |
| 6686 | } |
| 6687 | |
| 6688 | private: |
| 6689 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6690 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6691 | size_t index_; |
| 6692 | |
| 6693 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 6694 | }; |
| 6695 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6696 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6697 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 6698 | // post order. |
| 6699 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 6700 | public: |
| 6701 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 6702 | : blocks_in_loop_(info.GetBlocks()), |
| 6703 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 6704 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6705 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6706 | Advance(); |
| 6707 | } |
| 6708 | } |
| 6709 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6710 | bool Done() const { return index_ == blocks_.size(); } |
| 6711 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6712 | void Advance() { |
| 6713 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6714 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 6715 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6716 | break; |
| 6717 | } |
| 6718 | } |
| 6719 | } |
| 6720 | |
| 6721 | private: |
| 6722 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6723 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6724 | size_t index_; |
| 6725 | |
| 6726 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 6727 | }; |
| 6728 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6729 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6730 | if (constant->IsIntConstant()) { |
| 6731 | return constant->AsIntConstant()->GetValue(); |
| 6732 | } else if (constant->IsLongConstant()) { |
| 6733 | return constant->AsLongConstant()->GetValue(); |
| 6734 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6735 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6736 | return 0; |
| 6737 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6738 | } |
| 6739 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6740 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 6741 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } \ |
| 6742 | inline const H##type* HInstruction::As##type() const { \ |
| 6743 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 6744 | } \ |
| 6745 | inline H##type* HInstruction::As##type() { \ |
| 6746 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 6747 | } |
| 6748 | |
| 6749 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 6750 | #undef INSTRUCTION_TYPE_CHECK |
| 6751 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 6752 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 6753 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 6754 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 6755 | size_t number_of_new_blocks, |
| 6756 | size_t after) { |
| 6757 | DCHECK_LT(after, blocks->size()); |
| 6758 | size_t old_size = blocks->size(); |
| 6759 | size_t new_size = old_size + number_of_new_blocks; |
| 6760 | blocks->resize(new_size); |
| 6761 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 6762 | } |
| 6763 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6764 | } // namespace art |
| 6765 | |
| 6766 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |