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" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 32 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 33 | #include "handle.h" |
| 34 | #include "handle_scope.h" |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 35 | #include "invoke_type.h" |
Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 36 | #include "intrinsics_enum.h" |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 37 | #include "locations.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 38 | #include "method_reference.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 39 | #include "mirror/class.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 40 | #include "offsets.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 41 | #include "primitive.h" |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 42 | #include "utils/intrusive_forward_list.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 43 | |
| 44 | namespace art { |
| 45 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 46 | class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 47 | class HBasicBlock; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 48 | class HCurrentMethod; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 49 | class HDoubleConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 50 | class HEnvironment; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 51 | class HFloatConstant; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 52 | class HGraphBuilder; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 53 | class HGraphVisitor; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 54 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 55 | class HIntConstant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 56 | class HInvoke; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 57 | class HLongConstant; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 58 | class HNullConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 59 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 60 | class HSuspendCheck; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 61 | class HTryBoundary; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 62 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 63 | class LocationSummary; |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 64 | class SlowPathCode; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 65 | class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 66 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 67 | namespace mirror { |
| 68 | class DexCache; |
| 69 | } // namespace mirror |
| 70 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 71 | static const int kDefaultNumberOfBlocks = 8; |
| 72 | static const int kDefaultNumberOfSuccessors = 2; |
| 73 | static const int kDefaultNumberOfPredecessors = 2; |
David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 74 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 75 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 76 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 77 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 78 | // The maximum (meaningful) distance (31) that can be used in an integer shift/rotate operation. |
| 79 | static constexpr int32_t kMaxIntShiftDistance = 0x1f; |
| 80 | // The maximum (meaningful) distance (63) that can be used in a long shift/rotate operation. |
| 81 | static constexpr int32_t kMaxLongShiftDistance = 0x3f; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 82 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 83 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 84 | static constexpr uint16_t kUnknownClassDefIndex = static_cast<uint16_t>(-1); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 85 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 86 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 87 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 88 | static constexpr uint32_t kNoDexPc = -1; |
| 89 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 90 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 91 | // For the purposes of the compiler, the dex files must actually be the same object |
| 92 | // if we want to safely treat them as the same. This is especially important for JIT |
| 93 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 94 | // times and provide different class resolution but no two class loaders should ever |
| 95 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 96 | // all sorts of weird failures. |
| 97 | return &lhs == &rhs; |
| 98 | } |
| 99 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 100 | enum IfCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 101 | // All types. |
| 102 | kCondEQ, // == |
| 103 | kCondNE, // != |
| 104 | // Signed integers and floating-point numbers. |
| 105 | kCondLT, // < |
| 106 | kCondLE, // <= |
| 107 | kCondGT, // > |
| 108 | kCondGE, // >= |
| 109 | // Unsigned integers. |
| 110 | kCondB, // < |
| 111 | kCondBE, // <= |
| 112 | kCondA, // > |
| 113 | kCondAE, // >= |
Scott Wakeling | 2c76e06 | 2016-08-31 09:48:54 +0100 | [diff] [blame] | 114 | // First and last aliases. |
| 115 | kCondFirst = kCondEQ, |
| 116 | kCondLast = kCondAE, |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 117 | }; |
| 118 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 119 | enum GraphAnalysisResult { |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 120 | kAnalysisSkipped, |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 121 | kAnalysisInvalidBytecode, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 122 | kAnalysisFailThrowCatchLoop, |
| 123 | kAnalysisFailAmbiguousArrayOp, |
| 124 | kAnalysisSuccess, |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 125 | }; |
| 126 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 127 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 128 | public: |
| 129 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 130 | |
| 131 | void AddInstruction(HInstruction* instruction); |
| 132 | void RemoveInstruction(HInstruction* instruction); |
| 133 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 134 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 135 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 136 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 137 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 138 | // Return true if this list contains `instruction`. |
| 139 | bool Contains(HInstruction* instruction) const; |
| 140 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 141 | // Return true if `instruction1` is found before `instruction2` in |
| 142 | // this instruction list and false otherwise. Abort if none |
| 143 | // of these instructions is found. |
| 144 | bool FoundBefore(const HInstruction* instruction1, |
| 145 | const HInstruction* instruction2) const; |
| 146 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 147 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 148 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 149 | |
| 150 | // Update the block of all instructions to be `block`. |
| 151 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 152 | |
| 153 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 154 | void AddBefore(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 155 | void Add(const HInstructionList& instruction_list); |
| 156 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 157 | // Return the number of instructions in the list. This is an expensive operation. |
| 158 | size_t CountSize() const; |
| 159 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 160 | private: |
| 161 | HInstruction* first_instruction_; |
| 162 | HInstruction* last_instruction_; |
| 163 | |
| 164 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 165 | friend class HGraph; |
| 166 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 167 | friend class HInstructionIterator; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 168 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 169 | |
| 170 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 171 | }; |
| 172 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 173 | class ReferenceTypeInfo : ValueObject { |
| 174 | public: |
| 175 | typedef Handle<mirror::Class> TypeHandle; |
| 176 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 177 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact); |
| 178 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 179 | static ReferenceTypeInfo Create(TypeHandle type_handle) REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 94ab38f | 2016-06-21 17:48:19 +0100 | [diff] [blame] | 180 | return Create(type_handle, type_handle->CannotBeAssignedFromOtherTypes()); |
| 181 | } |
| 182 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 183 | static ReferenceTypeInfo CreateUnchecked(TypeHandle type_handle, bool is_exact) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 184 | return ReferenceTypeInfo(type_handle, is_exact); |
| 185 | } |
| 186 | |
| 187 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 188 | |
Vladimir Marko | f39745e | 2016-01-26 12:16:55 +0000 | [diff] [blame] | 189 | static bool IsValidHandle(TypeHandle handle) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 190 | return handle.GetReference() != nullptr; |
| 191 | } |
| 192 | |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 193 | bool IsValid() const { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 194 | return IsValidHandle(type_handle_); |
| 195 | } |
| 196 | |
| 197 | bool IsExact() const { return is_exact_; } |
| 198 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 199 | bool IsObjectClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 200 | DCHECK(IsValid()); |
| 201 | return GetTypeHandle()->IsObjectClass(); |
| 202 | } |
| 203 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 204 | bool IsStringClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 205 | DCHECK(IsValid()); |
| 206 | return GetTypeHandle()->IsStringClass(); |
| 207 | } |
| 208 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 209 | bool IsObjectArray() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 210 | DCHECK(IsValid()); |
| 211 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 212 | } |
| 213 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 214 | bool IsInterface() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 215 | DCHECK(IsValid()); |
| 216 | return GetTypeHandle()->IsInterface(); |
| 217 | } |
| 218 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 219 | bool IsArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 220 | DCHECK(IsValid()); |
| 221 | return GetTypeHandle()->IsArrayClass(); |
| 222 | } |
| 223 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 224 | bool IsPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 225 | DCHECK(IsValid()); |
| 226 | return GetTypeHandle()->IsPrimitiveArray(); |
| 227 | } |
| 228 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 229 | bool IsNonPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 230 | DCHECK(IsValid()); |
| 231 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 232 | } |
| 233 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 234 | bool CanArrayHold(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 235 | DCHECK(IsValid()); |
| 236 | if (!IsExact()) return false; |
| 237 | if (!IsArrayClass()) return false; |
| 238 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 239 | } |
| 240 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 241 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 242 | DCHECK(IsValid()); |
| 243 | if (!IsExact()) return false; |
| 244 | if (!IsArrayClass()) return false; |
| 245 | if (!rti.IsArrayClass()) return false; |
| 246 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 247 | rti.GetTypeHandle()->GetComponentType()); |
| 248 | } |
| 249 | |
| 250 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 251 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 252 | bool IsSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 253 | DCHECK(IsValid()); |
| 254 | DCHECK(rti.IsValid()); |
| 255 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 256 | } |
| 257 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 258 | bool IsStrictSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 259 | DCHECK(IsValid()); |
| 260 | DCHECK(rti.IsValid()); |
| 261 | return GetTypeHandle().Get() != rti.GetTypeHandle().Get() && |
| 262 | GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 263 | } |
| 264 | |
| 265 | // Returns true if the type information provide the same amount of details. |
| 266 | // Note that it does not mean that the instructions have the same actual type |
| 267 | // (because the type can be the result of a merge). |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 268 | bool IsEqual(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 269 | if (!IsValid() && !rti.IsValid()) { |
| 270 | // Invalid types are equal. |
| 271 | return true; |
| 272 | } |
| 273 | if (!IsValid() || !rti.IsValid()) { |
| 274 | // One is valid, the other not. |
| 275 | return false; |
| 276 | } |
| 277 | return IsExact() == rti.IsExact() |
| 278 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
| 279 | } |
| 280 | |
| 281 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 282 | ReferenceTypeInfo() : type_handle_(TypeHandle()), is_exact_(false) {} |
| 283 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact) |
| 284 | : type_handle_(type_handle), is_exact_(is_exact) { } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 285 | |
| 286 | // The class of the object. |
| 287 | TypeHandle type_handle_; |
| 288 | // Whether or not the type is exact or a superclass of the actual type. |
| 289 | // Whether or not we have any information about this type. |
| 290 | bool is_exact_; |
| 291 | }; |
| 292 | |
| 293 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 294 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 295 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 296 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 297 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 298 | HGraph(ArenaAllocator* arena, |
| 299 | const DexFile& dex_file, |
| 300 | uint32_t method_idx, |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 301 | bool should_generate_constructor_barrier, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 302 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 303 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 304 | bool debuggable = false, |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 305 | bool osr = false, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 306 | int start_instruction_id = 0) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 307 | : arena_(arena), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 308 | blocks_(arena->Adapter(kArenaAllocBlockList)), |
| 309 | reverse_post_order_(arena->Adapter(kArenaAllocReversePostOrder)), |
| 310 | linear_order_(arena->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 311 | entry_block_(nullptr), |
| 312 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 313 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 314 | number_of_vregs_(0), |
| 315 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 316 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 317 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 318 | has_try_catch_(false), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 319 | has_irreducible_loops_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 320 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 321 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 322 | dex_file_(dex_file), |
| 323 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 324 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 325 | in_ssa_form_(false), |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 326 | should_generate_constructor_barrier_(should_generate_constructor_barrier), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 327 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 328 | cached_null_constant_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 329 | cached_int_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 330 | cached_float_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 331 | cached_long_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 332 | cached_double_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 333 | cached_current_method_(nullptr), |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 334 | inexact_object_rti_(ReferenceTypeInfo::CreateInvalid()), |
| 335 | osr_(osr) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 336 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 337 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 338 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 339 | // 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] | 340 | void InitializeInexactObjectRTI(VariableSizedHandleScope* handles); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 341 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 342 | ArenaAllocator* GetArena() const { return arena_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 343 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 344 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 345 | bool IsInSsaForm() const { return in_ssa_form_; } |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 346 | void SetInSsaForm() { in_ssa_form_ = true; } |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 347 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 348 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 349 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 350 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 351 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 352 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 353 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 354 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 355 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 356 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 357 | void ComputeDominanceInformation(); |
| 358 | void ClearDominanceInformation(); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 359 | void ClearLoopInformation(); |
| 360 | void FindBackEdges(ArenaBitVector* visited); |
| 361 | GraphAnalysisResult BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 362 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 363 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 364 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 365 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 366 | // 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] | 367 | // 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] | 368 | GraphAnalysisResult AnalyzeLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 369 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 370 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 371 | // order and loop information. |
| 372 | void ComputeTryBlockInformation(); |
| 373 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 374 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 375 | // Returns the instruction to replace the invoke expression or null if the |
| 376 | // invoke is for a void method. Note that the caller is responsible for replacing |
| 377 | // and removing the invoke instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 378 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 379 | |
Nicolas Geoffray | a1d8ddf | 2016-02-29 11:46:58 +0000 | [diff] [blame] | 380 | // Update the loop and try membership of `block`, which was spawned from `reference`. |
| 381 | // In case `reference` is a back edge, `replace_if_back_edge` notifies whether `block` |
| 382 | // should be the new back edge. |
| 383 | void UpdateLoopAndTryInformationOfNewBlock(HBasicBlock* block, |
| 384 | HBasicBlock* reference, |
| 385 | bool replace_if_back_edge); |
| 386 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 387 | // Need to add a couple of blocks to test if the loop body is entered and |
| 388 | // put deoptimization instructions, etc. |
| 389 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 390 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 391 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 392 | // other blocks and has no instructions or phis. |
| 393 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 394 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 395 | // Splits the edge between `block` and `successor` while preserving the |
| 396 | // indices in the predecessor/successor lists. If there are multiple edges |
| 397 | // between the blocks, the lowest indices are used. |
| 398 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 399 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 400 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 401 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 402 | void SimplifyLoop(HBasicBlock* header); |
| 403 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 404 | int32_t GetNextInstructionId() { |
| 405 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 406 | return current_instruction_id_++; |
| 407 | } |
| 408 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 409 | int32_t GetCurrentInstructionId() const { |
| 410 | return current_instruction_id_; |
| 411 | } |
| 412 | |
| 413 | void SetCurrentInstructionId(int32_t id) { |
David Brazdil | 3f52306 | 2016-02-29 16:53:33 +0000 | [diff] [blame] | 414 | DCHECK_GE(id, current_instruction_id_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 415 | current_instruction_id_ = id; |
| 416 | } |
| 417 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 418 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 419 | return maximum_number_of_out_vregs_; |
| 420 | } |
| 421 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 422 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 423 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 424 | } |
| 425 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 426 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 427 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 428 | } |
| 429 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 430 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 431 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 432 | } |
| 433 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 434 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 435 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 436 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 437 | } |
| 438 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 439 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 440 | number_of_vregs_ = number_of_vregs; |
| 441 | } |
| 442 | |
| 443 | uint16_t GetNumberOfVRegs() const { |
| 444 | return number_of_vregs_; |
| 445 | } |
| 446 | |
| 447 | void SetNumberOfInVRegs(uint16_t value) { |
| 448 | number_of_in_vregs_ = value; |
| 449 | } |
| 450 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 451 | uint16_t GetNumberOfInVRegs() const { |
| 452 | return number_of_in_vregs_; |
| 453 | } |
| 454 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 455 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 456 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 457 | return number_of_vregs_ - number_of_in_vregs_; |
| 458 | } |
| 459 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 460 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 461 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 462 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 463 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 464 | ArrayRef<HBasicBlock* const> GetReversePostOrderSkipEntryBlock() { |
| 465 | DCHECK(GetReversePostOrder()[0] == entry_block_); |
| 466 | return ArrayRef<HBasicBlock* const>(GetReversePostOrder()).SubArray(1); |
| 467 | } |
| 468 | |
| 469 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetPostOrder() const { |
| 470 | return ReverseRange(GetReversePostOrder()); |
| 471 | } |
| 472 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 473 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 474 | return linear_order_; |
| 475 | } |
| 476 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 477 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetLinearPostOrder() const { |
| 478 | return ReverseRange(GetLinearOrder()); |
| 479 | } |
| 480 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 481 | bool HasBoundsChecks() const { |
| 482 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 483 | } |
| 484 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 485 | void SetHasBoundsChecks(bool value) { |
| 486 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 487 | } |
| 488 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 489 | bool ShouldGenerateConstructorBarrier() const { |
| 490 | return should_generate_constructor_barrier_; |
| 491 | } |
| 492 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 493 | bool IsDebuggable() const { return debuggable_; } |
| 494 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 495 | // 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] | 496 | // already, it is created and inserted into the graph. This method is only for |
| 497 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 498 | 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] | 499 | |
| 500 | // TODO: This is problematic for the consistency of reference type propagation |
| 501 | // because it can be created anytime after the pass and thus it will be left |
| 502 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 503 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 504 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 505 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 506 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 507 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 508 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 509 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 510 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 511 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 512 | 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] | 513 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 514 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 515 | 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] | 516 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 517 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 518 | HCurrentMethod* GetCurrentMethod(); |
| 519 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 520 | const DexFile& GetDexFile() const { |
| 521 | return dex_file_; |
| 522 | } |
| 523 | |
| 524 | uint32_t GetMethodIdx() const { |
| 525 | return method_idx_; |
| 526 | } |
| 527 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 528 | InvokeType GetInvokeType() const { |
| 529 | return invoke_type_; |
| 530 | } |
| 531 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 532 | InstructionSet GetInstructionSet() const { |
| 533 | return instruction_set_; |
| 534 | } |
| 535 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 536 | bool IsCompilingOsr() const { return osr_; } |
| 537 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 538 | bool HasTryCatch() const { return has_try_catch_; } |
| 539 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 540 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 541 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 542 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 543 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 544 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 545 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 546 | |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 547 | // Returns an instruction with the opposite boolean value from 'cond'. |
| 548 | // The instruction has been inserted into the graph, either as a constant, or |
| 549 | // before cursor. |
| 550 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 551 | |
Nicolas Geoffray | 18401b7 | 2016-03-11 13:35:51 +0000 | [diff] [blame] | 552 | ReferenceTypeInfo GetInexactObjectRti() const { return inexact_object_rti_; } |
| 553 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 554 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 555 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 556 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 557 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 558 | template <class InstructionType, typename ValueType> |
| 559 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 560 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 561 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 562 | // Try to find an existing constant of the given value. |
| 563 | InstructionType* constant = nullptr; |
| 564 | auto cached_constant = cache->find(value); |
| 565 | if (cached_constant != cache->end()) { |
| 566 | constant = cached_constant->second; |
| 567 | } |
| 568 | |
| 569 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 570 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 571 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 572 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 573 | cache->Overwrite(value, constant); |
| 574 | InsertConstant(constant); |
| 575 | } |
| 576 | return constant; |
| 577 | } |
| 578 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 579 | void InsertConstant(HConstant* instruction); |
| 580 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 581 | // Cache a float constant into the graph. This method should only be |
| 582 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 583 | void CacheFloatConstant(HFloatConstant* constant); |
| 584 | |
| 585 | // See CacheFloatConstant comment. |
| 586 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 587 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 588 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 589 | |
| 590 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 591 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 592 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 593 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 594 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 595 | |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 596 | // List of blocks to perform a linear order tree traversal. Unlike the reverse |
| 597 | // post order, this order is not incrementally kept up-to-date. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 598 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 599 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 600 | HBasicBlock* entry_block_; |
| 601 | HBasicBlock* exit_block_; |
| 602 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 603 | // 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] | 604 | uint16_t maximum_number_of_out_vregs_; |
| 605 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 606 | // The number of virtual registers in this method. Contains the parameters. |
| 607 | uint16_t number_of_vregs_; |
| 608 | |
| 609 | // The number of virtual registers used by parameters of this method. |
| 610 | uint16_t number_of_in_vregs_; |
| 611 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 612 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 613 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 614 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 615 | // Has bounds checks. We can totally skip BCE if it's false. |
| 616 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 617 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 618 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 619 | // try/catch-related passes if false. |
| 620 | bool has_try_catch_; |
| 621 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 622 | // Flag whether there are any irreducible loops in the graph. |
| 623 | bool has_irreducible_loops_; |
| 624 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 625 | // Indicates whether the graph should be compiled in a way that |
| 626 | // ensures full debuggability. If false, we can apply more |
| 627 | // aggressive optimizations that may limit the level of debugging. |
| 628 | const bool debuggable_; |
| 629 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 630 | // 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] | 631 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 632 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 633 | // The dex file from which the method is from. |
| 634 | const DexFile& dex_file_; |
| 635 | |
| 636 | // The method index in the dex file. |
| 637 | const uint32_t method_idx_; |
| 638 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 639 | // If inlined, this encodes how the callee is being invoked. |
| 640 | const InvokeType invoke_type_; |
| 641 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 642 | // Whether the graph has been transformed to SSA form. Only used |
| 643 | // in debug mode to ensure we are not using properties only valid |
| 644 | // for non-SSA form (like the number of temporaries). |
| 645 | bool in_ssa_form_; |
| 646 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 647 | const bool should_generate_constructor_barrier_; |
| 648 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 649 | const InstructionSet instruction_set_; |
| 650 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 651 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 652 | HNullConstant* cached_null_constant_; |
| 653 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 654 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 655 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 656 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 657 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 658 | HCurrentMethod* cached_current_method_; |
| 659 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 660 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 661 | // for example for methods whose declaring class could not be resolved |
| 662 | // (such as when the superclass could not be found). |
| 663 | ArtMethod* art_method_; |
| 664 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 665 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 666 | // collection pointer to passes which may create NullConstant. |
| 667 | ReferenceTypeInfo inexact_object_rti_; |
| 668 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 669 | // Whether we are compiling this graph for on stack replacement: this will |
| 670 | // make all loops seen as irreducible and emit special stack maps to mark |
| 671 | // compiled code entries which the interpreter can directly jump to. |
| 672 | const bool osr_; |
| 673 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 674 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 675 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 676 | friend class HInliner; // For the reverse post order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 677 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 678 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 679 | }; |
| 680 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 681 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 682 | public: |
| 683 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 684 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 685 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 686 | irreducible_(false), |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 687 | contains_irreducible_loop_(false), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 688 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 689 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | f6a35de | 2016-03-21 12:01:50 +0000 | [diff] [blame] | 690 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true, kArenaAllocLoopInfoBackEdges) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 691 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 692 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 693 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 694 | bool IsIrreducible() const { return irreducible_; } |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 695 | bool ContainsIrreducibleLoop() const { return contains_irreducible_loop_; } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 696 | |
| 697 | void Dump(std::ostream& os); |
| 698 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 699 | HBasicBlock* GetHeader() const { |
| 700 | return header_; |
| 701 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 702 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 703 | void SetHeader(HBasicBlock* block) { |
| 704 | header_ = block; |
| 705 | } |
| 706 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 707 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 708 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 709 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 710 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 711 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 712 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 713 | } |
| 714 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 715 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 716 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 717 | } |
| 718 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 719 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 720 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 721 | } |
| 722 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 723 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 724 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 725 | } |
| 726 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 727 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 728 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 729 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 730 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 731 | } |
| 732 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 733 | // Returns the lifetime position of the back edge that has the |
| 734 | // greatest lifetime position. |
| 735 | size_t GetLifetimeEnd() const; |
| 736 | |
| 737 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 738 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 739 | } |
| 740 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 741 | // Finds blocks that are part of this loop. |
| 742 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 743 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 744 | // Returns whether this loop information contains `block`. |
| 745 | // Note that this loop information *must* be populated before entering this function. |
| 746 | bool Contains(const HBasicBlock& block) const; |
| 747 | |
| 748 | // Returns whether this loop information is an inner loop of `other`. |
| 749 | // Note that `other` *must* be populated before entering this function. |
| 750 | bool IsIn(const HLoopInformation& other) const; |
| 751 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 752 | // Returns true if instruction is not defined within this loop. |
| 753 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 754 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 755 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 756 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 757 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 758 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 759 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 760 | void ClearAllBlocks() { |
| 761 | blocks_.ClearAllBits(); |
| 762 | } |
| 763 | |
David Brazdil | 3f4a522 | 2016-05-06 12:46:21 +0100 | [diff] [blame] | 764 | bool HasBackEdgeNotDominatedByHeader() const; |
| 765 | |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 766 | bool IsPopulated() const { |
| 767 | return blocks_.GetHighestBitSet() != -1; |
| 768 | } |
| 769 | |
Anton Shamin | f89381f | 2016-05-16 16:44:13 +0600 | [diff] [blame] | 770 | bool DominatesAllBackEdges(HBasicBlock* block); |
| 771 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 772 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 773 | // Internal recursive implementation of `Populate`. |
| 774 | void PopulateRecursive(HBasicBlock* block); |
David Brazdil | c2e8af9 | 2016-04-05 17:15:19 +0100 | [diff] [blame] | 775 | void PopulateIrreducibleRecursive(HBasicBlock* block, ArenaBitVector* finalized); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 776 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 777 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 778 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 779 | bool irreducible_; |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 780 | bool contains_irreducible_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 781 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 782 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 783 | |
| 784 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 785 | }; |
| 786 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 787 | // Stores try/catch information for basic blocks. |
| 788 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 789 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 790 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 791 | public: |
| 792 | // Try block information constructor. |
| 793 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 794 | : try_entry_(&try_entry), |
| 795 | catch_dex_file_(nullptr), |
| 796 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 797 | DCHECK(try_entry_ != nullptr); |
| 798 | } |
| 799 | |
| 800 | // Catch block information constructor. |
| 801 | TryCatchInformation(uint16_t catch_type_index, const DexFile& dex_file) |
| 802 | : try_entry_(nullptr), |
| 803 | catch_dex_file_(&dex_file), |
| 804 | catch_type_index_(catch_type_index) {} |
| 805 | |
| 806 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 807 | |
| 808 | const HTryBoundary& GetTryEntry() const { |
| 809 | DCHECK(IsTryBlock()); |
| 810 | return *try_entry_; |
| 811 | } |
| 812 | |
| 813 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 814 | |
| 815 | bool IsCatchAllTypeIndex() const { |
| 816 | DCHECK(IsCatchBlock()); |
| 817 | return catch_type_index_ == DexFile::kDexNoIndex16; |
| 818 | } |
| 819 | |
| 820 | uint16_t GetCatchTypeIndex() const { |
| 821 | DCHECK(IsCatchBlock()); |
| 822 | return catch_type_index_; |
| 823 | } |
| 824 | |
| 825 | const DexFile& GetCatchDexFile() const { |
| 826 | DCHECK(IsCatchBlock()); |
| 827 | return *catch_dex_file_; |
| 828 | } |
| 829 | |
| 830 | private: |
| 831 | // One of possibly several TryBoundary instructions entering the block's try. |
| 832 | // Only set for try blocks. |
| 833 | const HTryBoundary* try_entry_; |
| 834 | |
| 835 | // Exception type information. Only set for catch blocks. |
| 836 | const DexFile* catch_dex_file_; |
| 837 | const uint16_t catch_type_index_; |
| 838 | }; |
| 839 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 840 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 841 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 842 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 843 | // A block in a method. Contains the list of instructions represented |
| 844 | // as a double linked list. Each block knows its predecessors and |
| 845 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 846 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 847 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 848 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 849 | explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 850 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 851 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 852 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 853 | loop_information_(nullptr), |
| 854 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 855 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 856 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 857 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 858 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 859 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 860 | try_catch_information_(nullptr) { |
| 861 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 862 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 863 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 864 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 865 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 866 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 867 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 868 | } |
| 869 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 870 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 871 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 872 | } |
| 873 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 874 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 875 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 876 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 877 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 878 | return ContainsElement(successors_, block, start_from); |
| 879 | } |
| 880 | |
| 881 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 882 | return dominated_blocks_; |
| 883 | } |
| 884 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 885 | bool IsEntryBlock() const { |
| 886 | return graph_->GetEntryBlock() == this; |
| 887 | } |
| 888 | |
| 889 | bool IsExitBlock() const { |
| 890 | return graph_->GetExitBlock() == this; |
| 891 | } |
| 892 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 893 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 894 | bool IsSingleTryBoundary() const; |
| 895 | |
| 896 | // Returns true if this block emits nothing but a jump. |
| 897 | bool IsSingleJump() const { |
| 898 | HLoopInformation* loop_info = GetLoopInformation(); |
| 899 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 900 | // Back edges generate a suspend check. |
| 901 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 902 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 903 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 904 | void AddBackEdge(HBasicBlock* back_edge) { |
| 905 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 906 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 907 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 908 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 909 | loop_information_->AddBackEdge(back_edge); |
| 910 | } |
| 911 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 912 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 913 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 914 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 915 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 916 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 917 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 918 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 919 | HBasicBlock* GetDominator() const { return dominator_; } |
| 920 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 921 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 922 | |
| 923 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 924 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 925 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 926 | |
| 927 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 928 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 929 | } |
| 930 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 931 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 932 | |
| 933 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 934 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 935 | } |
| 936 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 937 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 938 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 939 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 940 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 941 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 942 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 943 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 944 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 945 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 946 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 947 | successors_.push_back(block); |
| 948 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 949 | } |
| 950 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 951 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 952 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 953 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 954 | new_block->predecessors_.push_back(this); |
| 955 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 956 | } |
| 957 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 958 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 959 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 960 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 961 | new_block->successors_.push_back(this); |
| 962 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 963 | } |
| 964 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 965 | // Insert `this` between `predecessor` and `successor. This method |
| 966 | // preserves the indicies, and will update the first edge found between |
| 967 | // `predecessor` and `successor`. |
| 968 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 969 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 970 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 971 | successor->predecessors_[predecessor_index] = this; |
| 972 | predecessor->successors_[successor_index] = this; |
| 973 | successors_.push_back(successor); |
| 974 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 975 | } |
| 976 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 977 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 978 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 979 | } |
| 980 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 981 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 982 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 983 | } |
| 984 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 985 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 986 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 990 | predecessors_.push_back(block); |
| 991 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 992 | } |
| 993 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 994 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 995 | DCHECK_EQ(predecessors_.size(), 2u); |
| 996 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 997 | } |
| 998 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 999 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1000 | DCHECK_EQ(successors_.size(), 2u); |
| 1001 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1002 | } |
| 1003 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1004 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1005 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1006 | } |
| 1007 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1008 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1009 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1010 | } |
| 1011 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1012 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1013 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1014 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1018 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1019 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | // Returns whether the first occurrence of `predecessor` in the list of |
| 1023 | // predecessors is at index `idx`. |
| 1024 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1025 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1026 | return GetPredecessorIndexOf(predecessor) == idx; |
| 1027 | } |
| 1028 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1029 | // Create a new block between this block and its predecessors. The new block |
| 1030 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 1031 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 1032 | // loop and try/catch information are not updated. |
| 1033 | HBasicBlock* CreateImmediateDominator(); |
| 1034 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1035 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 1036 | // created, latter block. Note that this method will add the block to the |
| 1037 | // graph, create a Goto at the end of the former block and will create an edge |
| 1038 | // 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] | 1039 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1040 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 1041 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1042 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1043 | // created block. Note that this method just updates raw block information, |
| 1044 | // like predecessors, successors, dominators, and instruction list. It does not |
| 1045 | // update the graph, reverse post order, loop information, nor make sure the |
| 1046 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1047 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 1048 | |
| 1049 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 1050 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1051 | |
| 1052 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1053 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1054 | // that this method does not update the graph, reverse post order, loop |
| 1055 | // information, nor make sure the blocks are consistent (for example ending |
| 1056 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1057 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1058 | |
| 1059 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1060 | // of `this` are moved to `other`. |
| 1061 | // Note that this method does not update the graph, reverse post order, loop |
| 1062 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1063 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1064 | void ReplaceWith(HBasicBlock* other); |
| 1065 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1066 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1067 | // order, links to predecessors, successors, dominators and deletes the block |
| 1068 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1069 | // predecessor of `other` and vice versa. |
| 1070 | void MergeWith(HBasicBlock* other); |
| 1071 | |
| 1072 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1073 | // removes it from all loops it is included in and eventually from the graph. |
| 1074 | // The block must not dominate any other block. Predecessors and successors |
| 1075 | // are safely updated. |
| 1076 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1077 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1078 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1079 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1080 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1081 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1082 | // Replace instruction `initial` with `replacement` within this block. |
| 1083 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1084 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1085 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1086 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1087 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1088 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1089 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1090 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1091 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1092 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1093 | |
| 1094 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1095 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1096 | } |
| 1097 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1098 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1099 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1100 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1101 | } |
| 1102 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1103 | bool IsFirstPredecessorBackEdge() const { |
| 1104 | DCHECK(IsLoopHeader()); |
| 1105 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1106 | } |
| 1107 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1108 | HLoopInformation* GetLoopInformation() const { |
| 1109 | return loop_information_; |
| 1110 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1111 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1112 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1113 | // 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] | 1114 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1115 | void SetInLoop(HLoopInformation* info) { |
| 1116 | if (IsLoopHeader()) { |
| 1117 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1118 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1119 | loop_information_ = info; |
| 1120 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1121 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1122 | // Note that a non loop header having a loop information means this loop information |
| 1123 | // has already been populated |
| 1124 | loop_information_ = info; |
| 1125 | } else { |
| 1126 | // Block is part of an inner loop. Do not update the loop information. |
| 1127 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1128 | // at this point, because this method is being called while populating `info`. |
| 1129 | } |
| 1130 | } |
| 1131 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1132 | // Raw update of the loop information. |
| 1133 | void SetLoopInformation(HLoopInformation* info) { |
| 1134 | loop_information_ = info; |
| 1135 | } |
| 1136 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1137 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1138 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1139 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1140 | |
| 1141 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1142 | try_catch_information_ = try_catch_information; |
| 1143 | } |
| 1144 | |
| 1145 | bool IsTryBlock() const { |
| 1146 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1147 | } |
| 1148 | |
| 1149 | bool IsCatchBlock() const { |
| 1150 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1151 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1152 | |
| 1153 | // Returns the try entry that this block's successors should have. They will |
| 1154 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1155 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1156 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1157 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1158 | bool HasThrowingInstructions() const; |
| 1159 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1160 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1161 | bool Dominates(HBasicBlock* block) const; |
| 1162 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1163 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1164 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1165 | |
| 1166 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1167 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1168 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1169 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1170 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1171 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1172 | bool HasSinglePhi() const; |
| 1173 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1174 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1175 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1176 | ArenaVector<HBasicBlock*> predecessors_; |
| 1177 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1178 | HInstructionList instructions_; |
| 1179 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1180 | HLoopInformation* loop_information_; |
| 1181 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1182 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1183 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1184 | // The dex program counter of the first instruction of this block. |
| 1185 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1186 | size_t lifetime_start_; |
| 1187 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1188 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1189 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1190 | friend class HGraph; |
| 1191 | friend class HInstruction; |
| 1192 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1193 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1194 | }; |
| 1195 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1196 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1197 | // from the innermost to the outermost. |
| 1198 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1199 | public: |
| 1200 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1201 | : current_(block.GetLoopInformation()) {} |
| 1202 | |
| 1203 | bool Done() const { return current_ == nullptr; } |
| 1204 | |
| 1205 | void Advance() { |
| 1206 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1207 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | HLoopInformation* Current() const { |
| 1211 | DCHECK(!Done()); |
| 1212 | return current_; |
| 1213 | } |
| 1214 | |
| 1215 | private: |
| 1216 | HLoopInformation* current_; |
| 1217 | |
| 1218 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1219 | }; |
| 1220 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1221 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1222 | M(Above, Condition) \ |
| 1223 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1224 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1225 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1226 | M(ArrayGet, Instruction) \ |
| 1227 | M(ArrayLength, Instruction) \ |
| 1228 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1229 | M(Below, Condition) \ |
| 1230 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1231 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1232 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1233 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1234 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1235 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1236 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1237 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1238 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1239 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1240 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1241 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1242 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1243 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1244 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1245 | M(Exit, Instruction) \ |
| 1246 | M(FloatConstant, Constant) \ |
| 1247 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1248 | M(GreaterThan, Condition) \ |
| 1249 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1250 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1251 | M(InstanceFieldGet, Instruction) \ |
| 1252 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1253 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1254 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1255 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1256 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1257 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1258 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1259 | M(LessThan, Condition) \ |
| 1260 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1261 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1262 | M(LoadException, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1263 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1264 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1265 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1266 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1267 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1268 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1269 | M(Neg, UnaryOperation) \ |
| 1270 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1271 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1272 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1273 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1274 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1275 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1276 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1277 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1278 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1279 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1280 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1281 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1282 | M(Return, Instruction) \ |
| 1283 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1284 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1285 | M(Shl, BinaryOperation) \ |
| 1286 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1287 | M(StaticFieldGet, Instruction) \ |
| 1288 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1289 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1290 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1291 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1292 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1293 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1294 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1295 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1296 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1297 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1298 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1299 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1300 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1301 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1302 | /* |
| 1303 | * Instructions, shared across several (not all) architectures. |
| 1304 | */ |
| 1305 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1306 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1307 | #else |
| 1308 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1309 | M(BitwiseNegatedRight, Instruction) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1310 | M(MultiplyAccumulate, Instruction) \ |
| 1311 | M(IntermediateAddress, Instruction) |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1312 | #endif |
| 1313 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1314 | #ifndef ART_ENABLE_CODEGEN_arm |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1315 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1316 | #else |
| 1317 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1318 | M(ArmDexCacheArraysBase, Instruction) |
| 1319 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1320 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1321 | #ifndef ART_ENABLE_CODEGEN_arm64 |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1322 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1323 | #else |
| 1324 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1325 | M(Arm64DataProcWithShifterOp, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1326 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1327 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1328 | #ifndef ART_ENABLE_CODEGEN_mips |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1329 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1330 | #else |
| 1331 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
| 1332 | M(MipsComputeBaseMethodAddress, Instruction) \ |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 1333 | M(MipsDexCacheArraysBase, Instruction) \ |
| 1334 | M(MipsPackedSwitch, Instruction) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1335 | #endif |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1336 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1337 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1338 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1339 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1340 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1341 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1342 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1343 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1344 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1345 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1346 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1347 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1348 | |
| 1349 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1350 | |
| 1351 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1352 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1353 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1354 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1355 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1356 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1357 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1358 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1359 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1360 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1361 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1362 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1363 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1364 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1365 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1366 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1367 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1368 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1369 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1370 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1371 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1372 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1373 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1374 | #undef FORWARD_DECLARATION |
| 1375 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1376 | #define DECLARE_INSTRUCTION(type) \ |
| 1377 | InstructionKind GetKindInternal() const OVERRIDE { return k##type; } \ |
| 1378 | const char* DebugName() const OVERRIDE { return #type; } \ |
| 1379 | bool InstructionTypeEquals(const HInstruction* other) const OVERRIDE { \ |
| 1380 | return other->Is##type(); \ |
| 1381 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1382 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1383 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1384 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
| 1385 | bool Is##type() const { return As##type() != nullptr; } \ |
| 1386 | const H##type* As##type() const { return this; } \ |
| 1387 | H##type* As##type() { return this; } |
| 1388 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1389 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1390 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1391 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1392 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1393 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1394 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1395 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1396 | // Hook for the IntrusiveForwardList<>. |
| 1397 | // TODO: Hide this better. |
| 1398 | IntrusiveForwardListHook hook; |
| 1399 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1400 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1401 | HUseListNode(T user, size_t index) |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1402 | : user_(user), index_(index) {} |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1403 | |
| 1404 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1405 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1406 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1407 | friend class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1408 | |
| 1409 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1410 | }; |
| 1411 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1412 | template <typename T> |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1413 | using HUseList = IntrusiveForwardList<HUseListNode<T>>; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1414 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1415 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1416 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1417 | // by the used instructions. |
| 1418 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1419 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1420 | public: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1421 | HUserRecord() : instruction_(nullptr), before_use_node_() {} |
| 1422 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), before_use_node_() {} |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1423 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1424 | HUserRecord(const HUserRecord<T>& old_record, typename HUseList<T>::iterator before_use_node) |
| 1425 | : HUserRecord(old_record.instruction_, before_use_node) {} |
| 1426 | HUserRecord(HInstruction* instruction, typename HUseList<T>::iterator before_use_node) |
| 1427 | : instruction_(instruction), before_use_node_(before_use_node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1428 | DCHECK(instruction_ != nullptr); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | HInstruction* GetInstruction() const { return instruction_; } |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1432 | typename HUseList<T>::iterator GetBeforeUseNode() const { return before_use_node_; } |
| 1433 | typename HUseList<T>::iterator GetUseNode() const { return ++GetBeforeUseNode(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1434 | |
| 1435 | private: |
| 1436 | // Instruction used by the user. |
| 1437 | HInstruction* instruction_; |
| 1438 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1439 | // Iterator before the corresponding entry in the use list kept by 'instruction_'. |
| 1440 | typename HUseList<T>::iterator before_use_node_; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1441 | }; |
| 1442 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1443 | // Helper class that extracts the input instruction from HUserRecord<HInstruction*>. |
| 1444 | // This is used for HInstruction::GetInputs() to return a container wrapper providing |
| 1445 | // HInstruction* values even though the underlying container has HUserRecord<>s. |
| 1446 | struct HInputExtractor { |
| 1447 | HInstruction* operator()(HUserRecord<HInstruction*>& record) const { |
| 1448 | return record.GetInstruction(); |
| 1449 | } |
| 1450 | const HInstruction* operator()(const HUserRecord<HInstruction*>& record) const { |
| 1451 | return record.GetInstruction(); |
| 1452 | } |
| 1453 | }; |
| 1454 | |
| 1455 | using HInputsRef = TransformArrayRef<HUserRecord<HInstruction*>, HInputExtractor>; |
| 1456 | using HConstInputsRef = TransformArrayRef<const HUserRecord<HInstruction*>, HInputExtractor>; |
| 1457 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1458 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1459 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1460 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1461 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1462 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1463 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1464 | * modify the value of a reference field read [although it may modify the |
| 1465 | * reference fetch prior to reading the field, which is represented by its own |
| 1466 | * write/read dependence]). The analysis makes conservative points-to |
| 1467 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1468 | * the same, and any reference read depends on any reference read without |
| 1469 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1470 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1471 | * The internal representation uses 38-bit and is described in the table below. |
| 1472 | * The first line indicates the side effect, and for field/array accesses the |
| 1473 | * second line indicates the type of the access (in the order of the |
| 1474 | * Primitive::Type enum). |
| 1475 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1476 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1477 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1478 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1479 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1480 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1481 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1482 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1483 | * |
| 1484 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1485 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1486 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1487 | class SideEffects : public ValueObject { |
| 1488 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1489 | SideEffects() : flags_(0) {} |
| 1490 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1491 | static SideEffects None() { |
| 1492 | return SideEffects(0); |
| 1493 | } |
| 1494 | |
| 1495 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1496 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1497 | } |
| 1498 | |
| 1499 | static SideEffects AllChanges() { |
| 1500 | return SideEffects(kAllChangeBits); |
| 1501 | } |
| 1502 | |
| 1503 | static SideEffects AllDependencies() { |
| 1504 | return SideEffects(kAllDependOnBits); |
| 1505 | } |
| 1506 | |
| 1507 | static SideEffects AllExceptGCDependency() { |
| 1508 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1509 | } |
| 1510 | |
| 1511 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1512 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1513 | } |
| 1514 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1515 | static SideEffects AllWrites() { |
| 1516 | return SideEffects(kAllWrites); |
| 1517 | } |
| 1518 | |
| 1519 | static SideEffects AllReads() { |
| 1520 | return SideEffects(kAllReads); |
| 1521 | } |
| 1522 | |
| 1523 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1524 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1525 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1526 | : SideEffects(TypeFlag(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1527 | } |
| 1528 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1529 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1530 | return SideEffects(TypeFlag(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1531 | } |
| 1532 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1533 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1534 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1535 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1536 | : SideEffects(TypeFlag(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1537 | } |
| 1538 | |
| 1539 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1540 | return SideEffects(TypeFlag(type, kArrayReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1541 | } |
| 1542 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1543 | static SideEffects CanTriggerGC() { |
| 1544 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1545 | } |
| 1546 | |
| 1547 | static SideEffects DependsOnGC() { |
| 1548 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1549 | } |
| 1550 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1551 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1552 | SideEffects Union(SideEffects other) const { |
| 1553 | return SideEffects(flags_ | other.flags_); |
| 1554 | } |
| 1555 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1556 | SideEffects Exclusion(SideEffects other) const { |
| 1557 | return SideEffects(flags_ & ~other.flags_); |
| 1558 | } |
| 1559 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1560 | void Add(SideEffects other) { |
| 1561 | flags_ |= other.flags_; |
| 1562 | } |
| 1563 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1564 | bool Includes(SideEffects other) const { |
| 1565 | return (other.flags_ & flags_) == other.flags_; |
| 1566 | } |
| 1567 | |
| 1568 | bool HasSideEffects() const { |
| 1569 | return (flags_ & kAllChangeBits); |
| 1570 | } |
| 1571 | |
| 1572 | bool HasDependencies() const { |
| 1573 | return (flags_ & kAllDependOnBits); |
| 1574 | } |
| 1575 | |
| 1576 | // Returns true if there are no side effects or dependencies. |
| 1577 | bool DoesNothing() const { |
| 1578 | return flags_ == 0; |
| 1579 | } |
| 1580 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1581 | // Returns true if something is written. |
| 1582 | bool DoesAnyWrite() const { |
| 1583 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1584 | } |
| 1585 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1586 | // Returns true if something is read. |
| 1587 | bool DoesAnyRead() const { |
| 1588 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1589 | } |
| 1590 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1591 | // Returns true if potentially everything is written and read |
| 1592 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1593 | bool DoesAllReadWrite() const { |
| 1594 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1595 | } |
| 1596 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1597 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1598 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1599 | } |
| 1600 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1601 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1602 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1603 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1604 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1605 | } |
| 1606 | |
| 1607 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1608 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1609 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1610 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1611 | for (int s = kLastBit; s >= 0; s--) { |
| 1612 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1613 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1614 | // This is a bit for the GC side effect. |
| 1615 | if (current_bit_is_set) { |
| 1616 | flags += "GC"; |
| 1617 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1618 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1619 | } else { |
| 1620 | // This is a bit for the array/field analysis. |
| 1621 | // The underscore character stands for the 'can trigger GC' bit. |
| 1622 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1623 | if (current_bit_is_set) { |
| 1624 | flags += kDebug[s]; |
| 1625 | } |
| 1626 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1627 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1628 | flags += "|"; |
| 1629 | } |
| 1630 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1631 | } |
| 1632 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1633 | } |
| 1634 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1635 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1636 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1637 | private: |
| 1638 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1639 | |
| 1640 | static constexpr int kFieldWriteOffset = 0; |
| 1641 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1642 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1643 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1644 | |
| 1645 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1646 | |
| 1647 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1648 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1649 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1650 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1651 | |
| 1652 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1653 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1654 | |
| 1655 | // Aliases. |
| 1656 | |
| 1657 | static_assert(kChangeBits == kDependOnBits, |
| 1658 | "the 'change' bits should match the 'depend on' bits."); |
| 1659 | |
| 1660 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1661 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1662 | static constexpr uint64_t kAllWrites = |
| 1663 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1664 | static constexpr uint64_t kAllReads = |
| 1665 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1666 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1667 | // Translates type to bit flag. |
| 1668 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1669 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1670 | const uint64_t one = 1; |
| 1671 | const int shift = type; // 0-based consecutive enum |
| 1672 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1673 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1674 | return one << (type + offset); |
| 1675 | } |
| 1676 | |
| 1677 | // Private constructor on direct flags value. |
| 1678 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1679 | |
| 1680 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1681 | }; |
| 1682 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1683 | // 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] | 1684 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1685 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1686 | HEnvironment(ArenaAllocator* arena, |
| 1687 | size_t number_of_vregs, |
| 1688 | const DexFile& dex_file, |
| 1689 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1690 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1691 | InvokeType invoke_type, |
| 1692 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1693 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1694 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1695 | parent_(nullptr), |
| 1696 | dex_file_(dex_file), |
| 1697 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1698 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1699 | invoke_type_(invoke_type), |
| 1700 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1701 | } |
| 1702 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1703 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1704 | : HEnvironment(arena, |
| 1705 | to_copy.Size(), |
| 1706 | to_copy.GetDexFile(), |
| 1707 | to_copy.GetMethodIdx(), |
| 1708 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1709 | to_copy.GetInvokeType(), |
| 1710 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1711 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1712 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1713 | if (parent_ != nullptr) { |
| 1714 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1715 | } else { |
| 1716 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1717 | parent_->CopyFrom(parent); |
| 1718 | if (parent->GetParent() != nullptr) { |
| 1719 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1720 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1721 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1722 | } |
| 1723 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1724 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1725 | void CopyFrom(HEnvironment* environment); |
| 1726 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1727 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1728 | // input to the loop phi instead. This is for inserting instructions that |
| 1729 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1730 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1731 | |
| 1732 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1733 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1737 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1738 | } |
| 1739 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1740 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1741 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1742 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1743 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1744 | HEnvironment* GetParent() const { return parent_; } |
| 1745 | |
| 1746 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1747 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1748 | } |
| 1749 | |
| 1750 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1751 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | uint32_t GetDexPc() const { |
| 1755 | return dex_pc_; |
| 1756 | } |
| 1757 | |
| 1758 | uint32_t GetMethodIdx() const { |
| 1759 | return method_idx_; |
| 1760 | } |
| 1761 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1762 | InvokeType GetInvokeType() const { |
| 1763 | return invoke_type_; |
| 1764 | } |
| 1765 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1766 | const DexFile& GetDexFile() const { |
| 1767 | return dex_file_; |
| 1768 | } |
| 1769 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1770 | HInstruction* GetHolder() const { |
| 1771 | return holder_; |
| 1772 | } |
| 1773 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1774 | |
| 1775 | bool IsFromInlinedInvoke() const { |
| 1776 | return GetParent() != nullptr; |
| 1777 | } |
| 1778 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1779 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1780 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1781 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1782 | HEnvironment* parent_; |
| 1783 | const DexFile& dex_file_; |
| 1784 | const uint32_t method_idx_; |
| 1785 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1786 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1787 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1788 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1789 | HInstruction* const holder_; |
| 1790 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1791 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1792 | |
| 1793 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1794 | }; |
| 1795 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1796 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1797 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1798 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1799 | : previous_(nullptr), |
| 1800 | next_(nullptr), |
| 1801 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1802 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1803 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1804 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1805 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1806 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1807 | locations_(nullptr), |
| 1808 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1809 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1810 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1811 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
| 1812 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 1813 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1814 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1815 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1816 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1817 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1818 | enum InstructionKind { |
| 1819 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1820 | }; |
| 1821 | #undef DECLARE_KIND |
| 1822 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1823 | HInstruction* GetNext() const { return next_; } |
| 1824 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1825 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1826 | HInstruction* GetNextDisregardingMoves() const; |
| 1827 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1828 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1829 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1830 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1831 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1832 | bool IsInBlock() const { return block_ != nullptr; } |
| 1833 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1834 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 1835 | bool IsIrreducibleLoopHeaderPhi() const { |
| 1836 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 1837 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1838 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1839 | virtual ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() = 0; |
| 1840 | |
| 1841 | ArrayRef<const HUserRecord<HInstruction*>> GetInputRecords() const { |
| 1842 | // One virtual method is enough, just const_cast<> and then re-add the const. |
| 1843 | return ArrayRef<const HUserRecord<HInstruction*>>( |
| 1844 | const_cast<HInstruction*>(this)->GetInputRecords()); |
| 1845 | } |
| 1846 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1847 | HInputsRef GetInputs() { |
| 1848 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1849 | } |
| 1850 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1851 | HConstInputsRef GetInputs() const { |
| 1852 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | size_t InputCount() const { return GetInputRecords().size(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1856 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1857 | |
Aart Bik | 2767f4b | 2016-10-28 15:03:53 -0700 | [diff] [blame] | 1858 | bool HasInput(HInstruction* input) const { |
| 1859 | for (const HInstruction* i : GetInputs()) { |
| 1860 | if (i == input) { |
| 1861 | return true; |
| 1862 | } |
| 1863 | } |
| 1864 | return false; |
| 1865 | } |
| 1866 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1867 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1868 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1869 | } |
| 1870 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1871 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1872 | virtual const char* DebugName() const = 0; |
| 1873 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1874 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
| 1875 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1876 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1877 | |
| 1878 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1879 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1880 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1881 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1882 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1883 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1884 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1885 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1886 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1887 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1888 | // Does not apply for all instructions, but having this at top level greatly |
| 1889 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1890 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1891 | virtual bool CanBeNull() const { |
| 1892 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1893 | return true; |
| 1894 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1895 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1896 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1897 | return false; |
| 1898 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1899 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 1900 | virtual bool IsActualObject() const { |
| 1901 | return GetType() == Primitive::kPrimNot; |
| 1902 | } |
| 1903 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1904 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1905 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1906 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1907 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1908 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 1909 | GetPackedFlag<kFlagReferenceTypeIsExact>()); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1910 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1911 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1912 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1913 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1914 | // Note: fixup_end remains valid across push_front(). |
| 1915 | auto fixup_end = uses_.empty() ? uses_.begin() : ++uses_.begin(); |
| 1916 | HUseListNode<HInstruction*>* new_node = |
| 1917 | new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HInstruction*>(user, index); |
| 1918 | uses_.push_front(*new_node); |
| 1919 | FixUpUserRecordsAfterUseInsertion(fixup_end); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1920 | } |
| 1921 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1922 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1923 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1924 | // Note: env_fixup_end remains valid across push_front(). |
| 1925 | auto env_fixup_end = env_uses_.empty() ? env_uses_.begin() : ++env_uses_.begin(); |
| 1926 | HUseListNode<HEnvironment*>* new_node = |
| 1927 | new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HEnvironment*>(user, index); |
| 1928 | env_uses_.push_front(*new_node); |
| 1929 | FixUpUserRecordsAfterEnvUseInsertion(env_fixup_end); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1930 | } |
| 1931 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1932 | void RemoveAsUserOfInput(size_t input) { |
| 1933 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1934 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 1935 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 1936 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1937 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1938 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1939 | void RemoveAsUserOfAllInputs() { |
| 1940 | for (const HUserRecord<HInstruction*>& input_use : GetInputRecords()) { |
| 1941 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 1942 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 1943 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
| 1944 | } |
| 1945 | } |
| 1946 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1947 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1948 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1949 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1950 | bool HasUses() const { return !uses_.empty() || !env_uses_.empty(); } |
| 1951 | bool HasEnvironmentUses() const { return !env_uses_.empty(); } |
| 1952 | bool HasNonEnvironmentUses() const { return !uses_.empty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1953 | bool HasOnlyOneNonEnvironmentUse() const { |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1954 | return !HasEnvironmentUses() && GetUses().HasExactlyOneElement(); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1955 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1956 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 1957 | bool IsRemovable() const { |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 1958 | return |
| 1959 | !HasSideEffects() && |
| 1960 | !CanThrow() && |
| 1961 | !IsSuspendCheck() && |
| 1962 | !IsControlFlow() && |
| 1963 | !IsNativeDebugInfo() && |
| 1964 | !IsParameterValue() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 1965 | // If we added an explicit barrier then we should keep it. |
| 1966 | !IsMemoryBarrier(); |
| 1967 | } |
| 1968 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 1969 | bool IsDeadAndRemovable() const { |
| 1970 | return IsRemovable() && !HasUses(); |
| 1971 | } |
| 1972 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1973 | // Does this instruction strictly dominate `other_instruction`? |
| 1974 | // Returns false if this instruction and `other_instruction` are the same. |
| 1975 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1976 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1977 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1978 | int GetId() const { return id_; } |
| 1979 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1980 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1981 | int GetSsaIndex() const { return ssa_index_; } |
| 1982 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 1983 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 1984 | |
| 1985 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 1986 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1987 | // Set the `environment_` field. Raw because this method does not |
| 1988 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1989 | void SetRawEnvironment(HEnvironment* environment) { |
| 1990 | DCHECK(environment_ == nullptr); |
| 1991 | DCHECK_EQ(environment->GetHolder(), this); |
| 1992 | environment_ = environment; |
| 1993 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1994 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 1995 | void InsertRawEnvironment(HEnvironment* environment) { |
| 1996 | DCHECK(environment_ != nullptr); |
| 1997 | DCHECK_EQ(environment->GetHolder(), this); |
| 1998 | DCHECK(environment->GetParent() == nullptr); |
| 1999 | environment->parent_ = environment_; |
| 2000 | environment_ = environment; |
| 2001 | } |
| 2002 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2003 | void RemoveEnvironment(); |
| 2004 | |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2005 | // Set the environment of this instruction, copying it from `environment`. While |
| 2006 | // copying, the uses lists are being updated. |
| 2007 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2008 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2009 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2010 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2011 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2012 | if (environment->GetParent() != nullptr) { |
| 2013 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2014 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2015 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2016 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2017 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 2018 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2019 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2020 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2021 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2022 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2023 | if (environment->GetParent() != nullptr) { |
| 2024 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2025 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2026 | } |
| 2027 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2028 | // Returns the number of entries in the environment. Typically, that is the |
| 2029 | // number of dex registers in a method. It could be more in case of inlining. |
| 2030 | size_t EnvironmentSize() const; |
| 2031 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2032 | LocationSummary* GetLocations() const { return locations_; } |
| 2033 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2034 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2035 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2036 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2037 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2038 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 2039 | // uses of this instruction by `other` are *not* updated. |
| 2040 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 2041 | ReplaceWith(other); |
| 2042 | other->ReplaceInput(this, use_index); |
| 2043 | } |
| 2044 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 2045 | // Move `this` instruction before `cursor`. |
| 2046 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2047 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2048 | // Move `this` before its first user and out of any loops. If there is no |
| 2049 | // out-of-loop user that dominates all other users, move the instruction |
| 2050 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2051 | // |
| 2052 | // This can be used only on non-throwing instructions with no side effects that |
| 2053 | // have at least one use but no environment uses. |
| 2054 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2055 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2056 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2057 | bool Is##type() const; \ |
| 2058 | const H##type* As##type() const; \ |
| 2059 | H##type* As##type(); |
| 2060 | |
| 2061 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2062 | #undef INSTRUCTION_TYPE_CHECK |
| 2063 | |
| 2064 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2065 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 2066 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2067 | virtual H##type* As##type() { return nullptr; } |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2068 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2069 | #undef INSTRUCTION_TYPE_CHECK |
| 2070 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2071 | // Returns whether the instruction can be moved within the graph. |
| 2072 | virtual bool CanBeMoved() const { return false; } |
| 2073 | |
| 2074 | // Returns whether the two instructions are of the same kind. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2075 | virtual bool InstructionTypeEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2076 | return false; |
| 2077 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2078 | |
| 2079 | // Returns whether any data encoded in the two instructions is equal. |
| 2080 | // This method does not look at the inputs. Both instructions must be |
| 2081 | // of the same type, otherwise the method has undefined behavior. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2082 | virtual bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2083 | return false; |
| 2084 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2085 | |
| 2086 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2087 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2088 | // 2) Their inputs are identical. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2089 | bool Equals(const HInstruction* other) const; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2090 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2091 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2092 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2093 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2094 | // apply the strong requirement for virtual functions, preventing optimizations. |
| 2095 | InstructionKind GetKind() const PURE; |
| 2096 | virtual InstructionKind GetKindInternal() const = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2097 | |
| 2098 | virtual size_t ComputeHashCode() const { |
| 2099 | size_t result = GetKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2100 | for (const HInstruction* input : GetInputs()) { |
| 2101 | result = (result * 31) + input->GetId(); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2102 | } |
| 2103 | return result; |
| 2104 | } |
| 2105 | |
| 2106 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2107 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2108 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2109 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2110 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2111 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2112 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2113 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2114 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2115 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2116 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2117 | |
| 2118 | // Returns whether the code generation of the instruction will require to have access |
| 2119 | // to the current method. Such instructions are: |
| 2120 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2121 | // 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] | 2122 | // (2): HCurrentMethod, potentially used by HInvokeStaticOrDirect, HLoadString, or HLoadClass |
| 2123 | // to access the dex cache. |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2124 | bool NeedsCurrentMethod() const { |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2125 | return NeedsEnvironment() || IsCurrentMethod(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2126 | } |
| 2127 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2128 | // Returns whether the code generation of the instruction will require to have access |
| 2129 | // to the dex cache of the current method's declaring class via the current method. |
| 2130 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2131 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2132 | // Does this instruction have any use in an environment before |
| 2133 | // control flow hits 'other'? |
| 2134 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2135 | |
| 2136 | // Remove all references to environment uses of this instruction. |
| 2137 | // The caller must ensure that this is safe to do. |
| 2138 | void RemoveEnvironmentUsers(); |
| 2139 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2140 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2141 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2142 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2143 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2144 | // If set, the machine code for this instruction is assumed to be generated by |
| 2145 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2146 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2147 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
| 2148 | static constexpr size_t kNumberOfGenericPackedBits = kFlagReferenceTypeIsExact + 1; |
| 2149 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2150 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2151 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const { |
| 2152 | return GetInputRecords()[i]; |
| 2153 | } |
| 2154 | |
| 2155 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) { |
| 2156 | ArrayRef<HUserRecord<HInstruction*>> input_records = GetInputRecords(); |
| 2157 | input_records[index] = input; |
| 2158 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2159 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2160 | uint32_t GetPackedFields() const { |
| 2161 | return packed_fields_; |
| 2162 | } |
| 2163 | |
| 2164 | template <size_t flag> |
| 2165 | bool GetPackedFlag() const { |
| 2166 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2167 | } |
| 2168 | |
| 2169 | template <size_t flag> |
| 2170 | void SetPackedFlag(bool value = true) { |
| 2171 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2172 | } |
| 2173 | |
| 2174 | template <typename BitFieldType> |
| 2175 | typename BitFieldType::value_type GetPackedField() const { |
| 2176 | return BitFieldType::Decode(packed_fields_); |
| 2177 | } |
| 2178 | |
| 2179 | template <typename BitFieldType> |
| 2180 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2181 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2182 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2183 | } |
| 2184 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2185 | private: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2186 | void FixUpUserRecordsAfterUseInsertion(HUseList<HInstruction*>::iterator fixup_end) { |
| 2187 | auto before_use_node = uses_.before_begin(); |
| 2188 | for (auto use_node = uses_.begin(); use_node != fixup_end; ++use_node) { |
| 2189 | HInstruction* user = use_node->GetUser(); |
| 2190 | size_t input_index = use_node->GetIndex(); |
| 2191 | user->SetRawInputRecordAt(input_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2192 | before_use_node = use_node; |
| 2193 | } |
| 2194 | } |
| 2195 | |
| 2196 | void FixUpUserRecordsAfterUseRemoval(HUseList<HInstruction*>::iterator before_use_node) { |
| 2197 | auto next = ++HUseList<HInstruction*>::iterator(before_use_node); |
| 2198 | if (next != uses_.end()) { |
| 2199 | HInstruction* next_user = next->GetUser(); |
| 2200 | size_t next_index = next->GetIndex(); |
| 2201 | DCHECK(next_user->InputRecordAt(next_index).GetInstruction() == this); |
| 2202 | next_user->SetRawInputRecordAt(next_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2203 | } |
| 2204 | } |
| 2205 | |
| 2206 | void FixUpUserRecordsAfterEnvUseInsertion(HUseList<HEnvironment*>::iterator env_fixup_end) { |
| 2207 | auto before_env_use_node = env_uses_.before_begin(); |
| 2208 | for (auto env_use_node = env_uses_.begin(); env_use_node != env_fixup_end; ++env_use_node) { |
| 2209 | HEnvironment* user = env_use_node->GetUser(); |
| 2210 | size_t input_index = env_use_node->GetIndex(); |
| 2211 | user->vregs_[input_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2212 | before_env_use_node = env_use_node; |
| 2213 | } |
| 2214 | } |
| 2215 | |
| 2216 | void FixUpUserRecordsAfterEnvUseRemoval(HUseList<HEnvironment*>::iterator before_env_use_node) { |
| 2217 | auto next = ++HUseList<HEnvironment*>::iterator(before_env_use_node); |
| 2218 | if (next != env_uses_.end()) { |
| 2219 | HEnvironment* next_user = next->GetUser(); |
| 2220 | size_t next_index = next->GetIndex(); |
| 2221 | DCHECK(next_user->vregs_[next_index].GetInstruction() == this); |
| 2222 | next_user->vregs_[next_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2223 | } |
| 2224 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2225 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2226 | HInstruction* previous_; |
| 2227 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2228 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2229 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2230 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2231 | // An instruction gets an id when it is added to the graph. |
| 2232 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2233 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2234 | int id_; |
| 2235 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2236 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2237 | int ssa_index_; |
| 2238 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2239 | // Packed fields. |
| 2240 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2241 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2242 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2243 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2244 | |
| 2245 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2246 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2247 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2248 | // The environment associated with this instruction. Not null if the instruction |
| 2249 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2250 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2251 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2252 | // Set by the code generator. |
| 2253 | LocationSummary* locations_; |
| 2254 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2255 | // Set by the liveness analysis. |
| 2256 | LiveInterval* live_interval_; |
| 2257 | |
| 2258 | // Set by the liveness analysis, this is the position in a linear |
| 2259 | // order of blocks where this instruction's live interval start. |
| 2260 | size_t lifetime_position_; |
| 2261 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2262 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2263 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2264 | // The reference handle part of the reference type info. |
| 2265 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2266 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2267 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2268 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2269 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2270 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2271 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2272 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2273 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2274 | |
| 2275 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2276 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2277 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2278 | |
| 2279 | class HInstructionIterator : public ValueObject { |
| 2280 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2281 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2282 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2283 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2284 | } |
| 2285 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2286 | bool Done() const { return instruction_ == nullptr; } |
| 2287 | HInstruction* Current() const { return instruction_; } |
| 2288 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2289 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2290 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2291 | } |
| 2292 | |
| 2293 | private: |
| 2294 | HInstruction* instruction_; |
| 2295 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2296 | |
| 2297 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2298 | }; |
| 2299 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2300 | class HBackwardInstructionIterator : public ValueObject { |
| 2301 | public: |
| 2302 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2303 | : instruction_(instructions.last_instruction_) { |
| 2304 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2305 | } |
| 2306 | |
| 2307 | bool Done() const { return instruction_ == nullptr; } |
| 2308 | HInstruction* Current() const { return instruction_; } |
| 2309 | void Advance() { |
| 2310 | instruction_ = next_; |
| 2311 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2312 | } |
| 2313 | |
| 2314 | private: |
| 2315 | HInstruction* instruction_; |
| 2316 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2317 | |
| 2318 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2319 | }; |
| 2320 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2321 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2322 | class HTemplateInstruction: public HInstruction { |
| 2323 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2324 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2325 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2326 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2327 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2328 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2329 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2330 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2331 | } |
| 2332 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2333 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2334 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2335 | |
| 2336 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2337 | }; |
| 2338 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2339 | // HTemplateInstruction specialization for N=0. |
| 2340 | template<> |
| 2341 | class HTemplateInstruction<0>: public HInstruction { |
| 2342 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2343 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2344 | : HInstruction(side_effects, dex_pc) {} |
| 2345 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2346 | virtual ~HTemplateInstruction() {} |
| 2347 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2348 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2349 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2350 | return ArrayRef<HUserRecord<HInstruction*>>(); |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2351 | } |
| 2352 | |
| 2353 | private: |
| 2354 | friend class SsaBuilder; |
| 2355 | }; |
| 2356 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2357 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2358 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2359 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2360 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2361 | : HTemplateInstruction<N>(side_effects, dex_pc) { |
| 2362 | this->template SetPackedField<TypeField>(type); |
| 2363 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2364 | virtual ~HExpression() {} |
| 2365 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2366 | Primitive::Type GetType() const OVERRIDE { |
| 2367 | return TypeField::Decode(this->GetPackedFields()); |
| 2368 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2369 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2370 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2371 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2372 | static constexpr size_t kFieldTypeSize = |
| 2373 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2374 | static constexpr size_t kNumberOfExpressionPackedBits = kFieldType + kFieldTypeSize; |
| 2375 | static_assert(kNumberOfExpressionPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 2376 | "Too many packed fields."); |
| 2377 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2378 | }; |
| 2379 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2380 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2381 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2382 | class HReturnVoid FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2383 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2384 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2385 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2386 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2387 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2388 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2389 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2390 | |
| 2391 | private: |
| 2392 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2393 | }; |
| 2394 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2395 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2396 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2397 | class HReturn FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2398 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2399 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2400 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2401 | SetRawInputAt(0, value); |
| 2402 | } |
| 2403 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2404 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2405 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2406 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2407 | |
| 2408 | private: |
| 2409 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2410 | }; |
| 2411 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2412 | class HPhi FINAL : public HInstruction { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2413 | public: |
| 2414 | HPhi(ArenaAllocator* arena, |
| 2415 | uint32_t reg_number, |
| 2416 | size_t number_of_inputs, |
| 2417 | Primitive::Type type, |
| 2418 | uint32_t dex_pc = kNoDexPc) |
| 2419 | : HInstruction(SideEffects::None(), dex_pc), |
| 2420 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
| 2421 | reg_number_(reg_number) { |
| 2422 | SetPackedField<TypeField>(ToPhiType(type)); |
| 2423 | DCHECK_NE(GetType(), Primitive::kPrimVoid); |
| 2424 | // Phis are constructed live and marked dead if conflicting or unused. |
| 2425 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 2426 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 2427 | SetPackedFlag<kFlagIsLive>(true); |
| 2428 | SetPackedFlag<kFlagCanBeNull>(true); |
| 2429 | } |
| 2430 | |
| 2431 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 2432 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 2433 | return Primitive::PrimitiveKind(type); |
| 2434 | } |
| 2435 | |
| 2436 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 2437 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2438 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2439 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2440 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 2441 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2442 | |
| 2443 | void AddInput(HInstruction* input); |
| 2444 | void RemoveInputAt(size_t index); |
| 2445 | |
| 2446 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<TypeField>(); } |
| 2447 | void SetType(Primitive::Type new_type) { |
| 2448 | // Make sure that only valid type changes occur. The following are allowed: |
| 2449 | // (1) int -> float/ref (primitive type propagation), |
| 2450 | // (2) long -> double (primitive type propagation). |
| 2451 | DCHECK(GetType() == new_type || |
| 2452 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimFloat) || |
| 2453 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimNot) || |
| 2454 | (GetType() == Primitive::kPrimLong && new_type == Primitive::kPrimDouble)); |
| 2455 | SetPackedField<TypeField>(new_type); |
| 2456 | } |
| 2457 | |
| 2458 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 2459 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
| 2460 | |
| 2461 | uint32_t GetRegNumber() const { return reg_number_; } |
| 2462 | |
| 2463 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 2464 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 2465 | bool IsDead() const { return !IsLive(); } |
| 2466 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
| 2467 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2468 | bool IsVRegEquivalentOf(const HInstruction* other) const { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2469 | return other != nullptr |
| 2470 | && other->IsPhi() |
| 2471 | && other->AsPhi()->GetBlock() == GetBlock() |
| 2472 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 2473 | } |
| 2474 | |
| 2475 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 2476 | // An equivalent phi is a phi having the same dex register and type. |
| 2477 | // It assumes that phis with the same dex register are adjacent. |
| 2478 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 2479 | HInstruction* next = GetNext(); |
| 2480 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 2481 | if (next->GetType() == GetType()) { |
| 2482 | return next->AsPhi(); |
| 2483 | } |
| 2484 | next = next->GetNext(); |
| 2485 | } |
| 2486 | return nullptr; |
| 2487 | } |
| 2488 | |
| 2489 | DECLARE_INSTRUCTION(Phi); |
| 2490 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2491 | private: |
| 2492 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2493 | static constexpr size_t kFieldTypeSize = |
| 2494 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2495 | static constexpr size_t kFlagIsLive = kFieldType + kFieldTypeSize; |
| 2496 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 2497 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 2498 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 2499 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
| 2500 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2501 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2502 | const uint32_t reg_number_; |
| 2503 | |
| 2504 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 2505 | }; |
| 2506 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2507 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2508 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2509 | // exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2510 | class HExit FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2511 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2512 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2513 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2514 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2515 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2516 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2517 | |
| 2518 | private: |
| 2519 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2520 | }; |
| 2521 | |
| 2522 | // Jumps from one block to another. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2523 | class HGoto FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2524 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2525 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2526 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2527 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2528 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2529 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2530 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2531 | } |
| 2532 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2533 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2534 | |
| 2535 | private: |
| 2536 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2537 | }; |
| 2538 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2539 | class HConstant : public HExpression<0> { |
| 2540 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2541 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2542 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2543 | |
| 2544 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2545 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2546 | // Is this constant -1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2547 | virtual bool IsMinusOne() const { return false; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2548 | // Is this constant 0 in the arithmetic sense? |
| 2549 | virtual bool IsArithmeticZero() const { return false; } |
| 2550 | // Is this constant a 0-bit pattern? |
| 2551 | virtual bool IsZeroBitPattern() const { return false; } |
| 2552 | // Is this constant 1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2553 | virtual bool IsOne() const { return false; } |
| 2554 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2555 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2556 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2557 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2558 | |
| 2559 | private: |
| 2560 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2561 | }; |
| 2562 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2563 | class HNullConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2564 | public: |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2565 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2566 | return true; |
| 2567 | } |
| 2568 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2569 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2570 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2571 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2572 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2573 | // The null constant representation is a 0-bit pattern. |
| 2574 | virtual bool IsZeroBitPattern() const { return true; } |
| 2575 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2576 | DECLARE_INSTRUCTION(NullConstant); |
| 2577 | |
| 2578 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2579 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2580 | |
| 2581 | friend class HGraph; |
| 2582 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2583 | }; |
| 2584 | |
| 2585 | // Constants of the type int. Those can be from Dex instructions, or |
| 2586 | // synthesized (for example with the if-eqz instruction). |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2587 | class HIntConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2588 | public: |
| 2589 | int32_t GetValue() const { return value_; } |
| 2590 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2591 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2592 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2593 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2594 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2595 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2596 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2597 | return other->AsIntConstant()->value_ == value_; |
| 2598 | } |
| 2599 | |
| 2600 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2601 | |
| 2602 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2603 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2604 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2605 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2606 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2607 | // Integer constants are used to encode Boolean values as well, |
| 2608 | // where 1 means true and 0 means false. |
| 2609 | bool IsTrue() const { return GetValue() == 1; } |
| 2610 | bool IsFalse() const { return GetValue() == 0; } |
| 2611 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2612 | DECLARE_INSTRUCTION(IntConstant); |
| 2613 | |
| 2614 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2615 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2616 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2617 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2618 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2619 | |
| 2620 | const int32_t value_; |
| 2621 | |
| 2622 | friend class HGraph; |
| 2623 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2624 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2625 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2626 | }; |
| 2627 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2628 | class HLongConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2629 | public: |
| 2630 | int64_t GetValue() const { return value_; } |
| 2631 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2632 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2633 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2634 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2635 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2636 | return other->AsLongConstant()->value_ == value_; |
| 2637 | } |
| 2638 | |
| 2639 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2640 | |
| 2641 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2642 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2643 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2644 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2645 | |
| 2646 | DECLARE_INSTRUCTION(LongConstant); |
| 2647 | |
| 2648 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2649 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2650 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2651 | |
| 2652 | const int64_t value_; |
| 2653 | |
| 2654 | friend class HGraph; |
| 2655 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2656 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2657 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2658 | class HFloatConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2659 | public: |
| 2660 | float GetValue() const { return value_; } |
| 2661 | |
| 2662 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2663 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2664 | } |
| 2665 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2666 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2667 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 2668 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2669 | } |
| 2670 | |
| 2671 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2672 | |
| 2673 | bool IsMinusOne() const OVERRIDE { |
| 2674 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 2675 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2676 | bool IsArithmeticZero() const OVERRIDE { |
| 2677 | return std::fpclassify(value_) == FP_ZERO; |
| 2678 | } |
| 2679 | bool IsArithmeticPositiveZero() const { |
| 2680 | return IsArithmeticZero() && !std::signbit(value_); |
| 2681 | } |
| 2682 | bool IsArithmeticNegativeZero() const { |
| 2683 | return IsArithmeticZero() && std::signbit(value_); |
| 2684 | } |
| 2685 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2686 | 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] | 2687 | } |
| 2688 | bool IsOne() const OVERRIDE { |
| 2689 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 2690 | } |
| 2691 | bool IsNaN() const { |
| 2692 | return std::isnan(value_); |
| 2693 | } |
| 2694 | |
| 2695 | DECLARE_INSTRUCTION(FloatConstant); |
| 2696 | |
| 2697 | private: |
| 2698 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 2699 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 2700 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2701 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
| 2702 | |
| 2703 | const float value_; |
| 2704 | |
| 2705 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2706 | friend class SsaBuilder; |
| 2707 | friend class HGraph; |
| 2708 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 2709 | }; |
| 2710 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2711 | class HDoubleConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2712 | public: |
| 2713 | double GetValue() const { return value_; } |
| 2714 | |
| 2715 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 2716 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2717 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2718 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 2719 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2720 | } |
| 2721 | |
| 2722 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2723 | |
| 2724 | bool IsMinusOne() const OVERRIDE { |
| 2725 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 2726 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2727 | bool IsArithmeticZero() const OVERRIDE { |
| 2728 | return std::fpclassify(value_) == FP_ZERO; |
| 2729 | } |
| 2730 | bool IsArithmeticPositiveZero() const { |
| 2731 | return IsArithmeticZero() && !std::signbit(value_); |
| 2732 | } |
| 2733 | bool IsArithmeticNegativeZero() const { |
| 2734 | return IsArithmeticZero() && std::signbit(value_); |
| 2735 | } |
| 2736 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2737 | 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] | 2738 | } |
| 2739 | bool IsOne() const OVERRIDE { |
| 2740 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 2741 | } |
| 2742 | bool IsNaN() const { |
| 2743 | return std::isnan(value_); |
| 2744 | } |
| 2745 | |
| 2746 | DECLARE_INSTRUCTION(DoubleConstant); |
| 2747 | |
| 2748 | private: |
| 2749 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 2750 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 2751 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2752 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
| 2753 | |
| 2754 | const double value_; |
| 2755 | |
| 2756 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2757 | friend class SsaBuilder; |
| 2758 | friend class HGraph; |
| 2759 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 2760 | }; |
| 2761 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2762 | // Conditional branch. A block ending with an HIf instruction must have |
| 2763 | // two successors. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2764 | class HIf FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2765 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2766 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2767 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2768 | SetRawInputAt(0, input); |
| 2769 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2770 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2771 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2772 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2773 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2774 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2775 | } |
| 2776 | |
| 2777 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2778 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2779 | } |
| 2780 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2781 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2782 | |
| 2783 | private: |
| 2784 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2785 | }; |
| 2786 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2787 | |
| 2788 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2789 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2790 | // non-exceptional control flow. |
| 2791 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2792 | // higher indices in no particular order. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2793 | class HTryBoundary FINAL : public HTemplateInstruction<0> { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2794 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2795 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2796 | kEntry, |
| 2797 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2798 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2799 | }; |
| 2800 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2801 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2802 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
| 2803 | SetPackedField<BoundaryKindField>(kind); |
| 2804 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2805 | |
| 2806 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2807 | |
| 2808 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2809 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2810 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 2811 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 2812 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 2813 | } |
| 2814 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2815 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2816 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2817 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2818 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2819 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2820 | } |
| 2821 | |
| 2822 | // If not present already, adds `handler` to its block's list of exception |
| 2823 | // handlers. |
| 2824 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2825 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2826 | GetBlock()->AddSuccessor(handler); |
| 2827 | } |
| 2828 | } |
| 2829 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2830 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 2831 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2832 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2833 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2834 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2835 | DECLARE_INSTRUCTION(TryBoundary); |
| 2836 | |
| 2837 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2838 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 2839 | static constexpr size_t kFieldBoundaryKindSize = |
| 2840 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 2841 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 2842 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 2843 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 2844 | "Too many packed fields."); |
| 2845 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2846 | |
| 2847 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2848 | }; |
| 2849 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2850 | // Deoptimize to interpreter, upon checking a condition. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2851 | class HDeoptimize FINAL : public HTemplateInstruction<1> { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2852 | public: |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2853 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 2854 | // at the point of the `HDeoptimize`. |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2855 | HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2856 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2857 | SetRawInputAt(0, cond); |
| 2858 | } |
| 2859 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2860 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2861 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2862 | return true; |
| 2863 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2864 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2865 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2866 | |
| 2867 | DECLARE_INSTRUCTION(Deoptimize); |
| 2868 | |
| 2869 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2870 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2871 | }; |
| 2872 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2873 | // Represents the ArtMethod that was passed as a first argument to |
| 2874 | // the method. It is used by instructions that depend on it, like |
| 2875 | // instructions that work with the dex cache. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2876 | class HCurrentMethod FINAL : public HExpression<0> { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2877 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2878 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2879 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2880 | |
| 2881 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2882 | |
| 2883 | private: |
| 2884 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2885 | }; |
| 2886 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2887 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 2888 | // of a class. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2889 | class HClassTableGet FINAL : public HExpression<1> { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2890 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2891 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2892 | kVTable, |
| 2893 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2894 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2895 | }; |
| 2896 | HClassTableGet(HInstruction* cls, |
| 2897 | Primitive::Type type, |
| 2898 | TableKind kind, |
| 2899 | size_t index, |
| 2900 | uint32_t dex_pc) |
| 2901 | : HExpression(type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2902 | index_(index) { |
| 2903 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2904 | SetRawInputAt(0, cls); |
| 2905 | } |
| 2906 | |
| 2907 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2908 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2909 | return other->AsClassTableGet()->GetIndex() == index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2910 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2911 | } |
| 2912 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2913 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2914 | size_t GetIndex() const { return index_; } |
| 2915 | |
| 2916 | DECLARE_INSTRUCTION(ClassTableGet); |
| 2917 | |
| 2918 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2919 | static constexpr size_t kFieldTableKind = kNumberOfExpressionPackedBits; |
| 2920 | static constexpr size_t kFieldTableKindSize = |
| 2921 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 2922 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 2923 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 2924 | "Too many packed fields."); |
| 2925 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 2926 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2927 | // The index of the ArtMethod in the table. |
| 2928 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2929 | |
| 2930 | DISALLOW_COPY_AND_ASSIGN(HClassTableGet); |
| 2931 | }; |
| 2932 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2933 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 2934 | // have one successor for each entry in the switch table, and the final successor |
| 2935 | // will be the block containing the next Dex opcode. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2936 | class HPackedSwitch FINAL : public HTemplateInstruction<1> { |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2937 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2938 | HPackedSwitch(int32_t start_value, |
| 2939 | uint32_t num_entries, |
| 2940 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2941 | uint32_t dex_pc = kNoDexPc) |
| 2942 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 2943 | start_value_(start_value), |
| 2944 | num_entries_(num_entries) { |
| 2945 | SetRawInputAt(0, input); |
| 2946 | } |
| 2947 | |
| 2948 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2949 | |
| 2950 | int32_t GetStartValue() const { return start_value_; } |
| 2951 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 2952 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2953 | |
| 2954 | HBasicBlock* GetDefaultBlock() const { |
| 2955 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2956 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2957 | } |
| 2958 | DECLARE_INSTRUCTION(PackedSwitch); |
| 2959 | |
| 2960 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2961 | const int32_t start_value_; |
| 2962 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2963 | |
| 2964 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 2965 | }; |
| 2966 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2967 | class HUnaryOperation : public HExpression<1> { |
| 2968 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2969 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2970 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2971 | SetRawInputAt(0, input); |
| 2972 | } |
| 2973 | |
| 2974 | HInstruction* GetInput() const { return InputAt(0); } |
| 2975 | Primitive::Type GetResultType() const { return GetType(); } |
| 2976 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2977 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2978 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2979 | return true; |
| 2980 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2981 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2982 | // Try to statically evaluate `this` and return a HConstant |
| 2983 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2984 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2985 | HConstant* TryStaticEvaluation() const; |
| 2986 | |
| 2987 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2988 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 2989 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2990 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 2991 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2992 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2993 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2994 | |
| 2995 | private: |
| 2996 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 2997 | }; |
| 2998 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2999 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3000 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3001 | HBinaryOperation(Primitive::Type result_type, |
| 3002 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3003 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3004 | SideEffects side_effects = SideEffects::None(), |
| 3005 | uint32_t dex_pc = kNoDexPc) |
| 3006 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3007 | SetRawInputAt(0, left); |
| 3008 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3009 | } |
| 3010 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3011 | HInstruction* GetLeft() const { return InputAt(0); } |
| 3012 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3013 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3014 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3015 | virtual bool IsCommutative() const { return false; } |
| 3016 | |
| 3017 | // Put constant on the right. |
| 3018 | // Returns whether order is changed. |
| 3019 | bool OrderInputsWithConstantOnTheRight() { |
| 3020 | HInstruction* left = InputAt(0); |
| 3021 | HInstruction* right = InputAt(1); |
| 3022 | if (left->IsConstant() && !right->IsConstant()) { |
| 3023 | ReplaceInput(right, 0); |
| 3024 | ReplaceInput(left, 1); |
| 3025 | return true; |
| 3026 | } |
| 3027 | return false; |
| 3028 | } |
| 3029 | |
| 3030 | // Order inputs by instruction id, but favor constant on the right side. |
| 3031 | // This helps GVN for commutative ops. |
| 3032 | void OrderInputs() { |
| 3033 | DCHECK(IsCommutative()); |
| 3034 | HInstruction* left = InputAt(0); |
| 3035 | HInstruction* right = InputAt(1); |
| 3036 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 3037 | return; |
| 3038 | } |
| 3039 | if (OrderInputsWithConstantOnTheRight()) { |
| 3040 | return; |
| 3041 | } |
| 3042 | // Order according to instruction id. |
| 3043 | if (left->GetId() > right->GetId()) { |
| 3044 | ReplaceInput(right, 0); |
| 3045 | ReplaceInput(left, 1); |
| 3046 | } |
| 3047 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3048 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3049 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3050 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3051 | return true; |
| 3052 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3053 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3054 | // Try to statically evaluate `this` and return a HConstant |
| 3055 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3056 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3057 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3058 | |
| 3059 | // Apply this operation to `x` and `y`. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3060 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3061 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3062 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 3063 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3064 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3065 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 3066 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3067 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 3068 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3069 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 3070 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3071 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3072 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 3073 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3074 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3075 | // 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] | 3076 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3077 | HConstant* GetConstantRight() const; |
| 3078 | |
| 3079 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3080 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3081 | HInstruction* GetLeastConstantLeft() const; |
| 3082 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3083 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 3084 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3085 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3086 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 3087 | }; |
| 3088 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3089 | // The comparison bias applies for floating point operations and indicates how NaN |
| 3090 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3091 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3092 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 3093 | kGtBias, // return 1 for NaN comparisons |
| 3094 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3095 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3096 | }; |
| 3097 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3098 | std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs); |
| 3099 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3100 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3101 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3102 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3103 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc) { |
| 3104 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 3105 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3106 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3107 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3108 | // `instruction`, and disregard moves in between. |
| 3109 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3110 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3111 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3112 | |
| 3113 | virtual IfCondition GetCondition() const = 0; |
| 3114 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3115 | virtual IfCondition GetOppositeCondition() const = 0; |
| 3116 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3117 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3118 | bool IsLtBias() const { return GetBias() == ComparisonBias::kLtBias; } |
| 3119 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3120 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 3121 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3122 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3123 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3124 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3125 | } |
| 3126 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3127 | bool IsFPConditionTrueIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3128 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3129 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3130 | if (if_cond == kCondNE) { |
| 3131 | return true; |
| 3132 | } else if (if_cond == kCondEQ) { |
| 3133 | return false; |
| 3134 | } |
| 3135 | return ((if_cond == kCondGT) || (if_cond == kCondGE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3136 | } |
| 3137 | |
| 3138 | bool IsFPConditionFalseIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3139 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3140 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3141 | if (if_cond == kCondEQ) { |
| 3142 | return true; |
| 3143 | } else if (if_cond == kCondNE) { |
| 3144 | return false; |
| 3145 | } |
| 3146 | return ((if_cond == kCondLT) || (if_cond == kCondLE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3147 | } |
| 3148 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3149 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3150 | // Needed if we merge a HCompare into a HCondition. |
| 3151 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3152 | static constexpr size_t kFieldComparisonBiasSize = |
| 3153 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3154 | static constexpr size_t kNumberOfConditionPackedBits = |
| 3155 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3156 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3157 | using ComparisonBiasField = |
| 3158 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3159 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3160 | template <typename T> |
| 3161 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3162 | |
| 3163 | template <typename T> |
| 3164 | int32_t CompareFP(T x, T y) const { |
| 3165 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3166 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3167 | // Handle the bias. |
| 3168 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 3169 | } |
| 3170 | |
| 3171 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3172 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3173 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3174 | } |
| 3175 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3176 | private: |
| 3177 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 3178 | }; |
| 3179 | |
| 3180 | // Instruction to check if two inputs are equal to each other. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3181 | class HEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3182 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3183 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3184 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3185 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3186 | bool IsCommutative() const OVERRIDE { return true; } |
| 3187 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3188 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3189 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3190 | return MakeConstantCondition(true, GetDexPc()); |
| 3191 | } |
| 3192 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3193 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3194 | } |
| 3195 | // In the following Evaluate methods, a HCompare instruction has |
| 3196 | // been merged into this HEqual instruction; evaluate it as |
| 3197 | // `Compare(x, y) == 0`. |
| 3198 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3199 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3200 | GetDexPc()); |
| 3201 | } |
| 3202 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3203 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3204 | } |
| 3205 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3206 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3207 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3208 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3209 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3210 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3211 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3212 | return kCondEQ; |
| 3213 | } |
| 3214 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3215 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3216 | return kCondNE; |
| 3217 | } |
| 3218 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3219 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3220 | 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] | 3221 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3222 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 3223 | }; |
| 3224 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3225 | class HNotEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3226 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3227 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3228 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3229 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3230 | bool IsCommutative() const OVERRIDE { return true; } |
| 3231 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3232 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3233 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3234 | return MakeConstantCondition(false, GetDexPc()); |
| 3235 | } |
| 3236 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3237 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3238 | } |
| 3239 | // In the following Evaluate methods, a HCompare instruction has |
| 3240 | // been merged into this HNotEqual instruction; evaluate it as |
| 3241 | // `Compare(x, y) != 0`. |
| 3242 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3243 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3244 | } |
| 3245 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3246 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3247 | } |
| 3248 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3249 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3250 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3251 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3252 | DECLARE_INSTRUCTION(NotEqual); |
| 3253 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3254 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3255 | return kCondNE; |
| 3256 | } |
| 3257 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3258 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3259 | return kCondEQ; |
| 3260 | } |
| 3261 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3262 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3263 | 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] | 3264 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3265 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 3266 | }; |
| 3267 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3268 | class HLessThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3269 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3270 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3271 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3272 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3273 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3274 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3275 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3276 | // In the following Evaluate methods, a HCompare instruction has |
| 3277 | // been merged into this HLessThan instruction; evaluate it as |
| 3278 | // `Compare(x, y) < 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3279 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3280 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3281 | } |
| 3282 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3283 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3284 | } |
| 3285 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3286 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3287 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3288 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3289 | DECLARE_INSTRUCTION(LessThan); |
| 3290 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3291 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3292 | return kCondLT; |
| 3293 | } |
| 3294 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3295 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3296 | return kCondGE; |
| 3297 | } |
| 3298 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3299 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3300 | 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] | 3301 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3302 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 3303 | }; |
| 3304 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3305 | class HLessThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3306 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3307 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3308 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3309 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3310 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3311 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3312 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3313 | // In the following Evaluate methods, a HCompare instruction has |
| 3314 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 3315 | // `Compare(x, y) <= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3316 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3317 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3318 | } |
| 3319 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3320 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3321 | } |
| 3322 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3323 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3324 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3325 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3326 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 3327 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3328 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3329 | return kCondLE; |
| 3330 | } |
| 3331 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3332 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3333 | return kCondGT; |
| 3334 | } |
| 3335 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3336 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3337 | 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] | 3338 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3339 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 3340 | }; |
| 3341 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3342 | class HGreaterThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3343 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3344 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3345 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3346 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3347 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3348 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3349 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3350 | // In the following Evaluate methods, a HCompare instruction has |
| 3351 | // been merged into this HGreaterThan instruction; evaluate it as |
| 3352 | // `Compare(x, y) > 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3353 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3354 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3355 | } |
| 3356 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3357 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3358 | } |
| 3359 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3360 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3361 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3362 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3363 | DECLARE_INSTRUCTION(GreaterThan); |
| 3364 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3365 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3366 | return kCondGT; |
| 3367 | } |
| 3368 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3369 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3370 | return kCondLE; |
| 3371 | } |
| 3372 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3373 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3374 | 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] | 3375 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3376 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 3377 | }; |
| 3378 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3379 | class HGreaterThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3380 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3381 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3382 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3383 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3384 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3385 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3386 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3387 | // In the following Evaluate methods, a HCompare instruction has |
| 3388 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 3389 | // `Compare(x, y) >= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3390 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3391 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3392 | } |
| 3393 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3394 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3395 | } |
| 3396 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3397 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3398 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3399 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3400 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 3401 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3402 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3403 | return kCondGE; |
| 3404 | } |
| 3405 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3406 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3407 | return kCondLT; |
| 3408 | } |
| 3409 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3410 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3411 | 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] | 3412 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3413 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 3414 | }; |
| 3415 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3416 | class HBelow FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3417 | public: |
| 3418 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3419 | : HCondition(first, second, dex_pc) {} |
| 3420 | |
| 3421 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3422 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3423 | } |
| 3424 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3425 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3426 | } |
| 3427 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3428 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3429 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3430 | UNREACHABLE(); |
| 3431 | } |
| 3432 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3433 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3434 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3435 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3436 | } |
| 3437 | |
| 3438 | DECLARE_INSTRUCTION(Below); |
| 3439 | |
| 3440 | IfCondition GetCondition() const OVERRIDE { |
| 3441 | return kCondB; |
| 3442 | } |
| 3443 | |
| 3444 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3445 | return kCondAE; |
| 3446 | } |
| 3447 | |
| 3448 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3449 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3450 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 3451 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3452 | |
| 3453 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 3454 | }; |
| 3455 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3456 | class HBelowOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3457 | public: |
| 3458 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3459 | : HCondition(first, second, dex_pc) {} |
| 3460 | |
| 3461 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3462 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3463 | } |
| 3464 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3465 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3466 | } |
| 3467 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3468 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3469 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3470 | UNREACHABLE(); |
| 3471 | } |
| 3472 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3473 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3474 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3475 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3476 | } |
| 3477 | |
| 3478 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 3479 | |
| 3480 | IfCondition GetCondition() const OVERRIDE { |
| 3481 | return kCondBE; |
| 3482 | } |
| 3483 | |
| 3484 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3485 | return kCondA; |
| 3486 | } |
| 3487 | |
| 3488 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3489 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3490 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 3491 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3492 | |
| 3493 | DISALLOW_COPY_AND_ASSIGN(HBelowOrEqual); |
| 3494 | }; |
| 3495 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3496 | class HAbove FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3497 | public: |
| 3498 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3499 | : HCondition(first, second, dex_pc) {} |
| 3500 | |
| 3501 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3502 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3503 | } |
| 3504 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3505 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3506 | } |
| 3507 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3508 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3509 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3510 | UNREACHABLE(); |
| 3511 | } |
| 3512 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3513 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3514 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3515 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3516 | } |
| 3517 | |
| 3518 | DECLARE_INSTRUCTION(Above); |
| 3519 | |
| 3520 | IfCondition GetCondition() const OVERRIDE { |
| 3521 | return kCondA; |
| 3522 | } |
| 3523 | |
| 3524 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3525 | return kCondBE; |
| 3526 | } |
| 3527 | |
| 3528 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3529 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3530 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 3531 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3532 | |
| 3533 | DISALLOW_COPY_AND_ASSIGN(HAbove); |
| 3534 | }; |
| 3535 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3536 | class HAboveOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3537 | public: |
| 3538 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3539 | : HCondition(first, second, dex_pc) {} |
| 3540 | |
| 3541 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3542 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3543 | } |
| 3544 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3545 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3546 | } |
| 3547 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3548 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3549 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3550 | UNREACHABLE(); |
| 3551 | } |
| 3552 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3553 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3554 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3555 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3556 | } |
| 3557 | |
| 3558 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 3559 | |
| 3560 | IfCondition GetCondition() const OVERRIDE { |
| 3561 | return kCondAE; |
| 3562 | } |
| 3563 | |
| 3564 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3565 | return kCondB; |
| 3566 | } |
| 3567 | |
| 3568 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3569 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3570 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 3571 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3572 | |
| 3573 | DISALLOW_COPY_AND_ASSIGN(HAboveOrEqual); |
| 3574 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3575 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3576 | // Instruction to check how two inputs compare to each other. |
| 3577 | // 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] | 3578 | class HCompare FINAL : public HBinaryOperation { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3579 | public: |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3580 | // Note that `comparison_type` is the type of comparison performed |
| 3581 | // between the comparison's inputs, not the type of the instantiated |
| 3582 | // HCompare instruction (which is always Primitive::kPrimInt). |
| 3583 | HCompare(Primitive::Type comparison_type, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3584 | HInstruction* first, |
| 3585 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3586 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3587 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3588 | : HBinaryOperation(Primitive::kPrimInt, |
| 3589 | first, |
| 3590 | second, |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3591 | SideEffectsForArchRuntimeCalls(comparison_type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3592 | dex_pc) { |
| 3593 | SetPackedField<ComparisonBiasField>(bias); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3594 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(first->GetType())); |
| 3595 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(second->GetType())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3596 | } |
| 3597 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3598 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3599 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3600 | |
| 3601 | template <typename T> |
| 3602 | int32_t ComputeFP(T x, T y) const { |
| 3603 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3604 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3605 | // Handle the bias. |
| 3606 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 3607 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3608 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3609 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3610 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 3611 | // reach this code path when processing a freshly built HIR |
| 3612 | // graph. However HCompare integer instructions can be synthesized |
| 3613 | // by the instruction simplifier to implement IntegerCompare and |
| 3614 | // IntegerSignum intrinsics, so we have to handle this case. |
| 3615 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3616 | } |
| 3617 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3618 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3619 | } |
| 3620 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3621 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3622 | } |
| 3623 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3624 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3625 | } |
| 3626 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3627 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3628 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3629 | } |
| 3630 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3631 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3632 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3633 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3634 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3635 | bool IsGtBias() const { |
| 3636 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3637 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3638 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3639 | |
Roland Levillain | 1693a1f | 2016-03-15 14:57:31 +0000 | [diff] [blame] | 3640 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type ATTRIBUTE_UNUSED) { |
| 3641 | // Comparisons do not require a runtime call in any back end. |
| 3642 | return SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3643 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3644 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3645 | DECLARE_INSTRUCTION(Compare); |
| 3646 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3647 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3648 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3649 | static constexpr size_t kFieldComparisonBiasSize = |
| 3650 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3651 | static constexpr size_t kNumberOfComparePackedBits = |
| 3652 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3653 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3654 | using ComparisonBiasField = |
| 3655 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3656 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3657 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 3658 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 3659 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 3660 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3661 | } |
| 3662 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3663 | private: |
| 3664 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3665 | }; |
| 3666 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3667 | class HNewInstance FINAL : public HExpression<2> { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3668 | public: |
| 3669 | HNewInstance(HInstruction* cls, |
| 3670 | HCurrentMethod* current_method, |
| 3671 | uint32_t dex_pc, |
| 3672 | uint16_t type_index, |
| 3673 | const DexFile& dex_file, |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3674 | bool needs_access_check, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3675 | bool finalizable, |
| 3676 | QuickEntrypointEnum entrypoint) |
| 3677 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
| 3678 | type_index_(type_index), |
| 3679 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3680 | entrypoint_(entrypoint) { |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3681 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3682 | SetPackedFlag<kFlagFinalizable>(finalizable); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3683 | SetRawInputAt(0, cls); |
| 3684 | SetRawInputAt(1, current_method); |
| 3685 | } |
| 3686 | |
| 3687 | uint16_t GetTypeIndex() const { return type_index_; } |
| 3688 | const DexFile& GetDexFile() const { return dex_file_; } |
| 3689 | |
| 3690 | // Calls runtime so needs an environment. |
| 3691 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3692 | |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3693 | // Can throw errors when out-of-memory or if it's not instantiable/accessible. |
| 3694 | bool CanThrow() const OVERRIDE { return true; } |
| 3695 | |
| 3696 | // Needs to call into runtime to make sure it's instantiable/accessible. |
| 3697 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3698 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3699 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3700 | |
| 3701 | bool CanBeNull() const OVERRIDE { return false; } |
| 3702 | |
| 3703 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3704 | |
| 3705 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 3706 | entrypoint_ = entrypoint; |
| 3707 | } |
| 3708 | |
| 3709 | bool IsStringAlloc() const; |
| 3710 | |
| 3711 | DECLARE_INSTRUCTION(NewInstance); |
| 3712 | |
| 3713 | private: |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3714 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfExpressionPackedBits; |
| 3715 | static constexpr size_t kFlagFinalizable = kFlagNeedsAccessCheck + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3716 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagFinalizable + 1; |
| 3717 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 3718 | "Too many packed fields."); |
| 3719 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3720 | const uint16_t type_index_; |
| 3721 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3722 | QuickEntrypointEnum entrypoint_; |
| 3723 | |
| 3724 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3725 | }; |
| 3726 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3727 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3728 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3729 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3730 | }; |
| 3731 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3732 | enum IntrinsicSideEffects { |
| 3733 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 3734 | kReadSideEffects, // Intrinsic may read heap memory. |
| 3735 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 3736 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 3737 | }; |
| 3738 | |
| 3739 | enum IntrinsicExceptions { |
| 3740 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 3741 | kCanThrow // Intrinsic may throw exceptions. |
| 3742 | }; |
| 3743 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3744 | class HInvoke : public HInstruction { |
| 3745 | public: |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3746 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3747 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3748 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 3749 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 3750 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 3751 | } |
| 3752 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3753 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3754 | SetRawInputAt(index, argument); |
| 3755 | } |
| 3756 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3757 | // Return the number of arguments. This number can be lower than |
| 3758 | // the number of inputs returned by InputCount(), as some invoke |
| 3759 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3760 | // inputs at the end of their list of inputs. |
| 3761 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3762 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3763 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<ReturnTypeField>(); } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3764 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3765 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3766 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3767 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3768 | InvokeType GetInvokeType() const { |
| 3769 | return GetPackedField<InvokeTypeField>(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3770 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3771 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3772 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3773 | return intrinsic_; |
| 3774 | } |
| 3775 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3776 | void SetIntrinsic(Intrinsics intrinsic, |
| 3777 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 3778 | IntrinsicSideEffects side_effects, |
| 3779 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3780 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3781 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 3782 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3783 | } |
| 3784 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3785 | bool CanThrow() const OVERRIDE { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3786 | |
| 3787 | bool CanBeMoved() const OVERRIDE { return IsIntrinsic(); } |
| 3788 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3789 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3790 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 3791 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3792 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3793 | uint32_t* GetIntrinsicOptimizations() { |
| 3794 | return &intrinsic_optimizations_; |
| 3795 | } |
| 3796 | |
| 3797 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3798 | return &intrinsic_optimizations_; |
| 3799 | } |
| 3800 | |
| 3801 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3802 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3803 | ArtMethod* GetResolvedMethod() const { return resolved_method_; } |
| 3804 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3805 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3806 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3807 | protected: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3808 | static constexpr size_t kFieldInvokeType = kNumberOfGenericPackedBits; |
| 3809 | static constexpr size_t kFieldInvokeTypeSize = |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3810 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 3811 | static constexpr size_t kFieldReturnType = |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3812 | kFieldInvokeType + kFieldInvokeTypeSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3813 | static constexpr size_t kFieldReturnTypeSize = |
| 3814 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 3815 | static constexpr size_t kFlagCanThrow = kFieldReturnType + kFieldReturnTypeSize; |
| 3816 | static constexpr size_t kNumberOfInvokePackedBits = kFlagCanThrow + 1; |
| 3817 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3818 | using InvokeTypeField = BitField<InvokeType, kFieldInvokeType, kFieldInvokeTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3819 | using ReturnTypeField = BitField<Primitive::Type, kFieldReturnType, kFieldReturnTypeSize>; |
| 3820 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3821 | HInvoke(ArenaAllocator* arena, |
| 3822 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3823 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3824 | Primitive::Type return_type, |
| 3825 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3826 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3827 | ArtMethod* resolved_method, |
| 3828 | InvokeType invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3829 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3830 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3831 | number_of_arguments_(number_of_arguments), |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3832 | resolved_method_(resolved_method), |
Vladimir Marko | b7d8e8c | 2015-09-17 15:47:05 +0100 | [diff] [blame] | 3833 | inputs_(number_of_arguments + number_of_other_inputs, |
| 3834 | arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3835 | dex_method_index_(dex_method_index), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3836 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3837 | intrinsic_optimizations_(0) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3838 | SetPackedField<ReturnTypeField>(return_type); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3839 | SetPackedField<InvokeTypeField>(invoke_type); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3840 | SetPackedFlag<kFlagCanThrow>(true); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3841 | } |
| 3842 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3843 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3844 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3845 | uint32_t number_of_arguments_; |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3846 | ArtMethod* const resolved_method_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3847 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3848 | const uint32_t dex_method_index_; |
| 3849 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3850 | |
| 3851 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3852 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3853 | |
| 3854 | private: |
| 3855 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3856 | }; |
| 3857 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3858 | class HInvokeUnresolved FINAL : public HInvoke { |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3859 | public: |
| 3860 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3861 | uint32_t number_of_arguments, |
| 3862 | Primitive::Type return_type, |
| 3863 | uint32_t dex_pc, |
| 3864 | uint32_t dex_method_index, |
| 3865 | InvokeType invoke_type) |
| 3866 | : HInvoke(arena, |
| 3867 | number_of_arguments, |
| 3868 | 0u /* number_of_other_inputs */, |
| 3869 | return_type, |
| 3870 | dex_pc, |
| 3871 | dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3872 | nullptr, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3873 | invoke_type) { |
| 3874 | } |
| 3875 | |
| 3876 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3877 | |
| 3878 | private: |
| 3879 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3880 | }; |
| 3881 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3882 | class HInvokeStaticOrDirect FINAL : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3883 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3884 | // Requirements of this method call regarding the class |
| 3885 | // initialization (clinit) check of its declaring class. |
| 3886 | enum class ClinitCheckRequirement { |
| 3887 | kNone, // Class already initialized. |
| 3888 | kExplicit, // Static call having explicit clinit check as last input. |
| 3889 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3890 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3891 | }; |
| 3892 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3893 | // Determines how to load the target ArtMethod*. |
| 3894 | enum class MethodLoadKind { |
| 3895 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3896 | kStringInit, |
| 3897 | |
| 3898 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3899 | kRecursive, |
| 3900 | |
| 3901 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3902 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3903 | kDirectAddress, |
| 3904 | |
| 3905 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3906 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3907 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3908 | // the image relocatable or not. |
| 3909 | kDirectAddressWithFixup, |
| 3910 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3911 | // 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] | 3912 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3913 | // may cause class initialization (the entry may point to a resolution method), |
| 3914 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3915 | kDexCachePcRelative, |
| 3916 | |
| 3917 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3918 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3919 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3920 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3921 | kDexCacheViaMethod, |
| 3922 | }; |
| 3923 | |
| 3924 | // Determines the location of the code pointer. |
| 3925 | enum class CodePtrLocation { |
| 3926 | // Recursive call, use local PC-relative call instruction. |
| 3927 | kCallSelf, |
| 3928 | |
| 3929 | // Use PC-relative call instruction patched at link time. |
| 3930 | // Used for calls within an oat file, boot->boot or app->app. |
| 3931 | kCallPCRelative, |
| 3932 | |
| 3933 | // Call to a known target address, embed the direct address in code. |
| 3934 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3935 | kCallDirect, |
| 3936 | |
| 3937 | // Call to a target address that will be known at link time, embed the direct |
| 3938 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3939 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3940 | // the image relocatable or not. |
| 3941 | kCallDirectWithFixup, |
| 3942 | |
| 3943 | // Use code pointer from the ArtMethod*. |
| 3944 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3945 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3946 | kCallArtMethod, |
| 3947 | }; |
| 3948 | |
| 3949 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3950 | MethodLoadKind method_load_kind; |
| 3951 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3952 | // The method load data holds |
| 3953 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3954 | // Note that there are multiple string init methods, each having its own offset. |
| 3955 | // - the method address for kDirectAddress |
| 3956 | // - the dex cache arrays offset for kDexCachePcRel. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3957 | uint64_t method_load_data; |
| 3958 | uint64_t direct_code_ptr; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3959 | }; |
| 3960 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3961 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 3962 | uint32_t number_of_arguments, |
| 3963 | Primitive::Type return_type, |
| 3964 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3965 | uint32_t method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3966 | ArtMethod* resolved_method, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3967 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3968 | InvokeType invoke_type, |
| 3969 | MethodReference target_method, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3970 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3971 | : HInvoke(arena, |
| 3972 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3973 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 3974 | // potentially one other if the clinit check is explicit, and potentially |
| 3975 | // one other if the method is a string factory. |
| 3976 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3977 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3978 | return_type, |
| 3979 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3980 | method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3981 | resolved_method, |
| 3982 | invoke_type), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3983 | target_method_(target_method), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3984 | dispatch_info_(dispatch_info) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3985 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 3986 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3987 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3988 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3989 | bool had_current_method_input = HasCurrentMethodInput(); |
| 3990 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 3991 | |
| 3992 | // Using the current method is the default and once we find a better |
| 3993 | // method load kind, we should not go back to using the current method. |
| 3994 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 3995 | |
| 3996 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3997 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 3998 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3999 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4000 | dispatch_info_ = dispatch_info; |
| 4001 | } |
| 4002 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4003 | void AddSpecialInput(HInstruction* input) { |
| 4004 | // We allow only one special input. |
| 4005 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 4006 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4007 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 4008 | InsertInputAt(GetSpecialInputIndex(), input); |
| 4009 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4010 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4011 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 4012 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 4013 | ArrayRef<HUserRecord<HInstruction*>> input_records = HInvoke::GetInputRecords(); |
| 4014 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck()) { |
| 4015 | DCHECK(!input_records.empty()); |
| 4016 | DCHECK_GT(input_records.size(), GetNumberOfArguments()); |
| 4017 | HInstruction* last_input = input_records.back().GetInstruction(); |
| 4018 | // Note: `last_input` may be null during arguments setup. |
| 4019 | if (last_input != nullptr) { |
| 4020 | // `last_input` is the last input of a static invoke marked as having |
| 4021 | // an explicit clinit check. It must either be: |
| 4022 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 4023 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 4024 | DCHECK(last_input->IsClinitCheck() || last_input->IsLoadClass()) << last_input->DebugName(); |
| 4025 | } |
| 4026 | } |
| 4027 | return input_records; |
| 4028 | } |
| 4029 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4030 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4031 | // We access the method via the dex cache so we can't do an implicit null check. |
| 4032 | // TODO: for intrinsics we can generate implicit null checks. |
| 4033 | return false; |
| 4034 | } |
| 4035 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4036 | bool CanBeNull() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4037 | return GetPackedField<ReturnTypeField>() == Primitive::kPrimNot && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4038 | } |
| 4039 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4040 | // Get the index of the special input, if any. |
| 4041 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4042 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 4043 | // method pointer; otherwise there may be one platform-specific special input, |
| 4044 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4045 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
Nicolas Geoffray | 9779307 | 2016-02-16 15:33:54 +0000 | [diff] [blame] | 4046 | bool HasSpecialInput() const { return GetNumberOfArguments() != InputCount(); } |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4047 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4048 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 4049 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 4050 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4051 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4052 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4053 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4054 | bool HasPcRelativeDexCache() const { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4055 | return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; |
| 4056 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4057 | bool HasCurrentMethodInput() const { |
| 4058 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 4059 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4060 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4061 | return true; |
| 4062 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4063 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4064 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4065 | return false; |
| 4066 | } |
| 4067 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4068 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4069 | |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4070 | QuickEntrypointEnum GetStringInitEntryPoint() const { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4071 | DCHECK(IsStringInit()); |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4072 | return static_cast<QuickEntrypointEnum>(dispatch_info_.method_load_data); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4073 | } |
| 4074 | |
| 4075 | uint64_t GetMethodAddress() const { |
| 4076 | DCHECK(HasMethodAddress()); |
| 4077 | return dispatch_info_.method_load_data; |
| 4078 | } |
| 4079 | |
| 4080 | uint32_t GetDexCacheArrayOffset() const { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4081 | DCHECK(HasPcRelativeDexCache()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4082 | return dispatch_info_.method_load_data; |
| 4083 | } |
| 4084 | |
| 4085 | uint64_t GetDirectCodePtr() const { |
| 4086 | DCHECK(HasDirectCodePtr()); |
| 4087 | return dispatch_info_.direct_code_ptr; |
| 4088 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4089 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4090 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 4091 | return GetPackedField<ClinitCheckRequirementField>(); |
| 4092 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 4093 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4094 | // Is this instruction a call to a static method? |
| 4095 | bool IsStatic() const { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4096 | return GetInvokeType() == kStatic; |
| 4097 | } |
| 4098 | |
| 4099 | MethodReference GetTargetMethod() const { |
| 4100 | return target_method_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4101 | } |
| 4102 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4103 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 4104 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 4105 | // instruction; only relevant for static calls with explicit clinit check. |
| 4106 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4107 | DCHECK(IsStaticWithExplicitClinitCheck()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4108 | size_t last_input_index = inputs_.size() - 1u; |
| 4109 | HInstruction* last_input = inputs_.back().GetInstruction(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4110 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4111 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4112 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4113 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4114 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4115 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4116 | } |
| 4117 | |
| 4118 | // 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] | 4119 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4120 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4121 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4122 | } |
| 4123 | |
| 4124 | // Is this a call to a static method whose declaring class has an |
| 4125 | // implicit intialization check requirement? |
| 4126 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4127 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4128 | } |
| 4129 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4130 | // Does this method load kind need the current method as an input? |
| 4131 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
| 4132 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kDexCacheViaMethod; |
| 4133 | } |
| 4134 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4135 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4136 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4137 | protected: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4138 | void InsertInputAt(size_t index, HInstruction* input); |
| 4139 | void RemoveInputAt(size_t index); |
| 4140 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4141 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4142 | static constexpr size_t kFieldClinitCheckRequirement = kNumberOfInvokePackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4143 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 4144 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 4145 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 4146 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 4147 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 4148 | "Too many packed fields."); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4149 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 4150 | kFieldClinitCheckRequirement, |
| 4151 | kFieldClinitCheckRequirementSize>; |
| 4152 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4153 | // Cached values of the resolved method, to avoid needing the mutator lock. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4154 | MethodReference target_method_; |
| 4155 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4156 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4157 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4158 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 4159 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4160 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4161 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4162 | class HInvokeVirtual FINAL : public HInvoke { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4163 | public: |
| 4164 | HInvokeVirtual(ArenaAllocator* arena, |
| 4165 | uint32_t number_of_arguments, |
| 4166 | Primitive::Type return_type, |
| 4167 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4168 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4169 | ArtMethod* resolved_method, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4170 | uint32_t vtable_index) |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4171 | : HInvoke(arena, |
| 4172 | number_of_arguments, |
| 4173 | 0u, |
| 4174 | return_type, |
| 4175 | dex_pc, |
| 4176 | dex_method_index, |
| 4177 | resolved_method, |
| 4178 | kVirtual), |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4179 | vtable_index_(vtable_index) {} |
| 4180 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4181 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4182 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4183 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4184 | } |
| 4185 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4186 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 4187 | |
| 4188 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 4189 | |
| 4190 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4191 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4192 | const uint32_t vtable_index_; |
| 4193 | |
| 4194 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 4195 | }; |
| 4196 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4197 | class HInvokeInterface FINAL : public HInvoke { |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4198 | public: |
| 4199 | HInvokeInterface(ArenaAllocator* arena, |
| 4200 | uint32_t number_of_arguments, |
| 4201 | Primitive::Type return_type, |
| 4202 | uint32_t dex_pc, |
| 4203 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4204 | ArtMethod* resolved_method, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4205 | uint32_t imt_index) |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4206 | : HInvoke(arena, |
| 4207 | number_of_arguments, |
| 4208 | 0u, |
| 4209 | return_type, |
| 4210 | dex_pc, |
| 4211 | dex_method_index, |
| 4212 | resolved_method, |
| 4213 | kInterface), |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4214 | imt_index_(imt_index) {} |
| 4215 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4216 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4217 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4218 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4219 | } |
| 4220 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4221 | uint32_t GetImtIndex() const { return imt_index_; } |
| 4222 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 4223 | |
| 4224 | DECLARE_INSTRUCTION(InvokeInterface); |
| 4225 | |
| 4226 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4227 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4228 | const uint32_t imt_index_; |
| 4229 | |
| 4230 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 4231 | }; |
| 4232 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4233 | class HNeg FINAL : public HUnaryOperation { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4234 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4235 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 937e6cd | 2016-03-22 11:54:37 +0000 | [diff] [blame] | 4236 | : HUnaryOperation(result_type, input, dex_pc) { |
| 4237 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(input->GetType())); |
| 4238 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4239 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4240 | template <typename T> static T Compute(T x) { return -x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4241 | |
| 4242 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4243 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4244 | } |
| 4245 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4246 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4247 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4248 | HConstant* Evaluate(HFloatConstant* x) const OVERRIDE { |
| 4249 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 4250 | } |
| 4251 | HConstant* Evaluate(HDoubleConstant* x) const OVERRIDE { |
| 4252 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 4253 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 4254 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4255 | DECLARE_INSTRUCTION(Neg); |
| 4256 | |
| 4257 | private: |
| 4258 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 4259 | }; |
| 4260 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4261 | class HNewArray FINAL : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4262 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4263 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4264 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4265 | uint32_t dex_pc, |
| 4266 | uint16_t type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4267 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4268 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4269 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4270 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4271 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4272 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4273 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4274 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4275 | } |
| 4276 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4277 | uint16_t GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4278 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4279 | |
| 4280 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4281 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4282 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4283 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 4284 | bool CanThrow() const OVERRIDE { return true; } |
| 4285 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4286 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4287 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4288 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 4289 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4290 | DECLARE_INSTRUCTION(NewArray); |
| 4291 | |
| 4292 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4293 | const uint16_t type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4294 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4295 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4296 | |
| 4297 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 4298 | }; |
| 4299 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4300 | class HAdd FINAL : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4301 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4302 | HAdd(Primitive::Type result_type, |
| 4303 | HInstruction* left, |
| 4304 | HInstruction* right, |
| 4305 | uint32_t dex_pc = kNoDexPc) |
| 4306 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4307 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4308 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4309 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4310 | 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] | 4311 | |
| 4312 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4313 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4314 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4315 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4316 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4317 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4318 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4319 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4320 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4321 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4322 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4323 | } |
| 4324 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4325 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4326 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4327 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4328 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4329 | DECLARE_INSTRUCTION(Add); |
| 4330 | |
| 4331 | private: |
| 4332 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 4333 | }; |
| 4334 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4335 | class HSub FINAL : public HBinaryOperation { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4336 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4337 | HSub(Primitive::Type result_type, |
| 4338 | HInstruction* left, |
| 4339 | HInstruction* right, |
| 4340 | uint32_t dex_pc = kNoDexPc) |
| 4341 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4342 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4343 | 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] | 4344 | |
| 4345 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4346 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4347 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4348 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4349 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4350 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4351 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4352 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4353 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4354 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4355 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4356 | } |
| 4357 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4358 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4359 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4360 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4361 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4362 | DECLARE_INSTRUCTION(Sub); |
| 4363 | |
| 4364 | private: |
| 4365 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 4366 | }; |
| 4367 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4368 | class HMul FINAL : public HBinaryOperation { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4369 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4370 | HMul(Primitive::Type result_type, |
| 4371 | HInstruction* left, |
| 4372 | HInstruction* right, |
| 4373 | uint32_t dex_pc = kNoDexPc) |
| 4374 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4375 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4376 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4377 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4378 | 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] | 4379 | |
| 4380 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4381 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4382 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4383 | } |
| 4384 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4385 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4386 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4387 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4388 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4389 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4390 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4391 | } |
| 4392 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4393 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4394 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4395 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4396 | |
| 4397 | DECLARE_INSTRUCTION(Mul); |
| 4398 | |
| 4399 | private: |
| 4400 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 4401 | }; |
| 4402 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4403 | class HDiv FINAL : public HBinaryOperation { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4404 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4405 | HDiv(Primitive::Type result_type, |
| 4406 | HInstruction* left, |
| 4407 | HInstruction* right, |
| 4408 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 4409 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4410 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4411 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4412 | T ComputeIntegral(T x, T y) const { |
| 4413 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4414 | // Our graph structure ensures we never have 0 for `y` during |
| 4415 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4416 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4417 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4418 | return (y == -1) ? -x : x / y; |
| 4419 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4420 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4421 | template <typename T> |
| 4422 | T ComputeFP(T x, T y) const { |
| 4423 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4424 | return x / y; |
| 4425 | } |
| 4426 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4427 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4428 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4429 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4430 | } |
| 4431 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4432 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4433 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4434 | } |
| 4435 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4436 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4437 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4438 | } |
| 4439 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4440 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4441 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4442 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4443 | |
| 4444 | DECLARE_INSTRUCTION(Div); |
| 4445 | |
| 4446 | private: |
| 4447 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 4448 | }; |
| 4449 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4450 | class HRem FINAL : public HBinaryOperation { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4451 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4452 | HRem(Primitive::Type result_type, |
| 4453 | HInstruction* left, |
| 4454 | HInstruction* right, |
| 4455 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 4456 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4457 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4458 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4459 | T ComputeIntegral(T x, T y) const { |
| 4460 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4461 | // Our graph structure ensures we never have 0 for `y` during |
| 4462 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4463 | DCHECK_NE(y, 0); |
| 4464 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 4465 | return (y == -1) ? 0 : x % y; |
| 4466 | } |
| 4467 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4468 | template <typename T> |
| 4469 | T ComputeFP(T x, T y) const { |
| 4470 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4471 | return std::fmod(x, y); |
| 4472 | } |
| 4473 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4474 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4475 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4476 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4477 | } |
| 4478 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4479 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4480 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4481 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4482 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4483 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4484 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4485 | } |
| 4486 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4487 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4488 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4489 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4490 | |
| 4491 | DECLARE_INSTRUCTION(Rem); |
| 4492 | |
| 4493 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4494 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 4495 | }; |
| 4496 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4497 | class HDivZeroCheck FINAL : public HExpression<1> { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4498 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4499 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
| 4500 | // constructor. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4501 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4502 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4503 | SetRawInputAt(0, value); |
| 4504 | } |
| 4505 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4506 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 4507 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4508 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4509 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4510 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4511 | return true; |
| 4512 | } |
| 4513 | |
| 4514 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4515 | bool CanThrow() const OVERRIDE { return true; } |
| 4516 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4517 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 4518 | |
| 4519 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4520 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 4521 | }; |
| 4522 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4523 | class HShl FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4524 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4525 | HShl(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4526 | HInstruction* value, |
| 4527 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4528 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4529 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4530 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4531 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4532 | } |
| 4533 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4534 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4535 | 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] | 4536 | return value << (distance & max_shift_distance); |
| 4537 | } |
| 4538 | |
| 4539 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4540 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4541 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4542 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4543 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4544 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4545 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4546 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4547 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4548 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4549 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4550 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4551 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4552 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4553 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4554 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4555 | UNREACHABLE(); |
| 4556 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4557 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4558 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4559 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4560 | UNREACHABLE(); |
| 4561 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4562 | |
| 4563 | DECLARE_INSTRUCTION(Shl); |
| 4564 | |
| 4565 | private: |
| 4566 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 4567 | }; |
| 4568 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4569 | class HShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4570 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4571 | HShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4572 | HInstruction* value, |
| 4573 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4574 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4575 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4576 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4577 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4578 | } |
| 4579 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4580 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4581 | 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] | 4582 | return value >> (distance & max_shift_distance); |
| 4583 | } |
| 4584 | |
| 4585 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4586 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4587 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4588 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4589 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4590 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4591 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4592 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4593 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4594 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4595 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4596 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4597 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4598 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4599 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4600 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4601 | UNREACHABLE(); |
| 4602 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4603 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4604 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4605 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4606 | UNREACHABLE(); |
| 4607 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4608 | |
| 4609 | DECLARE_INSTRUCTION(Shr); |
| 4610 | |
| 4611 | private: |
| 4612 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 4613 | }; |
| 4614 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4615 | class HUShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4616 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4617 | HUShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4618 | HInstruction* value, |
| 4619 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4620 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4621 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4622 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4623 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4624 | } |
| 4625 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4626 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4627 | 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] | 4628 | typedef typename std::make_unsigned<T>::type V; |
| 4629 | V ux = static_cast<V>(value); |
| 4630 | return static_cast<T>(ux >> (distance & max_shift_distance)); |
| 4631 | } |
| 4632 | |
| 4633 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4634 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4635 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4636 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4637 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4638 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4639 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4640 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4641 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4642 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4643 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4644 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4645 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4646 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4647 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4648 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4649 | UNREACHABLE(); |
| 4650 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4651 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4652 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4653 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4654 | UNREACHABLE(); |
| 4655 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4656 | |
| 4657 | DECLARE_INSTRUCTION(UShr); |
| 4658 | |
| 4659 | private: |
| 4660 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 4661 | }; |
| 4662 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4663 | class HAnd FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4664 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4665 | HAnd(Primitive::Type result_type, |
| 4666 | HInstruction* left, |
| 4667 | HInstruction* right, |
| 4668 | uint32_t dex_pc = kNoDexPc) |
| 4669 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4670 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4671 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4672 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4673 | 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] | 4674 | |
| 4675 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4676 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4677 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4678 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4679 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4680 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4681 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4682 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4683 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4684 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4685 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4686 | UNREACHABLE(); |
| 4687 | } |
| 4688 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4689 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4690 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4691 | UNREACHABLE(); |
| 4692 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4693 | |
| 4694 | DECLARE_INSTRUCTION(And); |
| 4695 | |
| 4696 | private: |
| 4697 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4698 | }; |
| 4699 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4700 | class HOr FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4701 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4702 | HOr(Primitive::Type result_type, |
| 4703 | HInstruction* left, |
| 4704 | HInstruction* right, |
| 4705 | uint32_t dex_pc = kNoDexPc) |
| 4706 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4707 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4708 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4709 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4710 | 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] | 4711 | |
| 4712 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4713 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4714 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4715 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4716 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4717 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4718 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4719 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4720 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4721 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4722 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4723 | UNREACHABLE(); |
| 4724 | } |
| 4725 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4726 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4727 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4728 | UNREACHABLE(); |
| 4729 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4730 | |
| 4731 | DECLARE_INSTRUCTION(Or); |
| 4732 | |
| 4733 | private: |
| 4734 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4735 | }; |
| 4736 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4737 | class HXor FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4738 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4739 | HXor(Primitive::Type result_type, |
| 4740 | HInstruction* left, |
| 4741 | HInstruction* right, |
| 4742 | uint32_t dex_pc = kNoDexPc) |
| 4743 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4744 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4745 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4746 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4747 | 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] | 4748 | |
| 4749 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4750 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4751 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4752 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4753 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4754 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4755 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4756 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4757 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4758 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4759 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4760 | UNREACHABLE(); |
| 4761 | } |
| 4762 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4763 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4764 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4765 | UNREACHABLE(); |
| 4766 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4767 | |
| 4768 | DECLARE_INSTRUCTION(Xor); |
| 4769 | |
| 4770 | private: |
| 4771 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 4772 | }; |
| 4773 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4774 | class HRor FINAL : public HBinaryOperation { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4775 | public: |
| 4776 | HRor(Primitive::Type result_type, HInstruction* value, HInstruction* distance) |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4777 | : HBinaryOperation(result_type, value, distance) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4778 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4779 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4780 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4781 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4782 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4783 | 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] | 4784 | typedef typename std::make_unsigned<T>::type V; |
| 4785 | V ux = static_cast<V>(value); |
| 4786 | if ((distance & max_shift_value) == 0) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4787 | return static_cast<T>(ux); |
| 4788 | } else { |
| 4789 | const V reg_bits = sizeof(T) * 8; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4790 | return static_cast<T>(ux >> (distance & max_shift_value)) | |
| 4791 | (value << (reg_bits - (distance & max_shift_value))); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4792 | } |
| 4793 | } |
| 4794 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4795 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4796 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4797 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4798 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4799 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4800 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4801 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4802 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4803 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4804 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4805 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4806 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4807 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4808 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4809 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4810 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4811 | UNREACHABLE(); |
| 4812 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4813 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4814 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4815 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4816 | UNREACHABLE(); |
| 4817 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4818 | |
| 4819 | DECLARE_INSTRUCTION(Ror); |
| 4820 | |
| 4821 | private: |
| 4822 | DISALLOW_COPY_AND_ASSIGN(HRor); |
| 4823 | }; |
| 4824 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4825 | // The value of a parameter in this method. Its location depends on |
| 4826 | // the calling convention. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4827 | class HParameterValue FINAL : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4828 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4829 | HParameterValue(const DexFile& dex_file, |
| 4830 | uint16_t type_index, |
| 4831 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4832 | Primitive::Type parameter_type, |
| 4833 | bool is_this = false) |
| 4834 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4835 | dex_file_(dex_file), |
| 4836 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4837 | index_(index) { |
| 4838 | SetPackedFlag<kFlagIsThis>(is_this); |
| 4839 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 4840 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4841 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4842 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4843 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4844 | uint8_t GetIndex() const { return index_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4845 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4846 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4847 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 4848 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4849 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4850 | DECLARE_INSTRUCTION(ParameterValue); |
| 4851 | |
| 4852 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4853 | // Whether or not the parameter value corresponds to 'this' argument. |
| 4854 | static constexpr size_t kFlagIsThis = kNumberOfExpressionPackedBits; |
| 4855 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 4856 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 4857 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 4858 | "Too many packed fields."); |
| 4859 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4860 | const DexFile& dex_file_; |
| 4861 | const uint16_t type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4862 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4863 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4864 | const uint8_t index_; |
| 4865 | |
| 4866 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 4867 | }; |
| 4868 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4869 | class HNot FINAL : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4870 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4871 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4872 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4873 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4874 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4875 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4876 | return true; |
| 4877 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4878 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4879 | template <typename T> static T Compute(T x) { return ~x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4880 | |
| 4881 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4882 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4883 | } |
| 4884 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4885 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4886 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4887 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4888 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4889 | UNREACHABLE(); |
| 4890 | } |
| 4891 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4892 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4893 | UNREACHABLE(); |
| 4894 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4895 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4896 | DECLARE_INSTRUCTION(Not); |
| 4897 | |
| 4898 | private: |
| 4899 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 4900 | }; |
| 4901 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4902 | class HBooleanNot FINAL : public HUnaryOperation { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4903 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4904 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4905 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4906 | |
| 4907 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4908 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4909 | return true; |
| 4910 | } |
| 4911 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4912 | template <typename T> static bool Compute(T x) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4913 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4914 | return !x; |
| 4915 | } |
| 4916 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4917 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4918 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4919 | } |
| 4920 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4921 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4922 | UNREACHABLE(); |
| 4923 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4924 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4925 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4926 | UNREACHABLE(); |
| 4927 | } |
| 4928 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4929 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4930 | UNREACHABLE(); |
| 4931 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4932 | |
| 4933 | DECLARE_INSTRUCTION(BooleanNot); |
| 4934 | |
| 4935 | private: |
| 4936 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 4937 | }; |
| 4938 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4939 | class HTypeConversion FINAL : public HExpression<1> { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4940 | public: |
| 4941 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4942 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 4943 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4944 | SetRawInputAt(0, input); |
Roland Levillain | f355c3f | 2016-03-30 19:09:03 +0100 | [diff] [blame] | 4945 | // Invariant: We should never generate a conversion to a Boolean value. |
| 4946 | DCHECK_NE(Primitive::kPrimBoolean, result_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4947 | } |
| 4948 | |
| 4949 | HInstruction* GetInput() const { return InputAt(0); } |
| 4950 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 4951 | Primitive::Type GetResultType() const { return GetType(); } |
| 4952 | |
| 4953 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4954 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4955 | return true; |
| 4956 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4957 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 4958 | // Try to statically evaluate the conversion and return a HConstant |
| 4959 | // containing the result. If the input cannot be converted, return nullptr. |
| 4960 | HConstant* TryStaticEvaluation() const; |
| 4961 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4962 | DECLARE_INSTRUCTION(TypeConversion); |
| 4963 | |
| 4964 | private: |
| 4965 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 4966 | }; |
| 4967 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 4968 | static constexpr uint32_t kNoRegNumber = -1; |
| 4969 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4970 | class HNullCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4971 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4972 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
| 4973 | // constructor. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4974 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4975 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4976 | SetRawInputAt(0, value); |
| 4977 | } |
| 4978 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4979 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4980 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4981 | return true; |
| 4982 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4983 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4984 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4985 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4986 | bool CanThrow() const OVERRIDE { return true; } |
| 4987 | |
| 4988 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4989 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4990 | |
| 4991 | DECLARE_INSTRUCTION(NullCheck); |
| 4992 | |
| 4993 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4994 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 4995 | }; |
| 4996 | |
| 4997 | class FieldInfo : public ValueObject { |
| 4998 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4999 | FieldInfo(MemberOffset field_offset, |
| 5000 | Primitive::Type field_type, |
| 5001 | bool is_volatile, |
| 5002 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5003 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5004 | const DexFile& dex_file, |
| 5005 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5006 | : field_offset_(field_offset), |
| 5007 | field_type_(field_type), |
| 5008 | is_volatile_(is_volatile), |
| 5009 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5010 | declaring_class_def_index_(declaring_class_def_index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5011 | dex_file_(dex_file), |
| 5012 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5013 | |
| 5014 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5015 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5016 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5017 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5018 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5019 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5020 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5021 | |
| 5022 | private: |
| 5023 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5024 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5025 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5026 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5027 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5028 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5029 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5030 | }; |
| 5031 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5032 | class HInstanceFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5033 | public: |
| 5034 | HInstanceFieldGet(HInstruction* value, |
| 5035 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5036 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5037 | bool is_volatile, |
| 5038 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5039 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5040 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5041 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5042 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5043 | : HExpression(field_type, SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5044 | field_info_(field_offset, |
| 5045 | field_type, |
| 5046 | is_volatile, |
| 5047 | field_idx, |
| 5048 | declaring_class_def_index, |
| 5049 | dex_file, |
| 5050 | dex_cache) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5051 | SetRawInputAt(0, value); |
| 5052 | } |
| 5053 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5054 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5055 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5056 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 5057 | const HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5058 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5059 | } |
| 5060 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5061 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5062 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5063 | } |
| 5064 | |
| 5065 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 5066 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5067 | } |
| 5068 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5069 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5070 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5071 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5072 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5073 | |
| 5074 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 5075 | |
| 5076 | private: |
| 5077 | const FieldInfo field_info_; |
| 5078 | |
| 5079 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 5080 | }; |
| 5081 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5082 | class HInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5083 | public: |
| 5084 | HInstanceFieldSet(HInstruction* object, |
| 5085 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5086 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5087 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5088 | bool is_volatile, |
| 5089 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5090 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5091 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5092 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5093 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5094 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5095 | field_info_(field_offset, |
| 5096 | field_type, |
| 5097 | is_volatile, |
| 5098 | field_idx, |
| 5099 | declaring_class_def_index, |
| 5100 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5101 | dex_cache) { |
| 5102 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5103 | SetRawInputAt(0, object); |
| 5104 | SetRawInputAt(1, value); |
| 5105 | } |
| 5106 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5107 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5108 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5109 | } |
| 5110 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5111 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5112 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5113 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5114 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5115 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5116 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5117 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5118 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5119 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 5120 | |
| 5121 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5122 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5123 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5124 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5125 | "Too many packed fields."); |
| 5126 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5127 | const FieldInfo field_info_; |
| 5128 | |
| 5129 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 5130 | }; |
| 5131 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5132 | class HArrayGet FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5133 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5134 | HArrayGet(HInstruction* array, |
| 5135 | HInstruction* index, |
| 5136 | Primitive::Type type, |
| 5137 | uint32_t dex_pc, |
| 5138 | bool is_string_char_at = false) |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5139 | : HExpression(type, SideEffects::ArrayReadOfType(type), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5140 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5141 | SetRawInputAt(0, array); |
| 5142 | SetRawInputAt(1, index); |
| 5143 | } |
| 5144 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5145 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5146 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5147 | return true; |
| 5148 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5149 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5150 | // TODO: We can be smarter here. |
| 5151 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 5152 | // which generates the implicit null check. There are cases when these can be removed |
| 5153 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 5154 | // implicit check here (as long as the address falls in the first page). |
| 5155 | return false; |
| 5156 | } |
| 5157 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5158 | bool IsEquivalentOf(HArrayGet* other) const { |
| 5159 | bool result = (GetDexPc() == other->GetDexPc()); |
| 5160 | if (kIsDebugBuild && result) { |
| 5161 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 5162 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 5163 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
| 5164 | if (Primitive::IsIntOrLongType(GetType())) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5165 | DCHECK(Primitive::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5166 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5167 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 5168 | DCHECK(Primitive::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5169 | } |
| 5170 | } |
| 5171 | return result; |
| 5172 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5173 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5174 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
| 5175 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5176 | HInstruction* GetArray() const { return InputAt(0); } |
| 5177 | HInstruction* GetIndex() const { return InputAt(1); } |
| 5178 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5179 | DECLARE_INSTRUCTION(ArrayGet); |
| 5180 | |
| 5181 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5182 | // We treat a String as an array, creating the HArrayGet from String.charAt() |
| 5183 | // intrinsic in the instruction simplifier. We can always determine whether |
| 5184 | // a particular HArrayGet is actually a String.charAt() by looking at the type |
| 5185 | // of the input but that requires holding the mutator lock, so we prefer to use |
| 5186 | // a flag, so that code generators don't need to do the locking. |
| 5187 | static constexpr size_t kFlagIsStringCharAt = kNumberOfExpressionPackedBits; |
| 5188 | static constexpr size_t kNumberOfArrayGetPackedBits = kFlagIsStringCharAt + 1; |
| 5189 | static_assert(kNumberOfArrayGetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5190 | "Too many packed fields."); |
| 5191 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5192 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 5193 | }; |
| 5194 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5195 | class HArraySet FINAL : public HTemplateInstruction<3> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5196 | public: |
| 5197 | HArraySet(HInstruction* array, |
| 5198 | HInstruction* index, |
| 5199 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5200 | Primitive::Type expected_component_type, |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5201 | uint32_t dex_pc) |
| 5202 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5203 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
| 5204 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == Primitive::kPrimNot); |
| 5205 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 5206 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5207 | SetRawInputAt(0, array); |
| 5208 | SetRawInputAt(1, index); |
| 5209 | SetRawInputAt(2, value); |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5210 | // Make a best guess now, may be refined during SSA building. |
| 5211 | ComputeSideEffects(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5212 | } |
| 5213 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5214 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5215 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5216 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5217 | } |
| 5218 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5219 | // Can throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5220 | bool CanThrow() const OVERRIDE { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5221 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5222 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5223 | // TODO: Same as for ArrayGet. |
| 5224 | return false; |
| 5225 | } |
| 5226 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5227 | void ClearNeedsTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5228 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5229 | } |
| 5230 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5231 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5232 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5233 | } |
| 5234 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5235 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5236 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5237 | } |
| 5238 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5239 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5240 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 5241 | bool StaticTypeOfArrayIsObjectArray() const { |
| 5242 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 5243 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5244 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5245 | HInstruction* GetArray() const { return InputAt(0); } |
| 5246 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5247 | HInstruction* GetValue() const { return InputAt(2); } |
| 5248 | |
| 5249 | Primitive::Type GetComponentType() const { |
| 5250 | // The Dex format does not type floating point index operations. Since the |
| 5251 | // `expected_component_type_` is set during building and can therefore not |
| 5252 | // be correct, we also check what is the value type. If it is a floating |
| 5253 | // point type, we must use that type. |
| 5254 | Primitive::Type value_type = GetValue()->GetType(); |
| 5255 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 5256 | ? value_type |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5257 | : GetRawExpectedComponentType(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5258 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5259 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5260 | Primitive::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5261 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5262 | } |
| 5263 | |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5264 | void ComputeSideEffects() { |
| 5265 | Primitive::Type type = GetComponentType(); |
| 5266 | SetSideEffects(SideEffects::ArrayWriteOfType(type).Union( |
| 5267 | SideEffectsForArchRuntimeCalls(type))); |
| 5268 | } |
| 5269 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5270 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 5271 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 5272 | } |
| 5273 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5274 | DECLARE_INSTRUCTION(ArraySet); |
| 5275 | |
| 5276 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5277 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 5278 | static constexpr size_t kFieldExpectedComponentTypeSize = |
| 5279 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5280 | static constexpr size_t kFlagNeedsTypeCheck = |
| 5281 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 5282 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5283 | // Cached information for the reference_type_info_ so that codegen |
| 5284 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5285 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 5286 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 5287 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 5288 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5289 | using ExpectedComponentTypeField = |
| 5290 | BitField<Primitive::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5291 | |
| 5292 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 5293 | }; |
| 5294 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5295 | class HArrayLength FINAL : public HExpression<1> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5296 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5297 | HArrayLength(HInstruction* array, uint32_t dex_pc, bool is_string_length = false) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5298 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5299 | SetPackedFlag<kFlagIsStringLength>(is_string_length); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5300 | // Note that arrays do not change length, so the instruction does not |
| 5301 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5302 | SetRawInputAt(0, array); |
| 5303 | } |
| 5304 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5305 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5306 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5307 | return true; |
| 5308 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5309 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5310 | return obj == InputAt(0); |
| 5311 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5312 | |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5313 | bool IsStringLength() const { return GetPackedFlag<kFlagIsStringLength>(); } |
| 5314 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5315 | DECLARE_INSTRUCTION(ArrayLength); |
| 5316 | |
| 5317 | private: |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5318 | // We treat a String as an array, creating the HArrayLength from String.length() |
| 5319 | // or String.isEmpty() intrinsic in the instruction simplifier. We can always |
| 5320 | // determine whether a particular HArrayLength is actually a String.length() by |
| 5321 | // looking at the type of the input but that requires holding the mutator lock, so |
| 5322 | // we prefer to use a flag, so that code generators don't need to do the locking. |
| 5323 | static constexpr size_t kFlagIsStringLength = kNumberOfExpressionPackedBits; |
| 5324 | static constexpr size_t kNumberOfArrayLengthPackedBits = kFlagIsStringLength + 1; |
| 5325 | static_assert(kNumberOfArrayLengthPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5326 | "Too many packed fields."); |
| 5327 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5328 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 5329 | }; |
| 5330 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5331 | class HBoundsCheck FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5332 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5333 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
| 5334 | // constructor. |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5335 | HBoundsCheck(HInstruction* index, |
| 5336 | HInstruction* length, |
| 5337 | uint32_t dex_pc, |
| 5338 | uint32_t string_char_at_method_index = DexFile::kDexNoIndex) |
| 5339 | : HExpression(index->GetType(), SideEffects::CanTriggerGC(), dex_pc), |
| 5340 | string_char_at_method_index_(string_char_at_method_index) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 5341 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(index->GetType())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5342 | SetRawInputAt(0, index); |
| 5343 | SetRawInputAt(1, length); |
| 5344 | } |
| 5345 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5346 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5347 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5348 | return true; |
| 5349 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5350 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5351 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5352 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5353 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5354 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5355 | bool IsStringCharAt() const { return GetStringCharAtMethodIndex() != DexFile::kDexNoIndex; } |
| 5356 | uint32_t GetStringCharAtMethodIndex() const { return string_char_at_method_index_; } |
| 5357 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5358 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5359 | |
| 5360 | DECLARE_INSTRUCTION(BoundsCheck); |
| 5361 | |
| 5362 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5363 | // We treat a String as an array, creating the HBoundsCheck from String.charAt() |
| 5364 | // intrinsic in the instruction simplifier. We want to include the String.charAt() |
| 5365 | // in the stack trace if we actually throw the StringIndexOutOfBoundsException, |
| 5366 | // so we need to create an HEnvironment which will be translated to an InlineInfo |
| 5367 | // indicating the extra stack frame. Since we add this HEnvironment quite late, |
| 5368 | // in the PrepareForRegisterAllocation pass, we need to remember the method index |
| 5369 | // from the invoke as we don't want to look again at the dex bytecode. |
| 5370 | uint32_t string_char_at_method_index_; // DexFile::kDexNoIndex if regular array. |
| 5371 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5372 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 5373 | }; |
| 5374 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5375 | class HSuspendCheck FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5376 | public: |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 5377 | explicit HSuspendCheck(uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5378 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5379 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5380 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5381 | return true; |
| 5382 | } |
| 5383 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5384 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 5385 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5386 | |
| 5387 | DECLARE_INSTRUCTION(SuspendCheck); |
| 5388 | |
| 5389 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5390 | // Only used for code generation, in order to share the same slow path between back edges |
| 5391 | // of a same loop. |
| 5392 | SlowPathCode* slow_path_; |
| 5393 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5394 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 5395 | }; |
| 5396 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 5397 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 5398 | // It ensures that we can generate line number and local variables at this point. |
| 5399 | class HNativeDebugInfo : public HTemplateInstruction<0> { |
| 5400 | public: |
| 5401 | explicit HNativeDebugInfo(uint32_t dex_pc) |
| 5402 | : HTemplateInstruction<0>(SideEffects::None(), dex_pc) {} |
| 5403 | |
| 5404 | bool NeedsEnvironment() const OVERRIDE { |
| 5405 | return true; |
| 5406 | } |
| 5407 | |
| 5408 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 5409 | |
| 5410 | private: |
| 5411 | DISALLOW_COPY_AND_ASSIGN(HNativeDebugInfo); |
| 5412 | }; |
| 5413 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5414 | /** |
| 5415 | * Instruction to load a Class object. |
| 5416 | */ |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5417 | class HLoadClass FINAL : public HInstruction { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5418 | public: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5419 | // Determines how to load the Class. |
| 5420 | enum class LoadKind { |
| 5421 | // Use the Class* from the method's own ArtMethod*. |
| 5422 | kReferrersClass, |
| 5423 | |
| 5424 | // Use boot image Class* address that will be known at link time. |
| 5425 | // Used for boot image classes referenced by boot image code in non-PIC mode. |
| 5426 | kBootImageLinkTimeAddress, |
| 5427 | |
| 5428 | // Use PC-relative boot image Class* address that will be known at link time. |
| 5429 | // Used for boot image classes referenced by boot image code in PIC mode. |
| 5430 | kBootImageLinkTimePcRelative, |
| 5431 | |
| 5432 | // Use a known boot image Class* address, embedded in the code by the codegen. |
| 5433 | // Used for boot image classes referenced by apps in AOT- and JIT-compiled code. |
| 5434 | // Note: codegen needs to emit a linker patch if indicated by compiler options' |
| 5435 | // GetIncludePatchInformation(). |
| 5436 | kBootImageAddress, |
| 5437 | |
| 5438 | // Load from the resolved types array at an absolute address. |
| 5439 | // Used for classes outside the boot image referenced by JIT-compiled code. |
| 5440 | kDexCacheAddress, |
| 5441 | |
| 5442 | // Load from resolved types array in the dex cache using a PC-relative load. |
| 5443 | // Used for classes outside boot image when we know that we can access |
| 5444 | // the dex cache arrays using a PC-relative load. |
| 5445 | kDexCachePcRelative, |
| 5446 | |
| 5447 | // Load from resolved types array accessed through the class loaded from |
| 5448 | // the compiled method's own ArtMethod*. This is the default access type when |
| 5449 | // all other types are unavailable. |
| 5450 | kDexCacheViaMethod, |
| 5451 | |
| 5452 | kLast = kDexCacheViaMethod |
| 5453 | }; |
| 5454 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5455 | HLoadClass(HCurrentMethod* current_method, |
| 5456 | uint16_t type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5457 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5458 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5459 | uint32_t dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5460 | bool needs_access_check, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5461 | bool is_in_dex_cache, |
| 5462 | bool is_in_boot_image) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5463 | : HInstruction(SideEffectsForArchRuntimeCalls(), dex_pc), |
| 5464 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5465 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5466 | dex_file_(dex_file), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5467 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5468 | // Referrers class should not need access check. We never inline unverified |
| 5469 | // methods so we can't possibly end up in this situation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5470 | DCHECK(!is_referrers_class || !needs_access_check); |
| 5471 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5472 | SetPackedField<LoadKindField>( |
| 5473 | is_referrers_class ? LoadKind::kReferrersClass : LoadKind::kDexCacheViaMethod); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5474 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
| 5475 | SetPackedFlag<kFlagIsInDexCache>(is_in_dex_cache); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5476 | SetPackedFlag<kFlagIsInBootImage>(is_in_boot_image); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5477 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5478 | } |
| 5479 | |
| 5480 | void SetLoadKindWithAddress(LoadKind load_kind, uint64_t address) { |
| 5481 | DCHECK(HasAddress(load_kind)); |
| 5482 | load_data_.address = address; |
| 5483 | SetLoadKindInternal(load_kind); |
| 5484 | } |
| 5485 | |
| 5486 | void SetLoadKindWithTypeReference(LoadKind load_kind, |
| 5487 | const DexFile& dex_file, |
| 5488 | uint32_t type_index) { |
| 5489 | DCHECK(HasTypeReference(load_kind)); |
| 5490 | DCHECK(IsSameDexFile(dex_file_, dex_file)); |
| 5491 | DCHECK_EQ(type_index_, type_index); |
| 5492 | SetLoadKindInternal(load_kind); |
| 5493 | } |
| 5494 | |
| 5495 | void SetLoadKindWithDexCacheReference(LoadKind load_kind, |
| 5496 | const DexFile& dex_file, |
| 5497 | uint32_t element_index) { |
| 5498 | DCHECK(HasDexCacheReference(load_kind)); |
| 5499 | DCHECK(IsSameDexFile(dex_file_, dex_file)); |
| 5500 | load_data_.dex_cache_element_index = element_index; |
| 5501 | SetLoadKindInternal(load_kind); |
| 5502 | } |
| 5503 | |
| 5504 | LoadKind GetLoadKind() const { |
| 5505 | return GetPackedField<LoadKindField>(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5506 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5507 | |
| 5508 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5509 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5510 | bool InstructionDataEquals(const HInstruction* other) const; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5511 | |
| 5512 | size_t ComputeHashCode() const OVERRIDE { return type_index_; } |
| 5513 | |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 5514 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5515 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5516 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5517 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5518 | } |
| 5519 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 5520 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 5521 | // The entrypoint the code generator is going to call does not do |
| 5522 | // clinit of the class. |
| 5523 | DCHECK(!NeedsAccessCheck()); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5524 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5525 | } |
| 5526 | |
| 5527 | bool CanCallRuntime() const { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5528 | return MustGenerateClinitCheck() || |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5529 | (!IsReferrersClass() && !IsInDexCache()) || |
| 5530 | NeedsAccessCheck(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5531 | } |
| 5532 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5533 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5534 | bool CanThrow() const OVERRIDE { |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 5535 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5536 | } |
| 5537 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5538 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 5539 | return loaded_class_rti_; |
| 5540 | } |
| 5541 | |
| 5542 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 5543 | // Make sure we only set exact types (the loaded class should never be merged). |
| 5544 | DCHECK(rti.IsExact()); |
| 5545 | loaded_class_rti_ = rti; |
| 5546 | } |
| 5547 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5548 | uint32_t GetTypeIndex() const { return type_index_; } |
| 5549 | const DexFile& GetDexFile() const { return dex_file_; } |
| 5550 | |
| 5551 | uint32_t GetDexCacheElementOffset() const; |
| 5552 | |
| 5553 | uint64_t GetAddress() const { |
| 5554 | DCHECK(HasAddress(GetLoadKind())); |
| 5555 | return load_data_.address; |
| 5556 | } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5557 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5558 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return !IsReferrersClass(); } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 5559 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5560 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5561 | return SideEffects::CanTriggerGC(); |
| 5562 | } |
| 5563 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5564 | bool IsReferrersClass() const { return GetLoadKind() == LoadKind::kReferrersClass; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5565 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
| 5566 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5567 | bool IsInBootImage() const { return GetPackedFlag<kFlagIsInBootImage>(); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5568 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5569 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5570 | void MarkInDexCache() { |
| 5571 | SetPackedFlag<kFlagIsInDexCache>(true); |
| 5572 | DCHECK(!NeedsEnvironment()); |
| 5573 | RemoveEnvironment(); |
| 5574 | SetSideEffects(SideEffects::None()); |
| 5575 | } |
| 5576 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5577 | void MarkInBootImage() { |
| 5578 | SetPackedFlag<kFlagIsInBootImage>(true); |
| 5579 | } |
| 5580 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5581 | void AddSpecialInput(HInstruction* special_input); |
| 5582 | |
| 5583 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 5584 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 5585 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 5586 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 5587 | } |
| 5588 | |
| 5589 | Primitive::Type GetType() const OVERRIDE { |
| 5590 | return Primitive::kPrimNot; |
| 5591 | } |
| 5592 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5593 | DECLARE_INSTRUCTION(LoadClass); |
| 5594 | |
| 5595 | private: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5596 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5597 | static constexpr size_t kFlagIsInDexCache = kFlagNeedsAccessCheck + 1; |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5598 | static constexpr size_t kFlagIsInBootImage = kFlagIsInDexCache + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5599 | // Whether this instruction must generate the initialization check. |
| 5600 | // Used for code generation. |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5601 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInBootImage + 1; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5602 | static constexpr size_t kFieldLoadKind = kFlagGenerateClInitCheck + 1; |
| 5603 | static constexpr size_t kFieldLoadKindSize = |
| 5604 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 5605 | static constexpr size_t kNumberOfLoadClassPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5606 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5607 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
| 5608 | |
| 5609 | static bool HasTypeReference(LoadKind load_kind) { |
| 5610 | return load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5611 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
| 5612 | load_kind == LoadKind::kDexCacheViaMethod || |
| 5613 | load_kind == LoadKind::kReferrersClass; |
| 5614 | } |
| 5615 | |
| 5616 | static bool HasAddress(LoadKind load_kind) { |
| 5617 | return load_kind == LoadKind::kBootImageAddress || load_kind == LoadKind::kDexCacheAddress; |
| 5618 | } |
| 5619 | |
| 5620 | static bool HasDexCacheReference(LoadKind load_kind) { |
| 5621 | return load_kind == LoadKind::kDexCachePcRelative; |
| 5622 | } |
| 5623 | |
| 5624 | void SetLoadKindInternal(LoadKind load_kind); |
| 5625 | |
| 5626 | // The special input is the HCurrentMethod for kDexCacheViaMethod or kReferrersClass. |
| 5627 | // For other load kinds it's empty or possibly some architecture-specific instruction |
| 5628 | // for PC-relative loads, i.e. kDexCachePcRelative or kBootImageLinkTimePcRelative. |
| 5629 | HUserRecord<HInstruction*> special_input_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5630 | |
| 5631 | const uint16_t type_index_; |
| 5632 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5633 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5634 | union { |
| 5635 | uint32_t dex_cache_element_index; // Only for dex cache reference. |
| 5636 | uint64_t address; // Up to 64-bit, needed for kDexCacheAddress on 64-bit targets. |
| 5637 | } load_data_; |
| 5638 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5639 | ReferenceTypeInfo loaded_class_rti_; |
| 5640 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5641 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 5642 | }; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5643 | std::ostream& operator<<(std::ostream& os, HLoadClass::LoadKind rhs); |
| 5644 | |
| 5645 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
| 5646 | inline uint32_t HLoadClass::GetDexCacheElementOffset() const { |
| 5647 | DCHECK(HasDexCacheReference(GetLoadKind())) << GetLoadKind(); |
| 5648 | return load_data_.dex_cache_element_index; |
| 5649 | } |
| 5650 | |
| 5651 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
| 5652 | inline void HLoadClass::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5653 | // The special input is used for PC-relative loads on some architectures, |
| 5654 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5655 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5656 | GetLoadKind() == LoadKind::kDexCachePcRelative || |
| 5657 | GetLoadKind() == LoadKind::kBootImageLinkTimeAddress || |
| 5658 | GetLoadKind() == LoadKind::kBootImageAddress) << GetLoadKind(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5659 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 5660 | special_input_ = HUserRecord<HInstruction*>(special_input); |
| 5661 | special_input->AddUseAt(this, 0); |
| 5662 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5663 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5664 | class HLoadString FINAL : public HInstruction { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5665 | public: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5666 | // Determines how to load the String. |
| 5667 | enum class LoadKind { |
| 5668 | // Use boot image String* address that will be known at link time. |
| 5669 | // Used for boot image strings referenced by boot image code in non-PIC mode. |
| 5670 | kBootImageLinkTimeAddress, |
| 5671 | |
| 5672 | // Use PC-relative boot image String* address that will be known at link time. |
| 5673 | // Used for boot image strings referenced by boot image code in PIC mode. |
| 5674 | kBootImageLinkTimePcRelative, |
| 5675 | |
| 5676 | // Use a known boot image String* address, embedded in the code by the codegen. |
| 5677 | // Used for boot image strings referenced by apps in AOT- and JIT-compiled code. |
| 5678 | // Note: codegen needs to emit a linker patch if indicated by compiler options' |
| 5679 | // GetIncludePatchInformation(). |
| 5680 | kBootImageAddress, |
| 5681 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5682 | // Load from an entry in the .bss section using a PC-relative load. |
| 5683 | // Used for strings outside boot image when .bss is accessible with a PC-relative load. |
| 5684 | kBssEntry, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5685 | |
| 5686 | // Load from resolved strings array accessed through the class loaded from |
| 5687 | // the compiled method's own ArtMethod*. This is the default access type when |
| 5688 | // all other types are unavailable. |
| 5689 | kDexCacheViaMethod, |
| 5690 | |
Nicolas Geoffray | ac3ebc3 | 2016-10-05 13:13:50 +0100 | [diff] [blame] | 5691 | // Load from the root table associated with the JIT compiled method. |
| 5692 | kJitTableAddress, |
| 5693 | |
| 5694 | kLast = kJitTableAddress, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5695 | }; |
| 5696 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5697 | HLoadString(HCurrentMethod* current_method, |
| 5698 | uint32_t string_index, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5699 | const DexFile& dex_file, |
| 5700 | uint32_t dex_pc) |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5701 | : HInstruction(SideEffectsForArchRuntimeCalls(), dex_pc), |
| 5702 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5703 | string_index_(string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5704 | SetPackedFlag<kFlagIsInDexCache>(false); |
| 5705 | SetPackedField<LoadKindField>(LoadKind::kDexCacheViaMethod); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5706 | load_data_.dex_file_ = &dex_file; |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5707 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5708 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5709 | void SetLoadKindWithAddress(LoadKind load_kind, uint64_t address) { |
| 5710 | DCHECK(HasAddress(load_kind)); |
| 5711 | load_data_.address = address; |
| 5712 | SetLoadKindInternal(load_kind); |
| 5713 | } |
| 5714 | |
| 5715 | void SetLoadKindWithStringReference(LoadKind load_kind, |
| 5716 | const DexFile& dex_file, |
| 5717 | uint32_t string_index) { |
| 5718 | DCHECK(HasStringReference(load_kind)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5719 | load_data_.dex_file_ = &dex_file; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5720 | string_index_ = string_index; |
| 5721 | SetLoadKindInternal(load_kind); |
| 5722 | } |
| 5723 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5724 | LoadKind GetLoadKind() const { |
| 5725 | return GetPackedField<LoadKindField>(); |
| 5726 | } |
| 5727 | |
| 5728 | const DexFile& GetDexFile() const; |
| 5729 | |
| 5730 | uint32_t GetStringIndex() const { |
| 5731 | DCHECK(HasStringReference(GetLoadKind()) || /* For slow paths. */ !IsInDexCache()); |
| 5732 | return string_index_; |
| 5733 | } |
| 5734 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5735 | uint64_t GetAddress() const { |
| 5736 | DCHECK(HasAddress(GetLoadKind())); |
| 5737 | return load_data_.address; |
| 5738 | } |
| 5739 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5740 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5741 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5742 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5743 | |
| 5744 | size_t ComputeHashCode() const OVERRIDE { return string_index_; } |
| 5745 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5746 | // Will call the runtime if we need to load the string through |
| 5747 | // the dex cache and the string is not guaranteed to be there yet. |
| 5748 | bool NeedsEnvironment() const OVERRIDE { |
| 5749 | LoadKind load_kind = GetLoadKind(); |
| 5750 | if (load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5751 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Nicolas Geoffray | ac3ebc3 | 2016-10-05 13:13:50 +0100 | [diff] [blame] | 5752 | load_kind == LoadKind::kBootImageAddress || |
| 5753 | load_kind == LoadKind::kJitTableAddress) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5754 | return false; |
| 5755 | } |
| 5756 | return !IsInDexCache(); |
| 5757 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5758 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5759 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
| 5760 | return GetLoadKind() == LoadKind::kDexCacheViaMethod; |
| 5761 | } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5762 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 5763 | bool CanBeNull() const OVERRIDE { return false; } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5764 | bool CanThrow() const OVERRIDE { return NeedsEnvironment(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5765 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5766 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5767 | return SideEffects::CanTriggerGC(); |
| 5768 | } |
| 5769 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5770 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
| 5771 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5772 | void MarkInDexCache() { |
| 5773 | SetPackedFlag<kFlagIsInDexCache>(true); |
| 5774 | DCHECK(!NeedsEnvironment()); |
| 5775 | RemoveEnvironment(); |
Vladimir Marko | ace7a00 | 2016-04-05 11:18:49 +0100 | [diff] [blame] | 5776 | SetSideEffects(SideEffects::None()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5777 | } |
| 5778 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5779 | void AddSpecialInput(HInstruction* special_input); |
| 5780 | |
| 5781 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 5782 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 5783 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 5784 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5785 | } |
| 5786 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5787 | Primitive::Type GetType() const OVERRIDE { |
| 5788 | return Primitive::kPrimNot; |
| 5789 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5790 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5791 | DECLARE_INSTRUCTION(LoadString); |
| 5792 | |
| 5793 | private: |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5794 | static constexpr size_t kFlagIsInDexCache = kNumberOfGenericPackedBits; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5795 | static constexpr size_t kFieldLoadKind = kFlagIsInDexCache + 1; |
| 5796 | static constexpr size_t kFieldLoadKindSize = |
| 5797 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 5798 | static constexpr size_t kNumberOfLoadStringPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5799 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5800 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5801 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5802 | static bool HasStringReference(LoadKind load_kind) { |
| 5803 | return load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5804 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5805 | load_kind == LoadKind::kBssEntry || |
Nicolas Geoffray | ac3ebc3 | 2016-10-05 13:13:50 +0100 | [diff] [blame] | 5806 | load_kind == LoadKind::kDexCacheViaMethod || |
| 5807 | load_kind == LoadKind::kJitTableAddress; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5808 | } |
| 5809 | |
| 5810 | static bool HasAddress(LoadKind load_kind) { |
Vladimir Marko | 54d6a20 | 2016-11-09 12:46:38 +0000 | [diff] [blame^] | 5811 | return load_kind == LoadKind::kBootImageAddress; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5812 | } |
| 5813 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5814 | void SetLoadKindInternal(LoadKind load_kind); |
| 5815 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5816 | // The special input is the HCurrentMethod for kDexCacheViaMethod. |
| 5817 | // For other load kinds it's empty or possibly some architecture-specific instruction |
| 5818 | // for PC-relative loads, i.e. kDexCachePcRelative or kBootImageLinkTimePcRelative. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5819 | HUserRecord<HInstruction*> special_input_; |
| 5820 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5821 | // String index serves also as the hash code and it's also needed for slow-paths, |
| 5822 | // so it must not be overwritten with other load data. |
| 5823 | uint32_t string_index_; |
| 5824 | |
| 5825 | union { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5826 | const DexFile* dex_file_; // For string reference. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5827 | uint64_t address; // Up to 64-bit, needed for kDexCacheAddress on 64-bit targets. |
| 5828 | } load_data_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5829 | |
| 5830 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 5831 | }; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5832 | std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs); |
| 5833 | |
| 5834 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5835 | inline const DexFile& HLoadString::GetDexFile() const { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5836 | DCHECK(HasStringReference(GetLoadKind())) << GetLoadKind(); |
| 5837 | return *load_data_.dex_file_; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5838 | } |
| 5839 | |
| 5840 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5841 | inline void HLoadString::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5842 | // The special input is used for PC-relative loads on some architectures, |
| 5843 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5844 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5845 | GetLoadKind() == LoadKind::kBssEntry || |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5846 | GetLoadKind() == LoadKind::kBootImageLinkTimeAddress || |
| 5847 | GetLoadKind() == LoadKind::kBootImageAddress) << GetLoadKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5848 | // HLoadString::GetInputRecords() returns an empty array at this point, |
| 5849 | // so use the GetInputRecords() from the base class to set the input record. |
| 5850 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 5851 | special_input_ = HUserRecord<HInstruction*>(special_input); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5852 | special_input->AddUseAt(this, 0); |
| 5853 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5854 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5855 | /** |
| 5856 | * Performs an initialization check on its Class object input. |
| 5857 | */ |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5858 | class HClinitCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5859 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 5860 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 5861 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5862 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5863 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 5864 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5865 | SetRawInputAt(0, constant); |
| 5866 | } |
| 5867 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5868 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5869 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5870 | return true; |
| 5871 | } |
| 5872 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5873 | bool NeedsEnvironment() const OVERRIDE { |
| 5874 | // May call runtime to initialize the class. |
| 5875 | return true; |
| 5876 | } |
| 5877 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 5878 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5879 | |
| 5880 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 5881 | |
| 5882 | DECLARE_INSTRUCTION(ClinitCheck); |
| 5883 | |
| 5884 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5885 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 5886 | }; |
| 5887 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5888 | class HStaticFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5889 | public: |
| 5890 | HStaticFieldGet(HInstruction* cls, |
| 5891 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5892 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5893 | bool is_volatile, |
| 5894 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5895 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5896 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5897 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5898 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5899 | : HExpression(field_type, SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5900 | field_info_(field_offset, |
| 5901 | field_type, |
| 5902 | is_volatile, |
| 5903 | field_idx, |
| 5904 | declaring_class_def_index, |
| 5905 | dex_file, |
| 5906 | dex_cache) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5907 | SetRawInputAt(0, cls); |
| 5908 | } |
| 5909 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5910 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5911 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5912 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5913 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 5914 | const HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5915 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5916 | } |
| 5917 | |
| 5918 | size_t ComputeHashCode() const OVERRIDE { |
| 5919 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5920 | } |
| 5921 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5922 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5923 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5924 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5925 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5926 | |
| 5927 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 5928 | |
| 5929 | private: |
| 5930 | const FieldInfo field_info_; |
| 5931 | |
| 5932 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 5933 | }; |
| 5934 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5935 | class HStaticFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5936 | public: |
| 5937 | HStaticFieldSet(HInstruction* cls, |
| 5938 | HInstruction* value, |
| 5939 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5940 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5941 | bool is_volatile, |
| 5942 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5943 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5944 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5945 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5946 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5947 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5948 | field_info_(field_offset, |
| 5949 | field_type, |
| 5950 | is_volatile, |
| 5951 | field_idx, |
| 5952 | declaring_class_def_index, |
| 5953 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5954 | dex_cache) { |
| 5955 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5956 | SetRawInputAt(0, cls); |
| 5957 | SetRawInputAt(1, value); |
| 5958 | } |
| 5959 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5960 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5961 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5962 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5963 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5964 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5965 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5966 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5967 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5968 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5969 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 5970 | |
| 5971 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5972 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5973 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5974 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5975 | "Too many packed fields."); |
| 5976 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5977 | const FieldInfo field_info_; |
| 5978 | |
| 5979 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 5980 | }; |
| 5981 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5982 | class HUnresolvedInstanceFieldGet FINAL : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5983 | public: |
| 5984 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 5985 | Primitive::Type field_type, |
| 5986 | uint32_t field_index, |
| 5987 | uint32_t dex_pc) |
| 5988 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5989 | field_index_(field_index) { |
| 5990 | SetRawInputAt(0, obj); |
| 5991 | } |
| 5992 | |
| 5993 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5994 | bool CanThrow() const OVERRIDE { return true; } |
| 5995 | |
| 5996 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5997 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5998 | |
| 5999 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 6000 | |
| 6001 | private: |
| 6002 | const uint32_t field_index_; |
| 6003 | |
| 6004 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 6005 | }; |
| 6006 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6007 | class HUnresolvedInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6008 | public: |
| 6009 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 6010 | HInstruction* value, |
| 6011 | Primitive::Type field_type, |
| 6012 | uint32_t field_index, |
| 6013 | uint32_t dex_pc) |
| 6014 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6015 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6016 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 6017 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6018 | SetRawInputAt(0, obj); |
| 6019 | SetRawInputAt(1, value); |
| 6020 | } |
| 6021 | |
| 6022 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6023 | bool CanThrow() const OVERRIDE { return true; } |
| 6024 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6025 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6026 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6027 | |
| 6028 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 6029 | |
| 6030 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6031 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6032 | static constexpr size_t kFieldFieldTypeSize = |
| 6033 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 6034 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6035 | kFieldFieldType + kFieldFieldTypeSize; |
| 6036 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6037 | "Too many packed fields."); |
| 6038 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 6039 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6040 | const uint32_t field_index_; |
| 6041 | |
| 6042 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 6043 | }; |
| 6044 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6045 | class HUnresolvedStaticFieldGet FINAL : public HExpression<0> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6046 | public: |
| 6047 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 6048 | uint32_t field_index, |
| 6049 | uint32_t dex_pc) |
| 6050 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 6051 | field_index_(field_index) { |
| 6052 | } |
| 6053 | |
| 6054 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6055 | bool CanThrow() const OVERRIDE { return true; } |
| 6056 | |
| 6057 | Primitive::Type GetFieldType() const { return GetType(); } |
| 6058 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6059 | |
| 6060 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 6061 | |
| 6062 | private: |
| 6063 | const uint32_t field_index_; |
| 6064 | |
| 6065 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 6066 | }; |
| 6067 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6068 | class HUnresolvedStaticFieldSet FINAL : public HTemplateInstruction<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6069 | public: |
| 6070 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 6071 | Primitive::Type field_type, |
| 6072 | uint32_t field_index, |
| 6073 | uint32_t dex_pc) |
| 6074 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6075 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6076 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 6077 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6078 | SetRawInputAt(0, value); |
| 6079 | } |
| 6080 | |
| 6081 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6082 | bool CanThrow() const OVERRIDE { return true; } |
| 6083 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6084 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6085 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6086 | |
| 6087 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 6088 | |
| 6089 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6090 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6091 | static constexpr size_t kFieldFieldTypeSize = |
| 6092 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 6093 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6094 | kFieldFieldType + kFieldFieldTypeSize; |
| 6095 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6096 | "Too many packed fields."); |
| 6097 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 6098 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6099 | const uint32_t field_index_; |
| 6100 | |
| 6101 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 6102 | }; |
| 6103 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6104 | // Implement the move-exception DEX instruction. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6105 | class HLoadException FINAL : public HExpression<0> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6106 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6107 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 6108 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6109 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 6110 | bool CanBeNull() const OVERRIDE { return false; } |
| 6111 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6112 | DECLARE_INSTRUCTION(LoadException); |
| 6113 | |
| 6114 | private: |
| 6115 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 6116 | }; |
| 6117 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6118 | // Implicit part of move-exception which clears thread-local exception storage. |
| 6119 | // 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] | 6120 | class HClearException FINAL : public HTemplateInstruction<0> { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6121 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6122 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 6123 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6124 | |
| 6125 | DECLARE_INSTRUCTION(ClearException); |
| 6126 | |
| 6127 | private: |
| 6128 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 6129 | }; |
| 6130 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6131 | class HThrow FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6132 | public: |
| 6133 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6134 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6135 | SetRawInputAt(0, exception); |
| 6136 | } |
| 6137 | |
| 6138 | bool IsControlFlow() const OVERRIDE { return true; } |
| 6139 | |
| 6140 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6141 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6142 | bool CanThrow() const OVERRIDE { return true; } |
| 6143 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6144 | |
| 6145 | DECLARE_INSTRUCTION(Throw); |
| 6146 | |
| 6147 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6148 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 6149 | }; |
| 6150 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6151 | /** |
| 6152 | * Implementation strategies for the code generator of a HInstanceOf |
| 6153 | * or `HCheckCast`. |
| 6154 | */ |
| 6155 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6156 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6157 | kExactCheck, // Can do a single class compare. |
| 6158 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 6159 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 6160 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 6161 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6162 | kArrayCheck, // No optimization yet when checking against a generic array. |
| 6163 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6164 | }; |
| 6165 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6166 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 6167 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6168 | class HInstanceOf FINAL : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6169 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6170 | HInstanceOf(HInstruction* object, |
| 6171 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6172 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6173 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6174 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6175 | SideEffectsForArchRuntimeCalls(check_kind), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6176 | dex_pc) { |
| 6177 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6178 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6179 | SetRawInputAt(0, object); |
| 6180 | SetRawInputAt(1, constant); |
| 6181 | } |
| 6182 | |
| 6183 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6184 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6185 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6186 | return true; |
| 6187 | } |
| 6188 | |
| 6189 | bool NeedsEnvironment() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6190 | return CanCallRuntime(GetTypeCheckKind()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6191 | } |
| 6192 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6193 | // Used only in code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6194 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6195 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6196 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6197 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6198 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6199 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 6200 | // Mips currently does runtime calls for any other checks. |
| 6201 | return check_kind != TypeCheckKind::kExactCheck; |
| 6202 | } |
| 6203 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6204 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6205 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6206 | } |
| 6207 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6208 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6209 | |
| 6210 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6211 | static constexpr size_t kFieldTypeCheckKind = kNumberOfExpressionPackedBits; |
| 6212 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6213 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6214 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6215 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagMustDoNullCheck + 1; |
| 6216 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6217 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6218 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6219 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 6220 | }; |
| 6221 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6222 | class HBoundType FINAL : public HExpression<1> { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6223 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 6224 | explicit HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6225 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6226 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 6227 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 6228 | SetPackedFlag<kFlagCanBeNull>(true); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 6229 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6230 | SetRawInputAt(0, input); |
| 6231 | } |
| 6232 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6233 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6234 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6235 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6236 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6237 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6238 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6239 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 6240 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6241 | } |
| 6242 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6243 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6244 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6245 | DECLARE_INSTRUCTION(BoundType); |
| 6246 | |
| 6247 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6248 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 6249 | // is false then CanBeNull() cannot be true). |
| 6250 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfExpressionPackedBits; |
| 6251 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 6252 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 6253 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6254 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6255 | // 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] | 6256 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 6257 | // It is used to bound the type in cases like: |
| 6258 | // if (x instanceof ClassX) { |
| 6259 | // // uper_bound_ will be ClassX |
| 6260 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6261 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6262 | |
| 6263 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 6264 | }; |
| 6265 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6266 | class HCheckCast FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6267 | public: |
| 6268 | HCheckCast(HInstruction* object, |
| 6269 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6270 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6271 | uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6272 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
| 6273 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6274 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6275 | SetRawInputAt(0, object); |
| 6276 | SetRawInputAt(1, constant); |
| 6277 | } |
| 6278 | |
| 6279 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6280 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6281 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6282 | return true; |
| 6283 | } |
| 6284 | |
| 6285 | bool NeedsEnvironment() const OVERRIDE { |
| 6286 | // Instruction may throw a CheckCastError. |
| 6287 | return true; |
| 6288 | } |
| 6289 | |
| 6290 | bool CanThrow() const OVERRIDE { return true; } |
| 6291 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6292 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6293 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6294 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6295 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6296 | |
| 6297 | DECLARE_INSTRUCTION(CheckCast); |
| 6298 | |
| 6299 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6300 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 6301 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6302 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6303 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6304 | static constexpr size_t kNumberOfCheckCastPackedBits = kFlagMustDoNullCheck + 1; |
| 6305 | static_assert(kNumberOfCheckCastPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6306 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6307 | |
| 6308 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6309 | }; |
| 6310 | |
Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame] | 6311 | /** |
| 6312 | * @brief Memory barrier types (see "The JSR-133 Cookbook for Compiler Writers"). |
| 6313 | * @details We define the combined barrier types that are actually required |
| 6314 | * by the Java Memory Model, rather than using exactly the terminology from |
| 6315 | * the JSR-133 cookbook. These should, in many cases, be replaced by acquire/release |
| 6316 | * primitives. Note that the JSR-133 cookbook generally does not deal with |
| 6317 | * store atomicity issues, and the recipes there are not always entirely sufficient. |
| 6318 | * The current recipe is as follows: |
| 6319 | * -# Use AnyStore ~= (LoadStore | StoreStore) ~= release barrier before volatile store. |
| 6320 | * -# Use AnyAny barrier after volatile store. (StoreLoad is as expensive.) |
| 6321 | * -# Use LoadAny barrier ~= (LoadLoad | LoadStore) ~= acquire barrier after each volatile load. |
| 6322 | * -# Use StoreStore barrier after all stores but before return from any constructor whose |
| 6323 | * class has final fields. |
| 6324 | * -# Use NTStoreStore to order non-temporal stores with respect to all later |
| 6325 | * store-to-memory instructions. Only generated together with non-temporal stores. |
| 6326 | */ |
| 6327 | enum MemBarrierKind { |
| 6328 | kAnyStore, |
| 6329 | kLoadAny, |
| 6330 | kStoreStore, |
| 6331 | kAnyAny, |
| 6332 | kNTStoreStore, |
| 6333 | kLastBarrierKind = kNTStoreStore |
| 6334 | }; |
| 6335 | std::ostream& operator<<(std::ostream& os, const MemBarrierKind& kind); |
| 6336 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6337 | class HMemoryBarrier FINAL : public HTemplateInstruction<0> { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6338 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6339 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 6340 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6341 | SideEffects::AllWritesAndReads(), dex_pc) { // Assume write/read on all fields/arrays. |
| 6342 | SetPackedField<BarrierKindField>(barrier_kind); |
| 6343 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6344 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6345 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6346 | |
| 6347 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 6348 | |
| 6349 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6350 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 6351 | static constexpr size_t kFieldBarrierKindSize = |
| 6352 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 6353 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 6354 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 6355 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 6356 | "Too many packed fields."); |
| 6357 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6358 | |
| 6359 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 6360 | }; |
| 6361 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6362 | class HMonitorOperation FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6363 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6364 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6365 | kEnter, |
| 6366 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6367 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6368 | }; |
| 6369 | |
| 6370 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6371 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6372 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 6373 | dex_pc) { |
| 6374 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6375 | SetRawInputAt(0, object); |
| 6376 | } |
| 6377 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6378 | // Instruction may go into runtime, so we need an environment. |
| 6379 | bool NeedsEnvironment() const OVERRIDE { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 6380 | |
| 6381 | bool CanThrow() const OVERRIDE { |
| 6382 | // Verifier guarantees that monitor-exit cannot throw. |
| 6383 | // This is important because it allows the HGraphBuilder to remove |
| 6384 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 6385 | return IsEnter(); |
| 6386 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6387 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6388 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 6389 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6390 | |
| 6391 | DECLARE_INSTRUCTION(MonitorOperation); |
| 6392 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6393 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6394 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 6395 | static constexpr size_t kFieldOperationKindSize = |
| 6396 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 6397 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 6398 | kFieldOperationKind + kFieldOperationKindSize; |
| 6399 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6400 | "Too many packed fields."); |
| 6401 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6402 | |
| 6403 | private: |
| 6404 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 6405 | }; |
| 6406 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6407 | class HSelect FINAL : public HExpression<3> { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6408 | public: |
| 6409 | HSelect(HInstruction* condition, |
| 6410 | HInstruction* true_value, |
| 6411 | HInstruction* false_value, |
| 6412 | uint32_t dex_pc) |
| 6413 | : HExpression(HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
| 6414 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 6415 | |
| 6416 | // First input must be `true_value` or `false_value` to allow codegens to |
| 6417 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 6418 | // that architectures which implement HSelect as a conditional move also |
| 6419 | // will not need to invert the condition. |
| 6420 | SetRawInputAt(0, false_value); |
| 6421 | SetRawInputAt(1, true_value); |
| 6422 | SetRawInputAt(2, condition); |
| 6423 | } |
| 6424 | |
| 6425 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 6426 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 6427 | HInstruction* GetCondition() const { return InputAt(2); } |
| 6428 | |
| 6429 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6430 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 6431 | return true; |
| 6432 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6433 | |
| 6434 | bool CanBeNull() const OVERRIDE { |
| 6435 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 6436 | } |
| 6437 | |
| 6438 | DECLARE_INSTRUCTION(Select); |
| 6439 | |
| 6440 | private: |
| 6441 | DISALLOW_COPY_AND_ASSIGN(HSelect); |
| 6442 | }; |
| 6443 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 6444 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6445 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6446 | MoveOperands(Location source, |
| 6447 | Location destination, |
| 6448 | Primitive::Type type, |
| 6449 | HInstruction* instruction) |
| 6450 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6451 | |
| 6452 | Location GetSource() const { return source_; } |
| 6453 | Location GetDestination() const { return destination_; } |
| 6454 | |
| 6455 | void SetSource(Location value) { source_ = value; } |
| 6456 | void SetDestination(Location value) { destination_ = value; } |
| 6457 | |
| 6458 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 6459 | // destination (but not the source). |
| 6460 | Location MarkPending() { |
| 6461 | DCHECK(!IsPending()); |
| 6462 | Location dest = destination_; |
| 6463 | destination_ = Location::NoLocation(); |
| 6464 | return dest; |
| 6465 | } |
| 6466 | |
| 6467 | void ClearPending(Location dest) { |
| 6468 | DCHECK(IsPending()); |
| 6469 | destination_ = dest; |
| 6470 | } |
| 6471 | |
| 6472 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6473 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 6474 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6475 | } |
| 6476 | |
| 6477 | // True if this blocks a move from the given location. |
| 6478 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 6479 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6480 | } |
| 6481 | |
| 6482 | // A move is redundant if it's been eliminated, if its source and |
| 6483 | // destination are the same, or if its destination is unneeded. |
| 6484 | bool IsRedundant() const { |
| 6485 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 6486 | } |
| 6487 | |
| 6488 | // We clear both operands to indicate move that's been eliminated. |
| 6489 | void Eliminate() { |
| 6490 | source_ = destination_ = Location::NoLocation(); |
| 6491 | } |
| 6492 | |
| 6493 | bool IsEliminated() const { |
| 6494 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 6495 | return source_.IsInvalid(); |
| 6496 | } |
| 6497 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6498 | Primitive::Type GetType() const { return type_; } |
| 6499 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6500 | bool Is64BitMove() const { |
| 6501 | return Primitive::Is64BitType(type_); |
| 6502 | } |
| 6503 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6504 | HInstruction* GetInstruction() const { return instruction_; } |
| 6505 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6506 | private: |
| 6507 | Location source_; |
| 6508 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6509 | // The type this move is for. |
| 6510 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6511 | // The instruction this move is assocatied with. Null when this move is |
| 6512 | // for moving an input in the expected locations of user (including a phi user). |
| 6513 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 6514 | // in the same parallel move. |
| 6515 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6516 | }; |
| 6517 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6518 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 6519 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6520 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 6521 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6522 | class HParallelMove FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6523 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6524 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6525 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 6526 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 6527 | moves_.reserve(kDefaultNumberOfMoves); |
| 6528 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6529 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6530 | void AddMove(Location source, |
| 6531 | Location destination, |
| 6532 | Primitive::Type type, |
| 6533 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6534 | DCHECK(source.IsValid()); |
| 6535 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6536 | if (kIsDebugBuild) { |
| 6537 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6538 | for (const MoveOperands& move : moves_) { |
| 6539 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6540 | // Special case the situation where the move is for the spill slot |
| 6541 | // of the instruction. |
| 6542 | if ((GetPrevious() == instruction) |
| 6543 | || ((GetPrevious() == nullptr) |
| 6544 | && instruction->IsPhi() |
| 6545 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6546 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6547 | << "Doing parallel moves for the same instruction."; |
| 6548 | } else { |
| 6549 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 6550 | } |
| 6551 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 6552 | } |
| 6553 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6554 | for (const MoveOperands& move : moves_) { |
| 6555 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6556 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6557 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6558 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6559 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6560 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6561 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6562 | } |
| 6563 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6564 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6565 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6566 | } |
| 6567 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6568 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6569 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 6570 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6571 | |
| 6572 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6573 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6574 | |
| 6575 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 6576 | }; |
| 6577 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6578 | } // namespace art |
| 6579 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 6580 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 6581 | #include "nodes_shared.h" |
| 6582 | #endif |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6583 | #ifdef ART_ENABLE_CODEGEN_arm |
| 6584 | #include "nodes_arm.h" |
| 6585 | #endif |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6586 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| 6587 | #include "nodes_arm64.h" |
| 6588 | #endif |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6589 | #ifdef ART_ENABLE_CODEGEN_mips |
| 6590 | #include "nodes_mips.h" |
| 6591 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6592 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 6593 | #include "nodes_x86.h" |
| 6594 | #endif |
| 6595 | |
| 6596 | namespace art { |
| 6597 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6598 | class HGraphVisitor : public ValueObject { |
| 6599 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 6600 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 6601 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6602 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6603 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6604 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 6605 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6606 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6607 | void VisitInsertionOrder(); |
| 6608 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6609 | // Visit the graph following dominator tree reverse post-order. |
| 6610 | void VisitReversePostOrder(); |
| 6611 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 6612 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 6613 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6614 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6615 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6616 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 6617 | |
| 6618 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6619 | |
| 6620 | #undef DECLARE_VISIT_INSTRUCTION |
| 6621 | |
| 6622 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 6623 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6624 | |
| 6625 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 6626 | }; |
| 6627 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6628 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 6629 | public: |
| 6630 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 6631 | virtual ~HGraphDelegateVisitor() {} |
| 6632 | |
| 6633 | // Visit functions that delegate to to super class. |
| 6634 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6635 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6636 | |
| 6637 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6638 | |
| 6639 | #undef DECLARE_VISIT_INSTRUCTION |
| 6640 | |
| 6641 | private: |
| 6642 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 6643 | }; |
| 6644 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6645 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6646 | // of an inner loop. The order in which the blocks are iterated is on their |
| 6647 | // block id. |
| 6648 | class HBlocksInLoopIterator : public ValueObject { |
| 6649 | public: |
| 6650 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 6651 | : blocks_in_loop_(info.GetBlocks()), |
| 6652 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 6653 | index_(0) { |
| 6654 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 6655 | Advance(); |
| 6656 | } |
| 6657 | } |
| 6658 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6659 | bool Done() const { return index_ == blocks_.size(); } |
| 6660 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6661 | void Advance() { |
| 6662 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6663 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6664 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 6665 | break; |
| 6666 | } |
| 6667 | } |
| 6668 | } |
| 6669 | |
| 6670 | private: |
| 6671 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6672 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6673 | size_t index_; |
| 6674 | |
| 6675 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 6676 | }; |
| 6677 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6678 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6679 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 6680 | // post order. |
| 6681 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 6682 | public: |
| 6683 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 6684 | : blocks_in_loop_(info.GetBlocks()), |
| 6685 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 6686 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6687 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6688 | Advance(); |
| 6689 | } |
| 6690 | } |
| 6691 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6692 | bool Done() const { return index_ == blocks_.size(); } |
| 6693 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6694 | void Advance() { |
| 6695 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6696 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 6697 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6698 | break; |
| 6699 | } |
| 6700 | } |
| 6701 | } |
| 6702 | |
| 6703 | private: |
| 6704 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6705 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6706 | size_t index_; |
| 6707 | |
| 6708 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 6709 | }; |
| 6710 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6711 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6712 | if (constant->IsIntConstant()) { |
| 6713 | return constant->AsIntConstant()->GetValue(); |
| 6714 | } else if (constant->IsLongConstant()) { |
| 6715 | return constant->AsLongConstant()->GetValue(); |
| 6716 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6717 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6718 | return 0; |
| 6719 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6720 | } |
| 6721 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6722 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 6723 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } \ |
| 6724 | inline const H##type* HInstruction::As##type() const { \ |
| 6725 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 6726 | } \ |
| 6727 | inline H##type* HInstruction::As##type() { \ |
| 6728 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 6729 | } |
| 6730 | |
| 6731 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 6732 | #undef INSTRUCTION_TYPE_CHECK |
| 6733 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 6734 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 6735 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 6736 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 6737 | size_t number_of_new_blocks, |
| 6738 | size_t after) { |
| 6739 | DCHECK_LT(after, blocks->size()); |
| 6740 | size_t old_size = blocks->size(); |
| 6741 | size_t new_size = old_size + number_of_new_blocks; |
| 6742 | blocks->resize(new_size); |
| 6743 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 6744 | } |
| 6745 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6746 | } // namespace art |
| 6747 | |
| 6748 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |