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 | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 28 | #include "base/stl_util.h" |
David Brazdil | d9c9037 | 2016-09-14 16:53:55 +0100 | [diff] [blame] | 29 | #include "base/transform_array_ref.h" |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 30 | #include "dex_file.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 31 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 32 | #include "handle.h" |
| 33 | #include "handle_scope.h" |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 34 | #include "invoke_type.h" |
Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 35 | #include "intrinsics_enum.h" |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 36 | #include "locations.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 37 | #include "method_reference.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 38 | #include "mirror/class.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 39 | #include "offsets.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 40 | #include "primitive.h" |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 41 | #include "utils/intrusive_forward_list.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 42 | |
| 43 | namespace art { |
| 44 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 45 | class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 46 | class HBasicBlock; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 47 | class HCurrentMethod; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 48 | class HDoubleConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 49 | class HEnvironment; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 50 | class HFloatConstant; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 51 | class HGraphBuilder; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 52 | class HGraphVisitor; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 53 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 54 | class HIntConstant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 55 | class HInvoke; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 56 | class HLongConstant; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 57 | class HNullConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 58 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 59 | class HSuspendCheck; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 60 | class HTryBoundary; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 61 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 62 | class LocationSummary; |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 63 | class SlowPathCode; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 64 | class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 65 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 66 | namespace mirror { |
| 67 | class DexCache; |
| 68 | } // namespace mirror |
| 69 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 70 | static const int kDefaultNumberOfBlocks = 8; |
| 71 | static const int kDefaultNumberOfSuccessors = 2; |
| 72 | static const int kDefaultNumberOfPredecessors = 2; |
David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 73 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 74 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 75 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 76 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 77 | // The maximum (meaningful) distance (31) that can be used in an integer shift/rotate operation. |
| 78 | static constexpr int32_t kMaxIntShiftDistance = 0x1f; |
| 79 | // The maximum (meaningful) distance (63) that can be used in a long shift/rotate operation. |
| 80 | static constexpr int32_t kMaxLongShiftDistance = 0x3f; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 81 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 82 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 83 | static constexpr uint16_t kUnknownClassDefIndex = static_cast<uint16_t>(-1); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 84 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 85 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 86 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 87 | static constexpr uint32_t kNoDexPc = -1; |
| 88 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 89 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 90 | // For the purposes of the compiler, the dex files must actually be the same object |
| 91 | // if we want to safely treat them as the same. This is especially important for JIT |
| 92 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 93 | // times and provide different class resolution but no two class loaders should ever |
| 94 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 95 | // all sorts of weird failures. |
| 96 | return &lhs == &rhs; |
| 97 | } |
| 98 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 99 | enum IfCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 100 | // All types. |
| 101 | kCondEQ, // == |
| 102 | kCondNE, // != |
| 103 | // Signed integers and floating-point numbers. |
| 104 | kCondLT, // < |
| 105 | kCondLE, // <= |
| 106 | kCondGT, // > |
| 107 | kCondGE, // >= |
| 108 | // Unsigned integers. |
| 109 | kCondB, // < |
| 110 | kCondBE, // <= |
| 111 | kCondA, // > |
| 112 | kCondAE, // >= |
Scott Wakeling | 2c76e06 | 2016-08-31 09:48:54 +0100 | [diff] [blame] | 113 | // First and last aliases. |
| 114 | kCondFirst = kCondEQ, |
| 115 | kCondLast = kCondAE, |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 116 | }; |
| 117 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 118 | enum GraphAnalysisResult { |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 119 | kAnalysisSkipped, |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 120 | kAnalysisInvalidBytecode, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 121 | kAnalysisFailThrowCatchLoop, |
| 122 | kAnalysisFailAmbiguousArrayOp, |
| 123 | kAnalysisSuccess, |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 124 | }; |
| 125 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 126 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 127 | public: |
| 128 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 129 | |
| 130 | void AddInstruction(HInstruction* instruction); |
| 131 | void RemoveInstruction(HInstruction* instruction); |
| 132 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 133 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 134 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 135 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 136 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 137 | // Return true if this list contains `instruction`. |
| 138 | bool Contains(HInstruction* instruction) const; |
| 139 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 140 | // Return true if `instruction1` is found before `instruction2` in |
| 141 | // this instruction list and false otherwise. Abort if none |
| 142 | // of these instructions is found. |
| 143 | bool FoundBefore(const HInstruction* instruction1, |
| 144 | const HInstruction* instruction2) const; |
| 145 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 146 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 147 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 148 | |
| 149 | // Update the block of all instructions to be `block`. |
| 150 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 151 | |
| 152 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 153 | void AddBefore(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 154 | void Add(const HInstructionList& instruction_list); |
| 155 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 156 | // Return the number of instructions in the list. This is an expensive operation. |
| 157 | size_t CountSize() const; |
| 158 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 159 | private: |
| 160 | HInstruction* first_instruction_; |
| 161 | HInstruction* last_instruction_; |
| 162 | |
| 163 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 164 | friend class HGraph; |
| 165 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 166 | friend class HInstructionIterator; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 167 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 168 | |
| 169 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 170 | }; |
| 171 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 172 | class ReferenceTypeInfo : ValueObject { |
| 173 | public: |
| 174 | typedef Handle<mirror::Class> TypeHandle; |
| 175 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 176 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact); |
| 177 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 178 | static ReferenceTypeInfo Create(TypeHandle type_handle) REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 94ab38f | 2016-06-21 17:48:19 +0100 | [diff] [blame] | 179 | return Create(type_handle, type_handle->CannotBeAssignedFromOtherTypes()); |
| 180 | } |
| 181 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 182 | static ReferenceTypeInfo CreateUnchecked(TypeHandle type_handle, bool is_exact) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 183 | return ReferenceTypeInfo(type_handle, is_exact); |
| 184 | } |
| 185 | |
| 186 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 187 | |
Vladimir Marko | f39745e | 2016-01-26 12:16:55 +0000 | [diff] [blame] | 188 | static bool IsValidHandle(TypeHandle handle) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 189 | return handle.GetReference() != nullptr; |
| 190 | } |
| 191 | |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 192 | bool IsValid() const { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 193 | return IsValidHandle(type_handle_); |
| 194 | } |
| 195 | |
| 196 | bool IsExact() const { return is_exact_; } |
| 197 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 198 | bool IsObjectClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 199 | DCHECK(IsValid()); |
| 200 | return GetTypeHandle()->IsObjectClass(); |
| 201 | } |
| 202 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 203 | bool IsStringClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 204 | DCHECK(IsValid()); |
| 205 | return GetTypeHandle()->IsStringClass(); |
| 206 | } |
| 207 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 208 | bool IsObjectArray() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 209 | DCHECK(IsValid()); |
| 210 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 211 | } |
| 212 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 213 | bool IsInterface() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 214 | DCHECK(IsValid()); |
| 215 | return GetTypeHandle()->IsInterface(); |
| 216 | } |
| 217 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 218 | bool IsArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 219 | DCHECK(IsValid()); |
| 220 | return GetTypeHandle()->IsArrayClass(); |
| 221 | } |
| 222 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 223 | bool IsPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 224 | DCHECK(IsValid()); |
| 225 | return GetTypeHandle()->IsPrimitiveArray(); |
| 226 | } |
| 227 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 228 | bool IsNonPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 229 | DCHECK(IsValid()); |
| 230 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 231 | } |
| 232 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 233 | bool CanArrayHold(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 234 | DCHECK(IsValid()); |
| 235 | if (!IsExact()) return false; |
| 236 | if (!IsArrayClass()) return false; |
| 237 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 238 | } |
| 239 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 240 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 241 | DCHECK(IsValid()); |
| 242 | if (!IsExact()) return false; |
| 243 | if (!IsArrayClass()) return false; |
| 244 | if (!rti.IsArrayClass()) return false; |
| 245 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 246 | rti.GetTypeHandle()->GetComponentType()); |
| 247 | } |
| 248 | |
| 249 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 250 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 251 | bool IsSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 252 | DCHECK(IsValid()); |
| 253 | DCHECK(rti.IsValid()); |
| 254 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 255 | } |
| 256 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 257 | bool IsStrictSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 258 | DCHECK(IsValid()); |
| 259 | DCHECK(rti.IsValid()); |
| 260 | return GetTypeHandle().Get() != rti.GetTypeHandle().Get() && |
| 261 | GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 262 | } |
| 263 | |
| 264 | // Returns true if the type information provide the same amount of details. |
| 265 | // Note that it does not mean that the instructions have the same actual type |
| 266 | // (because the type can be the result of a merge). |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 267 | bool IsEqual(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 268 | if (!IsValid() && !rti.IsValid()) { |
| 269 | // Invalid types are equal. |
| 270 | return true; |
| 271 | } |
| 272 | if (!IsValid() || !rti.IsValid()) { |
| 273 | // One is valid, the other not. |
| 274 | return false; |
| 275 | } |
| 276 | return IsExact() == rti.IsExact() |
| 277 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
| 278 | } |
| 279 | |
| 280 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 281 | ReferenceTypeInfo() : type_handle_(TypeHandle()), is_exact_(false) {} |
| 282 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact) |
| 283 | : type_handle_(type_handle), is_exact_(is_exact) { } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 284 | |
| 285 | // The class of the object. |
| 286 | TypeHandle type_handle_; |
| 287 | // Whether or not the type is exact or a superclass of the actual type. |
| 288 | // Whether or not we have any information about this type. |
| 289 | bool is_exact_; |
| 290 | }; |
| 291 | |
| 292 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 293 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 294 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 295 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 296 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 297 | HGraph(ArenaAllocator* arena, |
| 298 | const DexFile& dex_file, |
| 299 | uint32_t method_idx, |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 300 | bool should_generate_constructor_barrier, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 301 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 302 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 303 | bool debuggable = false, |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 304 | bool osr = false, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 305 | int start_instruction_id = 0) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 306 | : arena_(arena), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 307 | blocks_(arena->Adapter(kArenaAllocBlockList)), |
| 308 | reverse_post_order_(arena->Adapter(kArenaAllocReversePostOrder)), |
| 309 | linear_order_(arena->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 310 | entry_block_(nullptr), |
| 311 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 312 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 313 | number_of_vregs_(0), |
| 314 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 315 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 316 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 317 | has_try_catch_(false), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 318 | has_irreducible_loops_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 319 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 320 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 321 | dex_file_(dex_file), |
| 322 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 323 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 324 | in_ssa_form_(false), |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 325 | should_generate_constructor_barrier_(should_generate_constructor_barrier), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 326 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 327 | cached_null_constant_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 328 | cached_int_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 329 | cached_float_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 330 | cached_long_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 331 | cached_double_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 332 | cached_current_method_(nullptr), |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 333 | inexact_object_rti_(ReferenceTypeInfo::CreateInvalid()), |
| 334 | osr_(osr) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 335 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 336 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 337 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 338 | // 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] | 339 | void InitializeInexactObjectRTI(VariableSizedHandleScope* handles); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 340 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 341 | ArenaAllocator* GetArena() const { return arena_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 342 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 343 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 344 | bool IsInSsaForm() const { return in_ssa_form_; } |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 345 | void SetInSsaForm() { in_ssa_form_ = true; } |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 346 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 347 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 348 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 349 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 350 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 351 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 352 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 353 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 354 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 355 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 356 | void ComputeDominanceInformation(); |
| 357 | void ClearDominanceInformation(); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 358 | void ClearLoopInformation(); |
| 359 | void FindBackEdges(ArenaBitVector* visited); |
| 360 | GraphAnalysisResult BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 361 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 362 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 363 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 364 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 365 | // 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] | 366 | // 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] | 367 | GraphAnalysisResult AnalyzeLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 368 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 369 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 370 | // order and loop information. |
| 371 | void ComputeTryBlockInformation(); |
| 372 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 373 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 374 | // Returns the instruction to replace the invoke expression or null if the |
| 375 | // invoke is for a void method. Note that the caller is responsible for replacing |
| 376 | // and removing the invoke instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 377 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 378 | |
Nicolas Geoffray | a1d8ddf | 2016-02-29 11:46:58 +0000 | [diff] [blame] | 379 | // Update the loop and try membership of `block`, which was spawned from `reference`. |
| 380 | // In case `reference` is a back edge, `replace_if_back_edge` notifies whether `block` |
| 381 | // should be the new back edge. |
| 382 | void UpdateLoopAndTryInformationOfNewBlock(HBasicBlock* block, |
| 383 | HBasicBlock* reference, |
| 384 | bool replace_if_back_edge); |
| 385 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 386 | // Need to add a couple of blocks to test if the loop body is entered and |
| 387 | // put deoptimization instructions, etc. |
| 388 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 389 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 390 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 391 | // other blocks and has no instructions or phis. |
| 392 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 393 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 394 | // Splits the edge between `block` and `successor` while preserving the |
| 395 | // indices in the predecessor/successor lists. If there are multiple edges |
| 396 | // between the blocks, the lowest indices are used. |
| 397 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 398 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 399 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 400 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 401 | void SimplifyLoop(HBasicBlock* header); |
| 402 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 403 | int32_t GetNextInstructionId() { |
| 404 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 405 | return current_instruction_id_++; |
| 406 | } |
| 407 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 408 | int32_t GetCurrentInstructionId() const { |
| 409 | return current_instruction_id_; |
| 410 | } |
| 411 | |
| 412 | void SetCurrentInstructionId(int32_t id) { |
David Brazdil | 3f52306 | 2016-02-29 16:53:33 +0000 | [diff] [blame] | 413 | DCHECK_GE(id, current_instruction_id_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 414 | current_instruction_id_ = id; |
| 415 | } |
| 416 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 417 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 418 | return maximum_number_of_out_vregs_; |
| 419 | } |
| 420 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 421 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 422 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 423 | } |
| 424 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 425 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 426 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 427 | } |
| 428 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 429 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 430 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 431 | } |
| 432 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 433 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 434 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 435 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 436 | } |
| 437 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 438 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 439 | number_of_vregs_ = number_of_vregs; |
| 440 | } |
| 441 | |
| 442 | uint16_t GetNumberOfVRegs() const { |
| 443 | return number_of_vregs_; |
| 444 | } |
| 445 | |
| 446 | void SetNumberOfInVRegs(uint16_t value) { |
| 447 | number_of_in_vregs_ = value; |
| 448 | } |
| 449 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 450 | uint16_t GetNumberOfInVRegs() const { |
| 451 | return number_of_in_vregs_; |
| 452 | } |
| 453 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 454 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 455 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 456 | return number_of_vregs_ - number_of_in_vregs_; |
| 457 | } |
| 458 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 459 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 460 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 461 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 462 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 463 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 464 | return linear_order_; |
| 465 | } |
| 466 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 467 | bool HasBoundsChecks() const { |
| 468 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 469 | } |
| 470 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 471 | void SetHasBoundsChecks(bool value) { |
| 472 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 473 | } |
| 474 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 475 | bool ShouldGenerateConstructorBarrier() const { |
| 476 | return should_generate_constructor_barrier_; |
| 477 | } |
| 478 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 479 | bool IsDebuggable() const { return debuggable_; } |
| 480 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 481 | // 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] | 482 | // already, it is created and inserted into the graph. This method is only for |
| 483 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 484 | 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] | 485 | |
| 486 | // TODO: This is problematic for the consistency of reference type propagation |
| 487 | // because it can be created anytime after the pass and thus it will be left |
| 488 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 489 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 490 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 491 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 492 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 493 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 494 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 495 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 496 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 497 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 498 | 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] | 499 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 500 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 501 | 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] | 502 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 503 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 504 | HCurrentMethod* GetCurrentMethod(); |
| 505 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 506 | const DexFile& GetDexFile() const { |
| 507 | return dex_file_; |
| 508 | } |
| 509 | |
| 510 | uint32_t GetMethodIdx() const { |
| 511 | return method_idx_; |
| 512 | } |
| 513 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 514 | InvokeType GetInvokeType() const { |
| 515 | return invoke_type_; |
| 516 | } |
| 517 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 518 | InstructionSet GetInstructionSet() const { |
| 519 | return instruction_set_; |
| 520 | } |
| 521 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 522 | bool IsCompilingOsr() const { return osr_; } |
| 523 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 524 | bool HasTryCatch() const { return has_try_catch_; } |
| 525 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 526 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 527 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 528 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 529 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 530 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 531 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 532 | |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 533 | // Returns an instruction with the opposite boolean value from 'cond'. |
| 534 | // The instruction has been inserted into the graph, either as a constant, or |
| 535 | // before cursor. |
| 536 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 537 | |
Nicolas Geoffray | 18401b7 | 2016-03-11 13:35:51 +0000 | [diff] [blame] | 538 | ReferenceTypeInfo GetInexactObjectRti() const { return inexact_object_rti_; } |
| 539 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 540 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 541 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 542 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 543 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 544 | template <class InstructionType, typename ValueType> |
| 545 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 546 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 547 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 548 | // Try to find an existing constant of the given value. |
| 549 | InstructionType* constant = nullptr; |
| 550 | auto cached_constant = cache->find(value); |
| 551 | if (cached_constant != cache->end()) { |
| 552 | constant = cached_constant->second; |
| 553 | } |
| 554 | |
| 555 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 556 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 557 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 558 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 559 | cache->Overwrite(value, constant); |
| 560 | InsertConstant(constant); |
| 561 | } |
| 562 | return constant; |
| 563 | } |
| 564 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 565 | void InsertConstant(HConstant* instruction); |
| 566 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 567 | // Cache a float constant into the graph. This method should only be |
| 568 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 569 | void CacheFloatConstant(HFloatConstant* constant); |
| 570 | |
| 571 | // See CacheFloatConstant comment. |
| 572 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 573 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 574 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 575 | |
| 576 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 577 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 578 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 579 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 580 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 581 | |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 582 | // List of blocks to perform a linear order tree traversal. Unlike the reverse |
| 583 | // post order, this order is not incrementally kept up-to-date. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 584 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 585 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 586 | HBasicBlock* entry_block_; |
| 587 | HBasicBlock* exit_block_; |
| 588 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 589 | // 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] | 590 | uint16_t maximum_number_of_out_vregs_; |
| 591 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 592 | // The number of virtual registers in this method. Contains the parameters. |
| 593 | uint16_t number_of_vregs_; |
| 594 | |
| 595 | // The number of virtual registers used by parameters of this method. |
| 596 | uint16_t number_of_in_vregs_; |
| 597 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 598 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 599 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 600 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 601 | // Has bounds checks. We can totally skip BCE if it's false. |
| 602 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 603 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 604 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 605 | // try/catch-related passes if false. |
| 606 | bool has_try_catch_; |
| 607 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 608 | // Flag whether there are any irreducible loops in the graph. |
| 609 | bool has_irreducible_loops_; |
| 610 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 611 | // Indicates whether the graph should be compiled in a way that |
| 612 | // ensures full debuggability. If false, we can apply more |
| 613 | // aggressive optimizations that may limit the level of debugging. |
| 614 | const bool debuggable_; |
| 615 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 616 | // 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] | 617 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 618 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 619 | // The dex file from which the method is from. |
| 620 | const DexFile& dex_file_; |
| 621 | |
| 622 | // The method index in the dex file. |
| 623 | const uint32_t method_idx_; |
| 624 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 625 | // If inlined, this encodes how the callee is being invoked. |
| 626 | const InvokeType invoke_type_; |
| 627 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 628 | // Whether the graph has been transformed to SSA form. Only used |
| 629 | // in debug mode to ensure we are not using properties only valid |
| 630 | // for non-SSA form (like the number of temporaries). |
| 631 | bool in_ssa_form_; |
| 632 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 633 | const bool should_generate_constructor_barrier_; |
| 634 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 635 | const InstructionSet instruction_set_; |
| 636 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 637 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 638 | HNullConstant* cached_null_constant_; |
| 639 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 640 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 641 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 642 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 643 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 644 | HCurrentMethod* cached_current_method_; |
| 645 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 646 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 647 | // for example for methods whose declaring class could not be resolved |
| 648 | // (such as when the superclass could not be found). |
| 649 | ArtMethod* art_method_; |
| 650 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 651 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 652 | // collection pointer to passes which may create NullConstant. |
| 653 | ReferenceTypeInfo inexact_object_rti_; |
| 654 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 655 | // Whether we are compiling this graph for on stack replacement: this will |
| 656 | // make all loops seen as irreducible and emit special stack maps to mark |
| 657 | // compiled code entries which the interpreter can directly jump to. |
| 658 | const bool osr_; |
| 659 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 660 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 661 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 662 | friend class HInliner; // For the reverse post order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 663 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 664 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 665 | }; |
| 666 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 667 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 668 | public: |
| 669 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 670 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 671 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 672 | irreducible_(false), |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 673 | contains_irreducible_loop_(false), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 674 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 675 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | f6a35de | 2016-03-21 12:01:50 +0000 | [diff] [blame] | 676 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true, kArenaAllocLoopInfoBackEdges) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 677 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 678 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 679 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 680 | bool IsIrreducible() const { return irreducible_; } |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 681 | bool ContainsIrreducibleLoop() const { return contains_irreducible_loop_; } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 682 | |
| 683 | void Dump(std::ostream& os); |
| 684 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 685 | HBasicBlock* GetHeader() const { |
| 686 | return header_; |
| 687 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 688 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 689 | void SetHeader(HBasicBlock* block) { |
| 690 | header_ = block; |
| 691 | } |
| 692 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 693 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 694 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 695 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 696 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 697 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 698 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 699 | } |
| 700 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 701 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 702 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 703 | } |
| 704 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 705 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 706 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 707 | } |
| 708 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 709 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 710 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 711 | } |
| 712 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 713 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 714 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 715 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 716 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 717 | } |
| 718 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 719 | // Returns the lifetime position of the back edge that has the |
| 720 | // greatest lifetime position. |
| 721 | size_t GetLifetimeEnd() const; |
| 722 | |
| 723 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 724 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 725 | } |
| 726 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 727 | // Finds blocks that are part of this loop. |
| 728 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 729 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 730 | // Returns whether this loop information contains `block`. |
| 731 | // Note that this loop information *must* be populated before entering this function. |
| 732 | bool Contains(const HBasicBlock& block) const; |
| 733 | |
| 734 | // Returns whether this loop information is an inner loop of `other`. |
| 735 | // Note that `other` *must* be populated before entering this function. |
| 736 | bool IsIn(const HLoopInformation& other) const; |
| 737 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 738 | // Returns true if instruction is not defined within this loop. |
| 739 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 740 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 741 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 742 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 743 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 744 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 745 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 746 | void ClearAllBlocks() { |
| 747 | blocks_.ClearAllBits(); |
| 748 | } |
| 749 | |
David Brazdil | 3f4a522 | 2016-05-06 12:46:21 +0100 | [diff] [blame] | 750 | bool HasBackEdgeNotDominatedByHeader() const; |
| 751 | |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 752 | bool IsPopulated() const { |
| 753 | return blocks_.GetHighestBitSet() != -1; |
| 754 | } |
| 755 | |
Anton Shamin | f89381f | 2016-05-16 16:44:13 +0600 | [diff] [blame] | 756 | bool DominatesAllBackEdges(HBasicBlock* block); |
| 757 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 758 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 759 | // Internal recursive implementation of `Populate`. |
| 760 | void PopulateRecursive(HBasicBlock* block); |
David Brazdil | c2e8af9 | 2016-04-05 17:15:19 +0100 | [diff] [blame] | 761 | void PopulateIrreducibleRecursive(HBasicBlock* block, ArenaBitVector* finalized); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 762 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 763 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 764 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 765 | bool irreducible_; |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 766 | bool contains_irreducible_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 767 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 768 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 769 | |
| 770 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 771 | }; |
| 772 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 773 | // Stores try/catch information for basic blocks. |
| 774 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 775 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 776 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 777 | public: |
| 778 | // Try block information constructor. |
| 779 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 780 | : try_entry_(&try_entry), |
| 781 | catch_dex_file_(nullptr), |
| 782 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 783 | DCHECK(try_entry_ != nullptr); |
| 784 | } |
| 785 | |
| 786 | // Catch block information constructor. |
| 787 | TryCatchInformation(uint16_t catch_type_index, const DexFile& dex_file) |
| 788 | : try_entry_(nullptr), |
| 789 | catch_dex_file_(&dex_file), |
| 790 | catch_type_index_(catch_type_index) {} |
| 791 | |
| 792 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 793 | |
| 794 | const HTryBoundary& GetTryEntry() const { |
| 795 | DCHECK(IsTryBlock()); |
| 796 | return *try_entry_; |
| 797 | } |
| 798 | |
| 799 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 800 | |
| 801 | bool IsCatchAllTypeIndex() const { |
| 802 | DCHECK(IsCatchBlock()); |
| 803 | return catch_type_index_ == DexFile::kDexNoIndex16; |
| 804 | } |
| 805 | |
| 806 | uint16_t GetCatchTypeIndex() const { |
| 807 | DCHECK(IsCatchBlock()); |
| 808 | return catch_type_index_; |
| 809 | } |
| 810 | |
| 811 | const DexFile& GetCatchDexFile() const { |
| 812 | DCHECK(IsCatchBlock()); |
| 813 | return *catch_dex_file_; |
| 814 | } |
| 815 | |
| 816 | private: |
| 817 | // One of possibly several TryBoundary instructions entering the block's try. |
| 818 | // Only set for try blocks. |
| 819 | const HTryBoundary* try_entry_; |
| 820 | |
| 821 | // Exception type information. Only set for catch blocks. |
| 822 | const DexFile* catch_dex_file_; |
| 823 | const uint16_t catch_type_index_; |
| 824 | }; |
| 825 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 826 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 827 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 828 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 829 | // A block in a method. Contains the list of instructions represented |
| 830 | // as a double linked list. Each block knows its predecessors and |
| 831 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 832 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 833 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 834 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 835 | explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 836 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 837 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 838 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 839 | loop_information_(nullptr), |
| 840 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 841 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 842 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 843 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 844 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 845 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 846 | try_catch_information_(nullptr) { |
| 847 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 848 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 849 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 850 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 851 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 852 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 853 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 854 | } |
| 855 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 856 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 857 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 858 | } |
| 859 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 860 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 861 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 862 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 863 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 864 | return ContainsElement(successors_, block, start_from); |
| 865 | } |
| 866 | |
| 867 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 868 | return dominated_blocks_; |
| 869 | } |
| 870 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 871 | bool IsEntryBlock() const { |
| 872 | return graph_->GetEntryBlock() == this; |
| 873 | } |
| 874 | |
| 875 | bool IsExitBlock() const { |
| 876 | return graph_->GetExitBlock() == this; |
| 877 | } |
| 878 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 879 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 880 | bool IsSingleTryBoundary() const; |
| 881 | |
| 882 | // Returns true if this block emits nothing but a jump. |
| 883 | bool IsSingleJump() const { |
| 884 | HLoopInformation* loop_info = GetLoopInformation(); |
| 885 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 886 | // Back edges generate a suspend check. |
| 887 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 888 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 889 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 890 | void AddBackEdge(HBasicBlock* back_edge) { |
| 891 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 892 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 893 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 894 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 895 | loop_information_->AddBackEdge(back_edge); |
| 896 | } |
| 897 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 898 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 899 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 900 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 901 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 902 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 903 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 904 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 905 | HBasicBlock* GetDominator() const { return dominator_; } |
| 906 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 907 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 908 | |
| 909 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 910 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 911 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 912 | |
| 913 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 914 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 915 | } |
| 916 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 917 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 918 | |
| 919 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 920 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 921 | } |
| 922 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 923 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 924 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 925 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 926 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 927 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 928 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 929 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 930 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 931 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 932 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 933 | successors_.push_back(block); |
| 934 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 935 | } |
| 936 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 937 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 938 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 939 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 940 | new_block->predecessors_.push_back(this); |
| 941 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 942 | } |
| 943 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 944 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 945 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 946 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 947 | new_block->successors_.push_back(this); |
| 948 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 949 | } |
| 950 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 951 | // Insert `this` between `predecessor` and `successor. This method |
| 952 | // preserves the indicies, and will update the first edge found between |
| 953 | // `predecessor` and `successor`. |
| 954 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 955 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 956 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 957 | successor->predecessors_[predecessor_index] = this; |
| 958 | predecessor->successors_[successor_index] = this; |
| 959 | successors_.push_back(successor); |
| 960 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 961 | } |
| 962 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 963 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 964 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 965 | } |
| 966 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 967 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 968 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 969 | } |
| 970 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 971 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 972 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 976 | predecessors_.push_back(block); |
| 977 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 978 | } |
| 979 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 980 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 981 | DCHECK_EQ(predecessors_.size(), 2u); |
| 982 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 983 | } |
| 984 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 985 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 986 | DCHECK_EQ(successors_.size(), 2u); |
| 987 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 988 | } |
| 989 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 990 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 991 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 992 | } |
| 993 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 994 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 995 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 996 | } |
| 997 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 998 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 999 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1000 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1004 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1005 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | // Returns whether the first occurrence of `predecessor` in the list of |
| 1009 | // predecessors is at index `idx`. |
| 1010 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1011 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1012 | return GetPredecessorIndexOf(predecessor) == idx; |
| 1013 | } |
| 1014 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1015 | // Create a new block between this block and its predecessors. The new block |
| 1016 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 1017 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 1018 | // loop and try/catch information are not updated. |
| 1019 | HBasicBlock* CreateImmediateDominator(); |
| 1020 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1021 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 1022 | // created, latter block. Note that this method will add the block to the |
| 1023 | // graph, create a Goto at the end of the former block and will create an edge |
| 1024 | // 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] | 1025 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1026 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 1027 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1028 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1029 | // created block. Note that this method just updates raw block information, |
| 1030 | // like predecessors, successors, dominators, and instruction list. It does not |
| 1031 | // update the graph, reverse post order, loop information, nor make sure the |
| 1032 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1033 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 1034 | |
| 1035 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 1036 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1037 | |
| 1038 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1039 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1040 | // that this method does not update the graph, reverse post order, loop |
| 1041 | // information, nor make sure the blocks are consistent (for example ending |
| 1042 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1043 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1044 | |
| 1045 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1046 | // of `this` are moved to `other`. |
| 1047 | // Note that this method does not update the graph, reverse post order, loop |
| 1048 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1049 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1050 | void ReplaceWith(HBasicBlock* other); |
| 1051 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1052 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1053 | // order, links to predecessors, successors, dominators and deletes the block |
| 1054 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1055 | // predecessor of `other` and vice versa. |
| 1056 | void MergeWith(HBasicBlock* other); |
| 1057 | |
| 1058 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1059 | // removes it from all loops it is included in and eventually from the graph. |
| 1060 | // The block must not dominate any other block. Predecessors and successors |
| 1061 | // are safely updated. |
| 1062 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1063 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1064 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1065 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1066 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1067 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1068 | // Replace instruction `initial` with `replacement` within this block. |
| 1069 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1070 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1071 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1072 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1073 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1074 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1075 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1076 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1077 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1078 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1079 | |
| 1080 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1081 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1082 | } |
| 1083 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1084 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1085 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1086 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1087 | } |
| 1088 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1089 | bool IsFirstPredecessorBackEdge() const { |
| 1090 | DCHECK(IsLoopHeader()); |
| 1091 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1092 | } |
| 1093 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1094 | HLoopInformation* GetLoopInformation() const { |
| 1095 | return loop_information_; |
| 1096 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1097 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1098 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1099 | // 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] | 1100 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1101 | void SetInLoop(HLoopInformation* info) { |
| 1102 | if (IsLoopHeader()) { |
| 1103 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1104 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1105 | loop_information_ = info; |
| 1106 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1107 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1108 | // Note that a non loop header having a loop information means this loop information |
| 1109 | // has already been populated |
| 1110 | loop_information_ = info; |
| 1111 | } else { |
| 1112 | // Block is part of an inner loop. Do not update the loop information. |
| 1113 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1114 | // at this point, because this method is being called while populating `info`. |
| 1115 | } |
| 1116 | } |
| 1117 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1118 | // Raw update of the loop information. |
| 1119 | void SetLoopInformation(HLoopInformation* info) { |
| 1120 | loop_information_ = info; |
| 1121 | } |
| 1122 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1123 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1124 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1125 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1126 | |
| 1127 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1128 | try_catch_information_ = try_catch_information; |
| 1129 | } |
| 1130 | |
| 1131 | bool IsTryBlock() const { |
| 1132 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1133 | } |
| 1134 | |
| 1135 | bool IsCatchBlock() const { |
| 1136 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1137 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1138 | |
| 1139 | // Returns the try entry that this block's successors should have. They will |
| 1140 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1141 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1142 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1143 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1144 | bool HasThrowingInstructions() const; |
| 1145 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1146 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1147 | bool Dominates(HBasicBlock* block) const; |
| 1148 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1149 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1150 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1151 | |
| 1152 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1153 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1154 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1155 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1156 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1157 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1158 | bool HasSinglePhi() const; |
| 1159 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1160 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1161 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1162 | ArenaVector<HBasicBlock*> predecessors_; |
| 1163 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1164 | HInstructionList instructions_; |
| 1165 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1166 | HLoopInformation* loop_information_; |
| 1167 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1168 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1169 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1170 | // The dex program counter of the first instruction of this block. |
| 1171 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1172 | size_t lifetime_start_; |
| 1173 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1174 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1175 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1176 | friend class HGraph; |
| 1177 | friend class HInstruction; |
| 1178 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1179 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1180 | }; |
| 1181 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1182 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1183 | // from the innermost to the outermost. |
| 1184 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1185 | public: |
| 1186 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1187 | : current_(block.GetLoopInformation()) {} |
| 1188 | |
| 1189 | bool Done() const { return current_ == nullptr; } |
| 1190 | |
| 1191 | void Advance() { |
| 1192 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1193 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | HLoopInformation* Current() const { |
| 1197 | DCHECK(!Done()); |
| 1198 | return current_; |
| 1199 | } |
| 1200 | |
| 1201 | private: |
| 1202 | HLoopInformation* current_; |
| 1203 | |
| 1204 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1205 | }; |
| 1206 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1207 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1208 | M(Above, Condition) \ |
| 1209 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1210 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1211 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1212 | M(ArrayGet, Instruction) \ |
| 1213 | M(ArrayLength, Instruction) \ |
| 1214 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1215 | M(Below, Condition) \ |
| 1216 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1217 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1218 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1219 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1220 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1221 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1222 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1223 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1224 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1225 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1226 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1227 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1228 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1229 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1230 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1231 | M(Exit, Instruction) \ |
| 1232 | M(FloatConstant, Constant) \ |
| 1233 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1234 | M(GreaterThan, Condition) \ |
| 1235 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1236 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1237 | M(InstanceFieldGet, Instruction) \ |
| 1238 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1239 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1240 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1241 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1242 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1243 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1244 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1245 | M(LessThan, Condition) \ |
| 1246 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1247 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1248 | M(LoadException, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1249 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1250 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1251 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1252 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1253 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1254 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1255 | M(Neg, UnaryOperation) \ |
| 1256 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1257 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1258 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1259 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1260 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1261 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1262 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1263 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1264 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1265 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1266 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1267 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1268 | M(Return, Instruction) \ |
| 1269 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1270 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1271 | M(Shl, BinaryOperation) \ |
| 1272 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1273 | M(StaticFieldGet, Instruction) \ |
| 1274 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1275 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1276 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1277 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1278 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1279 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1280 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1281 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1282 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1283 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1284 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1285 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1286 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1287 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1288 | /* |
| 1289 | * Instructions, shared across several (not all) architectures. |
| 1290 | */ |
| 1291 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1292 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1293 | #else |
| 1294 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1295 | M(BitwiseNegatedRight, Instruction) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1296 | M(MultiplyAccumulate, Instruction) \ |
| 1297 | M(IntermediateAddress, Instruction) |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1298 | #endif |
| 1299 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1300 | #ifndef ART_ENABLE_CODEGEN_arm |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1301 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1302 | #else |
| 1303 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1304 | M(ArmDexCacheArraysBase, Instruction) |
| 1305 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1306 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1307 | #ifndef ART_ENABLE_CODEGEN_arm64 |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1308 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1309 | #else |
| 1310 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1311 | M(Arm64DataProcWithShifterOp, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1312 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1313 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1314 | #ifndef ART_ENABLE_CODEGEN_mips |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1315 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1316 | #else |
| 1317 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
| 1318 | M(MipsComputeBaseMethodAddress, Instruction) \ |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 1319 | M(MipsDexCacheArraysBase, Instruction) \ |
| 1320 | M(MipsPackedSwitch, Instruction) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1321 | #endif |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1322 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1323 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1324 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1325 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1326 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1327 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1328 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1329 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1330 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1331 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1332 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1333 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1334 | |
| 1335 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1336 | |
| 1337 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1338 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1339 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1340 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1341 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1342 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1343 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1344 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1345 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1346 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1347 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1348 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1349 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1350 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1351 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1352 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1353 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1354 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1355 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1356 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1357 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1358 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1359 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1360 | #undef FORWARD_DECLARATION |
| 1361 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1362 | #define DECLARE_INSTRUCTION(type) \ |
| 1363 | InstructionKind GetKindInternal() const OVERRIDE { return k##type; } \ |
| 1364 | const char* DebugName() const OVERRIDE { return #type; } \ |
| 1365 | bool InstructionTypeEquals(const HInstruction* other) const OVERRIDE { \ |
| 1366 | return other->Is##type(); \ |
| 1367 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1368 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1369 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1370 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
| 1371 | bool Is##type() const { return As##type() != nullptr; } \ |
| 1372 | const H##type* As##type() const { return this; } \ |
| 1373 | H##type* As##type() { return this; } |
| 1374 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1375 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1376 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1377 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1378 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1379 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1380 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1381 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1382 | // Hook for the IntrusiveForwardList<>. |
| 1383 | // TODO: Hide this better. |
| 1384 | IntrusiveForwardListHook hook; |
| 1385 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1386 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1387 | HUseListNode(T user, size_t index) |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1388 | : user_(user), index_(index) {} |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1389 | |
| 1390 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1391 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1392 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1393 | friend class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1394 | |
| 1395 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1396 | }; |
| 1397 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1398 | template <typename T> |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1399 | using HUseList = IntrusiveForwardList<HUseListNode<T>>; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1400 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1401 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1402 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1403 | // by the used instructions. |
| 1404 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1405 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1406 | public: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1407 | HUserRecord() : instruction_(nullptr), before_use_node_() {} |
| 1408 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), before_use_node_() {} |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1409 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1410 | HUserRecord(const HUserRecord<T>& old_record, typename HUseList<T>::iterator before_use_node) |
| 1411 | : HUserRecord(old_record.instruction_, before_use_node) {} |
| 1412 | HUserRecord(HInstruction* instruction, typename HUseList<T>::iterator before_use_node) |
| 1413 | : instruction_(instruction), before_use_node_(before_use_node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1414 | DCHECK(instruction_ != nullptr); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | HInstruction* GetInstruction() const { return instruction_; } |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1418 | typename HUseList<T>::iterator GetBeforeUseNode() const { return before_use_node_; } |
| 1419 | typename HUseList<T>::iterator GetUseNode() const { return ++GetBeforeUseNode(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1420 | |
| 1421 | private: |
| 1422 | // Instruction used by the user. |
| 1423 | HInstruction* instruction_; |
| 1424 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1425 | // Iterator before the corresponding entry in the use list kept by 'instruction_'. |
| 1426 | typename HUseList<T>::iterator before_use_node_; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1427 | }; |
| 1428 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1429 | // Helper class that extracts the input instruction from HUserRecord<HInstruction*>. |
| 1430 | // This is used for HInstruction::GetInputs() to return a container wrapper providing |
| 1431 | // HInstruction* values even though the underlying container has HUserRecord<>s. |
| 1432 | struct HInputExtractor { |
| 1433 | HInstruction* operator()(HUserRecord<HInstruction*>& record) const { |
| 1434 | return record.GetInstruction(); |
| 1435 | } |
| 1436 | const HInstruction* operator()(const HUserRecord<HInstruction*>& record) const { |
| 1437 | return record.GetInstruction(); |
| 1438 | } |
| 1439 | }; |
| 1440 | |
| 1441 | using HInputsRef = TransformArrayRef<HUserRecord<HInstruction*>, HInputExtractor>; |
| 1442 | using HConstInputsRef = TransformArrayRef<const HUserRecord<HInstruction*>, HInputExtractor>; |
| 1443 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1444 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1445 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1446 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1447 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1448 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1449 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1450 | * modify the value of a reference field read [although it may modify the |
| 1451 | * reference fetch prior to reading the field, which is represented by its own |
| 1452 | * write/read dependence]). The analysis makes conservative points-to |
| 1453 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1454 | * the same, and any reference read depends on any reference read without |
| 1455 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1456 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1457 | * The internal representation uses 38-bit and is described in the table below. |
| 1458 | * The first line indicates the side effect, and for field/array accesses the |
| 1459 | * second line indicates the type of the access (in the order of the |
| 1460 | * Primitive::Type enum). |
| 1461 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1462 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1463 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1464 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1465 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1466 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1467 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1468 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1469 | * |
| 1470 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1471 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1472 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1473 | class SideEffects : public ValueObject { |
| 1474 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1475 | SideEffects() : flags_(0) {} |
| 1476 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1477 | static SideEffects None() { |
| 1478 | return SideEffects(0); |
| 1479 | } |
| 1480 | |
| 1481 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1482 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1483 | } |
| 1484 | |
| 1485 | static SideEffects AllChanges() { |
| 1486 | return SideEffects(kAllChangeBits); |
| 1487 | } |
| 1488 | |
| 1489 | static SideEffects AllDependencies() { |
| 1490 | return SideEffects(kAllDependOnBits); |
| 1491 | } |
| 1492 | |
| 1493 | static SideEffects AllExceptGCDependency() { |
| 1494 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1495 | } |
| 1496 | |
| 1497 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1498 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1499 | } |
| 1500 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1501 | static SideEffects AllWrites() { |
| 1502 | return SideEffects(kAllWrites); |
| 1503 | } |
| 1504 | |
| 1505 | static SideEffects AllReads() { |
| 1506 | return SideEffects(kAllReads); |
| 1507 | } |
| 1508 | |
| 1509 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1510 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1511 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1512 | : SideEffects(TypeFlag(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1513 | } |
| 1514 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1515 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1516 | return SideEffects(TypeFlag(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1517 | } |
| 1518 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1519 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1520 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1521 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1522 | : SideEffects(TypeFlag(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1526 | return SideEffects(TypeFlag(type, kArrayReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1527 | } |
| 1528 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1529 | static SideEffects CanTriggerGC() { |
| 1530 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1531 | } |
| 1532 | |
| 1533 | static SideEffects DependsOnGC() { |
| 1534 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1535 | } |
| 1536 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1537 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1538 | SideEffects Union(SideEffects other) const { |
| 1539 | return SideEffects(flags_ | other.flags_); |
| 1540 | } |
| 1541 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1542 | SideEffects Exclusion(SideEffects other) const { |
| 1543 | return SideEffects(flags_ & ~other.flags_); |
| 1544 | } |
| 1545 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1546 | void Add(SideEffects other) { |
| 1547 | flags_ |= other.flags_; |
| 1548 | } |
| 1549 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1550 | bool Includes(SideEffects other) const { |
| 1551 | return (other.flags_ & flags_) == other.flags_; |
| 1552 | } |
| 1553 | |
| 1554 | bool HasSideEffects() const { |
| 1555 | return (flags_ & kAllChangeBits); |
| 1556 | } |
| 1557 | |
| 1558 | bool HasDependencies() const { |
| 1559 | return (flags_ & kAllDependOnBits); |
| 1560 | } |
| 1561 | |
| 1562 | // Returns true if there are no side effects or dependencies. |
| 1563 | bool DoesNothing() const { |
| 1564 | return flags_ == 0; |
| 1565 | } |
| 1566 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1567 | // Returns true if something is written. |
| 1568 | bool DoesAnyWrite() const { |
| 1569 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1570 | } |
| 1571 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1572 | // Returns true if something is read. |
| 1573 | bool DoesAnyRead() const { |
| 1574 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1575 | } |
| 1576 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1577 | // Returns true if potentially everything is written and read |
| 1578 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1579 | bool DoesAllReadWrite() const { |
| 1580 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1581 | } |
| 1582 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1583 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1584 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1585 | } |
| 1586 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1587 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1588 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1589 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1590 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1594 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1595 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1596 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1597 | for (int s = kLastBit; s >= 0; s--) { |
| 1598 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1599 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1600 | // This is a bit for the GC side effect. |
| 1601 | if (current_bit_is_set) { |
| 1602 | flags += "GC"; |
| 1603 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1604 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1605 | } else { |
| 1606 | // This is a bit for the array/field analysis. |
| 1607 | // The underscore character stands for the 'can trigger GC' bit. |
| 1608 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1609 | if (current_bit_is_set) { |
| 1610 | flags += kDebug[s]; |
| 1611 | } |
| 1612 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1613 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1614 | flags += "|"; |
| 1615 | } |
| 1616 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1617 | } |
| 1618 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1619 | } |
| 1620 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1621 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1622 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1623 | private: |
| 1624 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1625 | |
| 1626 | static constexpr int kFieldWriteOffset = 0; |
| 1627 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1628 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1629 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1630 | |
| 1631 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1632 | |
| 1633 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1634 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1635 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1636 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1637 | |
| 1638 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1639 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1640 | |
| 1641 | // Aliases. |
| 1642 | |
| 1643 | static_assert(kChangeBits == kDependOnBits, |
| 1644 | "the 'change' bits should match the 'depend on' bits."); |
| 1645 | |
| 1646 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1647 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1648 | static constexpr uint64_t kAllWrites = |
| 1649 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1650 | static constexpr uint64_t kAllReads = |
| 1651 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1652 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1653 | // Translates type to bit flag. |
| 1654 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1655 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1656 | const uint64_t one = 1; |
| 1657 | const int shift = type; // 0-based consecutive enum |
| 1658 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1659 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1660 | return one << (type + offset); |
| 1661 | } |
| 1662 | |
| 1663 | // Private constructor on direct flags value. |
| 1664 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1665 | |
| 1666 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1667 | }; |
| 1668 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1669 | // 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] | 1670 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1671 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1672 | HEnvironment(ArenaAllocator* arena, |
| 1673 | size_t number_of_vregs, |
| 1674 | const DexFile& dex_file, |
| 1675 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1676 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1677 | InvokeType invoke_type, |
| 1678 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1679 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1680 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1681 | parent_(nullptr), |
| 1682 | dex_file_(dex_file), |
| 1683 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1684 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1685 | invoke_type_(invoke_type), |
| 1686 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1687 | } |
| 1688 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1689 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1690 | : HEnvironment(arena, |
| 1691 | to_copy.Size(), |
| 1692 | to_copy.GetDexFile(), |
| 1693 | to_copy.GetMethodIdx(), |
| 1694 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1695 | to_copy.GetInvokeType(), |
| 1696 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1697 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1698 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1699 | if (parent_ != nullptr) { |
| 1700 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1701 | } else { |
| 1702 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1703 | parent_->CopyFrom(parent); |
| 1704 | if (parent->GetParent() != nullptr) { |
| 1705 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1706 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1707 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1708 | } |
| 1709 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1710 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1711 | void CopyFrom(HEnvironment* environment); |
| 1712 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1713 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1714 | // input to the loop phi instead. This is for inserting instructions that |
| 1715 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1716 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1717 | |
| 1718 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1719 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1723 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1724 | } |
| 1725 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1726 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1727 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1728 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1729 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1730 | HEnvironment* GetParent() const { return parent_; } |
| 1731 | |
| 1732 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1733 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1737 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | uint32_t GetDexPc() const { |
| 1741 | return dex_pc_; |
| 1742 | } |
| 1743 | |
| 1744 | uint32_t GetMethodIdx() const { |
| 1745 | return method_idx_; |
| 1746 | } |
| 1747 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1748 | InvokeType GetInvokeType() const { |
| 1749 | return invoke_type_; |
| 1750 | } |
| 1751 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1752 | const DexFile& GetDexFile() const { |
| 1753 | return dex_file_; |
| 1754 | } |
| 1755 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1756 | HInstruction* GetHolder() const { |
| 1757 | return holder_; |
| 1758 | } |
| 1759 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1760 | |
| 1761 | bool IsFromInlinedInvoke() const { |
| 1762 | return GetParent() != nullptr; |
| 1763 | } |
| 1764 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1765 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1766 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1767 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1768 | HEnvironment* parent_; |
| 1769 | const DexFile& dex_file_; |
| 1770 | const uint32_t method_idx_; |
| 1771 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1772 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1773 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1774 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1775 | HInstruction* const holder_; |
| 1776 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1777 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1778 | |
| 1779 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1780 | }; |
| 1781 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1782 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1783 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1784 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1785 | : previous_(nullptr), |
| 1786 | next_(nullptr), |
| 1787 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1788 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1789 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1790 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1791 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1792 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1793 | locations_(nullptr), |
| 1794 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1795 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1796 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1797 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
| 1798 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 1799 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1800 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1801 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1802 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1803 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1804 | enum InstructionKind { |
| 1805 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1806 | }; |
| 1807 | #undef DECLARE_KIND |
| 1808 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1809 | HInstruction* GetNext() const { return next_; } |
| 1810 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1811 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1812 | HInstruction* GetNextDisregardingMoves() const; |
| 1813 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1814 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1815 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1816 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1817 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1818 | bool IsInBlock() const { return block_ != nullptr; } |
| 1819 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1820 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 1821 | bool IsIrreducibleLoopHeaderPhi() const { |
| 1822 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 1823 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1824 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1825 | virtual ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() = 0; |
| 1826 | |
| 1827 | ArrayRef<const HUserRecord<HInstruction*>> GetInputRecords() const { |
| 1828 | // One virtual method is enough, just const_cast<> and then re-add the const. |
| 1829 | return ArrayRef<const HUserRecord<HInstruction*>>( |
| 1830 | const_cast<HInstruction*>(this)->GetInputRecords()); |
| 1831 | } |
| 1832 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1833 | HInputsRef GetInputs() { |
| 1834 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1835 | } |
| 1836 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1837 | HConstInputsRef GetInputs() const { |
| 1838 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | size_t InputCount() const { return GetInputRecords().size(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1842 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1843 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1844 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1845 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1846 | } |
| 1847 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1848 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1849 | virtual const char* DebugName() const = 0; |
| 1850 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1851 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
| 1852 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1853 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1854 | |
| 1855 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1856 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1857 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1858 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1859 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1860 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1861 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1862 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1863 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1864 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1865 | // Does not apply for all instructions, but having this at top level greatly |
| 1866 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1867 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1868 | virtual bool CanBeNull() const { |
| 1869 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1870 | return true; |
| 1871 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1872 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1873 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1874 | return false; |
| 1875 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1876 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 1877 | virtual bool IsActualObject() const { |
| 1878 | return GetType() == Primitive::kPrimNot; |
| 1879 | } |
| 1880 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1881 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1882 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1883 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1884 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1885 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 1886 | GetPackedFlag<kFlagReferenceTypeIsExact>()); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1887 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1888 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1889 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1890 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1891 | // Note: fixup_end remains valid across push_front(). |
| 1892 | auto fixup_end = uses_.empty() ? uses_.begin() : ++uses_.begin(); |
| 1893 | HUseListNode<HInstruction*>* new_node = |
| 1894 | new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HInstruction*>(user, index); |
| 1895 | uses_.push_front(*new_node); |
| 1896 | FixUpUserRecordsAfterUseInsertion(fixup_end); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1897 | } |
| 1898 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1899 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1900 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1901 | // Note: env_fixup_end remains valid across push_front(). |
| 1902 | auto env_fixup_end = env_uses_.empty() ? env_uses_.begin() : ++env_uses_.begin(); |
| 1903 | HUseListNode<HEnvironment*>* new_node = |
| 1904 | new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HEnvironment*>(user, index); |
| 1905 | env_uses_.push_front(*new_node); |
| 1906 | FixUpUserRecordsAfterEnvUseInsertion(env_fixup_end); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1907 | } |
| 1908 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1909 | void RemoveAsUserOfInput(size_t input) { |
| 1910 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1911 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 1912 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 1913 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1914 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1915 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1916 | void RemoveAsUserOfAllInputs() { |
| 1917 | for (const HUserRecord<HInstruction*>& input_use : GetInputRecords()) { |
| 1918 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 1919 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 1920 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
| 1921 | } |
| 1922 | } |
| 1923 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1924 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1925 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1926 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1927 | bool HasUses() const { return !uses_.empty() || !env_uses_.empty(); } |
| 1928 | bool HasEnvironmentUses() const { return !env_uses_.empty(); } |
| 1929 | bool HasNonEnvironmentUses() const { return !uses_.empty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1930 | bool HasOnlyOneNonEnvironmentUse() const { |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1931 | return !HasEnvironmentUses() && GetUses().HasExactlyOneElement(); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1932 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1933 | |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 1934 | bool IsDeadAndRemovable() const { |
| 1935 | return |
| 1936 | !HasSideEffects() && |
| 1937 | !CanThrow() && |
| 1938 | !IsSuspendCheck() && |
| 1939 | !IsControlFlow() && |
| 1940 | !IsNativeDebugInfo() && |
| 1941 | !IsParameterValue() && |
| 1942 | !HasUses() && |
| 1943 | // If we added an explicit barrier then we should keep it. |
| 1944 | !IsMemoryBarrier(); |
| 1945 | } |
| 1946 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1947 | // Does this instruction strictly dominate `other_instruction`? |
| 1948 | // Returns false if this instruction and `other_instruction` are the same. |
| 1949 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1950 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1951 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1952 | int GetId() const { return id_; } |
| 1953 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1954 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1955 | int GetSsaIndex() const { return ssa_index_; } |
| 1956 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 1957 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 1958 | |
| 1959 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 1960 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1961 | // Set the `environment_` field. Raw because this method does not |
| 1962 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1963 | void SetRawEnvironment(HEnvironment* environment) { |
| 1964 | DCHECK(environment_ == nullptr); |
| 1965 | DCHECK_EQ(environment->GetHolder(), this); |
| 1966 | environment_ = environment; |
| 1967 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1968 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 1969 | void InsertRawEnvironment(HEnvironment* environment) { |
| 1970 | DCHECK(environment_ != nullptr); |
| 1971 | DCHECK_EQ(environment->GetHolder(), this); |
| 1972 | DCHECK(environment->GetParent() == nullptr); |
| 1973 | environment->parent_ = environment_; |
| 1974 | environment_ = environment; |
| 1975 | } |
| 1976 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1977 | void RemoveEnvironment(); |
| 1978 | |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1979 | // Set the environment of this instruction, copying it from `environment`. While |
| 1980 | // copying, the uses lists are being updated. |
| 1981 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1982 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1983 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1984 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1985 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1986 | if (environment->GetParent() != nullptr) { |
| 1987 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1988 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1989 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1990 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1991 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 1992 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1993 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1994 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1995 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1996 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1997 | if (environment->GetParent() != nullptr) { |
| 1998 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1999 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2000 | } |
| 2001 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2002 | // Returns the number of entries in the environment. Typically, that is the |
| 2003 | // number of dex registers in a method. It could be more in case of inlining. |
| 2004 | size_t EnvironmentSize() const; |
| 2005 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2006 | LocationSummary* GetLocations() const { return locations_; } |
| 2007 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2008 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2009 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2010 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2011 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2012 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 2013 | // uses of this instruction by `other` are *not* updated. |
| 2014 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 2015 | ReplaceWith(other); |
| 2016 | other->ReplaceInput(this, use_index); |
| 2017 | } |
| 2018 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 2019 | // Move `this` instruction before `cursor`. |
| 2020 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2021 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2022 | // Move `this` before its first user and out of any loops. If there is no |
| 2023 | // out-of-loop user that dominates all other users, move the instruction |
| 2024 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2025 | // |
| 2026 | // This can be used only on non-throwing instructions with no side effects that |
| 2027 | // have at least one use but no environment uses. |
| 2028 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2029 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2030 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2031 | bool Is##type() const; \ |
| 2032 | const H##type* As##type() const; \ |
| 2033 | H##type* As##type(); |
| 2034 | |
| 2035 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2036 | #undef INSTRUCTION_TYPE_CHECK |
| 2037 | |
| 2038 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2039 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 2040 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2041 | virtual H##type* As##type() { return nullptr; } |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2042 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2043 | #undef INSTRUCTION_TYPE_CHECK |
| 2044 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2045 | // Returns whether the instruction can be moved within the graph. |
| 2046 | virtual bool CanBeMoved() const { return false; } |
| 2047 | |
| 2048 | // Returns whether the two instructions are of the same kind. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2049 | virtual bool InstructionTypeEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2050 | return false; |
| 2051 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2052 | |
| 2053 | // Returns whether any data encoded in the two instructions is equal. |
| 2054 | // This method does not look at the inputs. Both instructions must be |
| 2055 | // of the same type, otherwise the method has undefined behavior. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2056 | virtual bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2057 | return false; |
| 2058 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2059 | |
| 2060 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2061 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2062 | // 2) Their inputs are identical. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2063 | bool Equals(const HInstruction* other) const; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2064 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2065 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2066 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2067 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2068 | // apply the strong requirement for virtual functions, preventing optimizations. |
| 2069 | InstructionKind GetKind() const PURE; |
| 2070 | virtual InstructionKind GetKindInternal() const = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2071 | |
| 2072 | virtual size_t ComputeHashCode() const { |
| 2073 | size_t result = GetKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2074 | for (const HInstruction* input : GetInputs()) { |
| 2075 | result = (result * 31) + input->GetId(); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2076 | } |
| 2077 | return result; |
| 2078 | } |
| 2079 | |
| 2080 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2081 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2082 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2083 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2084 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2085 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2086 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2087 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2088 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2089 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2090 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2091 | |
| 2092 | // Returns whether the code generation of the instruction will require to have access |
| 2093 | // to the current method. Such instructions are: |
| 2094 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2095 | // to walk the stack and have the current method stored at a specific stack address. |
| 2096 | // (2): Object literals like classes and strings, that are loaded from the dex cache |
| 2097 | // fields of the current method. |
| 2098 | bool NeedsCurrentMethod() const { |
| 2099 | return NeedsEnvironment() || IsLoadClass() || IsLoadString(); |
| 2100 | } |
| 2101 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2102 | // Returns whether the code generation of the instruction will require to have access |
| 2103 | // to the dex cache of the current method's declaring class via the current method. |
| 2104 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2105 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2106 | // Does this instruction have any use in an environment before |
| 2107 | // control flow hits 'other'? |
| 2108 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2109 | |
| 2110 | // Remove all references to environment uses of this instruction. |
| 2111 | // The caller must ensure that this is safe to do. |
| 2112 | void RemoveEnvironmentUsers(); |
| 2113 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2114 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2115 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2116 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2117 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2118 | // If set, the machine code for this instruction is assumed to be generated by |
| 2119 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2120 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2121 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
| 2122 | static constexpr size_t kNumberOfGenericPackedBits = kFlagReferenceTypeIsExact + 1; |
| 2123 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2124 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2125 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const { |
| 2126 | return GetInputRecords()[i]; |
| 2127 | } |
| 2128 | |
| 2129 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) { |
| 2130 | ArrayRef<HUserRecord<HInstruction*>> input_records = GetInputRecords(); |
| 2131 | input_records[index] = input; |
| 2132 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2133 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2134 | uint32_t GetPackedFields() const { |
| 2135 | return packed_fields_; |
| 2136 | } |
| 2137 | |
| 2138 | template <size_t flag> |
| 2139 | bool GetPackedFlag() const { |
| 2140 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2141 | } |
| 2142 | |
| 2143 | template <size_t flag> |
| 2144 | void SetPackedFlag(bool value = true) { |
| 2145 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2146 | } |
| 2147 | |
| 2148 | template <typename BitFieldType> |
| 2149 | typename BitFieldType::value_type GetPackedField() const { |
| 2150 | return BitFieldType::Decode(packed_fields_); |
| 2151 | } |
| 2152 | |
| 2153 | template <typename BitFieldType> |
| 2154 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2155 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2156 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2157 | } |
| 2158 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2159 | private: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2160 | void FixUpUserRecordsAfterUseInsertion(HUseList<HInstruction*>::iterator fixup_end) { |
| 2161 | auto before_use_node = uses_.before_begin(); |
| 2162 | for (auto use_node = uses_.begin(); use_node != fixup_end; ++use_node) { |
| 2163 | HInstruction* user = use_node->GetUser(); |
| 2164 | size_t input_index = use_node->GetIndex(); |
| 2165 | user->SetRawInputRecordAt(input_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2166 | before_use_node = use_node; |
| 2167 | } |
| 2168 | } |
| 2169 | |
| 2170 | void FixUpUserRecordsAfterUseRemoval(HUseList<HInstruction*>::iterator before_use_node) { |
| 2171 | auto next = ++HUseList<HInstruction*>::iterator(before_use_node); |
| 2172 | if (next != uses_.end()) { |
| 2173 | HInstruction* next_user = next->GetUser(); |
| 2174 | size_t next_index = next->GetIndex(); |
| 2175 | DCHECK(next_user->InputRecordAt(next_index).GetInstruction() == this); |
| 2176 | next_user->SetRawInputRecordAt(next_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2177 | } |
| 2178 | } |
| 2179 | |
| 2180 | void FixUpUserRecordsAfterEnvUseInsertion(HUseList<HEnvironment*>::iterator env_fixup_end) { |
| 2181 | auto before_env_use_node = env_uses_.before_begin(); |
| 2182 | for (auto env_use_node = env_uses_.begin(); env_use_node != env_fixup_end; ++env_use_node) { |
| 2183 | HEnvironment* user = env_use_node->GetUser(); |
| 2184 | size_t input_index = env_use_node->GetIndex(); |
| 2185 | user->vregs_[input_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2186 | before_env_use_node = env_use_node; |
| 2187 | } |
| 2188 | } |
| 2189 | |
| 2190 | void FixUpUserRecordsAfterEnvUseRemoval(HUseList<HEnvironment*>::iterator before_env_use_node) { |
| 2191 | auto next = ++HUseList<HEnvironment*>::iterator(before_env_use_node); |
| 2192 | if (next != env_uses_.end()) { |
| 2193 | HEnvironment* next_user = next->GetUser(); |
| 2194 | size_t next_index = next->GetIndex(); |
| 2195 | DCHECK(next_user->vregs_[next_index].GetInstruction() == this); |
| 2196 | next_user->vregs_[next_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2197 | } |
| 2198 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2199 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2200 | HInstruction* previous_; |
| 2201 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2202 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2203 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2204 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2205 | // An instruction gets an id when it is added to the graph. |
| 2206 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2207 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2208 | int id_; |
| 2209 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2210 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2211 | int ssa_index_; |
| 2212 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2213 | // Packed fields. |
| 2214 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2215 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2216 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2217 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2218 | |
| 2219 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2220 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2221 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2222 | // The environment associated with this instruction. Not null if the instruction |
| 2223 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2224 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2225 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2226 | // Set by the code generator. |
| 2227 | LocationSummary* locations_; |
| 2228 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2229 | // Set by the liveness analysis. |
| 2230 | LiveInterval* live_interval_; |
| 2231 | |
| 2232 | // Set by the liveness analysis, this is the position in a linear |
| 2233 | // order of blocks where this instruction's live interval start. |
| 2234 | size_t lifetime_position_; |
| 2235 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2236 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2237 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2238 | // The reference handle part of the reference type info. |
| 2239 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2240 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2241 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2242 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2243 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2244 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2245 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2246 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2247 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2248 | |
| 2249 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2250 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2251 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2252 | |
| 2253 | class HInstructionIterator : public ValueObject { |
| 2254 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2255 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2256 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2257 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2258 | } |
| 2259 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2260 | bool Done() const { return instruction_ == nullptr; } |
| 2261 | HInstruction* Current() const { return instruction_; } |
| 2262 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2263 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2264 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2265 | } |
| 2266 | |
| 2267 | private: |
| 2268 | HInstruction* instruction_; |
| 2269 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2270 | |
| 2271 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2272 | }; |
| 2273 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2274 | class HBackwardInstructionIterator : public ValueObject { |
| 2275 | public: |
| 2276 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2277 | : instruction_(instructions.last_instruction_) { |
| 2278 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2279 | } |
| 2280 | |
| 2281 | bool Done() const { return instruction_ == nullptr; } |
| 2282 | HInstruction* Current() const { return instruction_; } |
| 2283 | void Advance() { |
| 2284 | instruction_ = next_; |
| 2285 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2286 | } |
| 2287 | |
| 2288 | private: |
| 2289 | HInstruction* instruction_; |
| 2290 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2291 | |
| 2292 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2293 | }; |
| 2294 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2295 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2296 | class HTemplateInstruction: public HInstruction { |
| 2297 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2298 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2299 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2300 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2301 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2302 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2303 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2304 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2305 | } |
| 2306 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2307 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2308 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2309 | |
| 2310 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2311 | }; |
| 2312 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2313 | // HTemplateInstruction specialization for N=0. |
| 2314 | template<> |
| 2315 | class HTemplateInstruction<0>: public HInstruction { |
| 2316 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2317 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2318 | : HInstruction(side_effects, dex_pc) {} |
| 2319 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2320 | virtual ~HTemplateInstruction() {} |
| 2321 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2322 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2323 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2324 | return ArrayRef<HUserRecord<HInstruction*>>(); |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2325 | } |
| 2326 | |
| 2327 | private: |
| 2328 | friend class SsaBuilder; |
| 2329 | }; |
| 2330 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2331 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2332 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2333 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2334 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2335 | : HTemplateInstruction<N>(side_effects, dex_pc) { |
| 2336 | this->template SetPackedField<TypeField>(type); |
| 2337 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2338 | virtual ~HExpression() {} |
| 2339 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2340 | Primitive::Type GetType() const OVERRIDE { |
| 2341 | return TypeField::Decode(this->GetPackedFields()); |
| 2342 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2343 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2344 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2345 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2346 | static constexpr size_t kFieldTypeSize = |
| 2347 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2348 | static constexpr size_t kNumberOfExpressionPackedBits = kFieldType + kFieldTypeSize; |
| 2349 | static_assert(kNumberOfExpressionPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 2350 | "Too many packed fields."); |
| 2351 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2352 | }; |
| 2353 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2354 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2355 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2356 | class HReturnVoid FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2357 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2358 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2359 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2360 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2361 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2362 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2363 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2364 | |
| 2365 | private: |
| 2366 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2367 | }; |
| 2368 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2369 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2370 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2371 | class HReturn FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2372 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2373 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2374 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2375 | SetRawInputAt(0, value); |
| 2376 | } |
| 2377 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2378 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2379 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2380 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2381 | |
| 2382 | private: |
| 2383 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2384 | }; |
| 2385 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2386 | class HPhi FINAL : public HInstruction { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2387 | public: |
| 2388 | HPhi(ArenaAllocator* arena, |
| 2389 | uint32_t reg_number, |
| 2390 | size_t number_of_inputs, |
| 2391 | Primitive::Type type, |
| 2392 | uint32_t dex_pc = kNoDexPc) |
| 2393 | : HInstruction(SideEffects::None(), dex_pc), |
| 2394 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
| 2395 | reg_number_(reg_number) { |
| 2396 | SetPackedField<TypeField>(ToPhiType(type)); |
| 2397 | DCHECK_NE(GetType(), Primitive::kPrimVoid); |
| 2398 | // Phis are constructed live and marked dead if conflicting or unused. |
| 2399 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 2400 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 2401 | SetPackedFlag<kFlagIsLive>(true); |
| 2402 | SetPackedFlag<kFlagCanBeNull>(true); |
| 2403 | } |
| 2404 | |
| 2405 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 2406 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 2407 | return Primitive::PrimitiveKind(type); |
| 2408 | } |
| 2409 | |
| 2410 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 2411 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2412 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2413 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2414 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 2415 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2416 | |
| 2417 | void AddInput(HInstruction* input); |
| 2418 | void RemoveInputAt(size_t index); |
| 2419 | |
| 2420 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<TypeField>(); } |
| 2421 | void SetType(Primitive::Type new_type) { |
| 2422 | // Make sure that only valid type changes occur. The following are allowed: |
| 2423 | // (1) int -> float/ref (primitive type propagation), |
| 2424 | // (2) long -> double (primitive type propagation). |
| 2425 | DCHECK(GetType() == new_type || |
| 2426 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimFloat) || |
| 2427 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimNot) || |
| 2428 | (GetType() == Primitive::kPrimLong && new_type == Primitive::kPrimDouble)); |
| 2429 | SetPackedField<TypeField>(new_type); |
| 2430 | } |
| 2431 | |
| 2432 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 2433 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
| 2434 | |
| 2435 | uint32_t GetRegNumber() const { return reg_number_; } |
| 2436 | |
| 2437 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 2438 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 2439 | bool IsDead() const { return !IsLive(); } |
| 2440 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
| 2441 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2442 | bool IsVRegEquivalentOf(const HInstruction* other) const { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2443 | return other != nullptr |
| 2444 | && other->IsPhi() |
| 2445 | && other->AsPhi()->GetBlock() == GetBlock() |
| 2446 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 2447 | } |
| 2448 | |
| 2449 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 2450 | // An equivalent phi is a phi having the same dex register and type. |
| 2451 | // It assumes that phis with the same dex register are adjacent. |
| 2452 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 2453 | HInstruction* next = GetNext(); |
| 2454 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 2455 | if (next->GetType() == GetType()) { |
| 2456 | return next->AsPhi(); |
| 2457 | } |
| 2458 | next = next->GetNext(); |
| 2459 | } |
| 2460 | return nullptr; |
| 2461 | } |
| 2462 | |
| 2463 | DECLARE_INSTRUCTION(Phi); |
| 2464 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2465 | private: |
| 2466 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2467 | static constexpr size_t kFieldTypeSize = |
| 2468 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2469 | static constexpr size_t kFlagIsLive = kFieldType + kFieldTypeSize; |
| 2470 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 2471 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 2472 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 2473 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
| 2474 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2475 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2476 | const uint32_t reg_number_; |
| 2477 | |
| 2478 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 2479 | }; |
| 2480 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2481 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2482 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2483 | // exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2484 | class HExit FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2485 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2486 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2487 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2488 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2489 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2490 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2491 | |
| 2492 | private: |
| 2493 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2494 | }; |
| 2495 | |
| 2496 | // Jumps from one block to another. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2497 | class HGoto FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2498 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2499 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2500 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2501 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2502 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2503 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2504 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2505 | } |
| 2506 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2507 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2508 | |
| 2509 | private: |
| 2510 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2511 | }; |
| 2512 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2513 | class HConstant : public HExpression<0> { |
| 2514 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2515 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2516 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2517 | |
| 2518 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2519 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2520 | // Is this constant -1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2521 | virtual bool IsMinusOne() const { return false; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2522 | // Is this constant 0 in the arithmetic sense? |
| 2523 | virtual bool IsArithmeticZero() const { return false; } |
| 2524 | // Is this constant a 0-bit pattern? |
| 2525 | virtual bool IsZeroBitPattern() const { return false; } |
| 2526 | // Is this constant 1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2527 | virtual bool IsOne() const { return false; } |
| 2528 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2529 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2530 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2531 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2532 | |
| 2533 | private: |
| 2534 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2535 | }; |
| 2536 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2537 | class HNullConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2538 | public: |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2539 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2540 | return true; |
| 2541 | } |
| 2542 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2543 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2544 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2545 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2546 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2547 | // The null constant representation is a 0-bit pattern. |
| 2548 | virtual bool IsZeroBitPattern() const { return true; } |
| 2549 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2550 | DECLARE_INSTRUCTION(NullConstant); |
| 2551 | |
| 2552 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2553 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2554 | |
| 2555 | friend class HGraph; |
| 2556 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2557 | }; |
| 2558 | |
| 2559 | // Constants of the type int. Those can be from Dex instructions, or |
| 2560 | // synthesized (for example with the if-eqz instruction). |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2561 | class HIntConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2562 | public: |
| 2563 | int32_t GetValue() const { return value_; } |
| 2564 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2565 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2566 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2567 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2568 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2569 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2570 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2571 | return other->AsIntConstant()->value_ == value_; |
| 2572 | } |
| 2573 | |
| 2574 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2575 | |
| 2576 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2577 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2578 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2579 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2580 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2581 | // Integer constants are used to encode Boolean values as well, |
| 2582 | // where 1 means true and 0 means false. |
| 2583 | bool IsTrue() const { return GetValue() == 1; } |
| 2584 | bool IsFalse() const { return GetValue() == 0; } |
| 2585 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2586 | DECLARE_INSTRUCTION(IntConstant); |
| 2587 | |
| 2588 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2589 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2590 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2591 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2592 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2593 | |
| 2594 | const int32_t value_; |
| 2595 | |
| 2596 | friend class HGraph; |
| 2597 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2598 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2599 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2600 | }; |
| 2601 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2602 | class HLongConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2603 | public: |
| 2604 | int64_t GetValue() const { return value_; } |
| 2605 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2606 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2607 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2608 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2609 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2610 | return other->AsLongConstant()->value_ == value_; |
| 2611 | } |
| 2612 | |
| 2613 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2614 | |
| 2615 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2616 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2617 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2618 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2619 | |
| 2620 | DECLARE_INSTRUCTION(LongConstant); |
| 2621 | |
| 2622 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2623 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2624 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2625 | |
| 2626 | const int64_t value_; |
| 2627 | |
| 2628 | friend class HGraph; |
| 2629 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2630 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2631 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2632 | class HFloatConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2633 | public: |
| 2634 | float GetValue() const { return value_; } |
| 2635 | |
| 2636 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2637 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2638 | } |
| 2639 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2640 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2641 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 2642 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2643 | } |
| 2644 | |
| 2645 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2646 | |
| 2647 | bool IsMinusOne() const OVERRIDE { |
| 2648 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 2649 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2650 | bool IsArithmeticZero() const OVERRIDE { |
| 2651 | return std::fpclassify(value_) == FP_ZERO; |
| 2652 | } |
| 2653 | bool IsArithmeticPositiveZero() const { |
| 2654 | return IsArithmeticZero() && !std::signbit(value_); |
| 2655 | } |
| 2656 | bool IsArithmeticNegativeZero() const { |
| 2657 | return IsArithmeticZero() && std::signbit(value_); |
| 2658 | } |
| 2659 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2660 | 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] | 2661 | } |
| 2662 | bool IsOne() const OVERRIDE { |
| 2663 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 2664 | } |
| 2665 | bool IsNaN() const { |
| 2666 | return std::isnan(value_); |
| 2667 | } |
| 2668 | |
| 2669 | DECLARE_INSTRUCTION(FloatConstant); |
| 2670 | |
| 2671 | private: |
| 2672 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 2673 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 2674 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2675 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
| 2676 | |
| 2677 | const float value_; |
| 2678 | |
| 2679 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2680 | friend class SsaBuilder; |
| 2681 | friend class HGraph; |
| 2682 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 2683 | }; |
| 2684 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2685 | class HDoubleConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2686 | public: |
| 2687 | double GetValue() const { return value_; } |
| 2688 | |
| 2689 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 2690 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2691 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2692 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 2693 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2694 | } |
| 2695 | |
| 2696 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2697 | |
| 2698 | bool IsMinusOne() const OVERRIDE { |
| 2699 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 2700 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2701 | bool IsArithmeticZero() const OVERRIDE { |
| 2702 | return std::fpclassify(value_) == FP_ZERO; |
| 2703 | } |
| 2704 | bool IsArithmeticPositiveZero() const { |
| 2705 | return IsArithmeticZero() && !std::signbit(value_); |
| 2706 | } |
| 2707 | bool IsArithmeticNegativeZero() const { |
| 2708 | return IsArithmeticZero() && std::signbit(value_); |
| 2709 | } |
| 2710 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2711 | 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] | 2712 | } |
| 2713 | bool IsOne() const OVERRIDE { |
| 2714 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 2715 | } |
| 2716 | bool IsNaN() const { |
| 2717 | return std::isnan(value_); |
| 2718 | } |
| 2719 | |
| 2720 | DECLARE_INSTRUCTION(DoubleConstant); |
| 2721 | |
| 2722 | private: |
| 2723 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 2724 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 2725 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2726 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
| 2727 | |
| 2728 | const double value_; |
| 2729 | |
| 2730 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2731 | friend class SsaBuilder; |
| 2732 | friend class HGraph; |
| 2733 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 2734 | }; |
| 2735 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2736 | // Conditional branch. A block ending with an HIf instruction must have |
| 2737 | // two successors. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2738 | class HIf FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2739 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2740 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2741 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2742 | SetRawInputAt(0, input); |
| 2743 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2744 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2745 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2746 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2747 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2748 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2749 | } |
| 2750 | |
| 2751 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2752 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2753 | } |
| 2754 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2755 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2756 | |
| 2757 | private: |
| 2758 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2759 | }; |
| 2760 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2761 | |
| 2762 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2763 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2764 | // non-exceptional control flow. |
| 2765 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2766 | // higher indices in no particular order. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2767 | class HTryBoundary FINAL : public HTemplateInstruction<0> { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2768 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2769 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2770 | kEntry, |
| 2771 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2772 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2773 | }; |
| 2774 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2775 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2776 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
| 2777 | SetPackedField<BoundaryKindField>(kind); |
| 2778 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2779 | |
| 2780 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2781 | |
| 2782 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2783 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2784 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 2785 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 2786 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 2787 | } |
| 2788 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2789 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2790 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2791 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2792 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2793 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2794 | } |
| 2795 | |
| 2796 | // If not present already, adds `handler` to its block's list of exception |
| 2797 | // handlers. |
| 2798 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2799 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2800 | GetBlock()->AddSuccessor(handler); |
| 2801 | } |
| 2802 | } |
| 2803 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2804 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 2805 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2806 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2807 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2808 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2809 | DECLARE_INSTRUCTION(TryBoundary); |
| 2810 | |
| 2811 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2812 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 2813 | static constexpr size_t kFieldBoundaryKindSize = |
| 2814 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 2815 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 2816 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 2817 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 2818 | "Too many packed fields."); |
| 2819 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2820 | |
| 2821 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2822 | }; |
| 2823 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2824 | // Deoptimize to interpreter, upon checking a condition. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2825 | class HDeoptimize FINAL : public HTemplateInstruction<1> { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2826 | public: |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2827 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 2828 | // at the point of the `HDeoptimize`. |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2829 | HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2830 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2831 | SetRawInputAt(0, cond); |
| 2832 | } |
| 2833 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2834 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2835 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2836 | return true; |
| 2837 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2838 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2839 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2840 | |
| 2841 | DECLARE_INSTRUCTION(Deoptimize); |
| 2842 | |
| 2843 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2844 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2845 | }; |
| 2846 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2847 | // Represents the ArtMethod that was passed as a first argument to |
| 2848 | // the method. It is used by instructions that depend on it, like |
| 2849 | // instructions that work with the dex cache. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2850 | class HCurrentMethod FINAL : public HExpression<0> { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2851 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2852 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2853 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2854 | |
| 2855 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2856 | |
| 2857 | private: |
| 2858 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2859 | }; |
| 2860 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2861 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 2862 | // of a class. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2863 | class HClassTableGet FINAL : public HExpression<1> { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2864 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2865 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2866 | kVTable, |
| 2867 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2868 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2869 | }; |
| 2870 | HClassTableGet(HInstruction* cls, |
| 2871 | Primitive::Type type, |
| 2872 | TableKind kind, |
| 2873 | size_t index, |
| 2874 | uint32_t dex_pc) |
| 2875 | : HExpression(type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2876 | index_(index) { |
| 2877 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2878 | SetRawInputAt(0, cls); |
| 2879 | } |
| 2880 | |
| 2881 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2882 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2883 | return other->AsClassTableGet()->GetIndex() == index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2884 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2885 | } |
| 2886 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2887 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2888 | size_t GetIndex() const { return index_; } |
| 2889 | |
| 2890 | DECLARE_INSTRUCTION(ClassTableGet); |
| 2891 | |
| 2892 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2893 | static constexpr size_t kFieldTableKind = kNumberOfExpressionPackedBits; |
| 2894 | static constexpr size_t kFieldTableKindSize = |
| 2895 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 2896 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 2897 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 2898 | "Too many packed fields."); |
| 2899 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 2900 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2901 | // The index of the ArtMethod in the table. |
| 2902 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2903 | |
| 2904 | DISALLOW_COPY_AND_ASSIGN(HClassTableGet); |
| 2905 | }; |
| 2906 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2907 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 2908 | // have one successor for each entry in the switch table, and the final successor |
| 2909 | // will be the block containing the next Dex opcode. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2910 | class HPackedSwitch FINAL : public HTemplateInstruction<1> { |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2911 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2912 | HPackedSwitch(int32_t start_value, |
| 2913 | uint32_t num_entries, |
| 2914 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2915 | uint32_t dex_pc = kNoDexPc) |
| 2916 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 2917 | start_value_(start_value), |
| 2918 | num_entries_(num_entries) { |
| 2919 | SetRawInputAt(0, input); |
| 2920 | } |
| 2921 | |
| 2922 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2923 | |
| 2924 | int32_t GetStartValue() const { return start_value_; } |
| 2925 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 2926 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2927 | |
| 2928 | HBasicBlock* GetDefaultBlock() const { |
| 2929 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2930 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2931 | } |
| 2932 | DECLARE_INSTRUCTION(PackedSwitch); |
| 2933 | |
| 2934 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2935 | const int32_t start_value_; |
| 2936 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2937 | |
| 2938 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 2939 | }; |
| 2940 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2941 | class HUnaryOperation : public HExpression<1> { |
| 2942 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2943 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2944 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2945 | SetRawInputAt(0, input); |
| 2946 | } |
| 2947 | |
| 2948 | HInstruction* GetInput() const { return InputAt(0); } |
| 2949 | Primitive::Type GetResultType() const { return GetType(); } |
| 2950 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2951 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2952 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2953 | return true; |
| 2954 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2955 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2956 | // Try to statically evaluate `this` and return a HConstant |
| 2957 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2958 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2959 | HConstant* TryStaticEvaluation() const; |
| 2960 | |
| 2961 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2962 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 2963 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2964 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 2965 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2966 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2967 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2968 | |
| 2969 | private: |
| 2970 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 2971 | }; |
| 2972 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2973 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2974 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2975 | HBinaryOperation(Primitive::Type result_type, |
| 2976 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2977 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2978 | SideEffects side_effects = SideEffects::None(), |
| 2979 | uint32_t dex_pc = kNoDexPc) |
| 2980 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2981 | SetRawInputAt(0, left); |
| 2982 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2983 | } |
| 2984 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2985 | HInstruction* GetLeft() const { return InputAt(0); } |
| 2986 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2987 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2988 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2989 | virtual bool IsCommutative() const { return false; } |
| 2990 | |
| 2991 | // Put constant on the right. |
| 2992 | // Returns whether order is changed. |
| 2993 | bool OrderInputsWithConstantOnTheRight() { |
| 2994 | HInstruction* left = InputAt(0); |
| 2995 | HInstruction* right = InputAt(1); |
| 2996 | if (left->IsConstant() && !right->IsConstant()) { |
| 2997 | ReplaceInput(right, 0); |
| 2998 | ReplaceInput(left, 1); |
| 2999 | return true; |
| 3000 | } |
| 3001 | return false; |
| 3002 | } |
| 3003 | |
| 3004 | // Order inputs by instruction id, but favor constant on the right side. |
| 3005 | // This helps GVN for commutative ops. |
| 3006 | void OrderInputs() { |
| 3007 | DCHECK(IsCommutative()); |
| 3008 | HInstruction* left = InputAt(0); |
| 3009 | HInstruction* right = InputAt(1); |
| 3010 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 3011 | return; |
| 3012 | } |
| 3013 | if (OrderInputsWithConstantOnTheRight()) { |
| 3014 | return; |
| 3015 | } |
| 3016 | // Order according to instruction id. |
| 3017 | if (left->GetId() > right->GetId()) { |
| 3018 | ReplaceInput(right, 0); |
| 3019 | ReplaceInput(left, 1); |
| 3020 | } |
| 3021 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3022 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3023 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3024 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3025 | return true; |
| 3026 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3027 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3028 | // Try to statically evaluate `this` and return a HConstant |
| 3029 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3030 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3031 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3032 | |
| 3033 | // Apply this operation to `x` and `y`. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3034 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3035 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3036 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 3037 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3038 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3039 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 3040 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3041 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 3042 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3043 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 3044 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3045 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3046 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 3047 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3048 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3049 | // 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] | 3050 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3051 | HConstant* GetConstantRight() const; |
| 3052 | |
| 3053 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3054 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3055 | HInstruction* GetLeastConstantLeft() const; |
| 3056 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3057 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 3058 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3059 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3060 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 3061 | }; |
| 3062 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3063 | // The comparison bias applies for floating point operations and indicates how NaN |
| 3064 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3065 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3066 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 3067 | kGtBias, // return 1 for NaN comparisons |
| 3068 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3069 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3070 | }; |
| 3071 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3072 | std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs); |
| 3073 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3074 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3075 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3076 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3077 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc) { |
| 3078 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 3079 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3080 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3081 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3082 | // `instruction`, and disregard moves in between. |
| 3083 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3084 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3085 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3086 | |
| 3087 | virtual IfCondition GetCondition() const = 0; |
| 3088 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3089 | virtual IfCondition GetOppositeCondition() const = 0; |
| 3090 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3091 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3092 | bool IsLtBias() const { return GetBias() == ComparisonBias::kLtBias; } |
| 3093 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3094 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 3095 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3096 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3097 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3098 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3099 | } |
| 3100 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3101 | bool IsFPConditionTrueIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3102 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3103 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3104 | if (if_cond == kCondNE) { |
| 3105 | return true; |
| 3106 | } else if (if_cond == kCondEQ) { |
| 3107 | return false; |
| 3108 | } |
| 3109 | return ((if_cond == kCondGT) || (if_cond == kCondGE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3110 | } |
| 3111 | |
| 3112 | bool IsFPConditionFalseIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3113 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3114 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3115 | if (if_cond == kCondEQ) { |
| 3116 | return true; |
| 3117 | } else if (if_cond == kCondNE) { |
| 3118 | return false; |
| 3119 | } |
| 3120 | return ((if_cond == kCondLT) || (if_cond == kCondLE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3121 | } |
| 3122 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3123 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3124 | // Needed if we merge a HCompare into a HCondition. |
| 3125 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3126 | static constexpr size_t kFieldComparisonBiasSize = |
| 3127 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3128 | static constexpr size_t kNumberOfConditionPackedBits = |
| 3129 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3130 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3131 | using ComparisonBiasField = |
| 3132 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3133 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3134 | template <typename T> |
| 3135 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3136 | |
| 3137 | template <typename T> |
| 3138 | int32_t CompareFP(T x, T y) const { |
| 3139 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3140 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3141 | // Handle the bias. |
| 3142 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 3143 | } |
| 3144 | |
| 3145 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3146 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3147 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3148 | } |
| 3149 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3150 | private: |
| 3151 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 3152 | }; |
| 3153 | |
| 3154 | // Instruction to check if two inputs are equal to each other. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3155 | class HEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3156 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3157 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3158 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3159 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3160 | bool IsCommutative() const OVERRIDE { return true; } |
| 3161 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3162 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3163 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3164 | return MakeConstantCondition(true, GetDexPc()); |
| 3165 | } |
| 3166 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3167 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3168 | } |
| 3169 | // In the following Evaluate methods, a HCompare instruction has |
| 3170 | // been merged into this HEqual instruction; evaluate it as |
| 3171 | // `Compare(x, y) == 0`. |
| 3172 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3173 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3174 | GetDexPc()); |
| 3175 | } |
| 3176 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3177 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3178 | } |
| 3179 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3180 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3181 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3182 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3183 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3184 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3185 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3186 | return kCondEQ; |
| 3187 | } |
| 3188 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3189 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3190 | return kCondNE; |
| 3191 | } |
| 3192 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3193 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3194 | 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] | 3195 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3196 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 3197 | }; |
| 3198 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3199 | class HNotEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3200 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3201 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3202 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3203 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3204 | bool IsCommutative() const OVERRIDE { return true; } |
| 3205 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3206 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3207 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3208 | return MakeConstantCondition(false, GetDexPc()); |
| 3209 | } |
| 3210 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3211 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3212 | } |
| 3213 | // In the following Evaluate methods, a HCompare instruction has |
| 3214 | // been merged into this HNotEqual instruction; evaluate it as |
| 3215 | // `Compare(x, y) != 0`. |
| 3216 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3217 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3218 | } |
| 3219 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3220 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3221 | } |
| 3222 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3223 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3224 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3225 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3226 | DECLARE_INSTRUCTION(NotEqual); |
| 3227 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3228 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3229 | return kCondNE; |
| 3230 | } |
| 3231 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3232 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3233 | return kCondEQ; |
| 3234 | } |
| 3235 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3236 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3237 | 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] | 3238 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3239 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 3240 | }; |
| 3241 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3242 | class HLessThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3243 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3244 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3245 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3246 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3247 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3248 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3249 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3250 | // In the following Evaluate methods, a HCompare instruction has |
| 3251 | // been merged into this HLessThan instruction; evaluate it as |
| 3252 | // `Compare(x, y) < 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3253 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3254 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3255 | } |
| 3256 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3257 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3258 | } |
| 3259 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3260 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3261 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3262 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3263 | DECLARE_INSTRUCTION(LessThan); |
| 3264 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3265 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3266 | return kCondLT; |
| 3267 | } |
| 3268 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3269 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3270 | return kCondGE; |
| 3271 | } |
| 3272 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3273 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3274 | 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] | 3275 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3276 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 3277 | }; |
| 3278 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3279 | class HLessThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3280 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3281 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3282 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3283 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3284 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3285 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3286 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3287 | // In the following Evaluate methods, a HCompare instruction has |
| 3288 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 3289 | // `Compare(x, y) <= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3290 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3291 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3292 | } |
| 3293 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3294 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3295 | } |
| 3296 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3297 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3298 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3299 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3300 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 3301 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3302 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3303 | return kCondLE; |
| 3304 | } |
| 3305 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3306 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3307 | return kCondGT; |
| 3308 | } |
| 3309 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3310 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3311 | 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] | 3312 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3313 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 3314 | }; |
| 3315 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3316 | class HGreaterThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3317 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3318 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3319 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3320 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3321 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3322 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3323 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3324 | // In the following Evaluate methods, a HCompare instruction has |
| 3325 | // been merged into this HGreaterThan instruction; evaluate it as |
| 3326 | // `Compare(x, y) > 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3327 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3328 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3329 | } |
| 3330 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3331 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3332 | } |
| 3333 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3334 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3335 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3336 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3337 | DECLARE_INSTRUCTION(GreaterThan); |
| 3338 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3339 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3340 | return kCondGT; |
| 3341 | } |
| 3342 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3343 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3344 | return kCondLE; |
| 3345 | } |
| 3346 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3347 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3348 | 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] | 3349 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3350 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 3351 | }; |
| 3352 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3353 | class HGreaterThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3354 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3355 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3356 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3357 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3358 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3359 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3360 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3361 | // In the following Evaluate methods, a HCompare instruction has |
| 3362 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 3363 | // `Compare(x, y) >= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3364 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3365 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3366 | } |
| 3367 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3368 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3369 | } |
| 3370 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3371 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3372 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3373 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3374 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 3375 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3376 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3377 | return kCondGE; |
| 3378 | } |
| 3379 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3380 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3381 | return kCondLT; |
| 3382 | } |
| 3383 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3384 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3385 | 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] | 3386 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3387 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 3388 | }; |
| 3389 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3390 | class HBelow FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3391 | public: |
| 3392 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3393 | : HCondition(first, second, dex_pc) {} |
| 3394 | |
| 3395 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3396 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3397 | } |
| 3398 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3399 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3400 | } |
| 3401 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3402 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3403 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3404 | UNREACHABLE(); |
| 3405 | } |
| 3406 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3407 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3408 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3409 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3410 | } |
| 3411 | |
| 3412 | DECLARE_INSTRUCTION(Below); |
| 3413 | |
| 3414 | IfCondition GetCondition() const OVERRIDE { |
| 3415 | return kCondB; |
| 3416 | } |
| 3417 | |
| 3418 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3419 | return kCondAE; |
| 3420 | } |
| 3421 | |
| 3422 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3423 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3424 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 3425 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3426 | |
| 3427 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 3428 | }; |
| 3429 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3430 | class HBelowOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3431 | public: |
| 3432 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3433 | : HCondition(first, second, dex_pc) {} |
| 3434 | |
| 3435 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3436 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3437 | } |
| 3438 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3439 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3440 | } |
| 3441 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3442 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3443 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3444 | UNREACHABLE(); |
| 3445 | } |
| 3446 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3447 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3448 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3449 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3450 | } |
| 3451 | |
| 3452 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 3453 | |
| 3454 | IfCondition GetCondition() const OVERRIDE { |
| 3455 | return kCondBE; |
| 3456 | } |
| 3457 | |
| 3458 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3459 | return kCondA; |
| 3460 | } |
| 3461 | |
| 3462 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3463 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3464 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 3465 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3466 | |
| 3467 | DISALLOW_COPY_AND_ASSIGN(HBelowOrEqual); |
| 3468 | }; |
| 3469 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3470 | class HAbove FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3471 | public: |
| 3472 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3473 | : HCondition(first, second, dex_pc) {} |
| 3474 | |
| 3475 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3476 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3477 | } |
| 3478 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3479 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3480 | } |
| 3481 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3482 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3483 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3484 | UNREACHABLE(); |
| 3485 | } |
| 3486 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3487 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3488 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3489 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3490 | } |
| 3491 | |
| 3492 | DECLARE_INSTRUCTION(Above); |
| 3493 | |
| 3494 | IfCondition GetCondition() const OVERRIDE { |
| 3495 | return kCondA; |
| 3496 | } |
| 3497 | |
| 3498 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3499 | return kCondBE; |
| 3500 | } |
| 3501 | |
| 3502 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3503 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3504 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 3505 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3506 | |
| 3507 | DISALLOW_COPY_AND_ASSIGN(HAbove); |
| 3508 | }; |
| 3509 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3510 | class HAboveOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3511 | public: |
| 3512 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3513 | : HCondition(first, second, dex_pc) {} |
| 3514 | |
| 3515 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3516 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3517 | } |
| 3518 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3519 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3520 | } |
| 3521 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3522 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3523 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3524 | UNREACHABLE(); |
| 3525 | } |
| 3526 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3527 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3528 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3529 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3530 | } |
| 3531 | |
| 3532 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 3533 | |
| 3534 | IfCondition GetCondition() const OVERRIDE { |
| 3535 | return kCondAE; |
| 3536 | } |
| 3537 | |
| 3538 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3539 | return kCondB; |
| 3540 | } |
| 3541 | |
| 3542 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3543 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3544 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 3545 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3546 | |
| 3547 | DISALLOW_COPY_AND_ASSIGN(HAboveOrEqual); |
| 3548 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3549 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3550 | // Instruction to check how two inputs compare to each other. |
| 3551 | // 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] | 3552 | class HCompare FINAL : public HBinaryOperation { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3553 | public: |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3554 | // Note that `comparison_type` is the type of comparison performed |
| 3555 | // between the comparison's inputs, not the type of the instantiated |
| 3556 | // HCompare instruction (which is always Primitive::kPrimInt). |
| 3557 | HCompare(Primitive::Type comparison_type, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3558 | HInstruction* first, |
| 3559 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3560 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3561 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3562 | : HBinaryOperation(Primitive::kPrimInt, |
| 3563 | first, |
| 3564 | second, |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3565 | SideEffectsForArchRuntimeCalls(comparison_type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3566 | dex_pc) { |
| 3567 | SetPackedField<ComparisonBiasField>(bias); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3568 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(first->GetType())); |
| 3569 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(second->GetType())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3570 | } |
| 3571 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3572 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3573 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3574 | |
| 3575 | template <typename T> |
| 3576 | int32_t ComputeFP(T x, T y) const { |
| 3577 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3578 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3579 | // Handle the bias. |
| 3580 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 3581 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3582 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3583 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3584 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 3585 | // reach this code path when processing a freshly built HIR |
| 3586 | // graph. However HCompare integer instructions can be synthesized |
| 3587 | // by the instruction simplifier to implement IntegerCompare and |
| 3588 | // IntegerSignum intrinsics, so we have to handle this case. |
| 3589 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3590 | } |
| 3591 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3592 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3593 | } |
| 3594 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3595 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3596 | } |
| 3597 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3598 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3599 | } |
| 3600 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3601 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3602 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3603 | } |
| 3604 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3605 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3606 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3607 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3608 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3609 | bool IsGtBias() const { |
| 3610 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3611 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3612 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3613 | |
Roland Levillain | 1693a1f | 2016-03-15 14:57:31 +0000 | [diff] [blame] | 3614 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type ATTRIBUTE_UNUSED) { |
| 3615 | // Comparisons do not require a runtime call in any back end. |
| 3616 | return SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3617 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3618 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3619 | DECLARE_INSTRUCTION(Compare); |
| 3620 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3621 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3622 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3623 | static constexpr size_t kFieldComparisonBiasSize = |
| 3624 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3625 | static constexpr size_t kNumberOfComparePackedBits = |
| 3626 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3627 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3628 | using ComparisonBiasField = |
| 3629 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3630 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3631 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 3632 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 3633 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 3634 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3635 | } |
| 3636 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3637 | private: |
| 3638 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3639 | }; |
| 3640 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3641 | class HNewInstance FINAL : public HExpression<2> { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3642 | public: |
| 3643 | HNewInstance(HInstruction* cls, |
| 3644 | HCurrentMethod* current_method, |
| 3645 | uint32_t dex_pc, |
| 3646 | uint16_t type_index, |
| 3647 | const DexFile& dex_file, |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3648 | bool needs_access_check, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3649 | bool finalizable, |
| 3650 | QuickEntrypointEnum entrypoint) |
| 3651 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
| 3652 | type_index_(type_index), |
| 3653 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3654 | entrypoint_(entrypoint) { |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3655 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3656 | SetPackedFlag<kFlagFinalizable>(finalizable); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3657 | SetRawInputAt(0, cls); |
| 3658 | SetRawInputAt(1, current_method); |
| 3659 | } |
| 3660 | |
| 3661 | uint16_t GetTypeIndex() const { return type_index_; } |
| 3662 | const DexFile& GetDexFile() const { return dex_file_; } |
| 3663 | |
| 3664 | // Calls runtime so needs an environment. |
| 3665 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3666 | |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3667 | // Can throw errors when out-of-memory or if it's not instantiable/accessible. |
| 3668 | bool CanThrow() const OVERRIDE { return true; } |
| 3669 | |
| 3670 | // Needs to call into runtime to make sure it's instantiable/accessible. |
| 3671 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3672 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3673 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3674 | |
| 3675 | bool CanBeNull() const OVERRIDE { return false; } |
| 3676 | |
| 3677 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3678 | |
| 3679 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 3680 | entrypoint_ = entrypoint; |
| 3681 | } |
| 3682 | |
| 3683 | bool IsStringAlloc() const; |
| 3684 | |
| 3685 | DECLARE_INSTRUCTION(NewInstance); |
| 3686 | |
| 3687 | private: |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3688 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfExpressionPackedBits; |
| 3689 | static constexpr size_t kFlagFinalizable = kFlagNeedsAccessCheck + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3690 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagFinalizable + 1; |
| 3691 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 3692 | "Too many packed fields."); |
| 3693 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3694 | const uint16_t type_index_; |
| 3695 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3696 | QuickEntrypointEnum entrypoint_; |
| 3697 | |
| 3698 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3699 | }; |
| 3700 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3701 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3702 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3703 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3704 | }; |
| 3705 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3706 | enum IntrinsicSideEffects { |
| 3707 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 3708 | kReadSideEffects, // Intrinsic may read heap memory. |
| 3709 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 3710 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 3711 | }; |
| 3712 | |
| 3713 | enum IntrinsicExceptions { |
| 3714 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 3715 | kCanThrow // Intrinsic may throw exceptions. |
| 3716 | }; |
| 3717 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3718 | class HInvoke : public HInstruction { |
| 3719 | public: |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3720 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3721 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3722 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 3723 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 3724 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 3725 | } |
| 3726 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3727 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3728 | SetRawInputAt(index, argument); |
| 3729 | } |
| 3730 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3731 | // Return the number of arguments. This number can be lower than |
| 3732 | // the number of inputs returned by InputCount(), as some invoke |
| 3733 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3734 | // inputs at the end of their list of inputs. |
| 3735 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3736 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3737 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<ReturnTypeField>(); } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3738 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3739 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3740 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3741 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3742 | InvokeType GetInvokeType() const { |
| 3743 | return GetPackedField<InvokeTypeField>(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3744 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3745 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3746 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3747 | return intrinsic_; |
| 3748 | } |
| 3749 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3750 | void SetIntrinsic(Intrinsics intrinsic, |
| 3751 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 3752 | IntrinsicSideEffects side_effects, |
| 3753 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3754 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3755 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 3756 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3757 | } |
| 3758 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3759 | bool CanThrow() const OVERRIDE { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3760 | |
| 3761 | bool CanBeMoved() const OVERRIDE { return IsIntrinsic(); } |
| 3762 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3763 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3764 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 3765 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3766 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3767 | uint32_t* GetIntrinsicOptimizations() { |
| 3768 | return &intrinsic_optimizations_; |
| 3769 | } |
| 3770 | |
| 3771 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3772 | return &intrinsic_optimizations_; |
| 3773 | } |
| 3774 | |
| 3775 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3776 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3777 | ArtMethod* GetResolvedMethod() const { return resolved_method_; } |
| 3778 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3779 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3780 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3781 | protected: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3782 | static constexpr size_t kFieldInvokeType = kNumberOfGenericPackedBits; |
| 3783 | static constexpr size_t kFieldInvokeTypeSize = |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3784 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 3785 | static constexpr size_t kFieldReturnType = |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3786 | kFieldInvokeType + kFieldInvokeTypeSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3787 | static constexpr size_t kFieldReturnTypeSize = |
| 3788 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 3789 | static constexpr size_t kFlagCanThrow = kFieldReturnType + kFieldReturnTypeSize; |
| 3790 | static constexpr size_t kNumberOfInvokePackedBits = kFlagCanThrow + 1; |
| 3791 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3792 | using InvokeTypeField = BitField<InvokeType, kFieldInvokeType, kFieldInvokeTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3793 | using ReturnTypeField = BitField<Primitive::Type, kFieldReturnType, kFieldReturnTypeSize>; |
| 3794 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3795 | HInvoke(ArenaAllocator* arena, |
| 3796 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3797 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3798 | Primitive::Type return_type, |
| 3799 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3800 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3801 | ArtMethod* resolved_method, |
| 3802 | InvokeType invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3803 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3804 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3805 | number_of_arguments_(number_of_arguments), |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3806 | resolved_method_(resolved_method), |
Vladimir Marko | b7d8e8c | 2015-09-17 15:47:05 +0100 | [diff] [blame] | 3807 | inputs_(number_of_arguments + number_of_other_inputs, |
| 3808 | arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3809 | dex_method_index_(dex_method_index), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3810 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3811 | intrinsic_optimizations_(0) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3812 | SetPackedField<ReturnTypeField>(return_type); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3813 | SetPackedField<InvokeTypeField>(invoke_type); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3814 | SetPackedFlag<kFlagCanThrow>(true); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3815 | } |
| 3816 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3817 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3818 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3819 | uint32_t number_of_arguments_; |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3820 | ArtMethod* const resolved_method_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3821 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3822 | const uint32_t dex_method_index_; |
| 3823 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3824 | |
| 3825 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3826 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3827 | |
| 3828 | private: |
| 3829 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3830 | }; |
| 3831 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3832 | class HInvokeUnresolved FINAL : public HInvoke { |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3833 | public: |
| 3834 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3835 | uint32_t number_of_arguments, |
| 3836 | Primitive::Type return_type, |
| 3837 | uint32_t dex_pc, |
| 3838 | uint32_t dex_method_index, |
| 3839 | InvokeType invoke_type) |
| 3840 | : HInvoke(arena, |
| 3841 | number_of_arguments, |
| 3842 | 0u /* number_of_other_inputs */, |
| 3843 | return_type, |
| 3844 | dex_pc, |
| 3845 | dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3846 | nullptr, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3847 | invoke_type) { |
| 3848 | } |
| 3849 | |
| 3850 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3851 | |
| 3852 | private: |
| 3853 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3854 | }; |
| 3855 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3856 | class HInvokeStaticOrDirect FINAL : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3857 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3858 | // Requirements of this method call regarding the class |
| 3859 | // initialization (clinit) check of its declaring class. |
| 3860 | enum class ClinitCheckRequirement { |
| 3861 | kNone, // Class already initialized. |
| 3862 | kExplicit, // Static call having explicit clinit check as last input. |
| 3863 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3864 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3865 | }; |
| 3866 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3867 | // Determines how to load the target ArtMethod*. |
| 3868 | enum class MethodLoadKind { |
| 3869 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3870 | kStringInit, |
| 3871 | |
| 3872 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3873 | kRecursive, |
| 3874 | |
| 3875 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3876 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3877 | kDirectAddress, |
| 3878 | |
| 3879 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3880 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3881 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3882 | // the image relocatable or not. |
| 3883 | kDirectAddressWithFixup, |
| 3884 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3885 | // 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] | 3886 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3887 | // may cause class initialization (the entry may point to a resolution method), |
| 3888 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3889 | kDexCachePcRelative, |
| 3890 | |
| 3891 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3892 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3893 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3894 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3895 | kDexCacheViaMethod, |
| 3896 | }; |
| 3897 | |
| 3898 | // Determines the location of the code pointer. |
| 3899 | enum class CodePtrLocation { |
| 3900 | // Recursive call, use local PC-relative call instruction. |
| 3901 | kCallSelf, |
| 3902 | |
| 3903 | // Use PC-relative call instruction patched at link time. |
| 3904 | // Used for calls within an oat file, boot->boot or app->app. |
| 3905 | kCallPCRelative, |
| 3906 | |
| 3907 | // Call to a known target address, embed the direct address in code. |
| 3908 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3909 | kCallDirect, |
| 3910 | |
| 3911 | // Call to a target address that will be known at link time, embed the direct |
| 3912 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3913 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3914 | // the image relocatable or not. |
| 3915 | kCallDirectWithFixup, |
| 3916 | |
| 3917 | // Use code pointer from the ArtMethod*. |
| 3918 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3919 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3920 | kCallArtMethod, |
| 3921 | }; |
| 3922 | |
| 3923 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3924 | MethodLoadKind method_load_kind; |
| 3925 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3926 | // The method load data holds |
| 3927 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3928 | // Note that there are multiple string init methods, each having its own offset. |
| 3929 | // - the method address for kDirectAddress |
| 3930 | // - the dex cache arrays offset for kDexCachePcRel. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3931 | uint64_t method_load_data; |
| 3932 | uint64_t direct_code_ptr; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3933 | }; |
| 3934 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3935 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 3936 | uint32_t number_of_arguments, |
| 3937 | Primitive::Type return_type, |
| 3938 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3939 | uint32_t method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3940 | ArtMethod* resolved_method, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3941 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3942 | InvokeType invoke_type, |
| 3943 | MethodReference target_method, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3944 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3945 | : HInvoke(arena, |
| 3946 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3947 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 3948 | // potentially one other if the clinit check is explicit, and potentially |
| 3949 | // one other if the method is a string factory. |
| 3950 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3951 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3952 | return_type, |
| 3953 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3954 | method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3955 | resolved_method, |
| 3956 | invoke_type), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3957 | target_method_(target_method), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3958 | dispatch_info_(dispatch_info) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3959 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 3960 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3961 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3962 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3963 | bool had_current_method_input = HasCurrentMethodInput(); |
| 3964 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 3965 | |
| 3966 | // Using the current method is the default and once we find a better |
| 3967 | // method load kind, we should not go back to using the current method. |
| 3968 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 3969 | |
| 3970 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3971 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 3972 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3973 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3974 | dispatch_info_ = dispatch_info; |
| 3975 | } |
| 3976 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3977 | void AddSpecialInput(HInstruction* input) { |
| 3978 | // We allow only one special input. |
| 3979 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 3980 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3981 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 3982 | InsertInputAt(GetSpecialInputIndex(), input); |
| 3983 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3984 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3985 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 3986 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 3987 | ArrayRef<HUserRecord<HInstruction*>> input_records = HInvoke::GetInputRecords(); |
| 3988 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck()) { |
| 3989 | DCHECK(!input_records.empty()); |
| 3990 | DCHECK_GT(input_records.size(), GetNumberOfArguments()); |
| 3991 | HInstruction* last_input = input_records.back().GetInstruction(); |
| 3992 | // Note: `last_input` may be null during arguments setup. |
| 3993 | if (last_input != nullptr) { |
| 3994 | // `last_input` is the last input of a static invoke marked as having |
| 3995 | // an explicit clinit check. It must either be: |
| 3996 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 3997 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 3998 | DCHECK(last_input->IsClinitCheck() || last_input->IsLoadClass()) << last_input->DebugName(); |
| 3999 | } |
| 4000 | } |
| 4001 | return input_records; |
| 4002 | } |
| 4003 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4004 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4005 | // We access the method via the dex cache so we can't do an implicit null check. |
| 4006 | // TODO: for intrinsics we can generate implicit null checks. |
| 4007 | return false; |
| 4008 | } |
| 4009 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4010 | bool CanBeNull() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4011 | return GetPackedField<ReturnTypeField>() == Primitive::kPrimNot && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4012 | } |
| 4013 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4014 | // Get the index of the special input, if any. |
| 4015 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4016 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 4017 | // method pointer; otherwise there may be one platform-specific special input, |
| 4018 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4019 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
Nicolas Geoffray | 9779307 | 2016-02-16 15:33:54 +0000 | [diff] [blame] | 4020 | bool HasSpecialInput() const { return GetNumberOfArguments() != InputCount(); } |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4021 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4022 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 4023 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 4024 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4025 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4026 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4027 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4028 | bool HasPcRelativeDexCache() const { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4029 | return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; |
| 4030 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4031 | bool HasCurrentMethodInput() const { |
| 4032 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 4033 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4034 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4035 | return true; |
| 4036 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4037 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4038 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4039 | return false; |
| 4040 | } |
| 4041 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4042 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4043 | |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4044 | QuickEntrypointEnum GetStringInitEntryPoint() const { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4045 | DCHECK(IsStringInit()); |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4046 | return static_cast<QuickEntrypointEnum>(dispatch_info_.method_load_data); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4047 | } |
| 4048 | |
| 4049 | uint64_t GetMethodAddress() const { |
| 4050 | DCHECK(HasMethodAddress()); |
| 4051 | return dispatch_info_.method_load_data; |
| 4052 | } |
| 4053 | |
| 4054 | uint32_t GetDexCacheArrayOffset() const { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4055 | DCHECK(HasPcRelativeDexCache()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4056 | return dispatch_info_.method_load_data; |
| 4057 | } |
| 4058 | |
| 4059 | uint64_t GetDirectCodePtr() const { |
| 4060 | DCHECK(HasDirectCodePtr()); |
| 4061 | return dispatch_info_.direct_code_ptr; |
| 4062 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4063 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4064 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 4065 | return GetPackedField<ClinitCheckRequirementField>(); |
| 4066 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 4067 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4068 | // Is this instruction a call to a static method? |
| 4069 | bool IsStatic() const { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4070 | return GetInvokeType() == kStatic; |
| 4071 | } |
| 4072 | |
| 4073 | MethodReference GetTargetMethod() const { |
| 4074 | return target_method_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4075 | } |
| 4076 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4077 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 4078 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 4079 | // instruction; only relevant for static calls with explicit clinit check. |
| 4080 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4081 | DCHECK(IsStaticWithExplicitClinitCheck()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4082 | size_t last_input_index = inputs_.size() - 1u; |
| 4083 | HInstruction* last_input = inputs_.back().GetInstruction(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4084 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4085 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4086 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4087 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4088 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4089 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4090 | } |
| 4091 | |
| 4092 | // 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] | 4093 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4094 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4095 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4096 | } |
| 4097 | |
| 4098 | // Is this a call to a static method whose declaring class has an |
| 4099 | // implicit intialization check requirement? |
| 4100 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4101 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4102 | } |
| 4103 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4104 | // Does this method load kind need the current method as an input? |
| 4105 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
| 4106 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kDexCacheViaMethod; |
| 4107 | } |
| 4108 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4109 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4110 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4111 | protected: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4112 | void InsertInputAt(size_t index, HInstruction* input); |
| 4113 | void RemoveInputAt(size_t index); |
| 4114 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4115 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4116 | static constexpr size_t kFieldClinitCheckRequirement = kNumberOfInvokePackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4117 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 4118 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 4119 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 4120 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 4121 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 4122 | "Too many packed fields."); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4123 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 4124 | kFieldClinitCheckRequirement, |
| 4125 | kFieldClinitCheckRequirementSize>; |
| 4126 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4127 | // Cached values of the resolved method, to avoid needing the mutator lock. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4128 | MethodReference target_method_; |
| 4129 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4130 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4131 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4132 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 4133 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4134 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4135 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4136 | class HInvokeVirtual FINAL : public HInvoke { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4137 | public: |
| 4138 | HInvokeVirtual(ArenaAllocator* arena, |
| 4139 | uint32_t number_of_arguments, |
| 4140 | Primitive::Type return_type, |
| 4141 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4142 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4143 | ArtMethod* resolved_method, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4144 | uint32_t vtable_index) |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4145 | : HInvoke(arena, |
| 4146 | number_of_arguments, |
| 4147 | 0u, |
| 4148 | return_type, |
| 4149 | dex_pc, |
| 4150 | dex_method_index, |
| 4151 | resolved_method, |
| 4152 | kVirtual), |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4153 | vtable_index_(vtable_index) {} |
| 4154 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4155 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4156 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4157 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4158 | } |
| 4159 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4160 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 4161 | |
| 4162 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 4163 | |
| 4164 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4165 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4166 | const uint32_t vtable_index_; |
| 4167 | |
| 4168 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 4169 | }; |
| 4170 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4171 | class HInvokeInterface FINAL : public HInvoke { |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4172 | public: |
| 4173 | HInvokeInterface(ArenaAllocator* arena, |
| 4174 | uint32_t number_of_arguments, |
| 4175 | Primitive::Type return_type, |
| 4176 | uint32_t dex_pc, |
| 4177 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4178 | ArtMethod* resolved_method, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4179 | uint32_t imt_index) |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4180 | : HInvoke(arena, |
| 4181 | number_of_arguments, |
| 4182 | 0u, |
| 4183 | return_type, |
| 4184 | dex_pc, |
| 4185 | dex_method_index, |
| 4186 | resolved_method, |
| 4187 | kInterface), |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4188 | imt_index_(imt_index) {} |
| 4189 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4190 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4191 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4192 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4193 | } |
| 4194 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4195 | uint32_t GetImtIndex() const { return imt_index_; } |
| 4196 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 4197 | |
| 4198 | DECLARE_INSTRUCTION(InvokeInterface); |
| 4199 | |
| 4200 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4201 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4202 | const uint32_t imt_index_; |
| 4203 | |
| 4204 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 4205 | }; |
| 4206 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4207 | class HNeg FINAL : public HUnaryOperation { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4208 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4209 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 937e6cd | 2016-03-22 11:54:37 +0000 | [diff] [blame] | 4210 | : HUnaryOperation(result_type, input, dex_pc) { |
| 4211 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(input->GetType())); |
| 4212 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4213 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4214 | template <typename T> static T Compute(T x) { return -x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4215 | |
| 4216 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4217 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4218 | } |
| 4219 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4220 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4221 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4222 | HConstant* Evaluate(HFloatConstant* x) const OVERRIDE { |
| 4223 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 4224 | } |
| 4225 | HConstant* Evaluate(HDoubleConstant* x) const OVERRIDE { |
| 4226 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 4227 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 4228 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4229 | DECLARE_INSTRUCTION(Neg); |
| 4230 | |
| 4231 | private: |
| 4232 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 4233 | }; |
| 4234 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4235 | class HNewArray FINAL : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4236 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4237 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4238 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4239 | uint32_t dex_pc, |
| 4240 | uint16_t type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4241 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4242 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4243 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4244 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4245 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4246 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4247 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4248 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4249 | } |
| 4250 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4251 | uint16_t GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4252 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4253 | |
| 4254 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4255 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4256 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4257 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 4258 | bool CanThrow() const OVERRIDE { return true; } |
| 4259 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4260 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4261 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4262 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 4263 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4264 | DECLARE_INSTRUCTION(NewArray); |
| 4265 | |
| 4266 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4267 | const uint16_t type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4268 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4269 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4270 | |
| 4271 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 4272 | }; |
| 4273 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4274 | class HAdd FINAL : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4275 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4276 | HAdd(Primitive::Type result_type, |
| 4277 | HInstruction* left, |
| 4278 | HInstruction* right, |
| 4279 | uint32_t dex_pc = kNoDexPc) |
| 4280 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4281 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4282 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4283 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4284 | 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] | 4285 | |
| 4286 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4287 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4288 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4289 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4290 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4291 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4292 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4293 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4294 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4295 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4296 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4297 | } |
| 4298 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4299 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4300 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4301 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4302 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4303 | DECLARE_INSTRUCTION(Add); |
| 4304 | |
| 4305 | private: |
| 4306 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 4307 | }; |
| 4308 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4309 | class HSub FINAL : public HBinaryOperation { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4310 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4311 | HSub(Primitive::Type result_type, |
| 4312 | HInstruction* left, |
| 4313 | HInstruction* right, |
| 4314 | uint32_t dex_pc = kNoDexPc) |
| 4315 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4316 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4317 | 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] | 4318 | |
| 4319 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4320 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4321 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4322 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4323 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4324 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4325 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4326 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4327 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4328 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4329 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4330 | } |
| 4331 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4332 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4333 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4334 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4335 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4336 | DECLARE_INSTRUCTION(Sub); |
| 4337 | |
| 4338 | private: |
| 4339 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 4340 | }; |
| 4341 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4342 | class HMul FINAL : public HBinaryOperation { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4343 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4344 | HMul(Primitive::Type result_type, |
| 4345 | HInstruction* left, |
| 4346 | HInstruction* right, |
| 4347 | uint32_t dex_pc = kNoDexPc) |
| 4348 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4349 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4350 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4351 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4352 | 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] | 4353 | |
| 4354 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4355 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4356 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4357 | } |
| 4358 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4359 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4360 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4361 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4362 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4363 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4364 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4365 | } |
| 4366 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4367 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4368 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4369 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4370 | |
| 4371 | DECLARE_INSTRUCTION(Mul); |
| 4372 | |
| 4373 | private: |
| 4374 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 4375 | }; |
| 4376 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4377 | class HDiv FINAL : public HBinaryOperation { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4378 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4379 | HDiv(Primitive::Type result_type, |
| 4380 | HInstruction* left, |
| 4381 | HInstruction* right, |
| 4382 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 4383 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4384 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4385 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4386 | T ComputeIntegral(T x, T y) const { |
| 4387 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4388 | // Our graph structure ensures we never have 0 for `y` during |
| 4389 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4390 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4391 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4392 | return (y == -1) ? -x : x / y; |
| 4393 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4394 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4395 | template <typename T> |
| 4396 | T ComputeFP(T x, T y) const { |
| 4397 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4398 | return x / y; |
| 4399 | } |
| 4400 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4401 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4402 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4403 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4404 | } |
| 4405 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4406 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4407 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4408 | } |
| 4409 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4410 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4411 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4412 | } |
| 4413 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4414 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4415 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4416 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4417 | |
| 4418 | DECLARE_INSTRUCTION(Div); |
| 4419 | |
| 4420 | private: |
| 4421 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 4422 | }; |
| 4423 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4424 | class HRem FINAL : public HBinaryOperation { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4425 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4426 | HRem(Primitive::Type result_type, |
| 4427 | HInstruction* left, |
| 4428 | HInstruction* right, |
| 4429 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 4430 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4431 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4432 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4433 | T ComputeIntegral(T x, T y) const { |
| 4434 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4435 | // Our graph structure ensures we never have 0 for `y` during |
| 4436 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4437 | DCHECK_NE(y, 0); |
| 4438 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 4439 | return (y == -1) ? 0 : x % y; |
| 4440 | } |
| 4441 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4442 | template <typename T> |
| 4443 | T ComputeFP(T x, T y) const { |
| 4444 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4445 | return std::fmod(x, y); |
| 4446 | } |
| 4447 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4448 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4449 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4450 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4451 | } |
| 4452 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4453 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4454 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4455 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4456 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4457 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4458 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4459 | } |
| 4460 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4461 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4462 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4463 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4464 | |
| 4465 | DECLARE_INSTRUCTION(Rem); |
| 4466 | |
| 4467 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4468 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 4469 | }; |
| 4470 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4471 | class HDivZeroCheck FINAL : public HExpression<1> { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4472 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4473 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
| 4474 | // constructor. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4475 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4476 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4477 | SetRawInputAt(0, value); |
| 4478 | } |
| 4479 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4480 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 4481 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4482 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4483 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4484 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4485 | return true; |
| 4486 | } |
| 4487 | |
| 4488 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4489 | bool CanThrow() const OVERRIDE { return true; } |
| 4490 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4491 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 4492 | |
| 4493 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4494 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 4495 | }; |
| 4496 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4497 | class HShl FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4498 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4499 | HShl(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4500 | HInstruction* value, |
| 4501 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4502 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4503 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4504 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4505 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4506 | } |
| 4507 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4508 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4509 | 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] | 4510 | return value << (distance & max_shift_distance); |
| 4511 | } |
| 4512 | |
| 4513 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4514 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4515 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4516 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4517 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4518 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4519 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4520 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4521 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4522 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4523 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4524 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4525 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4526 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4527 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4528 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4529 | UNREACHABLE(); |
| 4530 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4531 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4532 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4533 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4534 | UNREACHABLE(); |
| 4535 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4536 | |
| 4537 | DECLARE_INSTRUCTION(Shl); |
| 4538 | |
| 4539 | private: |
| 4540 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 4541 | }; |
| 4542 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4543 | class HShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4544 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4545 | HShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4546 | HInstruction* value, |
| 4547 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4548 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4549 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4550 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4551 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4552 | } |
| 4553 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4554 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4555 | 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] | 4556 | return value >> (distance & max_shift_distance); |
| 4557 | } |
| 4558 | |
| 4559 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4560 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4561 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4562 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4563 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4564 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4565 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4566 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4567 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4568 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4569 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4570 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4571 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4572 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4573 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4574 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4575 | UNREACHABLE(); |
| 4576 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4577 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4578 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4579 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4580 | UNREACHABLE(); |
| 4581 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4582 | |
| 4583 | DECLARE_INSTRUCTION(Shr); |
| 4584 | |
| 4585 | private: |
| 4586 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 4587 | }; |
| 4588 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4589 | class HUShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4590 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4591 | HUShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4592 | HInstruction* value, |
| 4593 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4594 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4595 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4596 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4597 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4598 | } |
| 4599 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4600 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4601 | 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] | 4602 | typedef typename std::make_unsigned<T>::type V; |
| 4603 | V ux = static_cast<V>(value); |
| 4604 | return static_cast<T>(ux >> (distance & max_shift_distance)); |
| 4605 | } |
| 4606 | |
| 4607 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4608 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4609 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4610 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4611 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4612 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4613 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4614 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4615 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4616 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4617 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4618 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4619 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4620 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4621 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4622 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4623 | UNREACHABLE(); |
| 4624 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4625 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4626 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4627 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4628 | UNREACHABLE(); |
| 4629 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4630 | |
| 4631 | DECLARE_INSTRUCTION(UShr); |
| 4632 | |
| 4633 | private: |
| 4634 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 4635 | }; |
| 4636 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4637 | class HAnd FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4638 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4639 | HAnd(Primitive::Type result_type, |
| 4640 | HInstruction* left, |
| 4641 | HInstruction* right, |
| 4642 | uint32_t dex_pc = kNoDexPc) |
| 4643 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4644 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4645 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4646 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4647 | 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] | 4648 | |
| 4649 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4650 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4651 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4652 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4653 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4654 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4655 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4656 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4657 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4658 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4659 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4660 | UNREACHABLE(); |
| 4661 | } |
| 4662 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4663 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4664 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4665 | UNREACHABLE(); |
| 4666 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4667 | |
| 4668 | DECLARE_INSTRUCTION(And); |
| 4669 | |
| 4670 | private: |
| 4671 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4672 | }; |
| 4673 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4674 | class HOr FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4675 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4676 | HOr(Primitive::Type result_type, |
| 4677 | HInstruction* left, |
| 4678 | HInstruction* right, |
| 4679 | uint32_t dex_pc = kNoDexPc) |
| 4680 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4681 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4682 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4683 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4684 | 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] | 4685 | |
| 4686 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4687 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4688 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4689 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4690 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4691 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4692 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4693 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4694 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4695 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4696 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4697 | UNREACHABLE(); |
| 4698 | } |
| 4699 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4700 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4701 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4702 | UNREACHABLE(); |
| 4703 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4704 | |
| 4705 | DECLARE_INSTRUCTION(Or); |
| 4706 | |
| 4707 | private: |
| 4708 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4709 | }; |
| 4710 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4711 | class HXor FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4712 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4713 | HXor(Primitive::Type result_type, |
| 4714 | HInstruction* left, |
| 4715 | HInstruction* right, |
| 4716 | uint32_t dex_pc = kNoDexPc) |
| 4717 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4718 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4719 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4720 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4721 | 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] | 4722 | |
| 4723 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4724 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4725 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4726 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4727 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4728 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4729 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4730 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4731 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4732 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4733 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4734 | UNREACHABLE(); |
| 4735 | } |
| 4736 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4737 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4738 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4739 | UNREACHABLE(); |
| 4740 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4741 | |
| 4742 | DECLARE_INSTRUCTION(Xor); |
| 4743 | |
| 4744 | private: |
| 4745 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 4746 | }; |
| 4747 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4748 | class HRor FINAL : public HBinaryOperation { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4749 | public: |
| 4750 | HRor(Primitive::Type result_type, HInstruction* value, HInstruction* distance) |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4751 | : HBinaryOperation(result_type, value, distance) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4752 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4753 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4754 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4755 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4756 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4757 | 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] | 4758 | typedef typename std::make_unsigned<T>::type V; |
| 4759 | V ux = static_cast<V>(value); |
| 4760 | if ((distance & max_shift_value) == 0) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4761 | return static_cast<T>(ux); |
| 4762 | } else { |
| 4763 | const V reg_bits = sizeof(T) * 8; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4764 | return static_cast<T>(ux >> (distance & max_shift_value)) | |
| 4765 | (value << (reg_bits - (distance & max_shift_value))); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4766 | } |
| 4767 | } |
| 4768 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4769 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4770 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4771 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4772 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4773 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4774 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4775 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4776 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4777 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4778 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4779 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4780 | UNREACHABLE(); |
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 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4783 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4784 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4785 | UNREACHABLE(); |
| 4786 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4787 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4788 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4789 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4790 | UNREACHABLE(); |
| 4791 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4792 | |
| 4793 | DECLARE_INSTRUCTION(Ror); |
| 4794 | |
| 4795 | private: |
| 4796 | DISALLOW_COPY_AND_ASSIGN(HRor); |
| 4797 | }; |
| 4798 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4799 | // The value of a parameter in this method. Its location depends on |
| 4800 | // the calling convention. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4801 | class HParameterValue FINAL : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4802 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4803 | HParameterValue(const DexFile& dex_file, |
| 4804 | uint16_t type_index, |
| 4805 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4806 | Primitive::Type parameter_type, |
| 4807 | bool is_this = false) |
| 4808 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4809 | dex_file_(dex_file), |
| 4810 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4811 | index_(index) { |
| 4812 | SetPackedFlag<kFlagIsThis>(is_this); |
| 4813 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 4814 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4815 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4816 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4817 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4818 | uint8_t GetIndex() const { return index_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4819 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4820 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4821 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 4822 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4823 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4824 | DECLARE_INSTRUCTION(ParameterValue); |
| 4825 | |
| 4826 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4827 | // Whether or not the parameter value corresponds to 'this' argument. |
| 4828 | static constexpr size_t kFlagIsThis = kNumberOfExpressionPackedBits; |
| 4829 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 4830 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 4831 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 4832 | "Too many packed fields."); |
| 4833 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4834 | const DexFile& dex_file_; |
| 4835 | const uint16_t type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4836 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4837 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4838 | const uint8_t index_; |
| 4839 | |
| 4840 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 4841 | }; |
| 4842 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4843 | class HNot FINAL : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4844 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4845 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4846 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4847 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4848 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4849 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4850 | return true; |
| 4851 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4852 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4853 | template <typename T> static T Compute(T x) { return ~x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4854 | |
| 4855 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4856 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4857 | } |
| 4858 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4859 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4860 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4861 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4862 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4863 | UNREACHABLE(); |
| 4864 | } |
| 4865 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4866 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4867 | UNREACHABLE(); |
| 4868 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4869 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4870 | DECLARE_INSTRUCTION(Not); |
| 4871 | |
| 4872 | private: |
| 4873 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 4874 | }; |
| 4875 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4876 | class HBooleanNot FINAL : public HUnaryOperation { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4877 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4878 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4879 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4880 | |
| 4881 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4882 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4883 | return true; |
| 4884 | } |
| 4885 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4886 | template <typename T> static bool Compute(T x) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4887 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4888 | return !x; |
| 4889 | } |
| 4890 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4891 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4892 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4893 | } |
| 4894 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4895 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4896 | UNREACHABLE(); |
| 4897 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4898 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4899 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4900 | UNREACHABLE(); |
| 4901 | } |
| 4902 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4903 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4904 | UNREACHABLE(); |
| 4905 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4906 | |
| 4907 | DECLARE_INSTRUCTION(BooleanNot); |
| 4908 | |
| 4909 | private: |
| 4910 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 4911 | }; |
| 4912 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4913 | class HTypeConversion FINAL : public HExpression<1> { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4914 | public: |
| 4915 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4916 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 4917 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4918 | SetRawInputAt(0, input); |
Roland Levillain | f355c3f | 2016-03-30 19:09:03 +0100 | [diff] [blame] | 4919 | // Invariant: We should never generate a conversion to a Boolean value. |
| 4920 | DCHECK_NE(Primitive::kPrimBoolean, result_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4921 | } |
| 4922 | |
| 4923 | HInstruction* GetInput() const { return InputAt(0); } |
| 4924 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 4925 | Primitive::Type GetResultType() const { return GetType(); } |
| 4926 | |
| 4927 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4928 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4929 | return true; |
| 4930 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4931 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 4932 | // Try to statically evaluate the conversion and return a HConstant |
| 4933 | // containing the result. If the input cannot be converted, return nullptr. |
| 4934 | HConstant* TryStaticEvaluation() const; |
| 4935 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4936 | DECLARE_INSTRUCTION(TypeConversion); |
| 4937 | |
| 4938 | private: |
| 4939 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 4940 | }; |
| 4941 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 4942 | static constexpr uint32_t kNoRegNumber = -1; |
| 4943 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4944 | class HNullCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4945 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4946 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
| 4947 | // constructor. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4948 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4949 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4950 | SetRawInputAt(0, value); |
| 4951 | } |
| 4952 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 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 { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4955 | return true; |
| 4956 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4957 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4958 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4959 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4960 | bool CanThrow() const OVERRIDE { return true; } |
| 4961 | |
| 4962 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4963 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4964 | |
| 4965 | DECLARE_INSTRUCTION(NullCheck); |
| 4966 | |
| 4967 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4968 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 4969 | }; |
| 4970 | |
| 4971 | class FieldInfo : public ValueObject { |
| 4972 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4973 | FieldInfo(MemberOffset field_offset, |
| 4974 | Primitive::Type field_type, |
| 4975 | bool is_volatile, |
| 4976 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4977 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4978 | const DexFile& dex_file, |
| 4979 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4980 | : field_offset_(field_offset), |
| 4981 | field_type_(field_type), |
| 4982 | is_volatile_(is_volatile), |
| 4983 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4984 | declaring_class_def_index_(declaring_class_def_index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4985 | dex_file_(dex_file), |
| 4986 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4987 | |
| 4988 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4989 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4990 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4991 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4992 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4993 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4994 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4995 | |
| 4996 | private: |
| 4997 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4998 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4999 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5000 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5001 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5002 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5003 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5004 | }; |
| 5005 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5006 | class HInstanceFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5007 | public: |
| 5008 | HInstanceFieldGet(HInstruction* value, |
| 5009 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5010 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5011 | bool is_volatile, |
| 5012 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5013 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5014 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5015 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5016 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5017 | : HExpression(field_type, SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5018 | field_info_(field_offset, |
| 5019 | field_type, |
| 5020 | is_volatile, |
| 5021 | field_idx, |
| 5022 | declaring_class_def_index, |
| 5023 | dex_file, |
| 5024 | dex_cache) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5025 | SetRawInputAt(0, value); |
| 5026 | } |
| 5027 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5028 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5029 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5030 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 5031 | const HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5032 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5033 | } |
| 5034 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5035 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5036 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5037 | } |
| 5038 | |
| 5039 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 5040 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5041 | } |
| 5042 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5043 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5044 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5045 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5046 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5047 | |
| 5048 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 5049 | |
| 5050 | private: |
| 5051 | const FieldInfo field_info_; |
| 5052 | |
| 5053 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 5054 | }; |
| 5055 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5056 | class HInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5057 | public: |
| 5058 | HInstanceFieldSet(HInstruction* object, |
| 5059 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5060 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5061 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5062 | bool is_volatile, |
| 5063 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5064 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5065 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5066 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5067 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5068 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5069 | field_info_(field_offset, |
| 5070 | field_type, |
| 5071 | is_volatile, |
| 5072 | field_idx, |
| 5073 | declaring_class_def_index, |
| 5074 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5075 | dex_cache) { |
| 5076 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5077 | SetRawInputAt(0, object); |
| 5078 | SetRawInputAt(1, value); |
| 5079 | } |
| 5080 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5081 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5082 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5083 | } |
| 5084 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5085 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5086 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5087 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5088 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5089 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5090 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5091 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5092 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5093 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 5094 | |
| 5095 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5096 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5097 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5098 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5099 | "Too many packed fields."); |
| 5100 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5101 | const FieldInfo field_info_; |
| 5102 | |
| 5103 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 5104 | }; |
| 5105 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5106 | class HArrayGet FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5107 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5108 | HArrayGet(HInstruction* array, |
| 5109 | HInstruction* index, |
| 5110 | Primitive::Type type, |
| 5111 | uint32_t dex_pc, |
| 5112 | bool is_string_char_at = false) |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5113 | : HExpression(type, SideEffects::ArrayReadOfType(type), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5114 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5115 | SetRawInputAt(0, array); |
| 5116 | SetRawInputAt(1, index); |
| 5117 | } |
| 5118 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5119 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5120 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5121 | return true; |
| 5122 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5123 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5124 | // TODO: We can be smarter here. |
| 5125 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 5126 | // which generates the implicit null check. There are cases when these can be removed |
| 5127 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 5128 | // implicit check here (as long as the address falls in the first page). |
| 5129 | return false; |
| 5130 | } |
| 5131 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5132 | bool IsEquivalentOf(HArrayGet* other) const { |
| 5133 | bool result = (GetDexPc() == other->GetDexPc()); |
| 5134 | if (kIsDebugBuild && result) { |
| 5135 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 5136 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 5137 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
| 5138 | if (Primitive::IsIntOrLongType(GetType())) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5139 | DCHECK(Primitive::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5140 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5141 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 5142 | DCHECK(Primitive::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5143 | } |
| 5144 | } |
| 5145 | return result; |
| 5146 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5147 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5148 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
| 5149 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5150 | HInstruction* GetArray() const { return InputAt(0); } |
| 5151 | HInstruction* GetIndex() const { return InputAt(1); } |
| 5152 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5153 | DECLARE_INSTRUCTION(ArrayGet); |
| 5154 | |
| 5155 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5156 | // We treat a String as an array, creating the HArrayGet from String.charAt() |
| 5157 | // intrinsic in the instruction simplifier. We can always determine whether |
| 5158 | // a particular HArrayGet is actually a String.charAt() by looking at the type |
| 5159 | // of the input but that requires holding the mutator lock, so we prefer to use |
| 5160 | // a flag, so that code generators don't need to do the locking. |
| 5161 | static constexpr size_t kFlagIsStringCharAt = kNumberOfExpressionPackedBits; |
| 5162 | static constexpr size_t kNumberOfArrayGetPackedBits = kFlagIsStringCharAt + 1; |
| 5163 | static_assert(kNumberOfArrayGetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5164 | "Too many packed fields."); |
| 5165 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5166 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 5167 | }; |
| 5168 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5169 | class HArraySet FINAL : public HTemplateInstruction<3> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5170 | public: |
| 5171 | HArraySet(HInstruction* array, |
| 5172 | HInstruction* index, |
| 5173 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5174 | Primitive::Type expected_component_type, |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5175 | uint32_t dex_pc) |
| 5176 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5177 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
| 5178 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == Primitive::kPrimNot); |
| 5179 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 5180 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5181 | SetRawInputAt(0, array); |
| 5182 | SetRawInputAt(1, index); |
| 5183 | SetRawInputAt(2, value); |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5184 | // Make a best guess now, may be refined during SSA building. |
| 5185 | ComputeSideEffects(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5186 | } |
| 5187 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5188 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5189 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5190 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5191 | } |
| 5192 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5193 | // Can throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5194 | bool CanThrow() const OVERRIDE { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5195 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5196 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5197 | // TODO: Same as for ArrayGet. |
| 5198 | return false; |
| 5199 | } |
| 5200 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5201 | void ClearNeedsTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5202 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5203 | } |
| 5204 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5205 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5206 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5207 | } |
| 5208 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5209 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5210 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5211 | } |
| 5212 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5213 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5214 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 5215 | bool StaticTypeOfArrayIsObjectArray() const { |
| 5216 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 5217 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5218 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5219 | HInstruction* GetArray() const { return InputAt(0); } |
| 5220 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5221 | HInstruction* GetValue() const { return InputAt(2); } |
| 5222 | |
| 5223 | Primitive::Type GetComponentType() const { |
| 5224 | // The Dex format does not type floating point index operations. Since the |
| 5225 | // `expected_component_type_` is set during building and can therefore not |
| 5226 | // be correct, we also check what is the value type. If it is a floating |
| 5227 | // point type, we must use that type. |
| 5228 | Primitive::Type value_type = GetValue()->GetType(); |
| 5229 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 5230 | ? value_type |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5231 | : GetRawExpectedComponentType(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5232 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5233 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5234 | Primitive::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5235 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5236 | } |
| 5237 | |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5238 | void ComputeSideEffects() { |
| 5239 | Primitive::Type type = GetComponentType(); |
| 5240 | SetSideEffects(SideEffects::ArrayWriteOfType(type).Union( |
| 5241 | SideEffectsForArchRuntimeCalls(type))); |
| 5242 | } |
| 5243 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5244 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 5245 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 5246 | } |
| 5247 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5248 | DECLARE_INSTRUCTION(ArraySet); |
| 5249 | |
| 5250 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5251 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 5252 | static constexpr size_t kFieldExpectedComponentTypeSize = |
| 5253 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5254 | static constexpr size_t kFlagNeedsTypeCheck = |
| 5255 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 5256 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5257 | // Cached information for the reference_type_info_ so that codegen |
| 5258 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5259 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 5260 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 5261 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 5262 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5263 | using ExpectedComponentTypeField = |
| 5264 | BitField<Primitive::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5265 | |
| 5266 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 5267 | }; |
| 5268 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5269 | class HArrayLength FINAL : public HExpression<1> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5270 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5271 | HArrayLength(HInstruction* array, uint32_t dex_pc, bool is_string_length = false) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5272 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5273 | SetPackedFlag<kFlagIsStringLength>(is_string_length); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5274 | // Note that arrays do not change length, so the instruction does not |
| 5275 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5276 | SetRawInputAt(0, array); |
| 5277 | } |
| 5278 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5279 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5280 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5281 | return true; |
| 5282 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5283 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5284 | return obj == InputAt(0); |
| 5285 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5286 | |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5287 | bool IsStringLength() const { return GetPackedFlag<kFlagIsStringLength>(); } |
| 5288 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5289 | DECLARE_INSTRUCTION(ArrayLength); |
| 5290 | |
| 5291 | private: |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5292 | // We treat a String as an array, creating the HArrayLength from String.length() |
| 5293 | // or String.isEmpty() intrinsic in the instruction simplifier. We can always |
| 5294 | // determine whether a particular HArrayLength is actually a String.length() by |
| 5295 | // looking at the type of the input but that requires holding the mutator lock, so |
| 5296 | // we prefer to use a flag, so that code generators don't need to do the locking. |
| 5297 | static constexpr size_t kFlagIsStringLength = kNumberOfExpressionPackedBits; |
| 5298 | static constexpr size_t kNumberOfArrayLengthPackedBits = kFlagIsStringLength + 1; |
| 5299 | static_assert(kNumberOfArrayLengthPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5300 | "Too many packed fields."); |
| 5301 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5302 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 5303 | }; |
| 5304 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5305 | class HBoundsCheck FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5306 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5307 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
| 5308 | // constructor. |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5309 | HBoundsCheck(HInstruction* index, |
| 5310 | HInstruction* length, |
| 5311 | uint32_t dex_pc, |
| 5312 | uint32_t string_char_at_method_index = DexFile::kDexNoIndex) |
| 5313 | : HExpression(index->GetType(), SideEffects::CanTriggerGC(), dex_pc), |
| 5314 | string_char_at_method_index_(string_char_at_method_index) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 5315 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(index->GetType())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5316 | SetRawInputAt(0, index); |
| 5317 | SetRawInputAt(1, length); |
| 5318 | } |
| 5319 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5320 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5321 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5322 | return true; |
| 5323 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5324 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5325 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5326 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5327 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5328 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5329 | bool IsStringCharAt() const { return GetStringCharAtMethodIndex() != DexFile::kDexNoIndex; } |
| 5330 | uint32_t GetStringCharAtMethodIndex() const { return string_char_at_method_index_; } |
| 5331 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5332 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5333 | |
| 5334 | DECLARE_INSTRUCTION(BoundsCheck); |
| 5335 | |
| 5336 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5337 | // We treat a String as an array, creating the HBoundsCheck from String.charAt() |
| 5338 | // intrinsic in the instruction simplifier. We want to include the String.charAt() |
| 5339 | // in the stack trace if we actually throw the StringIndexOutOfBoundsException, |
| 5340 | // so we need to create an HEnvironment which will be translated to an InlineInfo |
| 5341 | // indicating the extra stack frame. Since we add this HEnvironment quite late, |
| 5342 | // in the PrepareForRegisterAllocation pass, we need to remember the method index |
| 5343 | // from the invoke as we don't want to look again at the dex bytecode. |
| 5344 | uint32_t string_char_at_method_index_; // DexFile::kDexNoIndex if regular array. |
| 5345 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5346 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 5347 | }; |
| 5348 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5349 | class HSuspendCheck FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5350 | public: |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 5351 | explicit HSuspendCheck(uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5352 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5353 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5354 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5355 | return true; |
| 5356 | } |
| 5357 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5358 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 5359 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5360 | |
| 5361 | DECLARE_INSTRUCTION(SuspendCheck); |
| 5362 | |
| 5363 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5364 | // Only used for code generation, in order to share the same slow path between back edges |
| 5365 | // of a same loop. |
| 5366 | SlowPathCode* slow_path_; |
| 5367 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5368 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 5369 | }; |
| 5370 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 5371 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 5372 | // It ensures that we can generate line number and local variables at this point. |
| 5373 | class HNativeDebugInfo : public HTemplateInstruction<0> { |
| 5374 | public: |
| 5375 | explicit HNativeDebugInfo(uint32_t dex_pc) |
| 5376 | : HTemplateInstruction<0>(SideEffects::None(), dex_pc) {} |
| 5377 | |
| 5378 | bool NeedsEnvironment() const OVERRIDE { |
| 5379 | return true; |
| 5380 | } |
| 5381 | |
| 5382 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 5383 | |
| 5384 | private: |
| 5385 | DISALLOW_COPY_AND_ASSIGN(HNativeDebugInfo); |
| 5386 | }; |
| 5387 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5388 | /** |
| 5389 | * Instruction to load a Class object. |
| 5390 | */ |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5391 | class HLoadClass FINAL : public HInstruction { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5392 | public: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5393 | // Determines how to load the Class. |
| 5394 | enum class LoadKind { |
| 5395 | // Use the Class* from the method's own ArtMethod*. |
| 5396 | kReferrersClass, |
| 5397 | |
| 5398 | // Use boot image Class* address that will be known at link time. |
| 5399 | // Used for boot image classes referenced by boot image code in non-PIC mode. |
| 5400 | kBootImageLinkTimeAddress, |
| 5401 | |
| 5402 | // Use PC-relative boot image Class* address that will be known at link time. |
| 5403 | // Used for boot image classes referenced by boot image code in PIC mode. |
| 5404 | kBootImageLinkTimePcRelative, |
| 5405 | |
| 5406 | // Use a known boot image Class* address, embedded in the code by the codegen. |
| 5407 | // Used for boot image classes referenced by apps in AOT- and JIT-compiled code. |
| 5408 | // Note: codegen needs to emit a linker patch if indicated by compiler options' |
| 5409 | // GetIncludePatchInformation(). |
| 5410 | kBootImageAddress, |
| 5411 | |
| 5412 | // Load from the resolved types array at an absolute address. |
| 5413 | // Used for classes outside the boot image referenced by JIT-compiled code. |
| 5414 | kDexCacheAddress, |
| 5415 | |
| 5416 | // Load from resolved types array in the dex cache using a PC-relative load. |
| 5417 | // Used for classes outside boot image when we know that we can access |
| 5418 | // the dex cache arrays using a PC-relative load. |
| 5419 | kDexCachePcRelative, |
| 5420 | |
| 5421 | // Load from resolved types array accessed through the class loaded from |
| 5422 | // the compiled method's own ArtMethod*. This is the default access type when |
| 5423 | // all other types are unavailable. |
| 5424 | kDexCacheViaMethod, |
| 5425 | |
| 5426 | kLast = kDexCacheViaMethod |
| 5427 | }; |
| 5428 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5429 | HLoadClass(HCurrentMethod* current_method, |
| 5430 | uint16_t type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5431 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5432 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5433 | uint32_t dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5434 | bool needs_access_check, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5435 | bool is_in_dex_cache, |
| 5436 | bool is_in_boot_image) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5437 | : HInstruction(SideEffectsForArchRuntimeCalls(), dex_pc), |
| 5438 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5439 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5440 | dex_file_(dex_file), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5441 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5442 | // Referrers class should not need access check. We never inline unverified |
| 5443 | // methods so we can't possibly end up in this situation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5444 | DCHECK(!is_referrers_class || !needs_access_check); |
| 5445 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5446 | SetPackedField<LoadKindField>( |
| 5447 | is_referrers_class ? LoadKind::kReferrersClass : LoadKind::kDexCacheViaMethod); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5448 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
| 5449 | SetPackedFlag<kFlagIsInDexCache>(is_in_dex_cache); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5450 | SetPackedFlag<kFlagIsInBootImage>(is_in_boot_image); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5451 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5452 | } |
| 5453 | |
| 5454 | void SetLoadKindWithAddress(LoadKind load_kind, uint64_t address) { |
| 5455 | DCHECK(HasAddress(load_kind)); |
| 5456 | load_data_.address = address; |
| 5457 | SetLoadKindInternal(load_kind); |
| 5458 | } |
| 5459 | |
| 5460 | void SetLoadKindWithTypeReference(LoadKind load_kind, |
| 5461 | const DexFile& dex_file, |
| 5462 | uint32_t type_index) { |
| 5463 | DCHECK(HasTypeReference(load_kind)); |
| 5464 | DCHECK(IsSameDexFile(dex_file_, dex_file)); |
| 5465 | DCHECK_EQ(type_index_, type_index); |
| 5466 | SetLoadKindInternal(load_kind); |
| 5467 | } |
| 5468 | |
| 5469 | void SetLoadKindWithDexCacheReference(LoadKind load_kind, |
| 5470 | const DexFile& dex_file, |
| 5471 | uint32_t element_index) { |
| 5472 | DCHECK(HasDexCacheReference(load_kind)); |
| 5473 | DCHECK(IsSameDexFile(dex_file_, dex_file)); |
| 5474 | load_data_.dex_cache_element_index = element_index; |
| 5475 | SetLoadKindInternal(load_kind); |
| 5476 | } |
| 5477 | |
| 5478 | LoadKind GetLoadKind() const { |
| 5479 | return GetPackedField<LoadKindField>(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5480 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5481 | |
| 5482 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5483 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5484 | bool InstructionDataEquals(const HInstruction* other) const; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5485 | |
| 5486 | size_t ComputeHashCode() const OVERRIDE { return type_index_; } |
| 5487 | |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 5488 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5489 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5490 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5491 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5492 | } |
| 5493 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 5494 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 5495 | // The entrypoint the code generator is going to call does not do |
| 5496 | // clinit of the class. |
| 5497 | DCHECK(!NeedsAccessCheck()); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5498 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5499 | } |
| 5500 | |
| 5501 | bool CanCallRuntime() const { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5502 | return MustGenerateClinitCheck() || |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5503 | (!IsReferrersClass() && !IsInDexCache()) || |
| 5504 | NeedsAccessCheck(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5505 | } |
| 5506 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5507 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5508 | bool CanThrow() const OVERRIDE { |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 5509 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5510 | } |
| 5511 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5512 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 5513 | return loaded_class_rti_; |
| 5514 | } |
| 5515 | |
| 5516 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 5517 | // Make sure we only set exact types (the loaded class should never be merged). |
| 5518 | DCHECK(rti.IsExact()); |
| 5519 | loaded_class_rti_ = rti; |
| 5520 | } |
| 5521 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5522 | uint32_t GetTypeIndex() const { return type_index_; } |
| 5523 | const DexFile& GetDexFile() const { return dex_file_; } |
| 5524 | |
| 5525 | uint32_t GetDexCacheElementOffset() const; |
| 5526 | |
| 5527 | uint64_t GetAddress() const { |
| 5528 | DCHECK(HasAddress(GetLoadKind())); |
| 5529 | return load_data_.address; |
| 5530 | } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5531 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5532 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return !IsReferrersClass(); } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 5533 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5534 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5535 | return SideEffects::CanTriggerGC(); |
| 5536 | } |
| 5537 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5538 | bool IsReferrersClass() const { return GetLoadKind() == LoadKind::kReferrersClass; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5539 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
| 5540 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5541 | bool IsInBootImage() const { return GetPackedFlag<kFlagIsInBootImage>(); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5542 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5543 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5544 | void MarkInDexCache() { |
| 5545 | SetPackedFlag<kFlagIsInDexCache>(true); |
| 5546 | DCHECK(!NeedsEnvironment()); |
| 5547 | RemoveEnvironment(); |
| 5548 | SetSideEffects(SideEffects::None()); |
| 5549 | } |
| 5550 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5551 | void MarkInBootImage() { |
| 5552 | SetPackedFlag<kFlagIsInBootImage>(true); |
| 5553 | } |
| 5554 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5555 | void AddSpecialInput(HInstruction* special_input); |
| 5556 | |
| 5557 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 5558 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 5559 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 5560 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 5561 | } |
| 5562 | |
| 5563 | Primitive::Type GetType() const OVERRIDE { |
| 5564 | return Primitive::kPrimNot; |
| 5565 | } |
| 5566 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5567 | DECLARE_INSTRUCTION(LoadClass); |
| 5568 | |
| 5569 | private: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5570 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5571 | static constexpr size_t kFlagIsInDexCache = kFlagNeedsAccessCheck + 1; |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5572 | static constexpr size_t kFlagIsInBootImage = kFlagIsInDexCache + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5573 | // Whether this instruction must generate the initialization check. |
| 5574 | // Used for code generation. |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5575 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInBootImage + 1; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5576 | static constexpr size_t kFieldLoadKind = kFlagGenerateClInitCheck + 1; |
| 5577 | static constexpr size_t kFieldLoadKindSize = |
| 5578 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 5579 | static constexpr size_t kNumberOfLoadClassPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5580 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5581 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
| 5582 | |
| 5583 | static bool HasTypeReference(LoadKind load_kind) { |
| 5584 | return load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5585 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
| 5586 | load_kind == LoadKind::kDexCacheViaMethod || |
| 5587 | load_kind == LoadKind::kReferrersClass; |
| 5588 | } |
| 5589 | |
| 5590 | static bool HasAddress(LoadKind load_kind) { |
| 5591 | return load_kind == LoadKind::kBootImageAddress || load_kind == LoadKind::kDexCacheAddress; |
| 5592 | } |
| 5593 | |
| 5594 | static bool HasDexCacheReference(LoadKind load_kind) { |
| 5595 | return load_kind == LoadKind::kDexCachePcRelative; |
| 5596 | } |
| 5597 | |
| 5598 | void SetLoadKindInternal(LoadKind load_kind); |
| 5599 | |
| 5600 | // The special input is the HCurrentMethod for kDexCacheViaMethod or kReferrersClass. |
| 5601 | // For other load kinds it's empty or possibly some architecture-specific instruction |
| 5602 | // for PC-relative loads, i.e. kDexCachePcRelative or kBootImageLinkTimePcRelative. |
| 5603 | HUserRecord<HInstruction*> special_input_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5604 | |
| 5605 | const uint16_t type_index_; |
| 5606 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5607 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5608 | union { |
| 5609 | uint32_t dex_cache_element_index; // Only for dex cache reference. |
| 5610 | uint64_t address; // Up to 64-bit, needed for kDexCacheAddress on 64-bit targets. |
| 5611 | } load_data_; |
| 5612 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5613 | ReferenceTypeInfo loaded_class_rti_; |
| 5614 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5615 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 5616 | }; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5617 | std::ostream& operator<<(std::ostream& os, HLoadClass::LoadKind rhs); |
| 5618 | |
| 5619 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
| 5620 | inline uint32_t HLoadClass::GetDexCacheElementOffset() const { |
| 5621 | DCHECK(HasDexCacheReference(GetLoadKind())) << GetLoadKind(); |
| 5622 | return load_data_.dex_cache_element_index; |
| 5623 | } |
| 5624 | |
| 5625 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
| 5626 | inline void HLoadClass::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5627 | // The special input is used for PC-relative loads on some architectures, |
| 5628 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5629 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5630 | GetLoadKind() == LoadKind::kDexCachePcRelative || |
| 5631 | GetLoadKind() == LoadKind::kBootImageLinkTimeAddress || |
| 5632 | GetLoadKind() == LoadKind::kBootImageAddress) << GetLoadKind(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5633 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 5634 | special_input_ = HUserRecord<HInstruction*>(special_input); |
| 5635 | special_input->AddUseAt(this, 0); |
| 5636 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5637 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5638 | class HLoadString FINAL : public HInstruction { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5639 | public: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5640 | // Determines how to load the String. |
| 5641 | enum class LoadKind { |
| 5642 | // Use boot image String* address that will be known at link time. |
| 5643 | // Used for boot image strings referenced by boot image code in non-PIC mode. |
| 5644 | kBootImageLinkTimeAddress, |
| 5645 | |
| 5646 | // Use PC-relative boot image String* address that will be known at link time. |
| 5647 | // Used for boot image strings referenced by boot image code in PIC mode. |
| 5648 | kBootImageLinkTimePcRelative, |
| 5649 | |
| 5650 | // Use a known boot image String* address, embedded in the code by the codegen. |
| 5651 | // Used for boot image strings referenced by apps in AOT- and JIT-compiled code. |
| 5652 | // Note: codegen needs to emit a linker patch if indicated by compiler options' |
| 5653 | // GetIncludePatchInformation(). |
| 5654 | kBootImageAddress, |
| 5655 | |
| 5656 | // Load from the resolved strings array at an absolute address. |
| 5657 | // Used for strings outside the boot image referenced by JIT-compiled code. |
| 5658 | kDexCacheAddress, |
| 5659 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5660 | // Load from an entry in the .bss section using a PC-relative load. |
| 5661 | // Used for strings outside boot image when .bss is accessible with a PC-relative load. |
| 5662 | kBssEntry, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5663 | |
| 5664 | // Load from resolved strings array accessed through the class loaded from |
| 5665 | // the compiled method's own ArtMethod*. This is the default access type when |
| 5666 | // all other types are unavailable. |
| 5667 | kDexCacheViaMethod, |
| 5668 | |
| 5669 | kLast = kDexCacheViaMethod |
| 5670 | }; |
| 5671 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5672 | HLoadString(HCurrentMethod* current_method, |
| 5673 | uint32_t string_index, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5674 | const DexFile& dex_file, |
| 5675 | uint32_t dex_pc) |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5676 | : HInstruction(SideEffectsForArchRuntimeCalls(), dex_pc), |
| 5677 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5678 | string_index_(string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5679 | SetPackedFlag<kFlagIsInDexCache>(false); |
| 5680 | SetPackedField<LoadKindField>(LoadKind::kDexCacheViaMethod); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5681 | load_data_.dex_file_ = &dex_file; |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5682 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5683 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5684 | void SetLoadKindWithAddress(LoadKind load_kind, uint64_t address) { |
| 5685 | DCHECK(HasAddress(load_kind)); |
| 5686 | load_data_.address = address; |
| 5687 | SetLoadKindInternal(load_kind); |
| 5688 | } |
| 5689 | |
| 5690 | void SetLoadKindWithStringReference(LoadKind load_kind, |
| 5691 | const DexFile& dex_file, |
| 5692 | uint32_t string_index) { |
| 5693 | DCHECK(HasStringReference(load_kind)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5694 | load_data_.dex_file_ = &dex_file; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5695 | string_index_ = string_index; |
| 5696 | SetLoadKindInternal(load_kind); |
| 5697 | } |
| 5698 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5699 | LoadKind GetLoadKind() const { |
| 5700 | return GetPackedField<LoadKindField>(); |
| 5701 | } |
| 5702 | |
| 5703 | const DexFile& GetDexFile() const; |
| 5704 | |
| 5705 | uint32_t GetStringIndex() const { |
| 5706 | DCHECK(HasStringReference(GetLoadKind()) || /* For slow paths. */ !IsInDexCache()); |
| 5707 | return string_index_; |
| 5708 | } |
| 5709 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5710 | uint64_t GetAddress() const { |
| 5711 | DCHECK(HasAddress(GetLoadKind())); |
| 5712 | return load_data_.address; |
| 5713 | } |
| 5714 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5715 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5716 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5717 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5718 | |
| 5719 | size_t ComputeHashCode() const OVERRIDE { return string_index_; } |
| 5720 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5721 | // Will call the runtime if we need to load the string through |
| 5722 | // the dex cache and the string is not guaranteed to be there yet. |
| 5723 | bool NeedsEnvironment() const OVERRIDE { |
| 5724 | LoadKind load_kind = GetLoadKind(); |
| 5725 | if (load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5726 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
| 5727 | load_kind == LoadKind::kBootImageAddress) { |
| 5728 | return false; |
| 5729 | } |
| 5730 | return !IsInDexCache(); |
| 5731 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5732 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5733 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
| 5734 | return GetLoadKind() == LoadKind::kDexCacheViaMethod; |
| 5735 | } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5736 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 5737 | bool CanBeNull() const OVERRIDE { return false; } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5738 | bool CanThrow() const OVERRIDE { return NeedsEnvironment(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5739 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5740 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5741 | return SideEffects::CanTriggerGC(); |
| 5742 | } |
| 5743 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5744 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
| 5745 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5746 | void MarkInDexCache() { |
| 5747 | SetPackedFlag<kFlagIsInDexCache>(true); |
| 5748 | DCHECK(!NeedsEnvironment()); |
| 5749 | RemoveEnvironment(); |
Vladimir Marko | ace7a00 | 2016-04-05 11:18:49 +0100 | [diff] [blame] | 5750 | SetSideEffects(SideEffects::None()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5751 | } |
| 5752 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5753 | void AddSpecialInput(HInstruction* special_input); |
| 5754 | |
| 5755 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 5756 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 5757 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 5758 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5759 | } |
| 5760 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5761 | Primitive::Type GetType() const OVERRIDE { |
| 5762 | return Primitive::kPrimNot; |
| 5763 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5764 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5765 | DECLARE_INSTRUCTION(LoadString); |
| 5766 | |
| 5767 | private: |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5768 | static constexpr size_t kFlagIsInDexCache = kNumberOfGenericPackedBits; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5769 | static constexpr size_t kFieldLoadKind = kFlagIsInDexCache + 1; |
| 5770 | static constexpr size_t kFieldLoadKindSize = |
| 5771 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 5772 | static constexpr size_t kNumberOfLoadStringPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5773 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5774 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5775 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5776 | static bool HasStringReference(LoadKind load_kind) { |
| 5777 | return load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5778 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5779 | load_kind == LoadKind::kBssEntry || |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5780 | load_kind == LoadKind::kDexCacheViaMethod; |
| 5781 | } |
| 5782 | |
| 5783 | static bool HasAddress(LoadKind load_kind) { |
| 5784 | return load_kind == LoadKind::kBootImageAddress || load_kind == LoadKind::kDexCacheAddress; |
| 5785 | } |
| 5786 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5787 | void SetLoadKindInternal(LoadKind load_kind); |
| 5788 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5789 | // The special input is the HCurrentMethod for kDexCacheViaMethod. |
| 5790 | // For other load kinds it's empty or possibly some architecture-specific instruction |
| 5791 | // for PC-relative loads, i.e. kDexCachePcRelative or kBootImageLinkTimePcRelative. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5792 | HUserRecord<HInstruction*> special_input_; |
| 5793 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5794 | // String index serves also as the hash code and it's also needed for slow-paths, |
| 5795 | // so it must not be overwritten with other load data. |
| 5796 | uint32_t string_index_; |
| 5797 | |
| 5798 | union { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5799 | const DexFile* dex_file_; // For string reference. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5800 | uint64_t address; // Up to 64-bit, needed for kDexCacheAddress on 64-bit targets. |
| 5801 | } load_data_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5802 | |
| 5803 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 5804 | }; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5805 | std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs); |
| 5806 | |
| 5807 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5808 | inline const DexFile& HLoadString::GetDexFile() const { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5809 | DCHECK(HasStringReference(GetLoadKind())) << GetLoadKind(); |
| 5810 | return *load_data_.dex_file_; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5811 | } |
| 5812 | |
| 5813 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5814 | inline void HLoadString::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5815 | // The special input is used for PC-relative loads on some architectures, |
| 5816 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5817 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5818 | GetLoadKind() == LoadKind::kBssEntry || |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5819 | GetLoadKind() == LoadKind::kBootImageLinkTimeAddress || |
| 5820 | GetLoadKind() == LoadKind::kBootImageAddress) << GetLoadKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5821 | // HLoadString::GetInputRecords() returns an empty array at this point, |
| 5822 | // so use the GetInputRecords() from the base class to set the input record. |
| 5823 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 5824 | special_input_ = HUserRecord<HInstruction*>(special_input); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5825 | special_input->AddUseAt(this, 0); |
| 5826 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5827 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5828 | /** |
| 5829 | * Performs an initialization check on its Class object input. |
| 5830 | */ |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5831 | class HClinitCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5832 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 5833 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 5834 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5835 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5836 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 5837 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5838 | SetRawInputAt(0, constant); |
| 5839 | } |
| 5840 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5841 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5842 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5843 | return true; |
| 5844 | } |
| 5845 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5846 | bool NeedsEnvironment() const OVERRIDE { |
| 5847 | // May call runtime to initialize the class. |
| 5848 | return true; |
| 5849 | } |
| 5850 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 5851 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5852 | |
| 5853 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 5854 | |
| 5855 | DECLARE_INSTRUCTION(ClinitCheck); |
| 5856 | |
| 5857 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5858 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 5859 | }; |
| 5860 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5861 | class HStaticFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5862 | public: |
| 5863 | HStaticFieldGet(HInstruction* cls, |
| 5864 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5865 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5866 | bool is_volatile, |
| 5867 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5868 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5869 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5870 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5871 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5872 | : HExpression(field_type, SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5873 | field_info_(field_offset, |
| 5874 | field_type, |
| 5875 | is_volatile, |
| 5876 | field_idx, |
| 5877 | declaring_class_def_index, |
| 5878 | dex_file, |
| 5879 | dex_cache) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5880 | SetRawInputAt(0, cls); |
| 5881 | } |
| 5882 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5883 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5884 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5885 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5886 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 5887 | const HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5888 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5889 | } |
| 5890 | |
| 5891 | size_t ComputeHashCode() const OVERRIDE { |
| 5892 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5893 | } |
| 5894 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5895 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5896 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5897 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5898 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5899 | |
| 5900 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 5901 | |
| 5902 | private: |
| 5903 | const FieldInfo field_info_; |
| 5904 | |
| 5905 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 5906 | }; |
| 5907 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5908 | class HStaticFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5909 | public: |
| 5910 | HStaticFieldSet(HInstruction* cls, |
| 5911 | HInstruction* value, |
| 5912 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5913 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5914 | bool is_volatile, |
| 5915 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5916 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5917 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5918 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5919 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5920 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5921 | field_info_(field_offset, |
| 5922 | field_type, |
| 5923 | is_volatile, |
| 5924 | field_idx, |
| 5925 | declaring_class_def_index, |
| 5926 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5927 | dex_cache) { |
| 5928 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5929 | SetRawInputAt(0, cls); |
| 5930 | SetRawInputAt(1, value); |
| 5931 | } |
| 5932 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5933 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5934 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5935 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5936 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5937 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5938 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5939 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5940 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5941 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5942 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 5943 | |
| 5944 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5945 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5946 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5947 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5948 | "Too many packed fields."); |
| 5949 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5950 | const FieldInfo field_info_; |
| 5951 | |
| 5952 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 5953 | }; |
| 5954 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5955 | class HUnresolvedInstanceFieldGet FINAL : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5956 | public: |
| 5957 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 5958 | Primitive::Type field_type, |
| 5959 | uint32_t field_index, |
| 5960 | uint32_t dex_pc) |
| 5961 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5962 | field_index_(field_index) { |
| 5963 | SetRawInputAt(0, obj); |
| 5964 | } |
| 5965 | |
| 5966 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5967 | bool CanThrow() const OVERRIDE { return true; } |
| 5968 | |
| 5969 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5970 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5971 | |
| 5972 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 5973 | |
| 5974 | private: |
| 5975 | const uint32_t field_index_; |
| 5976 | |
| 5977 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 5978 | }; |
| 5979 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5980 | class HUnresolvedInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5981 | public: |
| 5982 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 5983 | HInstruction* value, |
| 5984 | Primitive::Type field_type, |
| 5985 | uint32_t field_index, |
| 5986 | uint32_t dex_pc) |
| 5987 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5988 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5989 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 5990 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5991 | SetRawInputAt(0, obj); |
| 5992 | SetRawInputAt(1, value); |
| 5993 | } |
| 5994 | |
| 5995 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5996 | bool CanThrow() const OVERRIDE { return true; } |
| 5997 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5998 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5999 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6000 | |
| 6001 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 6002 | |
| 6003 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6004 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6005 | static constexpr size_t kFieldFieldTypeSize = |
| 6006 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 6007 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6008 | kFieldFieldType + kFieldFieldTypeSize; |
| 6009 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6010 | "Too many packed fields."); |
| 6011 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 6012 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6013 | const uint32_t field_index_; |
| 6014 | |
| 6015 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 6016 | }; |
| 6017 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6018 | class HUnresolvedStaticFieldGet FINAL : public HExpression<0> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6019 | public: |
| 6020 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 6021 | uint32_t field_index, |
| 6022 | uint32_t dex_pc) |
| 6023 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 6024 | field_index_(field_index) { |
| 6025 | } |
| 6026 | |
| 6027 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6028 | bool CanThrow() const OVERRIDE { return true; } |
| 6029 | |
| 6030 | Primitive::Type GetFieldType() const { return GetType(); } |
| 6031 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6032 | |
| 6033 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 6034 | |
| 6035 | private: |
| 6036 | const uint32_t field_index_; |
| 6037 | |
| 6038 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 6039 | }; |
| 6040 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6041 | class HUnresolvedStaticFieldSet FINAL : public HTemplateInstruction<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6042 | public: |
| 6043 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 6044 | Primitive::Type field_type, |
| 6045 | uint32_t field_index, |
| 6046 | uint32_t dex_pc) |
| 6047 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6048 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6049 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 6050 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6051 | SetRawInputAt(0, value); |
| 6052 | } |
| 6053 | |
| 6054 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6055 | bool CanThrow() const OVERRIDE { return true; } |
| 6056 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6057 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6058 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6059 | |
| 6060 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 6061 | |
| 6062 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6063 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6064 | static constexpr size_t kFieldFieldTypeSize = |
| 6065 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 6066 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6067 | kFieldFieldType + kFieldFieldTypeSize; |
| 6068 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6069 | "Too many packed fields."); |
| 6070 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 6071 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6072 | const uint32_t field_index_; |
| 6073 | |
| 6074 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 6075 | }; |
| 6076 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6077 | // Implement the move-exception DEX instruction. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6078 | class HLoadException FINAL : public HExpression<0> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6079 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6080 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 6081 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6082 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 6083 | bool CanBeNull() const OVERRIDE { return false; } |
| 6084 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6085 | DECLARE_INSTRUCTION(LoadException); |
| 6086 | |
| 6087 | private: |
| 6088 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 6089 | }; |
| 6090 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6091 | // Implicit part of move-exception which clears thread-local exception storage. |
| 6092 | // 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] | 6093 | class HClearException FINAL : public HTemplateInstruction<0> { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6094 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6095 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 6096 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6097 | |
| 6098 | DECLARE_INSTRUCTION(ClearException); |
| 6099 | |
| 6100 | private: |
| 6101 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 6102 | }; |
| 6103 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6104 | class HThrow FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6105 | public: |
| 6106 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6107 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6108 | SetRawInputAt(0, exception); |
| 6109 | } |
| 6110 | |
| 6111 | bool IsControlFlow() const OVERRIDE { return true; } |
| 6112 | |
| 6113 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6114 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6115 | bool CanThrow() const OVERRIDE { return true; } |
| 6116 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6117 | |
| 6118 | DECLARE_INSTRUCTION(Throw); |
| 6119 | |
| 6120 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6121 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 6122 | }; |
| 6123 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6124 | /** |
| 6125 | * Implementation strategies for the code generator of a HInstanceOf |
| 6126 | * or `HCheckCast`. |
| 6127 | */ |
| 6128 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6129 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6130 | kExactCheck, // Can do a single class compare. |
| 6131 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 6132 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 6133 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 6134 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6135 | kArrayCheck, // No optimization yet when checking against a generic array. |
| 6136 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6137 | }; |
| 6138 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6139 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 6140 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6141 | class HInstanceOf FINAL : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6142 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6143 | HInstanceOf(HInstruction* object, |
| 6144 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6145 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6146 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6147 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6148 | SideEffectsForArchRuntimeCalls(check_kind), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6149 | dex_pc) { |
| 6150 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6151 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6152 | SetRawInputAt(0, object); |
| 6153 | SetRawInputAt(1, constant); |
| 6154 | } |
| 6155 | |
| 6156 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6157 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6158 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6159 | return true; |
| 6160 | } |
| 6161 | |
| 6162 | bool NeedsEnvironment() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6163 | return CanCallRuntime(GetTypeCheckKind()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6164 | } |
| 6165 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6166 | // Used only in code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6167 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6168 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6169 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6170 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6171 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6172 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 6173 | // Mips currently does runtime calls for any other checks. |
| 6174 | return check_kind != TypeCheckKind::kExactCheck; |
| 6175 | } |
| 6176 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6177 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6178 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6179 | } |
| 6180 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6181 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6182 | |
| 6183 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6184 | static constexpr size_t kFieldTypeCheckKind = kNumberOfExpressionPackedBits; |
| 6185 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6186 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6187 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6188 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagMustDoNullCheck + 1; |
| 6189 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6190 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6191 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6192 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 6193 | }; |
| 6194 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6195 | class HBoundType FINAL : public HExpression<1> { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6196 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 6197 | explicit HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6198 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6199 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 6200 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 6201 | SetPackedFlag<kFlagCanBeNull>(true); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 6202 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6203 | SetRawInputAt(0, input); |
| 6204 | } |
| 6205 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6206 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6207 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6208 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6209 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6210 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6211 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6212 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 6213 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6214 | } |
| 6215 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6216 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6217 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6218 | DECLARE_INSTRUCTION(BoundType); |
| 6219 | |
| 6220 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6221 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 6222 | // is false then CanBeNull() cannot be true). |
| 6223 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfExpressionPackedBits; |
| 6224 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 6225 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 6226 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6227 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6228 | // 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] | 6229 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 6230 | // It is used to bound the type in cases like: |
| 6231 | // if (x instanceof ClassX) { |
| 6232 | // // uper_bound_ will be ClassX |
| 6233 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6234 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6235 | |
| 6236 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 6237 | }; |
| 6238 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6239 | class HCheckCast FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6240 | public: |
| 6241 | HCheckCast(HInstruction* object, |
| 6242 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6243 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6244 | uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6245 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
| 6246 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6247 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6248 | SetRawInputAt(0, object); |
| 6249 | SetRawInputAt(1, constant); |
| 6250 | } |
| 6251 | |
| 6252 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6253 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6254 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6255 | return true; |
| 6256 | } |
| 6257 | |
| 6258 | bool NeedsEnvironment() const OVERRIDE { |
| 6259 | // Instruction may throw a CheckCastError. |
| 6260 | return true; |
| 6261 | } |
| 6262 | |
| 6263 | bool CanThrow() const OVERRIDE { return true; } |
| 6264 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6265 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6266 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6267 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6268 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6269 | |
| 6270 | DECLARE_INSTRUCTION(CheckCast); |
| 6271 | |
| 6272 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6273 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 6274 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6275 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6276 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6277 | static constexpr size_t kNumberOfCheckCastPackedBits = kFlagMustDoNullCheck + 1; |
| 6278 | static_assert(kNumberOfCheckCastPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6279 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6280 | |
| 6281 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6282 | }; |
| 6283 | |
Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame] | 6284 | /** |
| 6285 | * @brief Memory barrier types (see "The JSR-133 Cookbook for Compiler Writers"). |
| 6286 | * @details We define the combined barrier types that are actually required |
| 6287 | * by the Java Memory Model, rather than using exactly the terminology from |
| 6288 | * the JSR-133 cookbook. These should, in many cases, be replaced by acquire/release |
| 6289 | * primitives. Note that the JSR-133 cookbook generally does not deal with |
| 6290 | * store atomicity issues, and the recipes there are not always entirely sufficient. |
| 6291 | * The current recipe is as follows: |
| 6292 | * -# Use AnyStore ~= (LoadStore | StoreStore) ~= release barrier before volatile store. |
| 6293 | * -# Use AnyAny barrier after volatile store. (StoreLoad is as expensive.) |
| 6294 | * -# Use LoadAny barrier ~= (LoadLoad | LoadStore) ~= acquire barrier after each volatile load. |
| 6295 | * -# Use StoreStore barrier after all stores but before return from any constructor whose |
| 6296 | * class has final fields. |
| 6297 | * -# Use NTStoreStore to order non-temporal stores with respect to all later |
| 6298 | * store-to-memory instructions. Only generated together with non-temporal stores. |
| 6299 | */ |
| 6300 | enum MemBarrierKind { |
| 6301 | kAnyStore, |
| 6302 | kLoadAny, |
| 6303 | kStoreStore, |
| 6304 | kAnyAny, |
| 6305 | kNTStoreStore, |
| 6306 | kLastBarrierKind = kNTStoreStore |
| 6307 | }; |
| 6308 | std::ostream& operator<<(std::ostream& os, const MemBarrierKind& kind); |
| 6309 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6310 | class HMemoryBarrier FINAL : public HTemplateInstruction<0> { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6311 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6312 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 6313 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6314 | SideEffects::AllWritesAndReads(), dex_pc) { // Assume write/read on all fields/arrays. |
| 6315 | SetPackedField<BarrierKindField>(barrier_kind); |
| 6316 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6317 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6318 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6319 | |
| 6320 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 6321 | |
| 6322 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6323 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 6324 | static constexpr size_t kFieldBarrierKindSize = |
| 6325 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 6326 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 6327 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 6328 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 6329 | "Too many packed fields."); |
| 6330 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6331 | |
| 6332 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 6333 | }; |
| 6334 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6335 | class HMonitorOperation FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6336 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6337 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6338 | kEnter, |
| 6339 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6340 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6341 | }; |
| 6342 | |
| 6343 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6344 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6345 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 6346 | dex_pc) { |
| 6347 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6348 | SetRawInputAt(0, object); |
| 6349 | } |
| 6350 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6351 | // Instruction may go into runtime, so we need an environment. |
| 6352 | bool NeedsEnvironment() const OVERRIDE { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 6353 | |
| 6354 | bool CanThrow() const OVERRIDE { |
| 6355 | // Verifier guarantees that monitor-exit cannot throw. |
| 6356 | // This is important because it allows the HGraphBuilder to remove |
| 6357 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 6358 | return IsEnter(); |
| 6359 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6360 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6361 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 6362 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6363 | |
| 6364 | DECLARE_INSTRUCTION(MonitorOperation); |
| 6365 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6366 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6367 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 6368 | static constexpr size_t kFieldOperationKindSize = |
| 6369 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 6370 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 6371 | kFieldOperationKind + kFieldOperationKindSize; |
| 6372 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6373 | "Too many packed fields."); |
| 6374 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6375 | |
| 6376 | private: |
| 6377 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 6378 | }; |
| 6379 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6380 | class HSelect FINAL : public HExpression<3> { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6381 | public: |
| 6382 | HSelect(HInstruction* condition, |
| 6383 | HInstruction* true_value, |
| 6384 | HInstruction* false_value, |
| 6385 | uint32_t dex_pc) |
| 6386 | : HExpression(HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
| 6387 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 6388 | |
| 6389 | // First input must be `true_value` or `false_value` to allow codegens to |
| 6390 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 6391 | // that architectures which implement HSelect as a conditional move also |
| 6392 | // will not need to invert the condition. |
| 6393 | SetRawInputAt(0, false_value); |
| 6394 | SetRawInputAt(1, true_value); |
| 6395 | SetRawInputAt(2, condition); |
| 6396 | } |
| 6397 | |
| 6398 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 6399 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 6400 | HInstruction* GetCondition() const { return InputAt(2); } |
| 6401 | |
| 6402 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6403 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 6404 | return true; |
| 6405 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6406 | |
| 6407 | bool CanBeNull() const OVERRIDE { |
| 6408 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 6409 | } |
| 6410 | |
| 6411 | DECLARE_INSTRUCTION(Select); |
| 6412 | |
| 6413 | private: |
| 6414 | DISALLOW_COPY_AND_ASSIGN(HSelect); |
| 6415 | }; |
| 6416 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 6417 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6418 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6419 | MoveOperands(Location source, |
| 6420 | Location destination, |
| 6421 | Primitive::Type type, |
| 6422 | HInstruction* instruction) |
| 6423 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6424 | |
| 6425 | Location GetSource() const { return source_; } |
| 6426 | Location GetDestination() const { return destination_; } |
| 6427 | |
| 6428 | void SetSource(Location value) { source_ = value; } |
| 6429 | void SetDestination(Location value) { destination_ = value; } |
| 6430 | |
| 6431 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 6432 | // destination (but not the source). |
| 6433 | Location MarkPending() { |
| 6434 | DCHECK(!IsPending()); |
| 6435 | Location dest = destination_; |
| 6436 | destination_ = Location::NoLocation(); |
| 6437 | return dest; |
| 6438 | } |
| 6439 | |
| 6440 | void ClearPending(Location dest) { |
| 6441 | DCHECK(IsPending()); |
| 6442 | destination_ = dest; |
| 6443 | } |
| 6444 | |
| 6445 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6446 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 6447 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6448 | } |
| 6449 | |
| 6450 | // True if this blocks a move from the given location. |
| 6451 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 6452 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6453 | } |
| 6454 | |
| 6455 | // A move is redundant if it's been eliminated, if its source and |
| 6456 | // destination are the same, or if its destination is unneeded. |
| 6457 | bool IsRedundant() const { |
| 6458 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 6459 | } |
| 6460 | |
| 6461 | // We clear both operands to indicate move that's been eliminated. |
| 6462 | void Eliminate() { |
| 6463 | source_ = destination_ = Location::NoLocation(); |
| 6464 | } |
| 6465 | |
| 6466 | bool IsEliminated() const { |
| 6467 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 6468 | return source_.IsInvalid(); |
| 6469 | } |
| 6470 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6471 | Primitive::Type GetType() const { return type_; } |
| 6472 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6473 | bool Is64BitMove() const { |
| 6474 | return Primitive::Is64BitType(type_); |
| 6475 | } |
| 6476 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6477 | HInstruction* GetInstruction() const { return instruction_; } |
| 6478 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6479 | private: |
| 6480 | Location source_; |
| 6481 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6482 | // The type this move is for. |
| 6483 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6484 | // The instruction this move is assocatied with. Null when this move is |
| 6485 | // for moving an input in the expected locations of user (including a phi user). |
| 6486 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 6487 | // in the same parallel move. |
| 6488 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6489 | }; |
| 6490 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6491 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 6492 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6493 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 6494 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6495 | class HParallelMove FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6496 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6497 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6498 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 6499 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 6500 | moves_.reserve(kDefaultNumberOfMoves); |
| 6501 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6502 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6503 | void AddMove(Location source, |
| 6504 | Location destination, |
| 6505 | Primitive::Type type, |
| 6506 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6507 | DCHECK(source.IsValid()); |
| 6508 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6509 | if (kIsDebugBuild) { |
| 6510 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6511 | for (const MoveOperands& move : moves_) { |
| 6512 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6513 | // Special case the situation where the move is for the spill slot |
| 6514 | // of the instruction. |
| 6515 | if ((GetPrevious() == instruction) |
| 6516 | || ((GetPrevious() == nullptr) |
| 6517 | && instruction->IsPhi() |
| 6518 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6519 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6520 | << "Doing parallel moves for the same instruction."; |
| 6521 | } else { |
| 6522 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 6523 | } |
| 6524 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 6525 | } |
| 6526 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6527 | for (const MoveOperands& move : moves_) { |
| 6528 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6529 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6530 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6531 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6532 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6533 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6534 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6535 | } |
| 6536 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6537 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6538 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6539 | } |
| 6540 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6541 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6542 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 6543 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6544 | |
| 6545 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6546 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6547 | |
| 6548 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 6549 | }; |
| 6550 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6551 | } // namespace art |
| 6552 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 6553 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 6554 | #include "nodes_shared.h" |
| 6555 | #endif |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6556 | #ifdef ART_ENABLE_CODEGEN_arm |
| 6557 | #include "nodes_arm.h" |
| 6558 | #endif |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6559 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| 6560 | #include "nodes_arm64.h" |
| 6561 | #endif |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6562 | #ifdef ART_ENABLE_CODEGEN_mips |
| 6563 | #include "nodes_mips.h" |
| 6564 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6565 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 6566 | #include "nodes_x86.h" |
| 6567 | #endif |
| 6568 | |
| 6569 | namespace art { |
| 6570 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6571 | class HGraphVisitor : public ValueObject { |
| 6572 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 6573 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 6574 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6575 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6576 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6577 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 6578 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6579 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6580 | void VisitInsertionOrder(); |
| 6581 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6582 | // Visit the graph following dominator tree reverse post-order. |
| 6583 | void VisitReversePostOrder(); |
| 6584 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 6585 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 6586 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6587 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6588 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6589 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 6590 | |
| 6591 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6592 | |
| 6593 | #undef DECLARE_VISIT_INSTRUCTION |
| 6594 | |
| 6595 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 6596 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6597 | |
| 6598 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 6599 | }; |
| 6600 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6601 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 6602 | public: |
| 6603 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 6604 | virtual ~HGraphDelegateVisitor() {} |
| 6605 | |
| 6606 | // Visit functions that delegate to to super class. |
| 6607 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6608 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6609 | |
| 6610 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6611 | |
| 6612 | #undef DECLARE_VISIT_INSTRUCTION |
| 6613 | |
| 6614 | private: |
| 6615 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 6616 | }; |
| 6617 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6618 | class HInsertionOrderIterator : public ValueObject { |
| 6619 | public: |
| 6620 | explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {} |
| 6621 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6622 | bool Done() const { return index_ == graph_.GetBlocks().size(); } |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 6623 | HBasicBlock* Current() const { return graph_.GetBlocks()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6624 | void Advance() { ++index_; } |
| 6625 | |
| 6626 | private: |
| 6627 | const HGraph& graph_; |
| 6628 | size_t index_; |
| 6629 | |
| 6630 | DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator); |
| 6631 | }; |
| 6632 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6633 | class HReversePostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6634 | public: |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6635 | explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) { |
| 6636 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6637 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6638 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6639 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6640 | bool Done() const { return index_ == graph_.GetReversePostOrder().size(); } |
| 6641 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6642 | void Advance() { ++index_; } |
| 6643 | |
| 6644 | private: |
| 6645 | const HGraph& graph_; |
| 6646 | size_t index_; |
| 6647 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6648 | DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6649 | }; |
| 6650 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6651 | class HPostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6652 | public: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6653 | explicit HPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6654 | : graph_(graph), index_(graph_.GetReversePostOrder().size()) { |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6655 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6656 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6657 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6658 | |
| 6659 | bool Done() const { return index_ == 0; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6660 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_ - 1u]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6661 | void Advance() { --index_; } |
| 6662 | |
| 6663 | private: |
| 6664 | const HGraph& graph_; |
| 6665 | size_t index_; |
| 6666 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6667 | DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6668 | }; |
| 6669 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6670 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6671 | // of an inner loop. The order in which the blocks are iterated is on their |
| 6672 | // block id. |
| 6673 | class HBlocksInLoopIterator : public ValueObject { |
| 6674 | public: |
| 6675 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 6676 | : blocks_in_loop_(info.GetBlocks()), |
| 6677 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 6678 | index_(0) { |
| 6679 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 6680 | Advance(); |
| 6681 | } |
| 6682 | } |
| 6683 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6684 | bool Done() const { return index_ == blocks_.size(); } |
| 6685 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6686 | void Advance() { |
| 6687 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6688 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6689 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 6690 | break; |
| 6691 | } |
| 6692 | } |
| 6693 | } |
| 6694 | |
| 6695 | private: |
| 6696 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6697 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6698 | size_t index_; |
| 6699 | |
| 6700 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 6701 | }; |
| 6702 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6703 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6704 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 6705 | // post order. |
| 6706 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 6707 | public: |
| 6708 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 6709 | : blocks_in_loop_(info.GetBlocks()), |
| 6710 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 6711 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6712 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6713 | Advance(); |
| 6714 | } |
| 6715 | } |
| 6716 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6717 | bool Done() const { return index_ == blocks_.size(); } |
| 6718 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6719 | void Advance() { |
| 6720 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6721 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 6722 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6723 | break; |
| 6724 | } |
| 6725 | } |
| 6726 | } |
| 6727 | |
| 6728 | private: |
| 6729 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6730 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6731 | size_t index_; |
| 6732 | |
| 6733 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 6734 | }; |
| 6735 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6736 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6737 | if (constant->IsIntConstant()) { |
| 6738 | return constant->AsIntConstant()->GetValue(); |
| 6739 | } else if (constant->IsLongConstant()) { |
| 6740 | return constant->AsLongConstant()->GetValue(); |
| 6741 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6742 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6743 | return 0; |
| 6744 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6745 | } |
| 6746 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6747 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 6748 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } \ |
| 6749 | inline const H##type* HInstruction::As##type() const { \ |
| 6750 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 6751 | } \ |
| 6752 | inline H##type* HInstruction::As##type() { \ |
| 6753 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 6754 | } |
| 6755 | |
| 6756 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 6757 | #undef INSTRUCTION_TYPE_CHECK |
| 6758 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 6759 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 6760 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 6761 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 6762 | size_t number_of_new_blocks, |
| 6763 | size_t after) { |
| 6764 | DCHECK_LT(after, blocks->size()); |
| 6765 | size_t old_size = blocks->size(); |
| 6766 | size_t new_size = old_size + number_of_new_blocks; |
| 6767 | blocks->resize(new_size); |
| 6768 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 6769 | } |
| 6770 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6771 | } // namespace art |
| 6772 | |
| 6773 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |