Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | #include "code_generator_arm_vixl.h" |
| 18 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 19 | #include "arch/arm/asm_support_arm.h" |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 20 | #include "arch/arm/instruction_set_features_arm.h" |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 21 | #include "arch/arm/jni_frame_arm.h" |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 22 | #include "art_method-inl.h" |
Andreas Gampe | 5678db5 | 2017-06-08 14:11:18 -0700 | [diff] [blame] | 23 | #include "base/bit_utils.h" |
| 24 | #include "base/bit_utils_iterator.h" |
Vladimir Marko | 7968cae | 2021-01-19 12:02:35 +0000 | [diff] [blame] | 25 | #include "class_root-inl.h" |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 26 | #include "class_table.h" |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 27 | #include "code_generator_utils.h" |
| 28 | #include "common_arm.h" |
| 29 | #include "compiled_method.h" |
| 30 | #include "entrypoints/quick/quick_entrypoints.h" |
| 31 | #include "gc/accounting/card_table.h" |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 32 | #include "gc/space/image_space.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 33 | #include "heap_poisoning.h" |
Nicolas Geoffray | 8b8d93d | 2020-09-17 14:30:01 +0100 | [diff] [blame] | 34 | #include "interpreter/mterp/nterp.h" |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 35 | #include "intrinsics.h" |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 36 | #include "intrinsics_arm_vixl.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 37 | #include "linker/linker_patch.h" |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 38 | #include "mirror/array-inl.h" |
| 39 | #include "mirror/class-inl.h" |
Vladimir Marko | ac3fcff | 2020-11-17 12:17:58 +0000 | [diff] [blame] | 40 | #include "mirror/var_handle.h" |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 41 | #include "scoped_thread_state_change-inl.h" |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 42 | #include "thread.h" |
| 43 | #include "utils/arm/assembler_arm_vixl.h" |
| 44 | #include "utils/arm/managed_register_arm.h" |
| 45 | #include "utils/assembler.h" |
| 46 | #include "utils/stack_checks.h" |
| 47 | |
Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 48 | namespace art { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 49 | namespace arm { |
| 50 | |
| 51 | namespace vixl32 = vixl::aarch32; |
| 52 | using namespace vixl32; // NOLINT(build/namespaces) |
| 53 | |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 54 | using helpers::DRegisterFrom; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 55 | using helpers::HighRegisterFrom; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 56 | using helpers::InputDRegisterAt; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 57 | using helpers::InputOperandAt; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 58 | using helpers::InputRegister; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 59 | using helpers::InputRegisterAt; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 60 | using helpers::InputSRegisterAt; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 61 | using helpers::InputVRegister; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 62 | using helpers::InputVRegisterAt; |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 63 | using helpers::Int32ConstantFrom; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 64 | using helpers::Int64ConstantFrom; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 65 | using helpers::LocationFrom; |
| 66 | using helpers::LowRegisterFrom; |
| 67 | using helpers::LowSRegisterFrom; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 68 | using helpers::OperandFrom; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 69 | using helpers::OutputRegister; |
| 70 | using helpers::OutputSRegister; |
| 71 | using helpers::OutputVRegister; |
| 72 | using helpers::RegisterFrom; |
| 73 | using helpers::SRegisterFrom; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 74 | using helpers::Uint64ConstantFrom; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 75 | |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 76 | using vixl::EmissionCheckScope; |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 77 | using vixl::ExactAssemblyScope; |
| 78 | using vixl::CodeBufferCheckScope; |
| 79 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 80 | using RegisterList = vixl32::RegisterList; |
| 81 | |
| 82 | static bool ExpectedPairLayout(Location location) { |
| 83 | // We expected this for both core and fpu register pairs. |
| 84 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 85 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 86 | // Use a local definition to prevent copying mistakes. |
| 87 | static constexpr size_t kArmWordSize = static_cast<size_t>(kArmPointerSize); |
| 88 | static constexpr size_t kArmBitsPerWord = kArmWordSize * kBitsPerByte; |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 89 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 90 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 91 | // Reference load (except object array loads) is using LDR Rt, [Rn, #offset] which can handle |
| 92 | // offset < 4KiB. For offsets >= 4KiB, the load shall be emitted as two or more instructions. |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 93 | // For the Baker read barrier implementation using link-time generated thunks we need to split |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 94 | // the offset explicitly. |
| 95 | constexpr uint32_t kReferenceLoadMinFarOffset = 4 * KB; |
| 96 | |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 97 | // Using a base helps identify when we hit Marking Register check breakpoints. |
| 98 | constexpr int kMarkingRegisterCheckBreakCodeBaseCode = 0x10; |
| 99 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 100 | #ifdef __ |
| 101 | #error "ARM Codegen VIXL macro-assembler macro already defined." |
| 102 | #endif |
| 103 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 104 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 105 | #define __ down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()-> // NOLINT |
| 106 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, x).Int32Value() |
| 107 | |
| 108 | // Marker that code is yet to be, and must, be implemented. |
| 109 | #define TODO_VIXL32(level) LOG(level) << __PRETTY_FUNCTION__ << " unimplemented " |
| 110 | |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 111 | static inline bool CanEmitNarrowLdr(vixl32::Register rt, vixl32::Register rn, uint32_t offset) { |
| 112 | return rt.IsLow() && rn.IsLow() && offset < 32u; |
| 113 | } |
| 114 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 115 | class EmitAdrCode { |
| 116 | public: |
| 117 | EmitAdrCode(ArmVIXLMacroAssembler* assembler, vixl32::Register rd, vixl32::Label* label) |
| 118 | : assembler_(assembler), rd_(rd), label_(label) { |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 119 | DCHECK(!assembler->AllowMacroInstructions()); // In ExactAssemblyScope. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 120 | adr_location_ = assembler->GetCursorOffset(); |
| 121 | assembler->adr(EncodingSize(Wide), rd, label); |
| 122 | } |
| 123 | |
| 124 | ~EmitAdrCode() { |
| 125 | DCHECK(label_->IsBound()); |
| 126 | // The ADR emitted by the assembler does not set the Thumb mode bit we need. |
| 127 | // TODO: Maybe extend VIXL to allow ADR for return address? |
| 128 | uint8_t* raw_adr = assembler_->GetBuffer()->GetOffsetAddress<uint8_t*>(adr_location_); |
| 129 | // Expecting ADR encoding T3 with `(offset & 1) == 0`. |
| 130 | DCHECK_EQ(raw_adr[1] & 0xfbu, 0xf2u); // Check bits 24-31, except 26. |
| 131 | DCHECK_EQ(raw_adr[0] & 0xffu, 0x0fu); // Check bits 16-23. |
| 132 | DCHECK_EQ(raw_adr[3] & 0x8fu, rd_.GetCode()); // Check bits 8-11 and 15. |
| 133 | DCHECK_EQ(raw_adr[2] & 0x01u, 0x00u); // Check bit 0, i.e. the `offset & 1`. |
| 134 | // Add the Thumb mode bit. |
| 135 | raw_adr[2] |= 0x01u; |
| 136 | } |
| 137 | |
| 138 | private: |
| 139 | ArmVIXLMacroAssembler* const assembler_; |
| 140 | vixl32::Register rd_; |
| 141 | vixl32::Label* const label_; |
| 142 | int32_t adr_location_; |
| 143 | }; |
| 144 | |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 145 | static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() { |
| 146 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 147 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 148 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 149 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 150 | // that the the kPrimNot result register is the same as the first argument register. |
| 151 | return caller_saves; |
| 152 | } |
| 153 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 154 | // SaveLiveRegisters and RestoreLiveRegisters from SlowPathCodeARM operate on sets of S registers, |
| 155 | // for each live D registers they treat two corresponding S registers as live ones. |
| 156 | // |
| 157 | // Two following functions (SaveContiguousSRegisterList, RestoreContiguousSRegisterList) build |
| 158 | // from a list of contiguous S registers a list of contiguous D registers (processing first/last |
| 159 | // S registers corner cases) and save/restore this new list treating them as D registers. |
| 160 | // - decreasing code size |
| 161 | // - avoiding hazards on Cortex-A57, when a pair of S registers for an actual live D register is |
| 162 | // restored and then used in regular non SlowPath code as D register. |
| 163 | // |
| 164 | // For the following example (v means the S register is live): |
| 165 | // D names: | D0 | D1 | D2 | D4 | ... |
| 166 | // S names: | S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | ... |
| 167 | // Live? | | v | v | v | v | v | v | | ... |
| 168 | // |
| 169 | // S1 and S6 will be saved/restored independently; D registers list (D1, D2) will be processed |
| 170 | // as D registers. |
| 171 | // |
| 172 | // TODO(VIXL): All this code should be unnecessary once the VIXL AArch32 backend provides helpers |
| 173 | // for lists of floating-point registers. |
| 174 | static size_t SaveContiguousSRegisterList(size_t first, |
| 175 | size_t last, |
| 176 | CodeGenerator* codegen, |
| 177 | size_t stack_offset) { |
| 178 | static_assert(kSRegSizeInBytes == kArmWordSize, "Broken assumption on reg/word sizes."); |
| 179 | static_assert(kDRegSizeInBytes == 2 * kArmWordSize, "Broken assumption on reg/word sizes."); |
| 180 | DCHECK_LE(first, last); |
| 181 | if ((first == last) && (first == 0)) { |
| 182 | __ Vstr(vixl32::SRegister(first), MemOperand(sp, stack_offset)); |
| 183 | return stack_offset + kSRegSizeInBytes; |
| 184 | } |
| 185 | if (first % 2 == 1) { |
| 186 | __ Vstr(vixl32::SRegister(first++), MemOperand(sp, stack_offset)); |
| 187 | stack_offset += kSRegSizeInBytes; |
| 188 | } |
| 189 | |
| 190 | bool save_last = false; |
| 191 | if (last % 2 == 0) { |
| 192 | save_last = true; |
| 193 | --last; |
| 194 | } |
| 195 | |
| 196 | if (first < last) { |
| 197 | vixl32::DRegister d_reg = vixl32::DRegister(first / 2); |
| 198 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 199 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 200 | |
| 201 | if (number_of_d_regs == 1) { |
| 202 | __ Vstr(d_reg, MemOperand(sp, stack_offset)); |
| 203 | } else if (number_of_d_regs > 1) { |
| 204 | UseScratchRegisterScope temps(down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 205 | vixl32::Register base = sp; |
| 206 | if (stack_offset != 0) { |
| 207 | base = temps.Acquire(); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 208 | __ Add(base, sp, Operand::From(stack_offset)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 209 | } |
| 210 | __ Vstm(F64, base, NO_WRITE_BACK, DRegisterList(d_reg, number_of_d_regs)); |
| 211 | } |
| 212 | stack_offset += number_of_d_regs * kDRegSizeInBytes; |
| 213 | } |
| 214 | |
| 215 | if (save_last) { |
| 216 | __ Vstr(vixl32::SRegister(last + 1), MemOperand(sp, stack_offset)); |
| 217 | stack_offset += kSRegSizeInBytes; |
| 218 | } |
| 219 | |
| 220 | return stack_offset; |
| 221 | } |
| 222 | |
| 223 | static size_t RestoreContiguousSRegisterList(size_t first, |
| 224 | size_t last, |
| 225 | CodeGenerator* codegen, |
| 226 | size_t stack_offset) { |
| 227 | static_assert(kSRegSizeInBytes == kArmWordSize, "Broken assumption on reg/word sizes."); |
| 228 | static_assert(kDRegSizeInBytes == 2 * kArmWordSize, "Broken assumption on reg/word sizes."); |
| 229 | DCHECK_LE(first, last); |
| 230 | if ((first == last) && (first == 0)) { |
| 231 | __ Vldr(vixl32::SRegister(first), MemOperand(sp, stack_offset)); |
| 232 | return stack_offset + kSRegSizeInBytes; |
| 233 | } |
| 234 | if (first % 2 == 1) { |
| 235 | __ Vldr(vixl32::SRegister(first++), MemOperand(sp, stack_offset)); |
| 236 | stack_offset += kSRegSizeInBytes; |
| 237 | } |
| 238 | |
| 239 | bool restore_last = false; |
| 240 | if (last % 2 == 0) { |
| 241 | restore_last = true; |
| 242 | --last; |
| 243 | } |
| 244 | |
| 245 | if (first < last) { |
| 246 | vixl32::DRegister d_reg = vixl32::DRegister(first / 2); |
| 247 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 248 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 249 | if (number_of_d_regs == 1) { |
| 250 | __ Vldr(d_reg, MemOperand(sp, stack_offset)); |
| 251 | } else if (number_of_d_regs > 1) { |
| 252 | UseScratchRegisterScope temps(down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 253 | vixl32::Register base = sp; |
| 254 | if (stack_offset != 0) { |
| 255 | base = temps.Acquire(); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 256 | __ Add(base, sp, Operand::From(stack_offset)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 257 | } |
| 258 | __ Vldm(F64, base, NO_WRITE_BACK, DRegisterList(d_reg, number_of_d_regs)); |
| 259 | } |
| 260 | stack_offset += number_of_d_regs * kDRegSizeInBytes; |
| 261 | } |
| 262 | |
| 263 | if (restore_last) { |
| 264 | __ Vldr(vixl32::SRegister(last + 1), MemOperand(sp, stack_offset)); |
| 265 | stack_offset += kSRegSizeInBytes; |
| 266 | } |
| 267 | |
| 268 | return stack_offset; |
| 269 | } |
| 270 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 271 | static LoadOperandType GetLoadOperandType(DataType::Type type) { |
| 272 | switch (type) { |
| 273 | case DataType::Type::kReference: |
| 274 | return kLoadWord; |
| 275 | case DataType::Type::kBool: |
| 276 | case DataType::Type::kUint8: |
| 277 | return kLoadUnsignedByte; |
| 278 | case DataType::Type::kInt8: |
| 279 | return kLoadSignedByte; |
| 280 | case DataType::Type::kUint16: |
| 281 | return kLoadUnsignedHalfword; |
| 282 | case DataType::Type::kInt16: |
| 283 | return kLoadSignedHalfword; |
| 284 | case DataType::Type::kInt32: |
| 285 | return kLoadWord; |
| 286 | case DataType::Type::kInt64: |
| 287 | return kLoadWordPair; |
| 288 | case DataType::Type::kFloat32: |
| 289 | return kLoadSWord; |
| 290 | case DataType::Type::kFloat64: |
| 291 | return kLoadDWord; |
| 292 | default: |
| 293 | LOG(FATAL) << "Unreachable type " << type; |
| 294 | UNREACHABLE(); |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | static StoreOperandType GetStoreOperandType(DataType::Type type) { |
| 299 | switch (type) { |
| 300 | case DataType::Type::kReference: |
| 301 | return kStoreWord; |
| 302 | case DataType::Type::kBool: |
| 303 | case DataType::Type::kUint8: |
| 304 | case DataType::Type::kInt8: |
| 305 | return kStoreByte; |
| 306 | case DataType::Type::kUint16: |
| 307 | case DataType::Type::kInt16: |
| 308 | return kStoreHalfword; |
| 309 | case DataType::Type::kInt32: |
| 310 | return kStoreWord; |
| 311 | case DataType::Type::kInt64: |
| 312 | return kStoreWordPair; |
| 313 | case DataType::Type::kFloat32: |
| 314 | return kStoreSWord; |
| 315 | case DataType::Type::kFloat64: |
| 316 | return kStoreDWord; |
| 317 | default: |
| 318 | LOG(FATAL) << "Unreachable type " << type; |
| 319 | UNREACHABLE(); |
| 320 | } |
| 321 | } |
| 322 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 323 | void SlowPathCodeARMVIXL::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 324 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 325 | size_t orig_offset = stack_offset; |
| 326 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 327 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ true); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 328 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 329 | // If the register holds an object, update the stack mask. |
| 330 | if (locations->RegisterContainsObject(i)) { |
| 331 | locations->SetStackBit(stack_offset / kVRegSize); |
| 332 | } |
| 333 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 334 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 335 | saved_core_stack_offsets_[i] = stack_offset; |
| 336 | stack_offset += kArmWordSize; |
| 337 | } |
| 338 | |
| 339 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 340 | arm_codegen->GetAssembler()->StoreRegisterList(core_spills, orig_offset); |
| 341 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 342 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ false); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 343 | orig_offset = stack_offset; |
| 344 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 345 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 346 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 347 | stack_offset += kArmWordSize; |
| 348 | } |
| 349 | |
| 350 | stack_offset = orig_offset; |
| 351 | while (fp_spills != 0u) { |
| 352 | uint32_t begin = CTZ(fp_spills); |
| 353 | uint32_t tmp = fp_spills + (1u << begin); |
| 354 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 355 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 356 | stack_offset = SaveContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 357 | } |
| 358 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 359 | } |
| 360 | |
| 361 | void SlowPathCodeARMVIXL::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 362 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 363 | size_t orig_offset = stack_offset; |
| 364 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 365 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ true); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 366 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 367 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 368 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 369 | stack_offset += kArmWordSize; |
| 370 | } |
| 371 | |
| 372 | // TODO(VIXL): Check the coherency of stack_offset after this with a test. |
| 373 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 374 | arm_codegen->GetAssembler()->LoadRegisterList(core_spills, orig_offset); |
| 375 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 376 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ false); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 377 | while (fp_spills != 0u) { |
| 378 | uint32_t begin = CTZ(fp_spills); |
| 379 | uint32_t tmp = fp_spills + (1u << begin); |
| 380 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 381 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 382 | stack_offset = RestoreContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 383 | } |
| 384 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 385 | } |
| 386 | |
| 387 | class NullCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 388 | public: |
| 389 | explicit NullCheckSlowPathARMVIXL(HNullCheck* instruction) : SlowPathCodeARMVIXL(instruction) {} |
| 390 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 391 | void EmitNativeCode(CodeGenerator* codegen) override { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 392 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 393 | __ Bind(GetEntryLabel()); |
| 394 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 395 | // Live registers will be restored in the catch block if caught. |
| 396 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 397 | } |
| 398 | arm_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 399 | instruction_, |
| 400 | instruction_->GetDexPc(), |
| 401 | this); |
| 402 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| 403 | } |
| 404 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 405 | bool IsFatal() const override { return true; } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 406 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 407 | const char* GetDescription() const override { return "NullCheckSlowPathARMVIXL"; } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 408 | |
| 409 | private: |
| 410 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARMVIXL); |
| 411 | }; |
| 412 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 413 | class DivZeroCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 414 | public: |
| 415 | explicit DivZeroCheckSlowPathARMVIXL(HDivZeroCheck* instruction) |
| 416 | : SlowPathCodeARMVIXL(instruction) {} |
| 417 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 418 | void EmitNativeCode(CodeGenerator* codegen) override { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 419 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 420 | __ Bind(GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 421 | arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 422 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| 423 | } |
| 424 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 425 | bool IsFatal() const override { return true; } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 426 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 427 | const char* GetDescription() const override { return "DivZeroCheckSlowPathARMVIXL"; } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 428 | |
| 429 | private: |
| 430 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARMVIXL); |
| 431 | }; |
| 432 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 433 | class SuspendCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 434 | public: |
| 435 | SuspendCheckSlowPathARMVIXL(HSuspendCheck* instruction, HBasicBlock* successor) |
| 436 | : SlowPathCodeARMVIXL(instruction), successor_(successor) {} |
| 437 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 438 | void EmitNativeCode(CodeGenerator* codegen) override { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 439 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 440 | __ Bind(GetEntryLabel()); |
| 441 | arm_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
| 442 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
| 443 | if (successor_ == nullptr) { |
| 444 | __ B(GetReturnLabel()); |
| 445 | } else { |
| 446 | __ B(arm_codegen->GetLabelOf(successor_)); |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | vixl32::Label* GetReturnLabel() { |
| 451 | DCHECK(successor_ == nullptr); |
| 452 | return &return_label_; |
| 453 | } |
| 454 | |
| 455 | HBasicBlock* GetSuccessor() const { |
| 456 | return successor_; |
| 457 | } |
| 458 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 459 | const char* GetDescription() const override { return "SuspendCheckSlowPathARMVIXL"; } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 460 | |
| 461 | private: |
| 462 | // If not null, the block to branch to after the suspend check. |
| 463 | HBasicBlock* const successor_; |
| 464 | |
| 465 | // If `successor_` is null, the label to branch to after the suspend check. |
| 466 | vixl32::Label return_label_; |
| 467 | |
| 468 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARMVIXL); |
| 469 | }; |
| 470 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 471 | class BoundsCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 472 | public: |
| 473 | explicit BoundsCheckSlowPathARMVIXL(HBoundsCheck* instruction) |
| 474 | : SlowPathCodeARMVIXL(instruction) {} |
| 475 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 476 | void EmitNativeCode(CodeGenerator* codegen) override { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 477 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 478 | LocationSummary* locations = instruction_->GetLocations(); |
| 479 | |
| 480 | __ Bind(GetEntryLabel()); |
| 481 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 482 | // Live registers will be restored in the catch block if caught. |
| 483 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 484 | } |
| 485 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 486 | // move resolver. |
| 487 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 488 | codegen->EmitParallelMoves( |
| 489 | locations->InAt(0), |
| 490 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 491 | DataType::Type::kInt32, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 492 | locations->InAt(1), |
| 493 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 494 | DataType::Type::kInt32); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 495 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 496 | ? kQuickThrowStringBounds |
| 497 | : kQuickThrowArrayBounds; |
| 498 | arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
| 499 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
| 500 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| 501 | } |
| 502 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 503 | bool IsFatal() const override { return true; } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 504 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 505 | const char* GetDescription() const override { return "BoundsCheckSlowPathARMVIXL"; } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 506 | |
| 507 | private: |
| 508 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARMVIXL); |
| 509 | }; |
| 510 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 511 | class LoadClassSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 512 | public: |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 513 | LoadClassSlowPathARMVIXL(HLoadClass* cls, HInstruction* at) |
| 514 | : SlowPathCodeARMVIXL(at), cls_(cls) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 515 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 516 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 517 | } |
| 518 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 519 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 520 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 521 | Location out = locations->Out(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 522 | const uint32_t dex_pc = instruction_->GetDexPc(); |
| 523 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); |
| 524 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 525 | |
| 526 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 527 | __ Bind(GetEntryLabel()); |
| 528 | SaveLiveRegisters(codegen, locations); |
| 529 | |
| 530 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 531 | if (must_resolve_type) { |
| 532 | DCHECK(IsSameDexFile(cls_->GetDexFile(), arm_codegen->GetGraph()->GetDexFile())); |
| 533 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 534 | __ Mov(calling_convention.GetRegisterAt(0), type_index.index_); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 535 | if (cls_->NeedsAccessCheck()) { |
| 536 | CheckEntrypointTypes<kQuickResolveTypeAndVerifyAccess, void*, uint32_t>(); |
| 537 | arm_codegen->InvokeRuntime(kQuickResolveTypeAndVerifyAccess, instruction_, dex_pc, this); |
| 538 | } else { |
| 539 | CheckEntrypointTypes<kQuickResolveType, void*, uint32_t>(); |
| 540 | arm_codegen->InvokeRuntime(kQuickResolveType, instruction_, dex_pc, this); |
| 541 | } |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 542 | // If we also must_do_clinit, the resolved type is now in the correct register. |
| 543 | } else { |
| 544 | DCHECK(must_do_clinit); |
| 545 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); |
| 546 | arm_codegen->Move32(LocationFrom(calling_convention.GetRegisterAt(0)), source); |
| 547 | } |
| 548 | if (must_do_clinit) { |
| 549 | arm_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); |
| 550 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | // Move the class to the desired location. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 554 | if (out.IsValid()) { |
| 555 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 556 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
| 557 | } |
| 558 | RestoreLiveRegisters(codegen, locations); |
| 559 | __ B(GetExitLabel()); |
| 560 | } |
| 561 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 562 | const char* GetDescription() const override { return "LoadClassSlowPathARMVIXL"; } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 563 | |
| 564 | private: |
| 565 | // The class this slow path will load. |
| 566 | HLoadClass* const cls_; |
| 567 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 568 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARMVIXL); |
| 569 | }; |
| 570 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 571 | class LoadStringSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 572 | public: |
| 573 | explicit LoadStringSlowPathARMVIXL(HLoadString* instruction) |
| 574 | : SlowPathCodeARMVIXL(instruction) {} |
| 575 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 576 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 577 | DCHECK(instruction_->IsLoadString()); |
| 578 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 579 | LocationSummary* locations = instruction_->GetLocations(); |
| 580 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 581 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 582 | |
| 583 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 584 | __ Bind(GetEntryLabel()); |
| 585 | SaveLiveRegisters(codegen, locations); |
| 586 | |
| 587 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 588 | __ Mov(calling_convention.GetRegisterAt(0), string_index.index_); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 589 | arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 590 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 591 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 592 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
| 593 | RestoreLiveRegisters(codegen, locations); |
| 594 | |
| 595 | __ B(GetExitLabel()); |
| 596 | } |
| 597 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 598 | const char* GetDescription() const override { return "LoadStringSlowPathARMVIXL"; } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 599 | |
| 600 | private: |
| 601 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARMVIXL); |
| 602 | }; |
| 603 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 604 | class TypeCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 605 | public: |
| 606 | TypeCheckSlowPathARMVIXL(HInstruction* instruction, bool is_fatal) |
| 607 | : SlowPathCodeARMVIXL(instruction), is_fatal_(is_fatal) {} |
| 608 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 609 | void EmitNativeCode(CodeGenerator* codegen) override { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 610 | LocationSummary* locations = instruction_->GetLocations(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 611 | DCHECK(instruction_->IsCheckCast() |
| 612 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 613 | |
| 614 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 615 | __ Bind(GetEntryLabel()); |
| 616 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 617 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 618 | SaveLiveRegisters(codegen, locations); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 622 | // move resolver. |
| 623 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 624 | |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 625 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 626 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 627 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 628 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 629 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 630 | DataType::Type::kReference); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 631 | if (instruction_->IsInstanceOf()) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 632 | arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
| 633 | instruction_, |
| 634 | instruction_->GetDexPc(), |
| 635 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 636 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 637 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 638 | } else { |
| 639 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 640 | arm_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 641 | instruction_, |
| 642 | instruction_->GetDexPc(), |
| 643 | this); |
| 644 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | if (!is_fatal_) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 648 | RestoreLiveRegisters(codegen, locations); |
| 649 | __ B(GetExitLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 650 | } |
| 651 | } |
| 652 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 653 | const char* GetDescription() const override { return "TypeCheckSlowPathARMVIXL"; } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 654 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 655 | bool IsFatal() const override { return is_fatal_; } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 656 | |
| 657 | private: |
| 658 | const bool is_fatal_; |
| 659 | |
| 660 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARMVIXL); |
| 661 | }; |
| 662 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 663 | class DeoptimizationSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 664 | public: |
| 665 | explicit DeoptimizationSlowPathARMVIXL(HDeoptimize* instruction) |
| 666 | : SlowPathCodeARMVIXL(instruction) {} |
| 667 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 668 | void EmitNativeCode(CodeGenerator* codegen) override { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 669 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 670 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 671 | LocationSummary* locations = instruction_->GetLocations(); |
| 672 | SaveLiveRegisters(codegen, locations); |
| 673 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 674 | __ Mov(calling_convention.GetRegisterAt(0), |
| 675 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
| 676 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 677 | arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 678 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 679 | } |
| 680 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 681 | const char* GetDescription() const override { return "DeoptimizationSlowPathARMVIXL"; } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 682 | |
| 683 | private: |
| 684 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARMVIXL); |
| 685 | }; |
| 686 | |
| 687 | class ArraySetSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 688 | public: |
| 689 | explicit ArraySetSlowPathARMVIXL(HInstruction* instruction) : SlowPathCodeARMVIXL(instruction) {} |
| 690 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 691 | void EmitNativeCode(CodeGenerator* codegen) override { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 692 | LocationSummary* locations = instruction_->GetLocations(); |
| 693 | __ Bind(GetEntryLabel()); |
| 694 | SaveLiveRegisters(codegen, locations); |
| 695 | |
| 696 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 697 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 698 | parallel_move.AddMove( |
| 699 | locations->InAt(0), |
| 700 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 701 | DataType::Type::kReference, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 702 | nullptr); |
| 703 | parallel_move.AddMove( |
| 704 | locations->InAt(1), |
| 705 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 706 | DataType::Type::kInt32, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 707 | nullptr); |
| 708 | parallel_move.AddMove( |
| 709 | locations->InAt(2), |
| 710 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 711 | DataType::Type::kReference, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 712 | nullptr); |
| 713 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 714 | |
| 715 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 716 | arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| 717 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 718 | RestoreLiveRegisters(codegen, locations); |
| 719 | __ B(GetExitLabel()); |
| 720 | } |
| 721 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 722 | const char* GetDescription() const override { return "ArraySetSlowPathARMVIXL"; } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 723 | |
| 724 | private: |
| 725 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARMVIXL); |
| 726 | }; |
| 727 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 728 | // Slow path generating a read barrier for a heap reference. |
| 729 | class ReadBarrierForHeapReferenceSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 730 | public: |
| 731 | ReadBarrierForHeapReferenceSlowPathARMVIXL(HInstruction* instruction, |
| 732 | Location out, |
| 733 | Location ref, |
| 734 | Location obj, |
| 735 | uint32_t offset, |
| 736 | Location index) |
| 737 | : SlowPathCodeARMVIXL(instruction), |
| 738 | out_(out), |
| 739 | ref_(ref), |
| 740 | obj_(obj), |
| 741 | offset_(offset), |
| 742 | index_(index) { |
| 743 | DCHECK(kEmitCompilerReadBarrier); |
| 744 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 745 | // has been overwritten by (or after) the heap object reference load |
| 746 | // to be instrumented, e.g.: |
| 747 | // |
| 748 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
| 749 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| 750 | // |
| 751 | // In that case, we have lost the information about the original |
| 752 | // object, and the emitted read barrier cannot work properly. |
| 753 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 754 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 755 | } |
| 756 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 757 | void EmitNativeCode(CodeGenerator* codegen) override { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 758 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 759 | LocationSummary* locations = instruction_->GetLocations(); |
| 760 | vixl32::Register reg_out = RegisterFrom(out_); |
| 761 | DCHECK(locations->CanCall()); |
| 762 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.GetCode())); |
| 763 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 764 | instruction_->IsStaticFieldGet() || |
| 765 | instruction_->IsArrayGet() || |
| 766 | instruction_->IsInstanceOf() || |
| 767 | instruction_->IsCheckCast() || |
Vladimir Marko | 94d2c81 | 2020-11-05 10:04:45 +0000 | [diff] [blame] | 768 | (instruction_->IsInvoke() && instruction_->GetLocations()->Intrinsified())) |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 769 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 770 | << instruction_->DebugName(); |
| 771 | // The read barrier instrumentation of object ArrayGet |
| 772 | // instructions does not support the HIntermediateAddress |
| 773 | // instruction. |
| 774 | DCHECK(!(instruction_->IsArrayGet() && |
| 775 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 776 | |
| 777 | __ Bind(GetEntryLabel()); |
| 778 | SaveLiveRegisters(codegen, locations); |
| 779 | |
| 780 | // We may have to change the index's value, but as `index_` is a |
| 781 | // constant member (like other "inputs" of this slow path), |
| 782 | // introduce a copy of it, `index`. |
| 783 | Location index = index_; |
| 784 | if (index_.IsValid()) { |
| 785 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 786 | if (instruction_->IsArrayGet()) { |
| 787 | // Compute the actual memory offset and store it in `index`. |
| 788 | vixl32::Register index_reg = RegisterFrom(index_); |
| 789 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg.GetCode())); |
| 790 | if (codegen->IsCoreCalleeSaveRegister(index_reg.GetCode())) { |
| 791 | // We are about to change the value of `index_reg` (see the |
Roland Levillain | 9983e30 | 2017-07-14 14:34:22 +0100 | [diff] [blame] | 792 | // calls to art::arm::ArmVIXLMacroAssembler::Lsl and |
| 793 | // art::arm::ArmVIXLMacroAssembler::Add below), but it has |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 794 | // not been saved by the previous call to |
| 795 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 796 | // callee-save register -- |
| 797 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 798 | // callee-save registers, as it has been designed with the |
| 799 | // assumption that callee-save registers are supposed to be |
| 800 | // handled by the called function. So, as a callee-save |
| 801 | // register, `index_reg` _would_ eventually be saved onto |
| 802 | // the stack, but it would be too late: we would have |
| 803 | // changed its value earlier. Therefore, we manually save |
| 804 | // it here into another freely available register, |
| 805 | // `free_reg`, chosen of course among the caller-save |
| 806 | // registers (as a callee-save `free_reg` register would |
| 807 | // exhibit the same problem). |
| 808 | // |
| 809 | // Note we could have requested a temporary register from |
| 810 | // the register allocator instead; but we prefer not to, as |
| 811 | // this is a slow path, and we know we can find a |
| 812 | // caller-save register that is available. |
| 813 | vixl32::Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 814 | __ Mov(free_reg, index_reg); |
| 815 | index_reg = free_reg; |
| 816 | index = LocationFrom(index_reg); |
| 817 | } else { |
| 818 | // The initial register stored in `index_` has already been |
| 819 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 820 | // (as it is not a callee-save register), so we can freely |
| 821 | // use it. |
| 822 | } |
| 823 | // Shifting the index value contained in `index_reg` by the scale |
| 824 | // factor (2) cannot overflow in practice, as the runtime is |
| 825 | // unable to allocate object arrays with a size larger than |
| 826 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 827 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 828 | static_assert( |
| 829 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 830 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 831 | __ Add(index_reg, index_reg, offset_); |
| 832 | } else { |
| 833 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 834 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 835 | // (as in the case of ArrayGet), as it is actually an offset |
| 836 | // to an object field within an object. |
| 837 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| 838 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
Vladimir Marko | ac3fcff | 2020-11-17 12:17:58 +0000 | [diff] [blame] | 839 | Intrinsics intrinsic = instruction_->AsInvoke()->GetIntrinsic(); |
| 840 | DCHECK(intrinsic == Intrinsics::kUnsafeGetObject || |
| 841 | intrinsic == Intrinsics::kUnsafeGetObjectVolatile || |
| 842 | mirror::VarHandle::GetAccessModeTemplateByIntrinsic(intrinsic) == |
Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 843 | mirror::VarHandle::AccessModeTemplate::kGet || |
| 844 | mirror::VarHandle::GetAccessModeTemplateByIntrinsic(intrinsic) == |
| 845 | mirror::VarHandle::AccessModeTemplate::kCompareAndSet || |
| 846 | mirror::VarHandle::GetAccessModeTemplateByIntrinsic(intrinsic) == |
Vladimir Marko | 526569a | 2020-11-30 15:48:38 +0000 | [diff] [blame] | 847 | mirror::VarHandle::AccessModeTemplate::kCompareAndExchange || |
| 848 | mirror::VarHandle::GetAccessModeTemplateByIntrinsic(intrinsic) == |
| 849 | mirror::VarHandle::AccessModeTemplate::kGetAndUpdate) |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 850 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 851 | DCHECK_EQ(offset_, 0U); |
Vladimir Marko | ac3fcff | 2020-11-17 12:17:58 +0000 | [diff] [blame] | 852 | // Though UnsafeGet's offset location is a register pair, we only pass the low |
| 853 | // part (high part is irrelevant for 32-bit addresses) to the slow path. |
| 854 | // For VarHandle intrinsics, the index is always just a register. |
| 855 | DCHECK(index_.IsRegister()); |
| 856 | index = index_; |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 857 | } |
| 858 | } |
| 859 | |
| 860 | // We're moving two or three locations to locations that could |
| 861 | // overlap, so we need a parallel move resolver. |
| 862 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 863 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 864 | parallel_move.AddMove(ref_, |
| 865 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 866 | DataType::Type::kReference, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 867 | nullptr); |
| 868 | parallel_move.AddMove(obj_, |
| 869 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 870 | DataType::Type::kReference, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 871 | nullptr); |
| 872 | if (index.IsValid()) { |
| 873 | parallel_move.AddMove(index, |
| 874 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 875 | DataType::Type::kInt32, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 876 | nullptr); |
| 877 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 878 | } else { |
| 879 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 880 | __ Mov(calling_convention.GetRegisterAt(2), offset_); |
| 881 | } |
| 882 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
| 883 | CheckEntrypointTypes< |
| 884 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 885 | arm_codegen->Move32(out_, LocationFrom(r0)); |
| 886 | |
| 887 | RestoreLiveRegisters(codegen, locations); |
| 888 | __ B(GetExitLabel()); |
| 889 | } |
| 890 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 891 | const char* GetDescription() const override { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 892 | return "ReadBarrierForHeapReferenceSlowPathARMVIXL"; |
| 893 | } |
| 894 | |
| 895 | private: |
| 896 | vixl32::Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 897 | uint32_t ref = RegisterFrom(ref_).GetCode(); |
| 898 | uint32_t obj = RegisterFrom(obj_).GetCode(); |
| 899 | for (uint32_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 900 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 901 | return vixl32::Register(i); |
| 902 | } |
| 903 | } |
| 904 | // We shall never fail to find a free caller-save register, as |
| 905 | // there are more than two core caller-save registers on ARM |
| 906 | // (meaning it is possible to find one which is different from |
| 907 | // `ref` and `obj`). |
| 908 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 909 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 910 | UNREACHABLE(); |
| 911 | } |
| 912 | |
| 913 | const Location out_; |
| 914 | const Location ref_; |
| 915 | const Location obj_; |
| 916 | const uint32_t offset_; |
| 917 | // An additional location containing an index to an array. |
| 918 | // Only used for HArrayGet and the UnsafeGetObject & |
| 919 | // UnsafeGetObjectVolatile intrinsics. |
| 920 | const Location index_; |
| 921 | |
| 922 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARMVIXL); |
| 923 | }; |
| 924 | |
| 925 | // Slow path generating a read barrier for a GC root. |
| 926 | class ReadBarrierForRootSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 927 | public: |
| 928 | ReadBarrierForRootSlowPathARMVIXL(HInstruction* instruction, Location out, Location root) |
| 929 | : SlowPathCodeARMVIXL(instruction), out_(out), root_(root) { |
| 930 | DCHECK(kEmitCompilerReadBarrier); |
| 931 | } |
| 932 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 933 | void EmitNativeCode(CodeGenerator* codegen) override { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 934 | LocationSummary* locations = instruction_->GetLocations(); |
| 935 | vixl32::Register reg_out = RegisterFrom(out_); |
| 936 | DCHECK(locations->CanCall()); |
| 937 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.GetCode())); |
Vladimir Marko | ac3fcff | 2020-11-17 12:17:58 +0000 | [diff] [blame] | 938 | DCHECK(instruction_->IsLoadClass() || |
| 939 | instruction_->IsLoadString() || |
| 940 | (instruction_->IsInvoke() && instruction_->GetLocations()->Intrinsified())) |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 941 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 942 | << instruction_->DebugName(); |
| 943 | |
| 944 | __ Bind(GetEntryLabel()); |
| 945 | SaveLiveRegisters(codegen, locations); |
| 946 | |
| 947 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 948 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 949 | arm_codegen->Move32(LocationFrom(calling_convention.GetRegisterAt(0)), root_); |
| 950 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| 951 | instruction_, |
| 952 | instruction_->GetDexPc(), |
| 953 | this); |
| 954 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 955 | arm_codegen->Move32(out_, LocationFrom(r0)); |
| 956 | |
| 957 | RestoreLiveRegisters(codegen, locations); |
| 958 | __ B(GetExitLabel()); |
| 959 | } |
| 960 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 961 | const char* GetDescription() const override { return "ReadBarrierForRootSlowPathARMVIXL"; } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 962 | |
| 963 | private: |
| 964 | const Location out_; |
| 965 | const Location root_; |
| 966 | |
| 967 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARMVIXL); |
| 968 | }; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 969 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 970 | inline vixl32::Condition ARMCondition(IfCondition cond) { |
| 971 | switch (cond) { |
| 972 | case kCondEQ: return eq; |
| 973 | case kCondNE: return ne; |
| 974 | case kCondLT: return lt; |
| 975 | case kCondLE: return le; |
| 976 | case kCondGT: return gt; |
| 977 | case kCondGE: return ge; |
| 978 | case kCondB: return lo; |
| 979 | case kCondBE: return ls; |
| 980 | case kCondA: return hi; |
| 981 | case kCondAE: return hs; |
| 982 | } |
| 983 | LOG(FATAL) << "Unreachable"; |
| 984 | UNREACHABLE(); |
| 985 | } |
| 986 | |
| 987 | // Maps signed condition to unsigned condition. |
| 988 | inline vixl32::Condition ARMUnsignedCondition(IfCondition cond) { |
| 989 | switch (cond) { |
| 990 | case kCondEQ: return eq; |
| 991 | case kCondNE: return ne; |
| 992 | // Signed to unsigned. |
| 993 | case kCondLT: return lo; |
| 994 | case kCondLE: return ls; |
| 995 | case kCondGT: return hi; |
| 996 | case kCondGE: return hs; |
| 997 | // Unsigned remain unchanged. |
| 998 | case kCondB: return lo; |
| 999 | case kCondBE: return ls; |
| 1000 | case kCondA: return hi; |
| 1001 | case kCondAE: return hs; |
| 1002 | } |
| 1003 | LOG(FATAL) << "Unreachable"; |
| 1004 | UNREACHABLE(); |
| 1005 | } |
| 1006 | |
| 1007 | inline vixl32::Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 1008 | // The ARM condition codes can express all the necessary branches, see the |
| 1009 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 1010 | // There is no dex instruction or HIR that would need the missing conditions |
| 1011 | // "equal or unordered" or "not equal". |
| 1012 | switch (cond) { |
| 1013 | case kCondEQ: return eq; |
| 1014 | case kCondNE: return ne /* unordered */; |
| 1015 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 1016 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 1017 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 1018 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 1019 | default: |
| 1020 | LOG(FATAL) << "UNREACHABLE"; |
| 1021 | UNREACHABLE(); |
| 1022 | } |
| 1023 | } |
| 1024 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1025 | inline ShiftType ShiftFromOpKind(HDataProcWithShifterOp::OpKind op_kind) { |
| 1026 | switch (op_kind) { |
| 1027 | case HDataProcWithShifterOp::kASR: return ShiftType::ASR; |
| 1028 | case HDataProcWithShifterOp::kLSL: return ShiftType::LSL; |
| 1029 | case HDataProcWithShifterOp::kLSR: return ShiftType::LSR; |
| 1030 | default: |
| 1031 | LOG(FATAL) << "Unexpected op kind " << op_kind; |
| 1032 | UNREACHABLE(); |
| 1033 | } |
| 1034 | } |
| 1035 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1036 | void CodeGeneratorARMVIXL::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 1037 | stream << vixl32::Register(reg); |
| 1038 | } |
| 1039 | |
| 1040 | void CodeGeneratorARMVIXL::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| 1041 | stream << vixl32::SRegister(reg); |
| 1042 | } |
| 1043 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1044 | const ArmInstructionSetFeatures& CodeGeneratorARMVIXL::GetInstructionSetFeatures() const { |
| 1045 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsArmInstructionSetFeatures(); |
| 1046 | } |
| 1047 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1048 | static uint32_t ComputeSRegisterListMask(const SRegisterList& regs) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1049 | uint32_t mask = 0; |
| 1050 | for (uint32_t i = regs.GetFirstSRegister().GetCode(); |
| 1051 | i <= regs.GetLastSRegister().GetCode(); |
| 1052 | ++i) { |
| 1053 | mask |= (1 << i); |
| 1054 | } |
| 1055 | return mask; |
| 1056 | } |
| 1057 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1058 | // Saves the register in the stack. Returns the size taken on stack. |
| 1059 | size_t CodeGeneratorARMVIXL::SaveCoreRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1060 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1061 | TODO_VIXL32(FATAL); |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 1062 | UNREACHABLE(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | // Restores the register from the stack. Returns the size taken on stack. |
| 1066 | size_t CodeGeneratorARMVIXL::RestoreCoreRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1067 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1068 | TODO_VIXL32(FATAL); |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 1069 | UNREACHABLE(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | size_t CodeGeneratorARMVIXL::SaveFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1073 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1074 | TODO_VIXL32(FATAL); |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 1075 | UNREACHABLE(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | size_t CodeGeneratorARMVIXL::RestoreFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1079 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1080 | TODO_VIXL32(FATAL); |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 1081 | UNREACHABLE(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 1082 | } |
| 1083 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1084 | static void GenerateDataProcInstruction(HInstruction::InstructionKind kind, |
| 1085 | vixl32::Register out, |
| 1086 | vixl32::Register first, |
| 1087 | const Operand& second, |
| 1088 | CodeGeneratorARMVIXL* codegen) { |
| 1089 | if (second.IsImmediate() && second.GetImmediate() == 0) { |
| 1090 | const Operand in = kind == HInstruction::kAnd |
| 1091 | ? Operand(0) |
| 1092 | : Operand(first); |
| 1093 | |
| 1094 | __ Mov(out, in); |
| 1095 | } else { |
| 1096 | switch (kind) { |
| 1097 | case HInstruction::kAdd: |
| 1098 | __ Add(out, first, second); |
| 1099 | break; |
| 1100 | case HInstruction::kAnd: |
| 1101 | __ And(out, first, second); |
| 1102 | break; |
| 1103 | case HInstruction::kOr: |
| 1104 | __ Orr(out, first, second); |
| 1105 | break; |
| 1106 | case HInstruction::kSub: |
| 1107 | __ Sub(out, first, second); |
| 1108 | break; |
| 1109 | case HInstruction::kXor: |
| 1110 | __ Eor(out, first, second); |
| 1111 | break; |
| 1112 | default: |
| 1113 | LOG(FATAL) << "Unexpected instruction kind: " << kind; |
| 1114 | UNREACHABLE(); |
| 1115 | } |
| 1116 | } |
| 1117 | } |
| 1118 | |
| 1119 | static void GenerateDataProc(HInstruction::InstructionKind kind, |
| 1120 | const Location& out, |
| 1121 | const Location& first, |
| 1122 | const Operand& second_lo, |
| 1123 | const Operand& second_hi, |
| 1124 | CodeGeneratorARMVIXL* codegen) { |
| 1125 | const vixl32::Register first_hi = HighRegisterFrom(first); |
| 1126 | const vixl32::Register first_lo = LowRegisterFrom(first); |
| 1127 | const vixl32::Register out_hi = HighRegisterFrom(out); |
| 1128 | const vixl32::Register out_lo = LowRegisterFrom(out); |
| 1129 | |
| 1130 | if (kind == HInstruction::kAdd) { |
| 1131 | __ Adds(out_lo, first_lo, second_lo); |
| 1132 | __ Adc(out_hi, first_hi, second_hi); |
| 1133 | } else if (kind == HInstruction::kSub) { |
| 1134 | __ Subs(out_lo, first_lo, second_lo); |
| 1135 | __ Sbc(out_hi, first_hi, second_hi); |
| 1136 | } else { |
| 1137 | GenerateDataProcInstruction(kind, out_lo, first_lo, second_lo, codegen); |
| 1138 | GenerateDataProcInstruction(kind, out_hi, first_hi, second_hi, codegen); |
| 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | static Operand GetShifterOperand(vixl32::Register rm, ShiftType shift, uint32_t shift_imm) { |
| 1143 | return shift_imm == 0 ? Operand(rm) : Operand(rm, shift, shift_imm); |
| 1144 | } |
| 1145 | |
| 1146 | static void GenerateLongDataProc(HDataProcWithShifterOp* instruction, |
| 1147 | CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1148 | DCHECK_EQ(instruction->GetType(), DataType::Type::kInt64); |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1149 | DCHECK(HDataProcWithShifterOp::IsShiftOp(instruction->GetOpKind())); |
| 1150 | |
| 1151 | const LocationSummary* const locations = instruction->GetLocations(); |
| 1152 | const uint32_t shift_value = instruction->GetShiftAmount(); |
| 1153 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 1154 | const Location first = locations->InAt(0); |
| 1155 | const Location second = locations->InAt(1); |
| 1156 | const Location out = locations->Out(); |
| 1157 | const vixl32::Register first_hi = HighRegisterFrom(first); |
| 1158 | const vixl32::Register first_lo = LowRegisterFrom(first); |
| 1159 | const vixl32::Register out_hi = HighRegisterFrom(out); |
| 1160 | const vixl32::Register out_lo = LowRegisterFrom(out); |
| 1161 | const vixl32::Register second_hi = HighRegisterFrom(second); |
| 1162 | const vixl32::Register second_lo = LowRegisterFrom(second); |
| 1163 | const ShiftType shift = ShiftFromOpKind(instruction->GetOpKind()); |
| 1164 | |
| 1165 | if (shift_value >= 32) { |
| 1166 | if (shift == ShiftType::LSL) { |
| 1167 | GenerateDataProcInstruction(kind, |
| 1168 | out_hi, |
| 1169 | first_hi, |
| 1170 | Operand(second_lo, ShiftType::LSL, shift_value - 32), |
| 1171 | codegen); |
| 1172 | GenerateDataProcInstruction(kind, out_lo, first_lo, 0, codegen); |
| 1173 | } else if (shift == ShiftType::ASR) { |
| 1174 | GenerateDataProc(kind, |
| 1175 | out, |
| 1176 | first, |
| 1177 | GetShifterOperand(second_hi, ShiftType::ASR, shift_value - 32), |
| 1178 | Operand(second_hi, ShiftType::ASR, 31), |
| 1179 | codegen); |
| 1180 | } else { |
| 1181 | DCHECK_EQ(shift, ShiftType::LSR); |
| 1182 | GenerateDataProc(kind, |
| 1183 | out, |
| 1184 | first, |
| 1185 | GetShifterOperand(second_hi, ShiftType::LSR, shift_value - 32), |
| 1186 | 0, |
| 1187 | codegen); |
| 1188 | } |
| 1189 | } else { |
| 1190 | DCHECK_GT(shift_value, 1U); |
| 1191 | DCHECK_LT(shift_value, 32U); |
| 1192 | |
| 1193 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1194 | |
| 1195 | if (shift == ShiftType::LSL) { |
| 1196 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1197 | // Location::kOutputOverlap; not applicable to other cases. |
| 1198 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1199 | GenerateDataProcInstruction(kind, |
| 1200 | out_hi, |
| 1201 | first_hi, |
| 1202 | Operand(second_hi, ShiftType::LSL, shift_value), |
| 1203 | codegen); |
| 1204 | GenerateDataProcInstruction(kind, |
| 1205 | out_hi, |
| 1206 | out_hi, |
| 1207 | Operand(second_lo, ShiftType::LSR, 32 - shift_value), |
| 1208 | codegen); |
| 1209 | GenerateDataProcInstruction(kind, |
| 1210 | out_lo, |
| 1211 | first_lo, |
| 1212 | Operand(second_lo, ShiftType::LSL, shift_value), |
| 1213 | codegen); |
| 1214 | } else { |
| 1215 | const vixl32::Register temp = temps.Acquire(); |
| 1216 | |
| 1217 | __ Lsl(temp, second_hi, shift_value); |
| 1218 | __ Orr(temp, temp, Operand(second_lo, ShiftType::LSR, 32 - shift_value)); |
| 1219 | GenerateDataProc(kind, |
| 1220 | out, |
| 1221 | first, |
| 1222 | Operand(second_lo, ShiftType::LSL, shift_value), |
| 1223 | temp, |
| 1224 | codegen); |
| 1225 | } |
| 1226 | } else { |
| 1227 | DCHECK(shift == ShiftType::ASR || shift == ShiftType::LSR); |
| 1228 | |
| 1229 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1230 | // Location::kOutputOverlap; not applicable to other cases. |
| 1231 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1232 | GenerateDataProcInstruction(kind, |
| 1233 | out_lo, |
| 1234 | first_lo, |
| 1235 | Operand(second_lo, ShiftType::LSR, shift_value), |
| 1236 | codegen); |
| 1237 | GenerateDataProcInstruction(kind, |
| 1238 | out_lo, |
| 1239 | out_lo, |
| 1240 | Operand(second_hi, ShiftType::LSL, 32 - shift_value), |
| 1241 | codegen); |
| 1242 | GenerateDataProcInstruction(kind, |
| 1243 | out_hi, |
| 1244 | first_hi, |
| 1245 | Operand(second_hi, shift, shift_value), |
| 1246 | codegen); |
| 1247 | } else { |
| 1248 | const vixl32::Register temp = temps.Acquire(); |
| 1249 | |
| 1250 | __ Lsr(temp, second_lo, shift_value); |
| 1251 | __ Orr(temp, temp, Operand(second_hi, ShiftType::LSL, 32 - shift_value)); |
| 1252 | GenerateDataProc(kind, |
| 1253 | out, |
| 1254 | first, |
| 1255 | temp, |
| 1256 | Operand(second_hi, shift, shift_value), |
| 1257 | codegen); |
| 1258 | } |
| 1259 | } |
| 1260 | } |
| 1261 | } |
| 1262 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1263 | static void GenerateVcmp(HInstruction* instruction, CodeGeneratorARMVIXL* codegen) { |
| 1264 | const Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1265 | if (rhs_loc.IsConstant()) { |
| 1266 | // 0.0 is the only immediate that can be encoded directly in |
| 1267 | // a VCMP instruction. |
| 1268 | // |
| 1269 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1270 | // specify that in a floating-point comparison, positive zero |
| 1271 | // and negative zero are considered equal, so we can use the |
| 1272 | // literal 0.0 for both cases here. |
| 1273 | // |
| 1274 | // Note however that some methods (Float.equal, Float.compare, |
| 1275 | // Float.compareTo, Double.equal, Double.compare, |
| 1276 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1277 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1278 | // -0.0. So if we ever translate calls to these methods into a |
| 1279 | // HCompare instruction, we must handle the -0.0 case with |
| 1280 | // care here. |
| 1281 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1282 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1283 | const DataType::Type type = instruction->InputAt(0)->GetType(); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1284 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1285 | if (type == DataType::Type::kFloat32) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1286 | __ Vcmp(F32, InputSRegisterAt(instruction, 0), 0.0); |
| 1287 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1288 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1289 | __ Vcmp(F64, InputDRegisterAt(instruction, 0), 0.0); |
| 1290 | } |
| 1291 | } else { |
| 1292 | __ Vcmp(InputVRegisterAt(instruction, 0), InputVRegisterAt(instruction, 1)); |
| 1293 | } |
| 1294 | } |
| 1295 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1296 | static int64_t AdjustConstantForCondition(int64_t value, |
| 1297 | IfCondition* condition, |
| 1298 | IfCondition* opposite) { |
| 1299 | if (value == 1) { |
| 1300 | if (*condition == kCondB) { |
| 1301 | value = 0; |
| 1302 | *condition = kCondEQ; |
| 1303 | *opposite = kCondNE; |
| 1304 | } else if (*condition == kCondAE) { |
| 1305 | value = 0; |
| 1306 | *condition = kCondNE; |
| 1307 | *opposite = kCondEQ; |
| 1308 | } |
| 1309 | } else if (value == -1) { |
| 1310 | if (*condition == kCondGT) { |
| 1311 | value = 0; |
| 1312 | *condition = kCondGE; |
| 1313 | *opposite = kCondLT; |
| 1314 | } else if (*condition == kCondLE) { |
| 1315 | value = 0; |
| 1316 | *condition = kCondLT; |
| 1317 | *opposite = kCondGE; |
| 1318 | } |
| 1319 | } |
| 1320 | |
| 1321 | return value; |
| 1322 | } |
| 1323 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1324 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateLongTestConstant( |
| 1325 | HCondition* condition, |
| 1326 | bool invert, |
| 1327 | CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1328 | DCHECK_EQ(condition->GetLeft()->GetType(), DataType::Type::kInt64); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1329 | |
| 1330 | const LocationSummary* const locations = condition->GetLocations(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1331 | IfCondition cond = condition->GetCondition(); |
| 1332 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1333 | |
| 1334 | if (invert) { |
| 1335 | std::swap(cond, opposite); |
| 1336 | } |
| 1337 | |
| 1338 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1339 | const Location left = locations->InAt(0); |
| 1340 | const Location right = locations->InAt(1); |
| 1341 | |
| 1342 | DCHECK(right.IsConstant()); |
| 1343 | |
| 1344 | const vixl32::Register left_high = HighRegisterFrom(left); |
| 1345 | const vixl32::Register left_low = LowRegisterFrom(left); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1346 | int64_t value = AdjustConstantForCondition(Int64ConstantFrom(right), &cond, &opposite); |
| 1347 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1348 | |
| 1349 | // Comparisons against 0 are common enough to deserve special attention. |
| 1350 | if (value == 0) { |
| 1351 | switch (cond) { |
| 1352 | case kCondNE: |
| 1353 | // x > 0 iff x != 0 when the comparison is unsigned. |
| 1354 | case kCondA: |
| 1355 | ret = std::make_pair(ne, eq); |
| 1356 | FALLTHROUGH_INTENDED; |
| 1357 | case kCondEQ: |
| 1358 | // x <= 0 iff x == 0 when the comparison is unsigned. |
| 1359 | case kCondBE: |
| 1360 | __ Orrs(temps.Acquire(), left_low, left_high); |
| 1361 | return ret; |
| 1362 | case kCondLT: |
| 1363 | case kCondGE: |
| 1364 | __ Cmp(left_high, 0); |
| 1365 | return std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
| 1366 | // Trivially true or false. |
| 1367 | case kCondB: |
| 1368 | ret = std::make_pair(ne, eq); |
| 1369 | FALLTHROUGH_INTENDED; |
| 1370 | case kCondAE: |
| 1371 | __ Cmp(left_low, left_low); |
| 1372 | return ret; |
| 1373 | default: |
| 1374 | break; |
| 1375 | } |
| 1376 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1377 | |
| 1378 | switch (cond) { |
| 1379 | case kCondEQ: |
| 1380 | case kCondNE: |
| 1381 | case kCondB: |
| 1382 | case kCondBE: |
| 1383 | case kCondA: |
| 1384 | case kCondAE: { |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1385 | const uint32_t value_low = Low32Bits(value); |
| 1386 | Operand operand_low(value_low); |
| 1387 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1388 | __ Cmp(left_high, High32Bits(value)); |
| 1389 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1390 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1391 | // we must ensure that the operands corresponding to the least significant |
| 1392 | // halves of the inputs fit into a 16-bit CMP encoding. |
| 1393 | if (!left_low.IsLow() || !IsUint<8>(value_low)) { |
| 1394 | operand_low = Operand(temps.Acquire()); |
| 1395 | __ Mov(LeaveFlags, operand_low.GetBaseRegister(), value_low); |
| 1396 | } |
| 1397 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1398 | // We use the scope because of the IT block that follows. |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1399 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1400 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1401 | CodeBufferCheckScope::kExactSize); |
| 1402 | |
| 1403 | __ it(eq); |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1404 | __ cmp(eq, left_low, operand_low); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1405 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1406 | break; |
| 1407 | } |
| 1408 | case kCondLE: |
| 1409 | case kCondGT: |
| 1410 | // Trivially true or false. |
| 1411 | if (value == std::numeric_limits<int64_t>::max()) { |
| 1412 | __ Cmp(left_low, left_low); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1413 | ret = cond == kCondLE ? std::make_pair(eq, ne) : std::make_pair(ne, eq); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1414 | break; |
| 1415 | } |
| 1416 | |
| 1417 | if (cond == kCondLE) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1418 | DCHECK_EQ(opposite, kCondGT); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1419 | cond = kCondLT; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1420 | opposite = kCondGE; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1421 | } else { |
| 1422 | DCHECK_EQ(cond, kCondGT); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1423 | DCHECK_EQ(opposite, kCondLE); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1424 | cond = kCondGE; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1425 | opposite = kCondLT; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | value++; |
| 1429 | FALLTHROUGH_INTENDED; |
| 1430 | case kCondGE: |
| 1431 | case kCondLT: { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1432 | __ Cmp(left_low, Low32Bits(value)); |
| 1433 | __ Sbcs(temps.Acquire(), left_high, High32Bits(value)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1434 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1435 | break; |
| 1436 | } |
| 1437 | default: |
| 1438 | LOG(FATAL) << "Unreachable"; |
| 1439 | UNREACHABLE(); |
| 1440 | } |
| 1441 | |
| 1442 | return ret; |
| 1443 | } |
| 1444 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1445 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateLongTest( |
| 1446 | HCondition* condition, |
| 1447 | bool invert, |
| 1448 | CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1449 | DCHECK_EQ(condition->GetLeft()->GetType(), DataType::Type::kInt64); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1450 | |
| 1451 | const LocationSummary* const locations = condition->GetLocations(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1452 | IfCondition cond = condition->GetCondition(); |
| 1453 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1454 | |
| 1455 | if (invert) { |
| 1456 | std::swap(cond, opposite); |
| 1457 | } |
| 1458 | |
| 1459 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1460 | Location left = locations->InAt(0); |
| 1461 | Location right = locations->InAt(1); |
| 1462 | |
| 1463 | DCHECK(right.IsRegisterPair()); |
| 1464 | |
| 1465 | switch (cond) { |
| 1466 | case kCondEQ: |
| 1467 | case kCondNE: |
| 1468 | case kCondB: |
| 1469 | case kCondBE: |
| 1470 | case kCondA: |
| 1471 | case kCondAE: { |
| 1472 | __ Cmp(HighRegisterFrom(left), HighRegisterFrom(right)); |
| 1473 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1474 | // We use the scope because of the IT block that follows. |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1475 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1476 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1477 | CodeBufferCheckScope::kExactSize); |
| 1478 | |
| 1479 | __ it(eq); |
| 1480 | __ cmp(eq, LowRegisterFrom(left), LowRegisterFrom(right)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1481 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1482 | break; |
| 1483 | } |
| 1484 | case kCondLE: |
| 1485 | case kCondGT: |
| 1486 | if (cond == kCondLE) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1487 | DCHECK_EQ(opposite, kCondGT); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1488 | cond = kCondGE; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1489 | opposite = kCondLT; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1490 | } else { |
| 1491 | DCHECK_EQ(cond, kCondGT); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1492 | DCHECK_EQ(opposite, kCondLE); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1493 | cond = kCondLT; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1494 | opposite = kCondGE; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | std::swap(left, right); |
| 1498 | FALLTHROUGH_INTENDED; |
| 1499 | case kCondGE: |
| 1500 | case kCondLT: { |
| 1501 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1502 | |
| 1503 | __ Cmp(LowRegisterFrom(left), LowRegisterFrom(right)); |
| 1504 | __ Sbcs(temps.Acquire(), HighRegisterFrom(left), HighRegisterFrom(right)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1505 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1506 | break; |
| 1507 | } |
| 1508 | default: |
| 1509 | LOG(FATAL) << "Unreachable"; |
| 1510 | UNREACHABLE(); |
| 1511 | } |
| 1512 | |
| 1513 | return ret; |
| 1514 | } |
| 1515 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1516 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateTest(HCondition* condition, |
| 1517 | bool invert, |
| 1518 | CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1519 | const DataType::Type type = condition->GetLeft()->GetType(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1520 | IfCondition cond = condition->GetCondition(); |
| 1521 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1522 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1523 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1524 | if (invert) { |
| 1525 | std::swap(cond, opposite); |
| 1526 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1527 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1528 | if (type == DataType::Type::kInt64) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1529 | ret = condition->GetLocations()->InAt(1).IsConstant() |
| 1530 | ? GenerateLongTestConstant(condition, invert, codegen) |
| 1531 | : GenerateLongTest(condition, invert, codegen); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1532 | } else if (DataType::IsFloatingPointType(type)) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1533 | GenerateVcmp(condition, codegen); |
| 1534 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 1535 | ret = std::make_pair(ARMFPCondition(cond, condition->IsGtBias()), |
| 1536 | ARMFPCondition(opposite, condition->IsGtBias())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1537 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1538 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1539 | __ Cmp(InputRegisterAt(condition, 0), InputOperandAt(condition, 1)); |
| 1540 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1541 | } |
| 1542 | |
| 1543 | return ret; |
| 1544 | } |
| 1545 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1546 | static void GenerateConditionGeneric(HCondition* cond, CodeGeneratorARMVIXL* codegen) { |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1547 | const vixl32::Register out = OutputRegister(cond); |
| 1548 | const auto condition = GenerateTest(cond, false, codegen); |
| 1549 | |
| 1550 | __ Mov(LeaveFlags, out, 0); |
| 1551 | |
| 1552 | if (out.IsLow()) { |
| 1553 | // We use the scope because of the IT block that follows. |
| 1554 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1555 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1556 | CodeBufferCheckScope::kExactSize); |
| 1557 | |
| 1558 | __ it(condition.first); |
| 1559 | __ mov(condition.first, out, 1); |
| 1560 | } else { |
| 1561 | vixl32::Label done_label; |
| 1562 | vixl32::Label* const final_label = codegen->GetFinalLabel(cond, &done_label); |
| 1563 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1564 | __ B(condition.second, final_label, /* is_far_target= */ false); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1565 | __ Mov(out, 1); |
| 1566 | |
| 1567 | if (done_label.IsReferenced()) { |
| 1568 | __ Bind(&done_label); |
| 1569 | } |
| 1570 | } |
| 1571 | } |
| 1572 | |
| 1573 | static void GenerateEqualLong(HCondition* cond, CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1574 | DCHECK_EQ(cond->GetLeft()->GetType(), DataType::Type::kInt64); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1575 | |
| 1576 | const LocationSummary* const locations = cond->GetLocations(); |
| 1577 | IfCondition condition = cond->GetCondition(); |
| 1578 | const vixl32::Register out = OutputRegister(cond); |
| 1579 | const Location left = locations->InAt(0); |
| 1580 | const Location right = locations->InAt(1); |
| 1581 | vixl32::Register left_high = HighRegisterFrom(left); |
| 1582 | vixl32::Register left_low = LowRegisterFrom(left); |
| 1583 | vixl32::Register temp; |
| 1584 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1585 | |
| 1586 | if (right.IsConstant()) { |
| 1587 | IfCondition opposite = cond->GetOppositeCondition(); |
| 1588 | const int64_t value = AdjustConstantForCondition(Int64ConstantFrom(right), |
| 1589 | &condition, |
| 1590 | &opposite); |
| 1591 | Operand right_high = High32Bits(value); |
| 1592 | Operand right_low = Low32Bits(value); |
| 1593 | |
| 1594 | // The output uses Location::kNoOutputOverlap. |
| 1595 | if (out.Is(left_high)) { |
| 1596 | std::swap(left_low, left_high); |
| 1597 | std::swap(right_low, right_high); |
| 1598 | } |
| 1599 | |
| 1600 | __ Sub(out, left_low, right_low); |
| 1601 | temp = temps.Acquire(); |
| 1602 | __ Sub(temp, left_high, right_high); |
| 1603 | } else { |
| 1604 | DCHECK(right.IsRegisterPair()); |
| 1605 | temp = temps.Acquire(); |
| 1606 | __ Sub(temp, left_high, HighRegisterFrom(right)); |
| 1607 | __ Sub(out, left_low, LowRegisterFrom(right)); |
| 1608 | } |
| 1609 | |
| 1610 | // Need to check after calling AdjustConstantForCondition(). |
| 1611 | DCHECK(condition == kCondEQ || condition == kCondNE) << condition; |
| 1612 | |
| 1613 | if (condition == kCondNE && out.IsLow()) { |
| 1614 | __ Orrs(out, out, temp); |
| 1615 | |
| 1616 | // We use the scope because of the IT block that follows. |
| 1617 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1618 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1619 | CodeBufferCheckScope::kExactSize); |
| 1620 | |
| 1621 | __ it(ne); |
| 1622 | __ mov(ne, out, 1); |
| 1623 | } else { |
| 1624 | __ Orr(out, out, temp); |
| 1625 | codegen->GenerateConditionWithZero(condition, out, out, temp); |
| 1626 | } |
| 1627 | } |
| 1628 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1629 | static void GenerateConditionLong(HCondition* cond, CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1630 | DCHECK_EQ(cond->GetLeft()->GetType(), DataType::Type::kInt64); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1631 | |
| 1632 | const LocationSummary* const locations = cond->GetLocations(); |
| 1633 | IfCondition condition = cond->GetCondition(); |
| 1634 | const vixl32::Register out = OutputRegister(cond); |
| 1635 | const Location left = locations->InAt(0); |
| 1636 | const Location right = locations->InAt(1); |
| 1637 | |
| 1638 | if (right.IsConstant()) { |
| 1639 | IfCondition opposite = cond->GetOppositeCondition(); |
| 1640 | |
| 1641 | // Comparisons against 0 are common enough to deserve special attention. |
| 1642 | if (AdjustConstantForCondition(Int64ConstantFrom(right), &condition, &opposite) == 0) { |
| 1643 | switch (condition) { |
| 1644 | case kCondNE: |
| 1645 | case kCondA: |
| 1646 | if (out.IsLow()) { |
| 1647 | // We only care if both input registers are 0 or not. |
| 1648 | __ Orrs(out, LowRegisterFrom(left), HighRegisterFrom(left)); |
| 1649 | |
| 1650 | // We use the scope because of the IT block that follows. |
| 1651 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1652 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1653 | CodeBufferCheckScope::kExactSize); |
| 1654 | |
| 1655 | __ it(ne); |
| 1656 | __ mov(ne, out, 1); |
| 1657 | return; |
| 1658 | } |
| 1659 | |
| 1660 | FALLTHROUGH_INTENDED; |
| 1661 | case kCondEQ: |
| 1662 | case kCondBE: |
| 1663 | // We only care if both input registers are 0 or not. |
| 1664 | __ Orr(out, LowRegisterFrom(left), HighRegisterFrom(left)); |
| 1665 | codegen->GenerateConditionWithZero(condition, out, out); |
| 1666 | return; |
| 1667 | case kCondLT: |
| 1668 | case kCondGE: |
| 1669 | // We only care about the sign bit. |
| 1670 | FALLTHROUGH_INTENDED; |
| 1671 | case kCondAE: |
| 1672 | case kCondB: |
| 1673 | codegen->GenerateConditionWithZero(condition, out, HighRegisterFrom(left)); |
| 1674 | return; |
| 1675 | case kCondLE: |
| 1676 | case kCondGT: |
| 1677 | default: |
| 1678 | break; |
| 1679 | } |
| 1680 | } |
| 1681 | } |
| 1682 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1683 | // If `out` is a low register, then the GenerateConditionGeneric() |
| 1684 | // function generates a shorter code sequence that is still branchless. |
| 1685 | if ((condition == kCondEQ || condition == kCondNE) && !out.IsLow()) { |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1686 | GenerateEqualLong(cond, codegen); |
| 1687 | return; |
| 1688 | } |
| 1689 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1690 | GenerateConditionGeneric(cond, codegen); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1691 | } |
| 1692 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 1693 | static void GenerateConditionIntegralOrNonPrimitive(HCondition* cond, |
| 1694 | CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1695 | const DataType::Type type = cond->GetLeft()->GetType(); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1696 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1697 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1698 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1699 | if (type == DataType::Type::kInt64) { |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1700 | GenerateConditionLong(cond, codegen); |
| 1701 | return; |
| 1702 | } |
| 1703 | |
| 1704 | IfCondition condition = cond->GetCondition(); |
| 1705 | vixl32::Register in = InputRegisterAt(cond, 0); |
| 1706 | const vixl32::Register out = OutputRegister(cond); |
| 1707 | const Location right = cond->GetLocations()->InAt(1); |
| 1708 | int64_t value; |
| 1709 | |
| 1710 | if (right.IsConstant()) { |
| 1711 | IfCondition opposite = cond->GetOppositeCondition(); |
| 1712 | |
| 1713 | value = AdjustConstantForCondition(Int64ConstantFrom(right), &condition, &opposite); |
| 1714 | |
| 1715 | // Comparisons against 0 are common enough to deserve special attention. |
| 1716 | if (value == 0) { |
| 1717 | switch (condition) { |
| 1718 | case kCondNE: |
| 1719 | case kCondA: |
| 1720 | if (out.IsLow() && out.Is(in)) { |
| 1721 | __ Cmp(out, 0); |
| 1722 | |
| 1723 | // We use the scope because of the IT block that follows. |
| 1724 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1725 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1726 | CodeBufferCheckScope::kExactSize); |
| 1727 | |
| 1728 | __ it(ne); |
| 1729 | __ mov(ne, out, 1); |
| 1730 | return; |
| 1731 | } |
| 1732 | |
| 1733 | FALLTHROUGH_INTENDED; |
| 1734 | case kCondEQ: |
| 1735 | case kCondBE: |
| 1736 | case kCondLT: |
| 1737 | case kCondGE: |
| 1738 | case kCondAE: |
| 1739 | case kCondB: |
| 1740 | codegen->GenerateConditionWithZero(condition, out, in); |
| 1741 | return; |
| 1742 | case kCondLE: |
| 1743 | case kCondGT: |
| 1744 | default: |
| 1745 | break; |
| 1746 | } |
| 1747 | } |
| 1748 | } |
| 1749 | |
| 1750 | if (condition == kCondEQ || condition == kCondNE) { |
| 1751 | Operand operand(0); |
| 1752 | |
| 1753 | if (right.IsConstant()) { |
| 1754 | operand = Operand::From(value); |
| 1755 | } else if (out.Is(RegisterFrom(right))) { |
| 1756 | // Avoid 32-bit instructions if possible. |
| 1757 | operand = InputOperandAt(cond, 0); |
| 1758 | in = RegisterFrom(right); |
| 1759 | } else { |
| 1760 | operand = InputOperandAt(cond, 1); |
| 1761 | } |
| 1762 | |
| 1763 | if (condition == kCondNE && out.IsLow()) { |
| 1764 | __ Subs(out, in, operand); |
| 1765 | |
| 1766 | // We use the scope because of the IT block that follows. |
| 1767 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1768 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1769 | CodeBufferCheckScope::kExactSize); |
| 1770 | |
| 1771 | __ it(ne); |
| 1772 | __ mov(ne, out, 1); |
| 1773 | } else { |
| 1774 | __ Sub(out, in, operand); |
| 1775 | codegen->GenerateConditionWithZero(condition, out, out); |
| 1776 | } |
| 1777 | |
| 1778 | return; |
| 1779 | } |
| 1780 | |
| 1781 | GenerateConditionGeneric(cond, codegen); |
| 1782 | } |
| 1783 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1784 | static bool CanEncodeConstantAs8BitImmediate(HConstant* constant) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1785 | const DataType::Type type = constant->GetType(); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1786 | bool ret = false; |
| 1787 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1788 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1789 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1790 | if (type == DataType::Type::kInt64) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1791 | const uint64_t value = Uint64ConstantFrom(constant); |
| 1792 | |
| 1793 | ret = IsUint<8>(Low32Bits(value)) && IsUint<8>(High32Bits(value)); |
| 1794 | } else { |
| 1795 | ret = IsUint<8>(Int32ConstantFrom(constant)); |
| 1796 | } |
| 1797 | |
| 1798 | return ret; |
| 1799 | } |
| 1800 | |
| 1801 | static Location Arm8BitEncodableConstantOrRegister(HInstruction* constant) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1802 | DCHECK(!DataType::IsFloatingPointType(constant->GetType())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1803 | |
| 1804 | if (constant->IsConstant() && CanEncodeConstantAs8BitImmediate(constant->AsConstant())) { |
| 1805 | return Location::ConstantLocation(constant->AsConstant()); |
| 1806 | } |
| 1807 | |
| 1808 | return Location::RequiresRegister(); |
| 1809 | } |
| 1810 | |
| 1811 | static bool CanGenerateConditionalMove(const Location& out, const Location& src) { |
| 1812 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1813 | // we check that we are not dealing with floating-point output (there is no |
| 1814 | // 16-bit VMOV encoding). |
| 1815 | if (!out.IsRegister() && !out.IsRegisterPair()) { |
| 1816 | return false; |
| 1817 | } |
| 1818 | |
| 1819 | // For constants, we also check that the output is in one or two low registers, |
| 1820 | // and that the constants fit in an 8-bit unsigned integer, so that a 16-bit |
| 1821 | // MOV encoding can be used. |
| 1822 | if (src.IsConstant()) { |
| 1823 | if (!CanEncodeConstantAs8BitImmediate(src.GetConstant())) { |
| 1824 | return false; |
| 1825 | } |
| 1826 | |
| 1827 | if (out.IsRegister()) { |
| 1828 | if (!RegisterFrom(out).IsLow()) { |
| 1829 | return false; |
| 1830 | } |
| 1831 | } else { |
| 1832 | DCHECK(out.IsRegisterPair()); |
| 1833 | |
| 1834 | if (!HighRegisterFrom(out).IsLow()) { |
| 1835 | return false; |
| 1836 | } |
| 1837 | } |
| 1838 | } |
| 1839 | |
| 1840 | return true; |
| 1841 | } |
| 1842 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1843 | #undef __ |
| 1844 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1845 | vixl32::Label* CodeGeneratorARMVIXL::GetFinalLabel(HInstruction* instruction, |
| 1846 | vixl32::Label* final_label) { |
| 1847 | DCHECK(!instruction->IsControlFlow() && !instruction->IsSuspendCheck()); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 1848 | DCHECK(!instruction->IsInvoke() || !instruction->GetLocations()->CanCall()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1849 | |
| 1850 | const HBasicBlock* const block = instruction->GetBlock(); |
| 1851 | const HLoopInformation* const info = block->GetLoopInformation(); |
| 1852 | HInstruction* const next = instruction->GetNext(); |
| 1853 | |
| 1854 | // Avoid a branch to a branch. |
| 1855 | if (next->IsGoto() && (info == nullptr || |
| 1856 | !info->IsBackEdge(*block) || |
| 1857 | !info->HasSuspendCheck())) { |
| 1858 | final_label = GetLabelOf(next->AsGoto()->GetSuccessor()); |
| 1859 | } |
| 1860 | |
| 1861 | return final_label; |
| 1862 | } |
| 1863 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1864 | CodeGeneratorARMVIXL::CodeGeneratorARMVIXL(HGraph* graph, |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1865 | const CompilerOptions& compiler_options, |
| 1866 | OptimizingCompilerStats* stats) |
| 1867 | : CodeGenerator(graph, |
| 1868 | kNumberOfCoreRegisters, |
| 1869 | kNumberOfSRegisters, |
| 1870 | kNumberOfRegisterPairs, |
| 1871 | kCoreCalleeSaves.GetList(), |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1872 | ComputeSRegisterListMask(kFpuCalleeSaves), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1873 | compiler_options, |
| 1874 | stats), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1875 | block_labels_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1876 | jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1877 | location_builder_(graph, this), |
| 1878 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1879 | move_resolver_(graph->GetAllocator(), this), |
| 1880 | assembler_(graph->GetAllocator()), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1881 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1882 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1883 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1884 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 1885 | public_type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1886 | package_type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1887 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1888 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1889 | boot_image_other_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1890 | call_entrypoint_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1891 | baker_read_barrier_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1892 | uint32_literals_(std::less<uint32_t>(), |
| 1893 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 1894 | jit_string_patches_(StringReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1895 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 1896 | jit_class_patches_(TypeReferenceValueComparator(), |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1897 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1898 | jit_baker_read_barrier_slow_paths_(std::less<uint32_t>(), |
| 1899 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1900 | // Always save the LR register to mimic Quick. |
| 1901 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 1902 | // Give D30 and D31 as scratch register to VIXL. The register allocator only works on |
| 1903 | // S0-S31, which alias to D0-D15. |
| 1904 | GetVIXLAssembler()->GetScratchVRegisterList()->Combine(d31); |
| 1905 | GetVIXLAssembler()->GetScratchVRegisterList()->Combine(d30); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1906 | } |
| 1907 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1908 | void JumpTableARMVIXL::EmitTable(CodeGeneratorARMVIXL* codegen) { |
| 1909 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| 1910 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| 1911 | |
| 1912 | // We are about to use the assembler to place literals directly. Make sure we have enough |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 1913 | // underlying code buffer and we have generated a jump table of the right size, using |
| 1914 | // codegen->GetVIXLAssembler()->GetBuffer().Align(); |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 1915 | ExactAssemblyScope aas(codegen->GetVIXLAssembler(), |
| 1916 | num_entries * sizeof(int32_t), |
| 1917 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1918 | // TODO(VIXL): Check that using lower case bind is fine here. |
| 1919 | codegen->GetVIXLAssembler()->bind(&table_start_); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1920 | for (uint32_t i = 0; i < num_entries; i++) { |
| 1921 | codegen->GetVIXLAssembler()->place(bb_addresses_[i].get()); |
| 1922 | } |
| 1923 | } |
| 1924 | |
| 1925 | void JumpTableARMVIXL::FixTable(CodeGeneratorARMVIXL* codegen) { |
| 1926 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| 1927 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| 1928 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1929 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 1930 | for (uint32_t i = 0; i < num_entries; i++) { |
| 1931 | vixl32::Label* target_label = codegen->GetLabelOf(successors[i]); |
| 1932 | DCHECK(target_label->IsBound()); |
| 1933 | int32_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
| 1934 | // When doing BX to address we need to have lower bit set to 1 in T32. |
| 1935 | if (codegen->GetVIXLAssembler()->IsUsingT32()) { |
| 1936 | jump_offset++; |
| 1937 | } |
| 1938 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 1939 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1940 | |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 1941 | bb_addresses_[i].get()->UpdateValue(jump_offset, codegen->GetVIXLAssembler()->GetBuffer()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1942 | } |
| 1943 | } |
| 1944 | |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1945 | void CodeGeneratorARMVIXL::FixJumpTables() { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1946 | for (auto&& jump_table : jump_tables_) { |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1947 | jump_table->FixTable(this); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1948 | } |
| 1949 | } |
| 1950 | |
Andreas Gampe | ca620d7 | 2016-11-08 08:09:33 -0800 | [diff] [blame] | 1951 | #define __ reinterpret_cast<ArmVIXLAssembler*>(GetAssembler())->GetVIXLAssembler()-> // NOLINT |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1952 | |
| 1953 | void CodeGeneratorARMVIXL::Finalize(CodeAllocator* allocator) { |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1954 | FixJumpTables(); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1955 | |
| 1956 | // Emit JIT baker read barrier slow paths. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 1957 | DCHECK(GetCompilerOptions().IsJitCompiler() || jit_baker_read_barrier_slow_paths_.empty()); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1958 | for (auto& entry : jit_baker_read_barrier_slow_paths_) { |
| 1959 | uint32_t encoded_data = entry.first; |
| 1960 | vixl::aarch32::Label* slow_path_entry = &entry.second.label; |
| 1961 | __ Bind(slow_path_entry); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1962 | CompileBakerReadBarrierThunk(*GetAssembler(), encoded_data, /* debug_name= */ nullptr); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1963 | } |
| 1964 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1965 | GetAssembler()->FinalizeCode(); |
| 1966 | CodeGenerator::Finalize(allocator); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1967 | |
| 1968 | // Verify Baker read barrier linker patches. |
| 1969 | if (kIsDebugBuild) { |
| 1970 | ArrayRef<const uint8_t> code = allocator->GetMemory(); |
| 1971 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 1972 | DCHECK(info.label.IsBound()); |
| 1973 | uint32_t literal_offset = info.label.GetLocation(); |
| 1974 | DCHECK_ALIGNED(literal_offset, 2u); |
| 1975 | |
| 1976 | auto GetInsn16 = [&code](uint32_t offset) { |
| 1977 | DCHECK_ALIGNED(offset, 2u); |
| 1978 | return (static_cast<uint32_t>(code[offset + 0]) << 0) + |
| 1979 | (static_cast<uint32_t>(code[offset + 1]) << 8); |
| 1980 | }; |
| 1981 | auto GetInsn32 = [=](uint32_t offset) { |
| 1982 | return (GetInsn16(offset) << 16) + (GetInsn16(offset + 2u) << 0); |
| 1983 | }; |
| 1984 | |
| 1985 | uint32_t encoded_data = info.custom_data; |
| 1986 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 1987 | // Check that the next instruction matches the expected LDR. |
| 1988 | switch (kind) { |
| 1989 | case BakerReadBarrierKind::kField: { |
| 1990 | BakerReadBarrierWidth width = BakerReadBarrierWidthField::Decode(encoded_data); |
| 1991 | if (width == BakerReadBarrierWidth::kWide) { |
| 1992 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 1993 | uint32_t next_insn = GetInsn32(literal_offset + 4u); |
| 1994 | // LDR (immediate), encoding T3, with correct base_reg. |
| 1995 | CheckValidReg((next_insn >> 12) & 0xfu); // Check destination register. |
| 1996 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 1997 | CHECK_EQ(next_insn & 0xffff0000u, 0xf8d00000u | (base_reg << 16)); |
| 1998 | } else { |
| 1999 | DCHECK_GE(code.size() - literal_offset, 6u); |
| 2000 | uint32_t next_insn = GetInsn16(literal_offset + 4u); |
| 2001 | // LDR (immediate), encoding T1, with correct base_reg. |
| 2002 | CheckValidReg(next_insn & 0x7u); // Check destination register. |
| 2003 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 2004 | CHECK_EQ(next_insn & 0xf838u, 0x6800u | (base_reg << 3)); |
| 2005 | } |
| 2006 | break; |
| 2007 | } |
| 2008 | case BakerReadBarrierKind::kArray: { |
| 2009 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 2010 | uint32_t next_insn = GetInsn32(literal_offset + 4u); |
| 2011 | // LDR (register) with correct base_reg, S=1 and option=011 (LDR Wt, [Xn, Xm, LSL #2]). |
| 2012 | CheckValidReg((next_insn >> 12) & 0xfu); // Check destination register. |
| 2013 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 2014 | CHECK_EQ(next_insn & 0xffff0ff0u, 0xf8500020u | (base_reg << 16)); |
| 2015 | CheckValidReg(next_insn & 0xf); // Check index register |
| 2016 | break; |
| 2017 | } |
| 2018 | case BakerReadBarrierKind::kGcRoot: { |
| 2019 | BakerReadBarrierWidth width = BakerReadBarrierWidthField::Decode(encoded_data); |
| 2020 | if (width == BakerReadBarrierWidth::kWide) { |
| 2021 | DCHECK_GE(literal_offset, 4u); |
| 2022 | uint32_t prev_insn = GetInsn32(literal_offset - 4u); |
Vladimir Marko | f28be43 | 2018-08-14 12:20:51 +0000 | [diff] [blame] | 2023 | // LDR (immediate), encoding T3, with correct root_reg. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 2024 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
Vladimir Marko | f28be43 | 2018-08-14 12:20:51 +0000 | [diff] [blame] | 2025 | CHECK_EQ(prev_insn & 0xfff0f000u, 0xf8d00000u | (root_reg << 12)); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 2026 | } else { |
| 2027 | DCHECK_GE(literal_offset, 2u); |
| 2028 | uint32_t prev_insn = GetInsn16(literal_offset - 2u); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 2029 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 2030 | // Usually LDR (immediate), encoding T1, with correct root_reg but we may have |
| 2031 | // a `MOV marked, old_value` for intrinsic CAS where `marked` is a low register. |
| 2032 | if ((prev_insn & 0xff87u) != (0x4600 | root_reg)) { |
| 2033 | CHECK_EQ(prev_insn & 0xf807u, 0x6800u | root_reg); |
| 2034 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 2035 | } |
| 2036 | break; |
| 2037 | } |
Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 2038 | case BakerReadBarrierKind::kIntrinsicCas: { |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 2039 | DCHECK_GE(literal_offset, 4u); |
| 2040 | uint32_t prev_insn = GetInsn32(literal_offset - 4u); |
Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 2041 | // MOV (register), encoding T3, with correct root_reg. |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 2042 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 2043 | DCHECK_GE(root_reg, 8u); // Used only for high registers. |
| 2044 | CHECK_EQ(prev_insn & 0xfffffff0u, 0xea4f0000u | (root_reg << 8)); |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 2045 | break; |
| 2046 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 2047 | default: |
| 2048 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 2049 | UNREACHABLE(); |
| 2050 | } |
| 2051 | } |
| 2052 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2053 | } |
| 2054 | |
| 2055 | void CodeGeneratorARMVIXL::SetupBlockedRegisters() const { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2056 | // Stack register, LR and PC are always reserved. |
| 2057 | blocked_core_registers_[SP] = true; |
| 2058 | blocked_core_registers_[LR] = true; |
| 2059 | blocked_core_registers_[PC] = true; |
| 2060 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 2061 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2062 | // Reserve marking register. |
| 2063 | blocked_core_registers_[MR] = true; |
| 2064 | } |
| 2065 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2066 | // Reserve thread register. |
| 2067 | blocked_core_registers_[TR] = true; |
| 2068 | |
| 2069 | // Reserve temp register. |
| 2070 | blocked_core_registers_[IP] = true; |
| 2071 | |
| 2072 | if (GetGraph()->IsDebuggable()) { |
| 2073 | // Stubs do not save callee-save floating point registers. If the graph |
| 2074 | // is debuggable, we need to deal with these registers differently. For |
| 2075 | // now, just block them. |
| 2076 | for (uint32_t i = kFpuCalleeSaves.GetFirstSRegister().GetCode(); |
| 2077 | i <= kFpuCalleeSaves.GetLastSRegister().GetCode(); |
| 2078 | ++i) { |
| 2079 | blocked_fpu_registers_[i] = true; |
| 2080 | } |
| 2081 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2082 | } |
| 2083 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2084 | InstructionCodeGeneratorARMVIXL::InstructionCodeGeneratorARMVIXL(HGraph* graph, |
| 2085 | CodeGeneratorARMVIXL* codegen) |
| 2086 | : InstructionCodeGenerator(graph, codegen), |
| 2087 | assembler_(codegen->GetAssembler()), |
| 2088 | codegen_(codegen) {} |
| 2089 | |
| 2090 | void CodeGeneratorARMVIXL::ComputeSpillMask() { |
| 2091 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
Vladimir Marko | 460f054 | 2019-07-04 14:02:08 +0100 | [diff] [blame] | 2092 | DCHECK_NE(core_spill_mask_ & (1u << kLrCode), 0u) |
| 2093 | << "At least the return address register must be saved"; |
| 2094 | // 16-bit PUSH/POP (T1) can save/restore just the LR/PC. |
| 2095 | DCHECK(GetVIXLAssembler()->IsUsingT32()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2096 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 2097 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 2098 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 2099 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 2100 | // but in the range. |
| 2101 | if (fpu_spill_mask_ != 0) { |
| 2102 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 2103 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 2104 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 2105 | fpu_spill_mask_ |= (1 << i); |
| 2106 | } |
| 2107 | } |
| 2108 | } |
| 2109 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2110 | void CodeGeneratorARMVIXL::MaybeIncrementHotness(bool is_frame_entry) { |
| 2111 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 2112 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2113 | vixl32::Register temp = temps.Acquire(); |
| 2114 | static_assert(ArtMethod::MaxCounter() == 0xFFFF, "asm is probably wrong"); |
| 2115 | if (!is_frame_entry) { |
| 2116 | __ Push(vixl32::Register(kMethodRegister)); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2117 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2118 | GetAssembler()->LoadFromOffset(kLoadWord, kMethodRegister, sp, kArmWordSize); |
| 2119 | } |
| 2120 | // Load with zero extend to clear the high bits for integer overflow check. |
| 2121 | __ Ldrh(temp, MemOperand(kMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); |
| 2122 | __ Add(temp, temp, 1); |
| 2123 | // Subtract one if the counter would overflow. |
| 2124 | __ Sub(temp, temp, Operand(temp, ShiftType::LSR, 16)); |
| 2125 | __ Strh(temp, MemOperand(kMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); |
| 2126 | if (!is_frame_entry) { |
| 2127 | __ Pop(vixl32::Register(kMethodRegister)); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2128 | GetAssembler()->cfi().AdjustCFAOffset(-static_cast<int>(kArmWordSize)); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2129 | } |
| 2130 | } |
| 2131 | |
| 2132 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | 095dc46 | 2020-08-17 16:40:28 +0100 | [diff] [blame] | 2133 | ScopedProfilingInfoUse spiu( |
| 2134 | Runtime::Current()->GetJit(), GetGraph()->GetArtMethod(), Thread::Current()); |
| 2135 | ProfilingInfo* info = spiu.GetProfilingInfo(); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 2136 | if (info != nullptr) { |
| 2137 | uint32_t address = reinterpret_cast32<uint32_t>(info); |
| 2138 | vixl::aarch32::Label done; |
| 2139 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2140 | temps.Exclude(ip); |
| 2141 | if (!is_frame_entry) { |
| 2142 | __ Push(r4); // Will be used as temporary. For frame entry, r4 is always available. |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2143 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 2144 | } |
| 2145 | __ Mov(r4, address); |
| 2146 | __ Ldrh(ip, MemOperand(r4, ProfilingInfo::BaselineHotnessCountOffset().Int32Value())); |
| 2147 | __ Add(ip, ip, 1); |
Nicolas Geoffray | 8b8d93d | 2020-09-17 14:30:01 +0100 | [diff] [blame] | 2148 | instruction_visitor_.GenerateAndConst(ip, ip, interpreter::kTieredHotnessMask); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 2149 | __ Strh(ip, MemOperand(r4, ProfilingInfo::BaselineHotnessCountOffset().Int32Value())); |
| 2150 | if (!is_frame_entry) { |
| 2151 | __ Pop(r4); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2152 | GetAssembler()->cfi().AdjustCFAOffset(-static_cast<int>(kArmWordSize)); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 2153 | } |
| 2154 | __ Lsls(ip, ip, 16); |
| 2155 | __ B(ne, &done); |
| 2156 | uint32_t entry_point_offset = |
| 2157 | GetThreadOffset<kArmPointerSize>(kQuickCompileOptimized).Int32Value(); |
| 2158 | if (HasEmptyFrame()) { |
| 2159 | CHECK(is_frame_entry); |
| 2160 | // For leaf methods, we need to spill lr and r0. Also spill r1 and r2 for |
| 2161 | // alignment. |
| 2162 | uint32_t core_spill_mask = |
| 2163 | (1 << lr.GetCode()) | (1 << r0.GetCode()) | (1 << r1.GetCode()) | (1 << r2.GetCode()); |
| 2164 | __ Push(RegisterList(core_spill_mask)); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2165 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask)); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 2166 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 2167 | __ Blx(lr); |
| 2168 | __ Pop(RegisterList(core_spill_mask)); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2169 | GetAssembler()->cfi().AdjustCFAOffset( |
| 2170 | -static_cast<int>(kArmWordSize) * POPCOUNT(core_spill_mask)); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 2171 | } else { |
| 2172 | if (!RequiresCurrentMethod()) { |
| 2173 | CHECK(is_frame_entry); |
| 2174 | GetAssembler()->StoreToOffset(kStoreWord, kMethodRegister, sp, 0); |
| 2175 | } |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2176 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 2177 | __ Blx(lr); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2178 | } |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 2179 | __ Bind(&done); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2180 | } |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2181 | } |
| 2182 | } |
| 2183 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2184 | void CodeGeneratorARMVIXL::GenerateFrameEntry() { |
| 2185 | bool skip_overflow_check = |
| 2186 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
| 2187 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
| 2188 | __ Bind(&frame_entry_label_); |
| 2189 | |
| 2190 | if (HasEmptyFrame()) { |
David Srbecky | 3002184 | 2019-02-13 14:19:36 +0000 | [diff] [blame] | 2191 | // Ensure that the CFI opcode list is not empty. |
| 2192 | GetAssembler()->cfi().Nop(); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2193 | MaybeIncrementHotness(/* is_frame_entry= */ true); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2194 | return; |
| 2195 | } |
| 2196 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2197 | if (!skip_overflow_check) { |
xueliang.zhong | 1004955 | 2018-01-31 17:10:36 +0000 | [diff] [blame] | 2198 | // Using r4 instead of IP saves 2 bytes. |
Nicolas Geoffray | 1a4f3ca | 2018-01-25 14:07:15 +0000 | [diff] [blame] | 2199 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
xueliang.zhong | 1004955 | 2018-01-31 17:10:36 +0000 | [diff] [blame] | 2200 | vixl32::Register temp; |
| 2201 | // TODO: Remove this check when R4 is made a callee-save register |
| 2202 | // in ART compiled code (b/72801708). Currently we need to make |
| 2203 | // sure r4 is not blocked, e.g. in special purpose |
| 2204 | // TestCodeGeneratorARMVIXL; also asserting that r4 is available |
| 2205 | // here. |
| 2206 | if (!blocked_core_registers_[R4]) { |
| 2207 | for (vixl32::Register reg : kParameterCoreRegistersVIXL) { |
| 2208 | DCHECK(!reg.Is(r4)); |
| 2209 | } |
| 2210 | DCHECK(!kCoreCalleeSaves.Includes(r4)); |
| 2211 | temp = r4; |
| 2212 | } else { |
| 2213 | temp = temps.Acquire(); |
| 2214 | } |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 2215 | __ Sub(temp, sp, Operand::From(GetStackOverflowReservedBytes(InstructionSet::kArm))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2216 | // The load must immediately precede RecordPcInfo. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 2217 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2218 | vixl32::kMaxInstructionSizeInBytes, |
| 2219 | CodeBufferCheckScope::kMaximumSize); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2220 | __ ldr(temp, MemOperand(temp)); |
| 2221 | RecordPcInfo(nullptr, 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2222 | } |
| 2223 | |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 2224 | uint32_t frame_size = GetFrameSize(); |
| 2225 | uint32_t core_spills_offset = frame_size - GetCoreSpillSize(); |
| 2226 | uint32_t fp_spills_offset = frame_size - FrameEntrySpillSize(); |
| 2227 | if ((fpu_spill_mask_ == 0u || IsPowerOfTwo(fpu_spill_mask_)) && |
| 2228 | core_spills_offset <= 3u * kArmWordSize) { |
| 2229 | // Do a single PUSH for core registers including the method and up to two |
| 2230 | // filler registers. Then store the single FP spill if any. |
| 2231 | // (The worst case is when the method is not required and we actually |
| 2232 | // store 3 extra registers but they are stored in the same properly |
| 2233 | // aligned 16-byte chunk where we're already writing anyway.) |
| 2234 | DCHECK_EQ(kMethodRegister.GetCode(), 0u); |
| 2235 | uint32_t extra_regs = MaxInt<uint32_t>(core_spills_offset / kArmWordSize); |
| 2236 | DCHECK_LT(MostSignificantBit(extra_regs), LeastSignificantBit(core_spill_mask_)); |
| 2237 | __ Push(RegisterList(core_spill_mask_ | extra_regs)); |
| 2238 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
| 2239 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(kMethodRegister), |
| 2240 | core_spills_offset, |
| 2241 | core_spill_mask_, |
| 2242 | kArmWordSize); |
| 2243 | if (fpu_spill_mask_ != 0u) { |
| 2244 | DCHECK(IsPowerOfTwo(fpu_spill_mask_)); |
| 2245 | vixl::aarch32::SRegister sreg(LeastSignificantBit(fpu_spill_mask_)); |
| 2246 | GetAssembler()->StoreSToOffset(sreg, sp, fp_spills_offset); |
| 2247 | GetAssembler()->cfi().RelOffset(DWARFReg(sreg), /*offset=*/ fp_spills_offset); |
| 2248 | } |
| 2249 | } else { |
| 2250 | __ Push(RegisterList(core_spill_mask_)); |
| 2251 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 2252 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(kMethodRegister), |
| 2253 | /*offset=*/ 0, |
| 2254 | core_spill_mask_, |
| 2255 | kArmWordSize); |
| 2256 | if (fpu_spill_mask_ != 0) { |
| 2257 | uint32_t first = LeastSignificantBit(fpu_spill_mask_); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2258 | |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 2259 | // Check that list is contiguous. |
| 2260 | DCHECK_EQ(fpu_spill_mask_ >> CTZ(fpu_spill_mask_), ~0u >> (32 - POPCOUNT(fpu_spill_mask_))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2261 | |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 2262 | __ Vpush(SRegisterList(vixl32::SRegister(first), POPCOUNT(fpu_spill_mask_))); |
| 2263 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
| 2264 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(s0), |
| 2265 | /*offset=*/ 0, |
| 2266 | fpu_spill_mask_, |
| 2267 | kArmWordSize); |
| 2268 | } |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 2269 | |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 2270 | // Adjust SP and save the current method if we need it. Note that we do |
| 2271 | // not save the method in HCurrentMethod, as the instruction might have |
| 2272 | // been removed in the SSA graph. |
| 2273 | if (RequiresCurrentMethod() && fp_spills_offset <= 3 * kArmWordSize) { |
| 2274 | DCHECK_EQ(kMethodRegister.GetCode(), 0u); |
| 2275 | __ Push(RegisterList(MaxInt<uint32_t>(fp_spills_offset / kArmWordSize))); |
| 2276 | GetAssembler()->cfi().AdjustCFAOffset(fp_spills_offset); |
| 2277 | } else { |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2278 | IncreaseFrame(fp_spills_offset); |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 2279 | if (RequiresCurrentMethod()) { |
| 2280 | GetAssembler()->StoreToOffset(kStoreWord, kMethodRegister, sp, 0); |
| 2281 | } |
| 2282 | } |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 2283 | } |
Nicolas Geoffray | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 2284 | |
| 2285 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 2286 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2287 | vixl32::Register temp = temps.Acquire(); |
| 2288 | // Initialize should_deoptimize flag to 0. |
| 2289 | __ Mov(temp, 0); |
| 2290 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, GetStackOffsetOfShouldDeoptimizeFlag()); |
| 2291 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 2292 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2293 | MaybeIncrementHotness(/* is_frame_entry= */ true); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2294 | MaybeGenerateMarkingRegisterCheck(/* code= */ 1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2295 | } |
| 2296 | |
| 2297 | void CodeGeneratorARMVIXL::GenerateFrameExit() { |
| 2298 | if (HasEmptyFrame()) { |
| 2299 | __ Bx(lr); |
| 2300 | return; |
| 2301 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2302 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2303 | // Pop LR into PC to return. |
| 2304 | DCHECK_NE(core_spill_mask_ & (1 << kLrCode), 0U); |
| 2305 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << kLrCode))) | 1 << kPcCode; |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 2306 | |
| 2307 | uint32_t frame_size = GetFrameSize(); |
| 2308 | uint32_t core_spills_offset = frame_size - GetCoreSpillSize(); |
| 2309 | uint32_t fp_spills_offset = frame_size - FrameEntrySpillSize(); |
| 2310 | if ((fpu_spill_mask_ == 0u || IsPowerOfTwo(fpu_spill_mask_)) && |
| 2311 | // r4 is blocked by TestCodeGeneratorARMVIXL used by some tests. |
| 2312 | core_spills_offset <= (blocked_core_registers_[r4.GetCode()] ? 2u : 3u) * kArmWordSize) { |
| 2313 | // Load the FP spill if any and then do a single POP including the method |
| 2314 | // and up to two filler registers. If we have no FP spills, this also has |
| 2315 | // the advantage that we do not need to emit CFI directives. |
| 2316 | if (fpu_spill_mask_ != 0u) { |
| 2317 | DCHECK(IsPowerOfTwo(fpu_spill_mask_)); |
| 2318 | vixl::aarch32::SRegister sreg(LeastSignificantBit(fpu_spill_mask_)); |
| 2319 | GetAssembler()->cfi().RememberState(); |
| 2320 | GetAssembler()->LoadSFromOffset(sreg, sp, fp_spills_offset); |
| 2321 | GetAssembler()->cfi().Restore(DWARFReg(sreg)); |
| 2322 | } |
| 2323 | // Clobber registers r2-r4 as they are caller-save in ART managed ABI and |
| 2324 | // never hold the return value. |
| 2325 | uint32_t extra_regs = MaxInt<uint32_t>(core_spills_offset / kArmWordSize) << r2.GetCode(); |
| 2326 | DCHECK_EQ(extra_regs & kCoreCalleeSaves.GetList(), 0u); |
| 2327 | DCHECK_LT(MostSignificantBit(extra_regs), LeastSignificantBit(pop_mask)); |
| 2328 | __ Pop(RegisterList(pop_mask | extra_regs)); |
| 2329 | if (fpu_spill_mask_ != 0u) { |
| 2330 | GetAssembler()->cfi().RestoreState(); |
| 2331 | } |
| 2332 | } else { |
| 2333 | GetAssembler()->cfi().RememberState(); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2334 | DecreaseFrame(fp_spills_offset); |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 2335 | if (fpu_spill_mask_ != 0) { |
| 2336 | uint32_t first = LeastSignificantBit(fpu_spill_mask_); |
| 2337 | |
| 2338 | // Check that list is contiguous. |
| 2339 | DCHECK_EQ(fpu_spill_mask_ >> CTZ(fpu_spill_mask_), ~0u >> (32 - POPCOUNT(fpu_spill_mask_))); |
| 2340 | |
| 2341 | __ Vpop(SRegisterList(vixl32::SRegister(first), POPCOUNT(fpu_spill_mask_))); |
| 2342 | GetAssembler()->cfi().AdjustCFAOffset( |
| 2343 | -static_cast<int>(kArmWordSize) * POPCOUNT(fpu_spill_mask_)); |
| 2344 | GetAssembler()->cfi().RestoreMany(DWARFReg(vixl32::SRegister(0)), fpu_spill_mask_); |
| 2345 | } |
| 2346 | __ Pop(RegisterList(pop_mask)); |
| 2347 | GetAssembler()->cfi().RestoreState(); |
| 2348 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
| 2349 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2350 | } |
| 2351 | |
| 2352 | void CodeGeneratorARMVIXL::Bind(HBasicBlock* block) { |
| 2353 | __ Bind(GetLabelOf(block)); |
| 2354 | } |
| 2355 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2356 | Location InvokeDexCallingConventionVisitorARMVIXL::GetNextLocation(DataType::Type type) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2357 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2358 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2359 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2360 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2361 | case DataType::Type::kInt8: |
| 2362 | case DataType::Type::kUint16: |
| 2363 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2364 | case DataType::Type::kInt32: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2365 | uint32_t index = gp_index_++; |
| 2366 | uint32_t stack_index = stack_index_++; |
| 2367 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2368 | return LocationFrom(calling_convention.GetRegisterAt(index)); |
| 2369 | } else { |
| 2370 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2371 | } |
| 2372 | } |
| 2373 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2374 | case DataType::Type::kInt64: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2375 | uint32_t index = gp_index_; |
| 2376 | uint32_t stack_index = stack_index_; |
| 2377 | gp_index_ += 2; |
| 2378 | stack_index_ += 2; |
| 2379 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2380 | if (calling_convention.GetRegisterAt(index).Is(r1)) { |
| 2381 | // Skip R1, and use R2_R3 instead. |
| 2382 | gp_index_++; |
| 2383 | index++; |
| 2384 | } |
| 2385 | } |
| 2386 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2387 | DCHECK_EQ(calling_convention.GetRegisterAt(index).GetCode() + 1, |
| 2388 | calling_convention.GetRegisterAt(index + 1).GetCode()); |
| 2389 | |
| 2390 | return LocationFrom(calling_convention.GetRegisterAt(index), |
| 2391 | calling_convention.GetRegisterAt(index + 1)); |
| 2392 | } else { |
| 2393 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2394 | } |
| 2395 | } |
| 2396 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2397 | case DataType::Type::kFloat32: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2398 | uint32_t stack_index = stack_index_++; |
| 2399 | if (float_index_ % 2 == 0) { |
| 2400 | float_index_ = std::max(double_index_, float_index_); |
| 2401 | } |
| 2402 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 2403 | return LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 2404 | } else { |
| 2405 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2406 | } |
| 2407 | } |
| 2408 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2409 | case DataType::Type::kFloat64: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2410 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 2411 | uint32_t stack_index = stack_index_; |
| 2412 | stack_index_ += 2; |
| 2413 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 2414 | uint32_t index = double_index_; |
| 2415 | double_index_ += 2; |
| 2416 | Location result = LocationFrom( |
| 2417 | calling_convention.GetFpuRegisterAt(index), |
| 2418 | calling_convention.GetFpuRegisterAt(index + 1)); |
| 2419 | DCHECK(ExpectedPairLayout(result)); |
| 2420 | return result; |
| 2421 | } else { |
| 2422 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2423 | } |
| 2424 | } |
| 2425 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2426 | case DataType::Type::kUint32: |
| 2427 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2428 | case DataType::Type::kVoid: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2429 | LOG(FATAL) << "Unexpected parameter type " << type; |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 2430 | UNREACHABLE(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2431 | } |
| 2432 | return Location::NoLocation(); |
| 2433 | } |
| 2434 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2435 | Location InvokeDexCallingConventionVisitorARMVIXL::GetReturnLocation(DataType::Type type) const { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2436 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2437 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2438 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2439 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2440 | case DataType::Type::kInt8: |
| 2441 | case DataType::Type::kUint16: |
| 2442 | case DataType::Type::kInt16: |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2443 | case DataType::Type::kUint32: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2444 | case DataType::Type::kInt32: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2445 | return LocationFrom(r0); |
| 2446 | } |
| 2447 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2448 | case DataType::Type::kFloat32: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2449 | return LocationFrom(s0); |
| 2450 | } |
| 2451 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2452 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2453 | case DataType::Type::kInt64: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2454 | return LocationFrom(r0, r1); |
| 2455 | } |
| 2456 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2457 | case DataType::Type::kFloat64: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2458 | return LocationFrom(s0, s1); |
| 2459 | } |
| 2460 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2461 | case DataType::Type::kVoid: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2462 | return Location::NoLocation(); |
| 2463 | } |
| 2464 | |
| 2465 | UNREACHABLE(); |
| 2466 | } |
| 2467 | |
| 2468 | Location InvokeDexCallingConventionVisitorARMVIXL::GetMethodLocation() const { |
| 2469 | return LocationFrom(kMethodRegister); |
| 2470 | } |
| 2471 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 2472 | Location CriticalNativeCallingConventionVisitorARMVIXL::GetNextLocation(DataType::Type type) { |
| 2473 | DCHECK_NE(type, DataType::Type::kReference); |
| 2474 | |
| 2475 | // Native ABI uses the same registers as managed, except that the method register r0 |
| 2476 | // is a normal argument. |
| 2477 | Location location = Location::NoLocation(); |
| 2478 | if (DataType::Is64BitType(type)) { |
| 2479 | gpr_index_ = RoundUp(gpr_index_, 2u); |
| 2480 | stack_offset_ = RoundUp(stack_offset_, 2 * kFramePointerSize); |
| 2481 | if (gpr_index_ < 1u + kParameterCoreRegistersLengthVIXL) { |
| 2482 | location = LocationFrom(gpr_index_ == 0u ? r0 : kParameterCoreRegistersVIXL[gpr_index_ - 1u], |
| 2483 | kParameterCoreRegistersVIXL[gpr_index_]); |
| 2484 | gpr_index_ += 2u; |
| 2485 | } |
| 2486 | } else { |
| 2487 | if (gpr_index_ < 1u + kParameterCoreRegistersLengthVIXL) { |
| 2488 | location = LocationFrom(gpr_index_ == 0u ? r0 : kParameterCoreRegistersVIXL[gpr_index_ - 1u]); |
| 2489 | ++gpr_index_; |
| 2490 | } |
| 2491 | } |
| 2492 | if (location.IsInvalid()) { |
| 2493 | if (DataType::Is64BitType(type)) { |
| 2494 | location = Location::DoubleStackSlot(stack_offset_); |
| 2495 | stack_offset_ += 2 * kFramePointerSize; |
| 2496 | } else { |
| 2497 | location = Location::StackSlot(stack_offset_); |
| 2498 | stack_offset_ += kFramePointerSize; |
| 2499 | } |
| 2500 | |
| 2501 | if (for_register_allocation_) { |
| 2502 | location = Location::Any(); |
| 2503 | } |
| 2504 | } |
| 2505 | return location; |
| 2506 | } |
| 2507 | |
| 2508 | Location CriticalNativeCallingConventionVisitorARMVIXL::GetReturnLocation(DataType::Type type) |
| 2509 | const { |
| 2510 | // We perform conversion to the managed ABI return register after the call if needed. |
| 2511 | InvokeDexCallingConventionVisitorARMVIXL dex_calling_convention; |
| 2512 | return dex_calling_convention.GetReturnLocation(type); |
| 2513 | } |
| 2514 | |
| 2515 | Location CriticalNativeCallingConventionVisitorARMVIXL::GetMethodLocation() const { |
| 2516 | // Pass the method in the hidden argument R4. |
| 2517 | return Location::RegisterLocation(R4); |
| 2518 | } |
| 2519 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2520 | void CodeGeneratorARMVIXL::Move32(Location destination, Location source) { |
| 2521 | if (source.Equals(destination)) { |
| 2522 | return; |
| 2523 | } |
| 2524 | if (destination.IsRegister()) { |
| 2525 | if (source.IsRegister()) { |
| 2526 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 2527 | } else if (source.IsFpuRegister()) { |
| 2528 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
| 2529 | } else { |
| 2530 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 2531 | RegisterFrom(destination), |
| 2532 | sp, |
| 2533 | source.GetStackIndex()); |
| 2534 | } |
| 2535 | } else if (destination.IsFpuRegister()) { |
| 2536 | if (source.IsRegister()) { |
| 2537 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
| 2538 | } else if (source.IsFpuRegister()) { |
| 2539 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 2540 | } else { |
| 2541 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 2542 | } |
| 2543 | } else { |
| 2544 | DCHECK(destination.IsStackSlot()) << destination; |
| 2545 | if (source.IsRegister()) { |
| 2546 | GetAssembler()->StoreToOffset(kStoreWord, |
| 2547 | RegisterFrom(source), |
| 2548 | sp, |
| 2549 | destination.GetStackIndex()); |
| 2550 | } else if (source.IsFpuRegister()) { |
| 2551 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 2552 | } else { |
| 2553 | DCHECK(source.IsStackSlot()) << source; |
| 2554 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2555 | vixl32::Register temp = temps.Acquire(); |
| 2556 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 2557 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 2558 | } |
| 2559 | } |
| 2560 | } |
| 2561 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2562 | void CodeGeneratorARMVIXL::MoveConstant(Location location, int32_t value) { |
| 2563 | DCHECK(location.IsRegister()); |
| 2564 | __ Mov(RegisterFrom(location), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2565 | } |
| 2566 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2567 | void CodeGeneratorARMVIXL::MoveLocation(Location dst, Location src, DataType::Type dst_type) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2568 | // TODO(VIXL): Maybe refactor to have the 'move' implementation here and use it in |
| 2569 | // `ParallelMoveResolverARMVIXL::EmitMove`, as is done in the `arm64` backend. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2570 | HParallelMove move(GetGraph()->GetAllocator()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2571 | move.AddMove(src, dst, dst_type, nullptr); |
| 2572 | GetMoveResolver()->EmitNativeCode(&move); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2573 | } |
| 2574 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2575 | void CodeGeneratorARMVIXL::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 2576 | if (location.IsRegister()) { |
| 2577 | locations->AddTemp(location); |
| 2578 | } else if (location.IsRegisterPair()) { |
| 2579 | locations->AddTemp(LocationFrom(LowRegisterFrom(location))); |
| 2580 | locations->AddTemp(LocationFrom(HighRegisterFrom(location))); |
| 2581 | } else { |
| 2582 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 2583 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2584 | } |
| 2585 | |
| 2586 | void CodeGeneratorARMVIXL::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2587 | HInstruction* instruction, |
| 2588 | uint32_t dex_pc, |
| 2589 | SlowPathCode* slow_path) { |
| 2590 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 2591 | |
| 2592 | ThreadOffset32 entrypoint_offset = GetThreadOffset<kArmPointerSize>(entrypoint); |
| 2593 | // Reduce code size for AOT by using shared trampolines for slow path runtime calls across the |
| 2594 | // entire oat file. This adds an extra branch and we do not want to slow down the main path. |
| 2595 | // For JIT, thunk sharing is per-method, so the gains would be smaller or even negative. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 2596 | if (slow_path == nullptr || GetCompilerOptions().IsJitCompiler()) { |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 2597 | __ Ldr(lr, MemOperand(tr, entrypoint_offset.Int32Value())); |
| 2598 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 2599 | // blx in T32 has only 16bit encoding that's why a stricter check for the scope is used. |
| 2600 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2601 | vixl32::k16BitT32InstructionSizeInBytes, |
| 2602 | CodeBufferCheckScope::kExactSize); |
| 2603 | __ blx(lr); |
| 2604 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2605 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2606 | } |
| 2607 | } else { |
| 2608 | // Ensure the pc position is recorded immediately after the `bl` instruction. |
| 2609 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2610 | vixl32::k32BitT32InstructionSizeInBytes, |
| 2611 | CodeBufferCheckScope::kExactSize); |
| 2612 | EmitEntrypointThunkCall(entrypoint_offset); |
| 2613 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2614 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2615 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2616 | } |
| 2617 | } |
| 2618 | |
| 2619 | void CodeGeneratorARMVIXL::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2620 | HInstruction* instruction, |
| 2621 | SlowPathCode* slow_path) { |
| 2622 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2623 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2624 | __ Blx(lr); |
| 2625 | } |
| 2626 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2627 | void InstructionCodeGeneratorARMVIXL::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 2628 | if (successor->IsExitBlock()) { |
| 2629 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 2630 | return; // no code needed |
| 2631 | } |
| 2632 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2633 | HBasicBlock* block = got->GetBlock(); |
| 2634 | HInstruction* previous = got->GetPrevious(); |
| 2635 | HLoopInformation* info = block->GetLoopInformation(); |
| 2636 | |
| 2637 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2638 | codegen_->MaybeIncrementHotness(/* is_frame_entry= */ false); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2639 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2640 | return; |
| 2641 | } |
| 2642 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2643 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2644 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 2); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2645 | } |
| 2646 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 2647 | __ B(codegen_->GetLabelOf(successor)); |
| 2648 | } |
| 2649 | } |
| 2650 | |
| 2651 | void LocationsBuilderARMVIXL::VisitGoto(HGoto* got) { |
| 2652 | got->SetLocations(nullptr); |
| 2653 | } |
| 2654 | |
| 2655 | void InstructionCodeGeneratorARMVIXL::VisitGoto(HGoto* got) { |
| 2656 | HandleGoto(got, got->GetSuccessor()); |
| 2657 | } |
| 2658 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2659 | void LocationsBuilderARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2660 | try_boundary->SetLocations(nullptr); |
| 2661 | } |
| 2662 | |
| 2663 | void InstructionCodeGeneratorARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2664 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2665 | if (!successor->IsExitBlock()) { |
| 2666 | HandleGoto(try_boundary, successor); |
| 2667 | } |
| 2668 | } |
| 2669 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2670 | void LocationsBuilderARMVIXL::VisitExit(HExit* exit) { |
| 2671 | exit->SetLocations(nullptr); |
| 2672 | } |
| 2673 | |
| 2674 | void InstructionCodeGeneratorARMVIXL::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 2675 | } |
| 2676 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2677 | void InstructionCodeGeneratorARMVIXL::GenerateCompareTestAndBranch(HCondition* condition, |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2678 | vixl32::Label* true_target, |
| 2679 | vixl32::Label* false_target, |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2680 | bool is_far_target) { |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2681 | if (true_target == false_target) { |
| 2682 | DCHECK(true_target != nullptr); |
| 2683 | __ B(true_target); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2684 | return; |
| 2685 | } |
| 2686 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2687 | vixl32::Label* non_fallthrough_target; |
| 2688 | bool invert; |
| 2689 | bool emit_both_branches; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2690 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2691 | if (true_target == nullptr) { |
| 2692 | // The true target is fallthrough. |
| 2693 | DCHECK(false_target != nullptr); |
| 2694 | non_fallthrough_target = false_target; |
| 2695 | invert = true; |
| 2696 | emit_both_branches = false; |
| 2697 | } else { |
| 2698 | non_fallthrough_target = true_target; |
| 2699 | invert = false; |
| 2700 | // Either the false target is fallthrough, or there is no fallthrough |
| 2701 | // and both branches must be emitted. |
| 2702 | emit_both_branches = (false_target != nullptr); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2703 | } |
| 2704 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2705 | const auto cond = GenerateTest(condition, invert, codegen_); |
| 2706 | |
| 2707 | __ B(cond.first, non_fallthrough_target, is_far_target); |
| 2708 | |
| 2709 | if (emit_both_branches) { |
| 2710 | // No target falls through, we need to branch. |
| 2711 | __ B(false_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2712 | } |
| 2713 | } |
| 2714 | |
| 2715 | void InstructionCodeGeneratorARMVIXL::GenerateTestAndBranch(HInstruction* instruction, |
| 2716 | size_t condition_input_index, |
| 2717 | vixl32::Label* true_target, |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2718 | vixl32::Label* false_target, |
| 2719 | bool far_target) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2720 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 2721 | |
| 2722 | if (true_target == nullptr && false_target == nullptr) { |
| 2723 | // Nothing to do. The code always falls through. |
| 2724 | return; |
| 2725 | } else if (cond->IsIntConstant()) { |
| 2726 | // Constant condition, statically compared against "true" (integer value 1). |
| 2727 | if (cond->AsIntConstant()->IsTrue()) { |
| 2728 | if (true_target != nullptr) { |
| 2729 | __ B(true_target); |
| 2730 | } |
| 2731 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 2732 | DCHECK(cond->AsIntConstant()->IsFalse()) << Int32ConstantFrom(cond); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2733 | if (false_target != nullptr) { |
| 2734 | __ B(false_target); |
| 2735 | } |
| 2736 | } |
| 2737 | return; |
| 2738 | } |
| 2739 | |
| 2740 | // The following code generates these patterns: |
| 2741 | // (1) true_target == nullptr && false_target != nullptr |
| 2742 | // - opposite condition true => branch to false_target |
| 2743 | // (2) true_target != nullptr && false_target == nullptr |
| 2744 | // - condition true => branch to true_target |
| 2745 | // (3) true_target != nullptr && false_target != nullptr |
| 2746 | // - condition true => branch to true_target |
| 2747 | // - branch to false_target |
| 2748 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 2749 | // Condition has been materialized, compare the output to 0. |
| 2750 | if (kIsDebugBuild) { |
| 2751 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 2752 | DCHECK(cond_val.IsRegister()); |
| 2753 | } |
| 2754 | if (true_target == nullptr) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2755 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, condition_input_index), |
| 2756 | false_target, |
| 2757 | far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2758 | } else { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2759 | __ CompareAndBranchIfNonZero(InputRegisterAt(instruction, condition_input_index), |
| 2760 | true_target, |
| 2761 | far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2762 | } |
| 2763 | } else { |
| 2764 | // Condition has not been materialized. Use its inputs as the comparison and |
| 2765 | // its condition as the branch condition. |
| 2766 | HCondition* condition = cond->AsCondition(); |
| 2767 | |
| 2768 | // If this is a long or FP comparison that has been folded into |
| 2769 | // the HCondition, generate the comparison directly. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2770 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 2771 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2772 | GenerateCompareTestAndBranch(condition, true_target, false_target, far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2773 | return; |
| 2774 | } |
| 2775 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2776 | vixl32::Label* non_fallthrough_target; |
| 2777 | vixl32::Condition arm_cond = vixl32::Condition::None(); |
| 2778 | const vixl32::Register left = InputRegisterAt(cond, 0); |
| 2779 | const Operand right = InputOperandAt(cond, 1); |
| 2780 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2781 | if (true_target == nullptr) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2782 | arm_cond = ARMCondition(condition->GetOppositeCondition()); |
| 2783 | non_fallthrough_target = false_target; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2784 | } else { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2785 | arm_cond = ARMCondition(condition->GetCondition()); |
| 2786 | non_fallthrough_target = true_target; |
| 2787 | } |
| 2788 | |
| 2789 | if (right.IsImmediate() && right.GetImmediate() == 0 && (arm_cond.Is(ne) || arm_cond.Is(eq))) { |
| 2790 | if (arm_cond.Is(eq)) { |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2791 | __ CompareAndBranchIfZero(left, non_fallthrough_target, far_target); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2792 | } else { |
| 2793 | DCHECK(arm_cond.Is(ne)); |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2794 | __ CompareAndBranchIfNonZero(left, non_fallthrough_target, far_target); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2795 | } |
| 2796 | } else { |
| 2797 | __ Cmp(left, right); |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2798 | __ B(arm_cond, non_fallthrough_target, far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2799 | } |
| 2800 | } |
| 2801 | |
| 2802 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 2803 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 2804 | if (true_target != nullptr && false_target != nullptr) { |
| 2805 | __ B(false_target); |
| 2806 | } |
| 2807 | } |
| 2808 | |
| 2809 | void LocationsBuilderARMVIXL::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2810 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2811 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| 2812 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2813 | } |
| 2814 | } |
| 2815 | |
| 2816 | void InstructionCodeGeneratorARMVIXL::VisitIf(HIf* if_instr) { |
| 2817 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 2818 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2819 | vixl32::Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 2820 | nullptr : codegen_->GetLabelOf(true_successor); |
| 2821 | vixl32::Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 2822 | nullptr : codegen_->GetLabelOf(false_successor); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2823 | GenerateTestAndBranch(if_instr, /* condition_input_index= */ 0, true_target, false_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2824 | } |
| 2825 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2826 | void LocationsBuilderARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2827 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2828 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 2829 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 2830 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2831 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 2832 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2833 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| 2834 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2835 | } |
| 2836 | } |
| 2837 | |
| 2838 | void InstructionCodeGeneratorARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2839 | SlowPathCodeARMVIXL* slow_path = |
| 2840 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARMVIXL>(deoptimize); |
| 2841 | GenerateTestAndBranch(deoptimize, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2842 | /* condition_input_index= */ 0, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2843 | slow_path->GetEntryLabel(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2844 | /* false_target= */ nullptr); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2845 | } |
| 2846 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2847 | void LocationsBuilderARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2848 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2849 | LocationSummary(flag, LocationSummary::kNoCall); |
| 2850 | locations->SetOut(Location::RequiresRegister()); |
| 2851 | } |
| 2852 | |
| 2853 | void InstructionCodeGeneratorARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2854 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 2855 | OutputRegister(flag), |
| 2856 | sp, |
| 2857 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 2858 | } |
| 2859 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2860 | void LocationsBuilderARMVIXL::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2861 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2862 | const bool is_floating_point = DataType::IsFloatingPointType(select->GetType()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2863 | |
| 2864 | if (is_floating_point) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2865 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2866 | locations->SetInAt(1, Location::FpuRegisterOrConstant(select->GetTrueValue())); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2867 | } else { |
| 2868 | locations->SetInAt(0, Location::RequiresRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2869 | locations->SetInAt(1, Arm8BitEncodableConstantOrRegister(select->GetTrueValue())); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2870 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2871 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2872 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2873 | locations->SetInAt(2, Location::RegisterOrConstant(select->GetCondition())); |
| 2874 | // The code generator handles overlap with the values, but not with the condition. |
| 2875 | locations->SetOut(Location::SameAsFirstInput()); |
| 2876 | } else if (is_floating_point) { |
| 2877 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2878 | } else { |
| 2879 | if (!locations->InAt(1).IsConstant()) { |
| 2880 | locations->SetInAt(0, Arm8BitEncodableConstantOrRegister(select->GetFalseValue())); |
| 2881 | } |
| 2882 | |
| 2883 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2884 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2885 | } |
| 2886 | |
| 2887 | void InstructionCodeGeneratorARMVIXL::VisitSelect(HSelect* select) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2888 | HInstruction* const condition = select->GetCondition(); |
| 2889 | const LocationSummary* const locations = select->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2890 | const DataType::Type type = select->GetType(); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2891 | const Location first = locations->InAt(0); |
| 2892 | const Location out = locations->Out(); |
| 2893 | const Location second = locations->InAt(1); |
Nicolas Geoffray | 7b05c5f | 2018-09-21 11:31:38 +0100 | [diff] [blame] | 2894 | |
| 2895 | // In the unlucky case the output of this instruction overlaps |
| 2896 | // with an input of an "emitted-at-use-site" condition, and |
| 2897 | // the output of this instruction is not one of its inputs, we'll |
| 2898 | // need to fallback to branches instead of conditional ARM instructions. |
| 2899 | bool output_overlaps_with_condition_inputs = |
| 2900 | !IsBooleanValueOrMaterializedCondition(condition) && |
| 2901 | !out.Equals(first) && |
| 2902 | !out.Equals(second) && |
| 2903 | (condition->GetLocations()->InAt(0).Equals(out) || |
| 2904 | condition->GetLocations()->InAt(1).Equals(out)); |
| 2905 | DCHECK(!output_overlaps_with_condition_inputs || condition->IsCondition()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2906 | Location src; |
| 2907 | |
| 2908 | if (condition->IsIntConstant()) { |
| 2909 | if (condition->AsIntConstant()->IsFalse()) { |
| 2910 | src = first; |
| 2911 | } else { |
| 2912 | src = second; |
| 2913 | } |
| 2914 | |
| 2915 | codegen_->MoveLocation(out, src, type); |
| 2916 | return; |
| 2917 | } |
| 2918 | |
Nicolas Geoffray | 7b05c5f | 2018-09-21 11:31:38 +0100 | [diff] [blame] | 2919 | if (!DataType::IsFloatingPointType(type) && !output_overlaps_with_condition_inputs) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2920 | bool invert = false; |
| 2921 | |
| 2922 | if (out.Equals(second)) { |
| 2923 | src = first; |
| 2924 | invert = true; |
| 2925 | } else if (out.Equals(first)) { |
| 2926 | src = second; |
| 2927 | } else if (second.IsConstant()) { |
| 2928 | DCHECK(CanEncodeConstantAs8BitImmediate(second.GetConstant())); |
| 2929 | src = second; |
| 2930 | } else if (first.IsConstant()) { |
| 2931 | DCHECK(CanEncodeConstantAs8BitImmediate(first.GetConstant())); |
| 2932 | src = first; |
| 2933 | invert = true; |
| 2934 | } else { |
| 2935 | src = second; |
| 2936 | } |
| 2937 | |
| 2938 | if (CanGenerateConditionalMove(out, src)) { |
| 2939 | if (!out.Equals(first) && !out.Equals(second)) { |
| 2940 | codegen_->MoveLocation(out, src.Equals(first) ? second : first, type); |
| 2941 | } |
| 2942 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2943 | std::pair<vixl32::Condition, vixl32::Condition> cond(eq, ne); |
| 2944 | |
| 2945 | if (IsBooleanValueOrMaterializedCondition(condition)) { |
| 2946 | __ Cmp(InputRegisterAt(select, 2), 0); |
| 2947 | cond = invert ? std::make_pair(eq, ne) : std::make_pair(ne, eq); |
| 2948 | } else { |
| 2949 | cond = GenerateTest(condition->AsCondition(), invert, codegen_); |
| 2950 | } |
| 2951 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2952 | const size_t instr_count = out.IsRegisterPair() ? 4 : 2; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2953 | // We use the scope because of the IT block that follows. |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2954 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 2955 | instr_count * vixl32::k16BitT32InstructionSizeInBytes, |
| 2956 | CodeBufferCheckScope::kExactSize); |
| 2957 | |
| 2958 | if (out.IsRegister()) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2959 | __ it(cond.first); |
| 2960 | __ mov(cond.first, RegisterFrom(out), OperandFrom(src, type)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2961 | } else { |
| 2962 | DCHECK(out.IsRegisterPair()); |
| 2963 | |
| 2964 | Operand operand_high(0); |
| 2965 | Operand operand_low(0); |
| 2966 | |
| 2967 | if (src.IsConstant()) { |
| 2968 | const int64_t value = Int64ConstantFrom(src); |
| 2969 | |
| 2970 | operand_high = High32Bits(value); |
| 2971 | operand_low = Low32Bits(value); |
| 2972 | } else { |
| 2973 | DCHECK(src.IsRegisterPair()); |
| 2974 | operand_high = HighRegisterFrom(src); |
| 2975 | operand_low = LowRegisterFrom(src); |
| 2976 | } |
| 2977 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2978 | __ it(cond.first); |
| 2979 | __ mov(cond.first, LowRegisterFrom(out), operand_low); |
| 2980 | __ it(cond.first); |
| 2981 | __ mov(cond.first, HighRegisterFrom(out), operand_high); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2982 | } |
| 2983 | |
| 2984 | return; |
| 2985 | } |
| 2986 | } |
| 2987 | |
| 2988 | vixl32::Label* false_target = nullptr; |
| 2989 | vixl32::Label* true_target = nullptr; |
| 2990 | vixl32::Label select_end; |
Nicolas Geoffray | 7b05c5f | 2018-09-21 11:31:38 +0100 | [diff] [blame] | 2991 | vixl32::Label other_case; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2992 | vixl32::Label* const target = codegen_->GetFinalLabel(select, &select_end); |
| 2993 | |
| 2994 | if (out.Equals(second)) { |
| 2995 | true_target = target; |
| 2996 | src = first; |
| 2997 | } else { |
| 2998 | false_target = target; |
| 2999 | src = second; |
| 3000 | |
| 3001 | if (!out.Equals(first)) { |
Nicolas Geoffray | 7b05c5f | 2018-09-21 11:31:38 +0100 | [diff] [blame] | 3002 | if (output_overlaps_with_condition_inputs) { |
| 3003 | false_target = &other_case; |
| 3004 | } else { |
| 3005 | codegen_->MoveLocation(out, first, type); |
| 3006 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3007 | } |
| 3008 | } |
| 3009 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3010 | GenerateTestAndBranch(select, 2, true_target, false_target, /* far_target= */ false); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3011 | codegen_->MoveLocation(out, src, type); |
Nicolas Geoffray | 7b05c5f | 2018-09-21 11:31:38 +0100 | [diff] [blame] | 3012 | if (output_overlaps_with_condition_inputs) { |
| 3013 | __ B(target); |
| 3014 | __ Bind(&other_case); |
| 3015 | codegen_->MoveLocation(out, first, type); |
| 3016 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3017 | |
| 3018 | if (select_end.IsReferenced()) { |
| 3019 | __ Bind(&select_end); |
| 3020 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3021 | } |
| 3022 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 3023 | void LocationsBuilderARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3024 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 3025 | } |
| 3026 | |
| 3027 | void InstructionCodeGeneratorARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3028 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| 3029 | } |
| 3030 | |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3031 | void CodeGeneratorARMVIXL::IncreaseFrame(size_t adjustment) { |
| 3032 | __ Claim(adjustment); |
| 3033 | GetAssembler()->cfi().AdjustCFAOffset(adjustment); |
| 3034 | } |
| 3035 | |
| 3036 | void CodeGeneratorARMVIXL::DecreaseFrame(size_t adjustment) { |
| 3037 | __ Drop(adjustment); |
| 3038 | GetAssembler()->cfi().AdjustCFAOffset(-adjustment); |
| 3039 | } |
| 3040 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3041 | void CodeGeneratorARMVIXL::GenerateNop() { |
| 3042 | __ Nop(); |
| 3043 | } |
| 3044 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3045 | // `temp` is an extra temporary register that is used for some conditions; |
| 3046 | // callers may not specify it, in which case the method will use a scratch |
| 3047 | // register instead. |
| 3048 | void CodeGeneratorARMVIXL::GenerateConditionWithZero(IfCondition condition, |
| 3049 | vixl32::Register out, |
| 3050 | vixl32::Register in, |
| 3051 | vixl32::Register temp) { |
| 3052 | switch (condition) { |
| 3053 | case kCondEQ: |
| 3054 | // x <= 0 iff x == 0 when the comparison is unsigned. |
| 3055 | case kCondBE: |
| 3056 | if (!temp.IsValid() || (out.IsLow() && !out.Is(in))) { |
| 3057 | temp = out; |
| 3058 | } |
| 3059 | |
| 3060 | // Avoid 32-bit instructions if possible; note that `in` and `temp` must be |
| 3061 | // different as well. |
| 3062 | if (in.IsLow() && temp.IsLow() && !in.Is(temp)) { |
| 3063 | // temp = - in; only 0 sets the carry flag. |
| 3064 | __ Rsbs(temp, in, 0); |
| 3065 | |
| 3066 | if (out.Is(in)) { |
| 3067 | std::swap(in, temp); |
| 3068 | } |
| 3069 | |
| 3070 | // out = - in + in + carry = carry |
| 3071 | __ Adc(out, temp, in); |
| 3072 | } else { |
| 3073 | // If `in` is 0, then it has 32 leading zeros, and less than that otherwise. |
| 3074 | __ Clz(out, in); |
| 3075 | // Any number less than 32 logically shifted right by 5 bits results in 0; |
| 3076 | // the same operation on 32 yields 1. |
| 3077 | __ Lsr(out, out, 5); |
| 3078 | } |
| 3079 | |
| 3080 | break; |
| 3081 | case kCondNE: |
| 3082 | // x > 0 iff x != 0 when the comparison is unsigned. |
| 3083 | case kCondA: { |
| 3084 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3085 | |
| 3086 | if (out.Is(in)) { |
| 3087 | if (!temp.IsValid() || in.Is(temp)) { |
| 3088 | temp = temps.Acquire(); |
| 3089 | } |
| 3090 | } else if (!temp.IsValid() || !temp.IsLow()) { |
| 3091 | temp = out; |
| 3092 | } |
| 3093 | |
| 3094 | // temp = in - 1; only 0 does not set the carry flag. |
| 3095 | __ Subs(temp, in, 1); |
| 3096 | // out = in + ~temp + carry = in + (-(in - 1) - 1) + carry = in - in + 1 - 1 + carry = carry |
| 3097 | __ Sbc(out, in, temp); |
| 3098 | break; |
| 3099 | } |
| 3100 | case kCondGE: |
| 3101 | __ Mvn(out, in); |
| 3102 | in = out; |
| 3103 | FALLTHROUGH_INTENDED; |
| 3104 | case kCondLT: |
| 3105 | // We only care about the sign bit. |
| 3106 | __ Lsr(out, in, 31); |
| 3107 | break; |
| 3108 | case kCondAE: |
| 3109 | // Trivially true. |
| 3110 | __ Mov(out, 1); |
| 3111 | break; |
| 3112 | case kCondB: |
| 3113 | // Trivially false. |
| 3114 | __ Mov(out, 0); |
| 3115 | break; |
| 3116 | default: |
| 3117 | LOG(FATAL) << "Unexpected condition " << condition; |
| 3118 | UNREACHABLE(); |
| 3119 | } |
| 3120 | } |
| 3121 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3122 | void LocationsBuilderARMVIXL::HandleCondition(HCondition* cond) { |
| 3123 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3124 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
Nicolas Geoffray | 7b05c5f | 2018-09-21 11:31:38 +0100 | [diff] [blame] | 3125 | const DataType::Type type = cond->InputAt(0)->GetType(); |
| 3126 | if (DataType::IsFloatingPointType(type)) { |
| 3127 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3128 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
| 3129 | } else { |
| 3130 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3131 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 3132 | } |
| 3133 | if (!cond->IsEmittedAtUseSite()) { |
| 3134 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3135 | } |
| 3136 | } |
| 3137 | |
| 3138 | void InstructionCodeGeneratorARMVIXL::HandleCondition(HCondition* cond) { |
| 3139 | if (cond->IsEmittedAtUseSite()) { |
| 3140 | return; |
| 3141 | } |
| 3142 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3143 | const DataType::Type type = cond->GetLeft()->GetType(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3144 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3145 | if (DataType::IsFloatingPointType(type)) { |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3146 | GenerateConditionGeneric(cond, codegen_); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3147 | return; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3148 | } |
| 3149 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3150 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3151 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3152 | const IfCondition condition = cond->GetCondition(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3153 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3154 | // A condition with only one boolean input, or two boolean inputs without being equality or |
| 3155 | // inequality results from transformations done by the instruction simplifier, and is handled |
| 3156 | // as a regular condition with integral inputs. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3157 | if (type == DataType::Type::kBool && |
| 3158 | cond->GetRight()->GetType() == DataType::Type::kBool && |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3159 | (condition == kCondEQ || condition == kCondNE)) { |
| 3160 | vixl32::Register left = InputRegisterAt(cond, 0); |
| 3161 | const vixl32::Register out = OutputRegister(cond); |
| 3162 | const Location right_loc = cond->GetLocations()->InAt(1); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3163 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3164 | // The constant case is handled by the instruction simplifier. |
| 3165 | DCHECK(!right_loc.IsConstant()); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3166 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3167 | vixl32::Register right = RegisterFrom(right_loc); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3168 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3169 | // Avoid 32-bit instructions if possible. |
| 3170 | if (out.Is(right)) { |
| 3171 | std::swap(left, right); |
| 3172 | } |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3173 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3174 | __ Eor(out, left, right); |
| 3175 | |
| 3176 | if (condition == kCondEQ) { |
| 3177 | __ Eor(out, out, 1); |
| 3178 | } |
| 3179 | |
| 3180 | return; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3181 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 3182 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3183 | GenerateConditionIntegralOrNonPrimitive(cond, codegen_); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3184 | } |
| 3185 | |
| 3186 | void LocationsBuilderARMVIXL::VisitEqual(HEqual* comp) { |
| 3187 | HandleCondition(comp); |
| 3188 | } |
| 3189 | |
| 3190 | void InstructionCodeGeneratorARMVIXL::VisitEqual(HEqual* comp) { |
| 3191 | HandleCondition(comp); |
| 3192 | } |
| 3193 | |
| 3194 | void LocationsBuilderARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 3195 | HandleCondition(comp); |
| 3196 | } |
| 3197 | |
| 3198 | void InstructionCodeGeneratorARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 3199 | HandleCondition(comp); |
| 3200 | } |
| 3201 | |
| 3202 | void LocationsBuilderARMVIXL::VisitLessThan(HLessThan* comp) { |
| 3203 | HandleCondition(comp); |
| 3204 | } |
| 3205 | |
| 3206 | void InstructionCodeGeneratorARMVIXL::VisitLessThan(HLessThan* comp) { |
| 3207 | HandleCondition(comp); |
| 3208 | } |
| 3209 | |
| 3210 | void LocationsBuilderARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 3211 | HandleCondition(comp); |
| 3212 | } |
| 3213 | |
| 3214 | void InstructionCodeGeneratorARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 3215 | HandleCondition(comp); |
| 3216 | } |
| 3217 | |
| 3218 | void LocationsBuilderARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 3219 | HandleCondition(comp); |
| 3220 | } |
| 3221 | |
| 3222 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 3223 | HandleCondition(comp); |
| 3224 | } |
| 3225 | |
| 3226 | void LocationsBuilderARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 3227 | HandleCondition(comp); |
| 3228 | } |
| 3229 | |
| 3230 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 3231 | HandleCondition(comp); |
| 3232 | } |
| 3233 | |
| 3234 | void LocationsBuilderARMVIXL::VisitBelow(HBelow* comp) { |
| 3235 | HandleCondition(comp); |
| 3236 | } |
| 3237 | |
| 3238 | void InstructionCodeGeneratorARMVIXL::VisitBelow(HBelow* comp) { |
| 3239 | HandleCondition(comp); |
| 3240 | } |
| 3241 | |
| 3242 | void LocationsBuilderARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 3243 | HandleCondition(comp); |
| 3244 | } |
| 3245 | |
| 3246 | void InstructionCodeGeneratorARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 3247 | HandleCondition(comp); |
| 3248 | } |
| 3249 | |
| 3250 | void LocationsBuilderARMVIXL::VisitAbove(HAbove* comp) { |
| 3251 | HandleCondition(comp); |
| 3252 | } |
| 3253 | |
| 3254 | void InstructionCodeGeneratorARMVIXL::VisitAbove(HAbove* comp) { |
| 3255 | HandleCondition(comp); |
| 3256 | } |
| 3257 | |
| 3258 | void LocationsBuilderARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 3259 | HandleCondition(comp); |
| 3260 | } |
| 3261 | |
| 3262 | void InstructionCodeGeneratorARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 3263 | HandleCondition(comp); |
| 3264 | } |
| 3265 | |
| 3266 | void LocationsBuilderARMVIXL::VisitIntConstant(HIntConstant* constant) { |
| 3267 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3268 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3269 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3270 | } |
| 3271 | |
| 3272 | void InstructionCodeGeneratorARMVIXL::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 3273 | // Will be generated at use site. |
| 3274 | } |
| 3275 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3276 | void LocationsBuilderARMVIXL::VisitNullConstant(HNullConstant* constant) { |
| 3277 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3278 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3279 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3280 | } |
| 3281 | |
| 3282 | void InstructionCodeGeneratorARMVIXL::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 3283 | // Will be generated at use site. |
| 3284 | } |
| 3285 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3286 | void LocationsBuilderARMVIXL::VisitLongConstant(HLongConstant* constant) { |
| 3287 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3288 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3289 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3290 | } |
| 3291 | |
| 3292 | void InstructionCodeGeneratorARMVIXL::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 3293 | // Will be generated at use site. |
| 3294 | } |
| 3295 | |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3296 | void LocationsBuilderARMVIXL::VisitFloatConstant(HFloatConstant* constant) { |
| 3297 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3298 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3299 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3300 | } |
| 3301 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3302 | void InstructionCodeGeneratorARMVIXL::VisitFloatConstant( |
| 3303 | HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3304 | // Will be generated at use site. |
| 3305 | } |
| 3306 | |
| 3307 | void LocationsBuilderARMVIXL::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3308 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3309 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3310 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3311 | } |
| 3312 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3313 | void InstructionCodeGeneratorARMVIXL::VisitDoubleConstant( |
| 3314 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3315 | // Will be generated at use site. |
| 3316 | } |
| 3317 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 3318 | void LocationsBuilderARMVIXL::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 3319 | constructor_fence->SetLocations(nullptr); |
| 3320 | } |
| 3321 | |
| 3322 | void InstructionCodeGeneratorARMVIXL::VisitConstructorFence( |
| 3323 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 3324 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 3325 | } |
| 3326 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3327 | void LocationsBuilderARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3328 | memory_barrier->SetLocations(nullptr); |
| 3329 | } |
| 3330 | |
| 3331 | void InstructionCodeGeneratorARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3332 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 3333 | } |
| 3334 | |
| 3335 | void LocationsBuilderARMVIXL::VisitReturnVoid(HReturnVoid* ret) { |
| 3336 | ret->SetLocations(nullptr); |
| 3337 | } |
| 3338 | |
| 3339 | void InstructionCodeGeneratorARMVIXL::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 3340 | codegen_->GenerateFrameExit(); |
| 3341 | } |
| 3342 | |
| 3343 | void LocationsBuilderARMVIXL::VisitReturn(HReturn* ret) { |
| 3344 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3345 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3346 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
| 3347 | } |
| 3348 | |
Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 3349 | void InstructionCodeGeneratorARMVIXL::VisitReturn(HReturn* ret) { |
| 3350 | if (GetGraph()->IsCompilingOsr()) { |
| 3351 | // To simplify callers of an OSR method, we put the return value in both |
| 3352 | // floating point and core registers. |
| 3353 | switch (ret->InputAt(0)->GetType()) { |
| 3354 | case DataType::Type::kFloat32: |
| 3355 | __ Vmov(r0, s0); |
| 3356 | break; |
| 3357 | case DataType::Type::kFloat64: |
| 3358 | __ Vmov(r0, r1, d0); |
| 3359 | break; |
| 3360 | default: |
| 3361 | break; |
| 3362 | } |
| 3363 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3364 | codegen_->GenerateFrameExit(); |
| 3365 | } |
| 3366 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3367 | void LocationsBuilderARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3368 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3369 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3370 | // the method_idx. |
| 3371 | HandleInvoke(invoke); |
| 3372 | } |
| 3373 | |
| 3374 | void InstructionCodeGeneratorARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3375 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3376 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 3); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3377 | } |
| 3378 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3379 | void LocationsBuilderARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3380 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3381 | // art::PrepareForRegisterAllocation. |
| 3382 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 3383 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3384 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3385 | if (intrinsic.TryDispatch(invoke)) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3386 | return; |
| 3387 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3388 | |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 3389 | if (invoke->GetCodePtrLocation() == CodePtrLocation::kCallCriticalNative) { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 3390 | CriticalNativeCallingConventionVisitorARMVIXL calling_convention_visitor( |
| 3391 | /*for_register_allocation=*/ true); |
| 3392 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 3393 | } else { |
| 3394 | HandleInvoke(invoke); |
| 3395 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3396 | } |
| 3397 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3398 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARMVIXL* codegen) { |
| 3399 | if (invoke->GetLocations()->Intrinsified()) { |
| 3400 | IntrinsicCodeGeneratorARMVIXL intrinsic(codegen); |
| 3401 | intrinsic.Dispatch(invoke); |
| 3402 | return true; |
| 3403 | } |
| 3404 | return false; |
| 3405 | } |
| 3406 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3407 | void InstructionCodeGeneratorARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3408 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3409 | // art::PrepareForRegisterAllocation. |
| 3410 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 3411 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3412 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3413 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 4); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3414 | return; |
| 3415 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3416 | |
| 3417 | LocationSummary* locations = invoke->GetLocations(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3418 | codegen_->GenerateStaticOrDirectCall( |
| 3419 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3420 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3421 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 5); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3422 | } |
| 3423 | |
| 3424 | void LocationsBuilderARMVIXL::HandleInvoke(HInvoke* invoke) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3425 | InvokeDexCallingConventionVisitorARMVIXL calling_convention_visitor; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3426 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 3427 | } |
| 3428 | |
| 3429 | void LocationsBuilderARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3430 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3431 | if (intrinsic.TryDispatch(invoke)) { |
| 3432 | return; |
| 3433 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3434 | |
| 3435 | HandleInvoke(invoke); |
| 3436 | } |
| 3437 | |
| 3438 | void InstructionCodeGeneratorARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3439 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3440 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 6); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3441 | return; |
| 3442 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3443 | |
| 3444 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3445 | DCHECK(!codegen_->IsLeafMethod()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3446 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3447 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 7); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3448 | } |
| 3449 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3450 | void LocationsBuilderARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3451 | HandleInvoke(invoke); |
| 3452 | // Add the hidden argument. |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 3453 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRecursive) { |
| 3454 | // We cannot request r12 as it's blocked by the register allocator. |
| 3455 | invoke->GetLocations()->SetInAt(invoke->GetNumberOfArguments() - 1, Location::Any()); |
| 3456 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3457 | } |
| 3458 | |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 3459 | void CodeGeneratorARMVIXL::MaybeGenerateInlineCacheCheck(HInstruction* instruction, |
| 3460 | vixl32::Register klass) { |
| 3461 | DCHECK_EQ(r0.GetCode(), klass.GetCode()); |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 3462 | // We know the destination of an intrinsic, so no need to record inline |
| 3463 | // caches. |
| 3464 | if (!instruction->GetLocations()->Intrinsified() && |
Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 3465 | GetGraph()->IsCompilingBaseline() && |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 3466 | !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 3467 | DCHECK(!instruction->GetEnvironment()->IsFromInlinedInvoke()); |
Nicolas Geoffray | 095dc46 | 2020-08-17 16:40:28 +0100 | [diff] [blame] | 3468 | ScopedProfilingInfoUse spiu( |
| 3469 | Runtime::Current()->GetJit(), GetGraph()->GetArtMethod(), Thread::Current()); |
| 3470 | ProfilingInfo* info = spiu.GetProfilingInfo(); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 3471 | if (info != nullptr) { |
| 3472 | InlineCache* cache = info->GetInlineCache(instruction->GetDexPc()); |
| 3473 | uint32_t address = reinterpret_cast32<uint32_t>(cache); |
| 3474 | vixl32::Label done; |
| 3475 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3476 | temps.Exclude(ip); |
| 3477 | __ Mov(r4, address); |
| 3478 | __ Ldr(ip, MemOperand(r4, InlineCache::ClassesOffset().Int32Value())); |
| 3479 | // Fast path for a monomorphic cache. |
| 3480 | __ Cmp(klass, ip); |
| 3481 | __ B(eq, &done, /* is_far_target= */ false); |
| 3482 | InvokeRuntime(kQuickUpdateInlineCache, instruction, instruction->GetDexPc()); |
| 3483 | __ Bind(&done); |
| 3484 | } |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 3485 | } |
| 3486 | } |
| 3487 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3488 | void InstructionCodeGeneratorARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3489 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 3490 | LocationSummary* locations = invoke->GetLocations(); |
| 3491 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3492 | Location receiver = locations->InAt(0); |
| 3493 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3494 | |
| 3495 | DCHECK(!receiver.IsStackSlot()); |
| 3496 | |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3497 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
| 3498 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 3499 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 3500 | vixl32::kMaxInstructionSizeInBytes, |
| 3501 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3502 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 3503 | __ ldr(temp, MemOperand(RegisterFrom(receiver), class_offset)); |
| 3504 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 3505 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3506 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3507 | // emit a read barrier for the previous class reference load. |
| 3508 | // However this is not required in practice, as this is an |
| 3509 | // intermediate/temporary reference and because the current |
| 3510 | // concurrent copying collector keeps the from-space memory |
| 3511 | // intact/accessible until the end of the marking phase (the |
| 3512 | // concurrent copying collector may not in the future). |
| 3513 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 3514 | |
| 3515 | // If we're compiling baseline, update the inline cache. |
| 3516 | codegen_->MaybeGenerateInlineCacheCheck(invoke, temp); |
| 3517 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3518 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3519 | temp, |
| 3520 | temp, |
| 3521 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 3522 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3523 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 3524 | invoke->GetImtIndex(), kArmPointerSize)); |
| 3525 | // temp = temp->GetImtEntryAt(method_offset); |
| 3526 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 3527 | uint32_t entry_point = |
| 3528 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
| 3529 | // LR = temp->GetEntryPoint(); |
| 3530 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
| 3531 | |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3532 | { |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 3533 | // Set the hidden (in r12) argument. It is done here, right before a BLX to prevent other |
| 3534 | // instruction from clobbering it as they might use r12 as a scratch register. |
| 3535 | Location hidden_reg = Location::RegisterLocation(r12.GetCode()); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3536 | // The VIXL macro assembler may clobber any of the scratch registers that are available to it, |
| 3537 | // so it checks if the application is using them (by passing them to the macro assembler |
| 3538 | // methods). The following application of UseScratchRegisterScope corrects VIXL's notion of |
| 3539 | // what is available, and is the opposite of the standard usage: Instead of requesting a |
| 3540 | // temporary location, it imposes an external constraint (i.e. a specific register is reserved |
| 3541 | // for the hidden argument). Note that this works even if VIXL needs a scratch register itself |
| 3542 | // (to materialize the constant), since the destination register becomes available for such use |
| 3543 | // internally for the duration of the macro instruction. |
| 3544 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 3545 | temps.Exclude(RegisterFrom(hidden_reg)); |
| 3546 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRecursive) { |
| 3547 | Location current_method = locations->InAt(invoke->GetNumberOfArguments() - 1); |
| 3548 | if (current_method.IsStackSlot()) { |
| 3549 | GetAssembler()->LoadFromOffset( |
| 3550 | kLoadWord, RegisterFrom(hidden_reg), sp, current_method.GetStackIndex()); |
| 3551 | } else { |
| 3552 | __ Mov(RegisterFrom(hidden_reg), RegisterFrom(current_method)); |
| 3553 | } |
Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame] | 3554 | } else if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRuntimeCall) { |
| 3555 | // We pass the method from the IMT in case of a conflict. This will ensure |
| 3556 | // we go into the runtime to resolve the actual method. |
| 3557 | CHECK_NE(temp.GetCode(), lr.GetCode()); |
| 3558 | __ Mov(RegisterFrom(hidden_reg), temp); |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 3559 | } else { |
| 3560 | codegen_->LoadMethod(invoke->GetHiddenArgumentLoadKind(), hidden_reg, invoke); |
| 3561 | } |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3562 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3563 | { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3564 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 3565 | // blx in T32 has only 16bit encoding that's why a stricter check for the scope is used. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 3566 | ExactAssemblyScope aas(GetVIXLAssembler(), |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3567 | vixl32::k16BitT32InstructionSizeInBytes, |
| 3568 | CodeBufferCheckScope::kExactSize); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3569 | // LR(); |
| 3570 | __ blx(lr); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3571 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3572 | DCHECK(!codegen_->IsLeafMethod()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3573 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3574 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3575 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 8); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3576 | } |
| 3577 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3578 | void LocationsBuilderARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 3579 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3580 | if (intrinsic.TryDispatch(invoke)) { |
| 3581 | return; |
| 3582 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3583 | HandleInvoke(invoke); |
| 3584 | } |
| 3585 | |
| 3586 | void InstructionCodeGeneratorARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 3587 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3588 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 9); |
| 3589 | return; |
| 3590 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3591 | codegen_->GenerateInvokePolymorphicCall(invoke); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 3592 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 10); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3593 | } |
| 3594 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 3595 | void LocationsBuilderARMVIXL::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 3596 | HandleInvoke(invoke); |
| 3597 | } |
| 3598 | |
| 3599 | void InstructionCodeGeneratorARMVIXL::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 3600 | codegen_->GenerateInvokeCustomCall(invoke); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 3601 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 11); |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 3602 | } |
| 3603 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3604 | void LocationsBuilderARMVIXL::VisitNeg(HNeg* neg) { |
| 3605 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3606 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3607 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3608 | case DataType::Type::kInt32: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3609 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3610 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3611 | break; |
| 3612 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3613 | case DataType::Type::kInt64: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3614 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3615 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3616 | break; |
| 3617 | } |
| 3618 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3619 | case DataType::Type::kFloat32: |
| 3620 | case DataType::Type::kFloat64: |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3621 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3622 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3623 | break; |
| 3624 | |
| 3625 | default: |
| 3626 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3627 | } |
| 3628 | } |
| 3629 | |
| 3630 | void InstructionCodeGeneratorARMVIXL::VisitNeg(HNeg* neg) { |
| 3631 | LocationSummary* locations = neg->GetLocations(); |
| 3632 | Location out = locations->Out(); |
| 3633 | Location in = locations->InAt(0); |
| 3634 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3635 | case DataType::Type::kInt32: |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3636 | __ Rsb(OutputRegister(neg), InputRegisterAt(neg, 0), 0); |
| 3637 | break; |
| 3638 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3639 | case DataType::Type::kInt64: |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3640 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 3641 | __ Rsbs(LowRegisterFrom(out), LowRegisterFrom(in), 0); |
| 3642 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 3643 | // instruction here, as it does not exist in the Thumb-2 |
| 3644 | // instruction set. We use the following approach |
| 3645 | // using SBC and SUB instead. |
| 3646 | // |
| 3647 | // out.hi = -C |
| 3648 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(out)); |
| 3649 | // out.hi = out.hi - in.hi |
| 3650 | __ Sub(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(in)); |
| 3651 | break; |
| 3652 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3653 | case DataType::Type::kFloat32: |
| 3654 | case DataType::Type::kFloat64: |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 3655 | __ Vneg(OutputVRegister(neg), InputVRegister(neg)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3656 | break; |
| 3657 | |
| 3658 | default: |
| 3659 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3660 | } |
| 3661 | } |
| 3662 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3663 | void LocationsBuilderARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3664 | DataType::Type result_type = conversion->GetResultType(); |
| 3665 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3666 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 3667 | << input_type << " -> " << result_type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3668 | |
| 3669 | // The float-to-long, double-to-long and long-to-float type conversions |
| 3670 | // rely on a call to the runtime. |
| 3671 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3672 | (((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) |
| 3673 | && result_type == DataType::Type::kInt64) |
| 3674 | || (input_type == DataType::Type::kInt64 && result_type == DataType::Type::kFloat32)) |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3675 | ? LocationSummary::kCallOnMainOnly |
| 3676 | : LocationSummary::kNoCall; |
| 3677 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3678 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3679 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3680 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3681 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3682 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3683 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3684 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3685 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 3686 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3687 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3688 | break; |
| 3689 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3690 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3691 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3692 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3693 | locations->SetInAt(0, Location::Any()); |
| 3694 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3695 | break; |
| 3696 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3697 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3698 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3699 | locations->SetOut(Location::RequiresRegister()); |
| 3700 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3701 | break; |
| 3702 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3703 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3704 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3705 | locations->SetOut(Location::RequiresRegister()); |
| 3706 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3707 | break; |
| 3708 | |
| 3709 | default: |
| 3710 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3711 | << " to " << result_type; |
| 3712 | } |
| 3713 | break; |
| 3714 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3715 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3716 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3717 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3718 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3719 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3720 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3721 | case DataType::Type::kInt16: |
| 3722 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3723 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3724 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3725 | break; |
| 3726 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3727 | case DataType::Type::kFloat32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3728 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3729 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 3730 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3731 | break; |
| 3732 | } |
| 3733 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3734 | case DataType::Type::kFloat64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3735 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3736 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0), |
| 3737 | calling_convention.GetFpuRegisterAt(1))); |
| 3738 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3739 | break; |
| 3740 | } |
| 3741 | |
| 3742 | default: |
| 3743 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3744 | << " to " << result_type; |
| 3745 | } |
| 3746 | break; |
| 3747 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3748 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3749 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3750 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3751 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3752 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3753 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3754 | case DataType::Type::kInt16: |
| 3755 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3756 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3757 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3758 | break; |
| 3759 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3760 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3761 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3762 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0), |
| 3763 | calling_convention.GetRegisterAt(1))); |
| 3764 | locations->SetOut(LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3765 | break; |
| 3766 | } |
| 3767 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3768 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3769 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3770 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3771 | break; |
| 3772 | |
| 3773 | default: |
| 3774 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3775 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3776 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3777 | break; |
| 3778 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3779 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3780 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3781 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3782 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3783 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3784 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3785 | case DataType::Type::kInt16: |
| 3786 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3787 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3788 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3789 | break; |
| 3790 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3791 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3792 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3793 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3794 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3795 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3796 | break; |
| 3797 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3798 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3799 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3800 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3801 | break; |
| 3802 | |
| 3803 | default: |
| 3804 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3805 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3806 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3807 | break; |
| 3808 | |
| 3809 | default: |
| 3810 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3811 | << " to " << result_type; |
| 3812 | } |
| 3813 | } |
| 3814 | |
| 3815 | void InstructionCodeGeneratorARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
| 3816 | LocationSummary* locations = conversion->GetLocations(); |
| 3817 | Location out = locations->Out(); |
| 3818 | Location in = locations->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3819 | DataType::Type result_type = conversion->GetResultType(); |
| 3820 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3821 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 3822 | << input_type << " -> " << result_type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3823 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3824 | case DataType::Type::kUint8: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3825 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3826 | case DataType::Type::kInt8: |
| 3827 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3828 | case DataType::Type::kInt16: |
| 3829 | case DataType::Type::kInt32: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3830 | __ Ubfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 8); |
| 3831 | break; |
| 3832 | case DataType::Type::kInt64: |
| 3833 | __ Ubfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 8); |
| 3834 | break; |
| 3835 | |
| 3836 | default: |
| 3837 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3838 | << " to " << result_type; |
| 3839 | } |
| 3840 | break; |
| 3841 | |
| 3842 | case DataType::Type::kInt8: |
| 3843 | switch (input_type) { |
| 3844 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3845 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3846 | case DataType::Type::kInt16: |
| 3847 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3848 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 8); |
| 3849 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3850 | case DataType::Type::kInt64: |
| 3851 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 8); |
| 3852 | break; |
| 3853 | |
| 3854 | default: |
| 3855 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3856 | << " to " << result_type; |
| 3857 | } |
| 3858 | break; |
| 3859 | |
| 3860 | case DataType::Type::kUint16: |
| 3861 | switch (input_type) { |
| 3862 | case DataType::Type::kInt8: |
| 3863 | case DataType::Type::kInt16: |
| 3864 | case DataType::Type::kInt32: |
| 3865 | __ Ubfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 3866 | break; |
| 3867 | case DataType::Type::kInt64: |
| 3868 | __ Ubfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
| 3869 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3870 | |
| 3871 | default: |
| 3872 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3873 | << " to " << result_type; |
| 3874 | } |
| 3875 | break; |
| 3876 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3877 | case DataType::Type::kInt16: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3878 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3879 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3880 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3881 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 3882 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3883 | case DataType::Type::kInt64: |
| 3884 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
| 3885 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3886 | |
| 3887 | default: |
| 3888 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3889 | << " to " << result_type; |
| 3890 | } |
| 3891 | break; |
| 3892 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3893 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3894 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3895 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3896 | DCHECK(out.IsRegister()); |
| 3897 | if (in.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3898 | __ Mov(OutputRegister(conversion), LowRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3899 | } else if (in.IsDoubleStackSlot()) { |
| 3900 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3901 | OutputRegister(conversion), |
| 3902 | sp, |
| 3903 | in.GetStackIndex()); |
| 3904 | } else { |
| 3905 | DCHECK(in.IsConstant()); |
| 3906 | DCHECK(in.GetConstant()->IsLongConstant()); |
Vladimir Marko | ba1a48e | 2017-04-13 11:50:14 +0100 | [diff] [blame] | 3907 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3908 | __ Mov(OutputRegister(conversion), static_cast<int32_t>(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3909 | } |
| 3910 | break; |
| 3911 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3912 | case DataType::Type::kFloat32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3913 | vixl32::SRegister temp = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3914 | __ Vcvt(S32, F32, temp, InputSRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3915 | __ Vmov(OutputRegister(conversion), temp); |
| 3916 | break; |
| 3917 | } |
| 3918 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3919 | case DataType::Type::kFloat64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3920 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3921 | __ Vcvt(S32, F64, temp_s, DRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3922 | __ Vmov(OutputRegister(conversion), temp_s); |
| 3923 | break; |
| 3924 | } |
| 3925 | |
| 3926 | default: |
| 3927 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3928 | << " to " << result_type; |
| 3929 | } |
| 3930 | break; |
| 3931 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3932 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3933 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3934 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3935 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3936 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3937 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3938 | case DataType::Type::kInt16: |
| 3939 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3940 | DCHECK(out.IsRegisterPair()); |
| 3941 | DCHECK(in.IsRegister()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3942 | __ Mov(LowRegisterFrom(out), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3943 | // Sign extension. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3944 | __ Asr(HighRegisterFrom(out), LowRegisterFrom(out), 31); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3945 | break; |
| 3946 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3947 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3948 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
| 3949 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 3950 | break; |
| 3951 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3952 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3953 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
| 3954 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 3955 | break; |
| 3956 | |
| 3957 | default: |
| 3958 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3959 | << " to " << result_type; |
| 3960 | } |
| 3961 | break; |
| 3962 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3963 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3964 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3965 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3966 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3967 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3968 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3969 | case DataType::Type::kInt16: |
| 3970 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3971 | __ Vmov(OutputSRegister(conversion), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3972 | __ Vcvt(F32, S32, OutputSRegister(conversion), OutputSRegister(conversion)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3973 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3974 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3975 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3976 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
| 3977 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 3978 | break; |
| 3979 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3980 | case DataType::Type::kFloat64: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3981 | __ Vcvt(F32, F64, OutputSRegister(conversion), DRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3982 | break; |
| 3983 | |
| 3984 | default: |
| 3985 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3986 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3987 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3988 | break; |
| 3989 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3990 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3991 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3992 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3993 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3994 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3995 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3996 | case DataType::Type::kInt16: |
| 3997 | case DataType::Type::kInt32: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3998 | __ Vmov(LowSRegisterFrom(out), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3999 | __ Vcvt(F64, S32, DRegisterFrom(out), LowSRegisterFrom(out)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4000 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4001 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4002 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4003 | vixl32::Register low = LowRegisterFrom(in); |
| 4004 | vixl32::Register high = HighRegisterFrom(in); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4005 | vixl32::SRegister out_s = LowSRegisterFrom(out); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4006 | vixl32::DRegister out_d = DRegisterFrom(out); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4007 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4008 | vixl32::DRegister temp_d = DRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4009 | vixl32::DRegister constant_d = DRegisterFrom(locations->GetTemp(1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4010 | |
| 4011 | // temp_d = int-to-double(high) |
| 4012 | __ Vmov(temp_s, high); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4013 | __ Vcvt(F64, S32, temp_d, temp_s); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4014 | // constant_d = k2Pow32EncodingForDouble |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4015 | __ Vmov(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4016 | // out_d = unsigned-to-double(low) |
| 4017 | __ Vmov(out_s, low); |
| 4018 | __ Vcvt(F64, U32, out_d, out_s); |
| 4019 | // out_d += temp_d * constant_d |
| 4020 | __ Vmla(F64, out_d, temp_d, constant_d); |
| 4021 | break; |
| 4022 | } |
| 4023 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4024 | case DataType::Type::kFloat32: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4025 | __ Vcvt(F64, F32, DRegisterFrom(out), InputSRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4026 | break; |
| 4027 | |
| 4028 | default: |
| 4029 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4030 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 4031 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4032 | break; |
| 4033 | |
| 4034 | default: |
| 4035 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4036 | << " to " << result_type; |
| 4037 | } |
| 4038 | } |
| 4039 | |
| 4040 | void LocationsBuilderARMVIXL::VisitAdd(HAdd* add) { |
| 4041 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4042 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4043 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4044 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4045 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4046 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 4047 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4048 | break; |
| 4049 | } |
| 4050 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4051 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4052 | locations->SetInAt(0, Location::RequiresRegister()); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4053 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4054 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4055 | break; |
| 4056 | } |
| 4057 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4058 | case DataType::Type::kFloat32: |
| 4059 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4060 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4061 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4062 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4063 | break; |
| 4064 | } |
| 4065 | |
| 4066 | default: |
| 4067 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 4068 | } |
| 4069 | } |
| 4070 | |
| 4071 | void InstructionCodeGeneratorARMVIXL::VisitAdd(HAdd* add) { |
| 4072 | LocationSummary* locations = add->GetLocations(); |
| 4073 | Location out = locations->Out(); |
| 4074 | Location first = locations->InAt(0); |
| 4075 | Location second = locations->InAt(1); |
| 4076 | |
| 4077 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4078 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4079 | __ Add(OutputRegister(add), InputRegisterAt(add, 0), InputOperandAt(add, 1)); |
| 4080 | } |
| 4081 | break; |
| 4082 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4083 | case DataType::Type::kInt64: { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4084 | if (second.IsConstant()) { |
| 4085 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 4086 | GenerateAddLongConst(out, first, value); |
| 4087 | } else { |
| 4088 | DCHECK(second.IsRegisterPair()); |
| 4089 | __ Adds(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 4090 | __ Adc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 4091 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4092 | break; |
| 4093 | } |
| 4094 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4095 | case DataType::Type::kFloat32: |
| 4096 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4097 | __ Vadd(OutputVRegister(add), InputVRegisterAt(add, 0), InputVRegisterAt(add, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4098 | break; |
| 4099 | |
| 4100 | default: |
| 4101 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 4102 | } |
| 4103 | } |
| 4104 | |
| 4105 | void LocationsBuilderARMVIXL::VisitSub(HSub* sub) { |
| 4106 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4107 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4108 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4109 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4110 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4111 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
| 4112 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4113 | break; |
| 4114 | } |
| 4115 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4116 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4117 | locations->SetInAt(0, Location::RequiresRegister()); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4118 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4119 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4120 | break; |
| 4121 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4122 | case DataType::Type::kFloat32: |
| 4123 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4124 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4125 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4126 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4127 | break; |
| 4128 | } |
| 4129 | default: |
| 4130 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 4131 | } |
| 4132 | } |
| 4133 | |
| 4134 | void InstructionCodeGeneratorARMVIXL::VisitSub(HSub* sub) { |
| 4135 | LocationSummary* locations = sub->GetLocations(); |
| 4136 | Location out = locations->Out(); |
| 4137 | Location first = locations->InAt(0); |
| 4138 | Location second = locations->InAt(1); |
| 4139 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4140 | case DataType::Type::kInt32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4141 | __ Sub(OutputRegister(sub), InputRegisterAt(sub, 0), InputOperandAt(sub, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4142 | break; |
| 4143 | } |
| 4144 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4145 | case DataType::Type::kInt64: { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4146 | if (second.IsConstant()) { |
| 4147 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 4148 | GenerateAddLongConst(out, first, -value); |
| 4149 | } else { |
| 4150 | DCHECK(second.IsRegisterPair()); |
| 4151 | __ Subs(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 4152 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 4153 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4154 | break; |
| 4155 | } |
| 4156 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4157 | case DataType::Type::kFloat32: |
| 4158 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4159 | __ Vsub(OutputVRegister(sub), InputVRegisterAt(sub, 0), InputVRegisterAt(sub, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4160 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4161 | |
| 4162 | default: |
| 4163 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 4164 | } |
| 4165 | } |
| 4166 | |
| 4167 | void LocationsBuilderARMVIXL::VisitMul(HMul* mul) { |
| 4168 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4169 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4170 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4171 | case DataType::Type::kInt32: |
| 4172 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4173 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4174 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4175 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4176 | break; |
| 4177 | } |
| 4178 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4179 | case DataType::Type::kFloat32: |
| 4180 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4181 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4182 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4183 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4184 | break; |
| 4185 | } |
| 4186 | |
| 4187 | default: |
| 4188 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4189 | } |
| 4190 | } |
| 4191 | |
| 4192 | void InstructionCodeGeneratorARMVIXL::VisitMul(HMul* mul) { |
| 4193 | LocationSummary* locations = mul->GetLocations(); |
| 4194 | Location out = locations->Out(); |
| 4195 | Location first = locations->InAt(0); |
| 4196 | Location second = locations->InAt(1); |
| 4197 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4198 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4199 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 4200 | break; |
| 4201 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4202 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4203 | vixl32::Register out_hi = HighRegisterFrom(out); |
| 4204 | vixl32::Register out_lo = LowRegisterFrom(out); |
| 4205 | vixl32::Register in1_hi = HighRegisterFrom(first); |
| 4206 | vixl32::Register in1_lo = LowRegisterFrom(first); |
| 4207 | vixl32::Register in2_hi = HighRegisterFrom(second); |
| 4208 | vixl32::Register in2_lo = LowRegisterFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4209 | |
| 4210 | // Extra checks to protect caused by the existence of R1_R2. |
| 4211 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 4212 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4213 | DCHECK(!out_hi.Is(in1_lo)); |
| 4214 | DCHECK(!out_hi.Is(in2_lo)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4215 | |
| 4216 | // input: in1 - 64 bits, in2 - 64 bits |
| 4217 | // output: out |
| 4218 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 4219 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 4220 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 4221 | |
| 4222 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4223 | vixl32::Register temp = temps.Acquire(); |
| 4224 | // temp <- in1.lo * in2.hi |
| 4225 | __ Mul(temp, in1_lo, in2_hi); |
| 4226 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 4227 | __ Mla(out_hi, in1_hi, in2_lo, temp); |
| 4228 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 4229 | __ Umull(out_lo, temp, in1_lo, in2_lo); |
| 4230 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4231 | __ Add(out_hi, out_hi, temp); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4232 | break; |
| 4233 | } |
| 4234 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4235 | case DataType::Type::kFloat32: |
| 4236 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4237 | __ Vmul(OutputVRegister(mul), InputVRegisterAt(mul, 0), InputVRegisterAt(mul, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4238 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4239 | |
| 4240 | default: |
| 4241 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4242 | } |
| 4243 | } |
| 4244 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4245 | void InstructionCodeGeneratorARMVIXL::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 4246 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4247 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4248 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4249 | Location second = instruction->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4250 | DCHECK(second.IsConstant()); |
| 4251 | |
| 4252 | vixl32::Register out = OutputRegister(instruction); |
| 4253 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4254 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4255 | DCHECK(imm == 1 || imm == -1); |
| 4256 | |
| 4257 | if (instruction->IsRem()) { |
| 4258 | __ Mov(out, 0); |
| 4259 | } else { |
| 4260 | if (imm == 1) { |
| 4261 | __ Mov(out, dividend); |
| 4262 | } else { |
| 4263 | __ Rsb(out, dividend, 0); |
| 4264 | } |
| 4265 | } |
| 4266 | } |
| 4267 | |
| 4268 | void InstructionCodeGeneratorARMVIXL::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 4269 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4270 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4271 | |
| 4272 | LocationSummary* locations = instruction->GetLocations(); |
| 4273 | Location second = locations->InAt(1); |
| 4274 | DCHECK(second.IsConstant()); |
| 4275 | |
| 4276 | vixl32::Register out = OutputRegister(instruction); |
| 4277 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4278 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4279 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 4280 | int ctz_imm = CTZ(abs_imm); |
| 4281 | |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 4282 | auto generate_div_code = [this, imm, ctz_imm](vixl32::Register out, vixl32::Register in) { |
| 4283 | __ Asr(out, in, ctz_imm); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4284 | if (imm < 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4285 | __ Rsb(out, out, 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4286 | } |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 4287 | }; |
| 4288 | |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 4289 | if (HasNonNegativeOrMinIntInputAt(instruction, 0)) { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 4290 | // No need to adjust the result for non-negative dividends or the INT32_MIN dividend. |
| 4291 | // NOTE: The generated code for HDiv/HRem correctly works for the INT32_MIN dividend: |
| 4292 | // imm == 2 |
| 4293 | // HDiv |
| 4294 | // add out, dividend(0x80000000), dividend(0x80000000), lsr #31 => out = 0x80000001 |
| 4295 | // asr out, out(0x80000001), #1 => out = 0xc0000000 |
| 4296 | // This is the same as 'asr out, dividend(0x80000000), #1' |
| 4297 | // |
| 4298 | // imm > 2 |
| 4299 | // HDiv |
| 4300 | // asr out, dividend(0x80000000), #31 => out = -1 |
| 4301 | // add out, dividend(0x80000000), out(-1), lsr #(32 - ctz_imm) => out = 0b10..01..1, |
| 4302 | // where the number of the rightmost 1s is ctz_imm. |
| 4303 | // asr out, out(0b10..01..1), #ctz_imm => out = 0b1..10..0, where the number of the |
| 4304 | // leftmost 1s is ctz_imm + 1. |
| 4305 | // This is the same as 'asr out, dividend(0x80000000), #ctz_imm'. |
| 4306 | // |
| 4307 | // imm == INT32_MIN |
| 4308 | // HDiv |
| 4309 | // asr out, dividend(0x80000000), #31 => out = -1 |
| 4310 | // add out, dividend(0x80000000), out(-1), lsr #1 => out = 0xc0000000 |
| 4311 | // asr out, out(0xc0000000), #31 => out = -1 |
| 4312 | // rsb out, out(-1), #0 => out = 1 |
| 4313 | // This is the same as |
| 4314 | // asr out, dividend(0x80000000), #31 |
| 4315 | // rsb out, out, #0 |
| 4316 | // |
| 4317 | // |
| 4318 | // INT_MIN % imm must be 0 for any imm of power 2. 'and' and 'ubfx' work only with bits |
| 4319 | // 0..30 of a dividend. For INT32_MIN those bits are zeros. So 'and' and 'ubfx' always |
| 4320 | // produce zero. |
| 4321 | if (instruction->IsDiv()) { |
| 4322 | generate_div_code(out, dividend); |
| 4323 | } else { |
| 4324 | if (GetVIXLAssembler()->IsModifiedImmediate(abs_imm - 1)) { |
| 4325 | __ And(out, dividend, abs_imm - 1); |
| 4326 | } else { |
| 4327 | __ Ubfx(out, dividend, 0, ctz_imm); |
| 4328 | } |
| 4329 | return; |
| 4330 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4331 | } else { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 4332 | vixl32::Register add_right_input = dividend; |
| 4333 | if (ctz_imm > 1) { |
| 4334 | __ Asr(out, dividend, 31); |
| 4335 | add_right_input = out; |
| 4336 | } |
| 4337 | __ Add(out, dividend, Operand(add_right_input, vixl32::LSR, 32 - ctz_imm)); |
| 4338 | |
| 4339 | if (instruction->IsDiv()) { |
| 4340 | generate_div_code(out, out); |
| 4341 | } else { |
| 4342 | __ Bfc(out, 0, ctz_imm); |
| 4343 | __ Sub(out, dividend, out); |
| 4344 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4345 | } |
| 4346 | } |
| 4347 | |
| 4348 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 4349 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4350 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4351 | |
| 4352 | LocationSummary* locations = instruction->GetLocations(); |
| 4353 | Location second = locations->InAt(1); |
| 4354 | DCHECK(second.IsConstant()); |
| 4355 | |
| 4356 | vixl32::Register out = OutputRegister(instruction); |
| 4357 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4358 | vixl32::Register temp1 = RegisterFrom(locations->GetTemp(0)); |
| 4359 | vixl32::Register temp2 = RegisterFrom(locations->GetTemp(1)); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4360 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4361 | |
| 4362 | int64_t magic; |
| 4363 | int shift; |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4364 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ false, &magic, &shift); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4365 | |
Evgeny Astigeevich | f938841 | 2020-07-02 15:25:13 +0100 | [diff] [blame] | 4366 | auto generate_unsigned_div_code =[this, magic, shift](vixl32::Register out, |
| 4367 | vixl32::Register dividend, |
| 4368 | vixl32::Register temp1, |
| 4369 | vixl32::Register temp2) { |
| 4370 | // TODO(VIXL): Change the static cast to Operand::From() after VIXL is fixed. |
| 4371 | __ Mov(temp1, static_cast<int32_t>(magic)); |
| 4372 | if (magic > 0 && shift == 0) { |
| 4373 | __ Smull(temp2, out, dividend, temp1); |
| 4374 | } else { |
| 4375 | __ Smull(temp2, temp1, dividend, temp1); |
| 4376 | if (magic < 0) { |
| 4377 | // The negative magic M = static_cast<int>(m) means that the multiplier m is greater |
| 4378 | // than INT32_MAX. In such a case shift is never 0. |
| 4379 | // Proof: |
| 4380 | // m = (2^p + d - 2^p % d) / d, where p = 32 + shift, d > 2 |
| 4381 | // |
| 4382 | // If shift == 0, m = (2^32 + d - 2^32 % d) / d = |
| 4383 | // = (2^32 + d - (2^32 - (2^32 / d) * d)) / d = |
| 4384 | // = (d + (2^32 / d) * d) / d = 1 + (2^32 / d), here '/' is the integer division. |
| 4385 | // |
| 4386 | // 1 + (2^32 / d) is decreasing when d is increasing. |
| 4387 | // The maximum is 1 431 655 766, when d == 3. This value is less than INT32_MAX. |
| 4388 | // the minimum is 3, when d = 2^31 -1. |
| 4389 | // So for all values of d in [3, INT32_MAX] m with p == 32 is in [3, INT32_MAX) and |
| 4390 | // is never less than 0. |
| 4391 | __ Add(temp1, temp1, dividend); |
| 4392 | } |
| 4393 | DCHECK_NE(shift, 0); |
| 4394 | __ Lsr(out, temp1, shift); |
| 4395 | } |
| 4396 | }; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4397 | |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 4398 | if (imm > 0 && HasNonNegativeInputAt(instruction, 0)) { |
Evgeny Astigeevich | f938841 | 2020-07-02 15:25:13 +0100 | [diff] [blame] | 4399 | // No need to adjust the result for a non-negative dividend and a positive divisor. |
| 4400 | if (instruction->IsDiv()) { |
| 4401 | generate_unsigned_div_code(out, dividend, temp1, temp2); |
| 4402 | } else { |
| 4403 | generate_unsigned_div_code(temp1, dividend, temp1, temp2); |
| 4404 | __ Mov(temp2, imm); |
| 4405 | __ Mls(out, temp1, temp2, dividend); |
| 4406 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4407 | } else { |
Evgeny Astigeevich | f938841 | 2020-07-02 15:25:13 +0100 | [diff] [blame] | 4408 | // TODO(VIXL): Change the static cast to Operand::From() after VIXL is fixed. |
| 4409 | __ Mov(temp1, static_cast<int32_t>(magic)); |
| 4410 | __ Smull(temp2, temp1, dividend, temp1); |
| 4411 | |
| 4412 | if (imm > 0 && magic < 0) { |
| 4413 | __ Add(temp1, temp1, dividend); |
| 4414 | } else if (imm < 0 && magic > 0) { |
| 4415 | __ Sub(temp1, temp1, dividend); |
| 4416 | } |
| 4417 | |
| 4418 | if (shift != 0) { |
| 4419 | __ Asr(temp1, temp1, shift); |
| 4420 | } |
| 4421 | |
| 4422 | if (instruction->IsDiv()) { |
| 4423 | __ Sub(out, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 4424 | } else { |
| 4425 | __ Sub(temp1, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 4426 | // TODO: Strength reduction for mls. |
| 4427 | __ Mov(temp2, imm); |
| 4428 | __ Mls(out, temp1, temp2, dividend); |
| 4429 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4430 | } |
| 4431 | } |
| 4432 | |
| 4433 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemConstantIntegral( |
| 4434 | HBinaryOperation* instruction) { |
| 4435 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4436 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4437 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4438 | Location second = instruction->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4439 | DCHECK(second.IsConstant()); |
| 4440 | |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4441 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4442 | if (imm == 0) { |
| 4443 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4444 | } else if (imm == 1 || imm == -1) { |
| 4445 | DivRemOneOrMinusOne(instruction); |
| 4446 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 4447 | DivRemByPowerOfTwo(instruction); |
| 4448 | } else { |
| 4449 | DCHECK(imm <= -2 || imm >= 2); |
| 4450 | GenerateDivRemWithAnyConstant(instruction); |
| 4451 | } |
| 4452 | } |
| 4453 | |
| 4454 | void LocationsBuilderARMVIXL::VisitDiv(HDiv* div) { |
| 4455 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4456 | if (div->GetResultType() == DataType::Type::kInt64) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4457 | // pLdiv runtime call. |
| 4458 | call_kind = LocationSummary::kCallOnMainOnly; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4459 | } else if (div->GetResultType() == DataType::Type::kInt32 && div->InputAt(1)->IsConstant()) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4460 | // sdiv will be replaced by other instruction sequence. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4461 | } else if (div->GetResultType() == DataType::Type::kInt32 && |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4462 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4463 | // pIdivmod runtime call. |
| 4464 | call_kind = LocationSummary::kCallOnMainOnly; |
| 4465 | } |
| 4466 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4467 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4468 | |
| 4469 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4470 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4471 | if (div->InputAt(1)->IsConstant()) { |
| 4472 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4473 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4474 | int32_t value = Int32ConstantFrom(div->InputAt(1)); |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4475 | Location::OutputOverlap out_overlaps = Location::kNoOutputOverlap; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4476 | if (value == 1 || value == 0 || value == -1) { |
| 4477 | // No temp register required. |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 4478 | } else if (IsPowerOfTwo(AbsOrMin(value)) && |
| 4479 | value != 2 && |
| 4480 | value != -2 && |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 4481 | !HasNonNegativeOrMinIntInputAt(div, 0)) { |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4482 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 4483 | out_overlaps = Location::kOutputOverlap; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4484 | } else { |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4485 | locations->AddRegisterTemps(2); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4486 | } |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4487 | locations->SetOut(Location::RequiresRegister(), out_overlaps); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4488 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4489 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4490 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4491 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4492 | } else { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4493 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4494 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4495 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4496 | // Note: divmod will compute both the quotient and the remainder as the pair R0 and R1, but |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4497 | // we only need the former. |
| 4498 | locations->SetOut(LocationFrom(r0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4499 | } |
| 4500 | break; |
| 4501 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4502 | case DataType::Type::kInt64: { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4503 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4504 | locations->SetInAt(0, LocationFrom( |
| 4505 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4506 | locations->SetInAt(1, LocationFrom( |
| 4507 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4508 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4509 | break; |
| 4510 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4511 | case DataType::Type::kFloat32: |
| 4512 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4513 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4514 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4515 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4516 | break; |
| 4517 | } |
| 4518 | |
| 4519 | default: |
| 4520 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4521 | } |
| 4522 | } |
| 4523 | |
| 4524 | void InstructionCodeGeneratorARMVIXL::VisitDiv(HDiv* div) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4525 | Location lhs = div->GetLocations()->InAt(0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4526 | Location rhs = div->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4527 | |
| 4528 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4529 | case DataType::Type::kInt32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4530 | if (rhs.IsConstant()) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4531 | GenerateDivRemConstantIntegral(div); |
| 4532 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4533 | __ Sdiv(OutputRegister(div), InputRegisterAt(div, 0), InputRegisterAt(div, 1)); |
| 4534 | } else { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4535 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4536 | DCHECK(calling_convention.GetRegisterAt(0).Is(RegisterFrom(lhs))); |
| 4537 | DCHECK(calling_convention.GetRegisterAt(1).Is(RegisterFrom(rhs))); |
| 4538 | DCHECK(r0.Is(OutputRegister(div))); |
| 4539 | |
| 4540 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
| 4541 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4542 | } |
| 4543 | break; |
| 4544 | } |
| 4545 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4546 | case DataType::Type::kInt64: { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4547 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4548 | DCHECK(calling_convention.GetRegisterAt(0).Is(LowRegisterFrom(lhs))); |
| 4549 | DCHECK(calling_convention.GetRegisterAt(1).Is(HighRegisterFrom(lhs))); |
| 4550 | DCHECK(calling_convention.GetRegisterAt(2).Is(LowRegisterFrom(rhs))); |
| 4551 | DCHECK(calling_convention.GetRegisterAt(3).Is(HighRegisterFrom(rhs))); |
| 4552 | DCHECK(LowRegisterFrom(div->GetLocations()->Out()).Is(r0)); |
| 4553 | DCHECK(HighRegisterFrom(div->GetLocations()->Out()).Is(r1)); |
| 4554 | |
| 4555 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
| 4556 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4557 | break; |
| 4558 | } |
| 4559 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4560 | case DataType::Type::kFloat32: |
| 4561 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4562 | __ Vdiv(OutputVRegister(div), InputVRegisterAt(div, 0), InputVRegisterAt(div, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4563 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4564 | |
| 4565 | default: |
| 4566 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4567 | } |
| 4568 | } |
| 4569 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4570 | void LocationsBuilderARMVIXL::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4571 | DataType::Type type = rem->GetResultType(); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4572 | |
| 4573 | // Most remainders are implemented in the runtime. |
| 4574 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4575 | if (rem->GetResultType() == DataType::Type::kInt32 && rem->InputAt(1)->IsConstant()) { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4576 | // sdiv will be replaced by other instruction sequence. |
| 4577 | call_kind = LocationSummary::kNoCall; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4578 | } else if ((rem->GetResultType() == DataType::Type::kInt32) |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4579 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4580 | // Have hardware divide instruction for int, do it with three instructions. |
| 4581 | call_kind = LocationSummary::kNoCall; |
| 4582 | } |
| 4583 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4584 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4585 | |
| 4586 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4587 | case DataType::Type::kInt32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4588 | if (rem->InputAt(1)->IsConstant()) { |
| 4589 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4590 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4591 | int32_t value = Int32ConstantFrom(rem->InputAt(1)); |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4592 | Location::OutputOverlap out_overlaps = Location::kNoOutputOverlap; |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4593 | if (value == 1 || value == 0 || value == -1) { |
| 4594 | // No temp register required. |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 4595 | } else if (IsPowerOfTwo(AbsOrMin(value)) && !HasNonNegativeOrMinIntInputAt(rem, 0)) { |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4596 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 4597 | out_overlaps = Location::kOutputOverlap; |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4598 | } else { |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4599 | locations->AddRegisterTemps(2); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4600 | } |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4601 | locations->SetOut(Location::RequiresRegister(), out_overlaps); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4602 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4603 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4604 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4605 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4606 | locations->AddTemp(Location::RequiresRegister()); |
| 4607 | } else { |
| 4608 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4609 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4610 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4611 | // Note: divmod will compute both the quotient and the remainder as the pair R0 and R1, but |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4612 | // we only need the latter. |
| 4613 | locations->SetOut(LocationFrom(r1)); |
| 4614 | } |
| 4615 | break; |
| 4616 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4617 | case DataType::Type::kInt64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4618 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4619 | locations->SetInAt(0, LocationFrom( |
| 4620 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4621 | locations->SetInAt(1, LocationFrom( |
| 4622 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4623 | // The runtime helper puts the output in R2,R3. |
| 4624 | locations->SetOut(LocationFrom(r2, r3)); |
| 4625 | break; |
| 4626 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4627 | case DataType::Type::kFloat32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4628 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4629 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 4630 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 4631 | locations->SetOut(LocationFrom(s0)); |
| 4632 | break; |
| 4633 | } |
| 4634 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4635 | case DataType::Type::kFloat64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4636 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4637 | locations->SetInAt(0, LocationFrom( |
| 4638 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 4639 | locations->SetInAt(1, LocationFrom( |
| 4640 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 4641 | locations->SetOut(LocationFrom(s0, s1)); |
| 4642 | break; |
| 4643 | } |
| 4644 | |
| 4645 | default: |
| 4646 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4647 | } |
| 4648 | } |
| 4649 | |
| 4650 | void InstructionCodeGeneratorARMVIXL::VisitRem(HRem* rem) { |
| 4651 | LocationSummary* locations = rem->GetLocations(); |
| 4652 | Location second = locations->InAt(1); |
| 4653 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4654 | DataType::Type type = rem->GetResultType(); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4655 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4656 | case DataType::Type::kInt32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4657 | vixl32::Register reg1 = InputRegisterAt(rem, 0); |
| 4658 | vixl32::Register out_reg = OutputRegister(rem); |
| 4659 | if (second.IsConstant()) { |
| 4660 | GenerateDivRemConstantIntegral(rem); |
| 4661 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4662 | vixl32::Register reg2 = RegisterFrom(second); |
| 4663 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 4664 | |
| 4665 | // temp = reg1 / reg2 (integer division) |
| 4666 | // dest = reg1 - temp * reg2 |
| 4667 | __ Sdiv(temp, reg1, reg2); |
| 4668 | __ Mls(out_reg, temp, reg2, reg1); |
| 4669 | } else { |
| 4670 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4671 | DCHECK(reg1.Is(calling_convention.GetRegisterAt(0))); |
| 4672 | DCHECK(RegisterFrom(second).Is(calling_convention.GetRegisterAt(1))); |
| 4673 | DCHECK(out_reg.Is(r1)); |
| 4674 | |
| 4675 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
| 4676 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
| 4677 | } |
| 4678 | break; |
| 4679 | } |
| 4680 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4681 | case DataType::Type::kInt64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4682 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
| 4683 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 4684 | break; |
| 4685 | } |
| 4686 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4687 | case DataType::Type::kFloat32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4688 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
| 4689 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 4690 | break; |
| 4691 | } |
| 4692 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4693 | case DataType::Type::kFloat64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4694 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
| 4695 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 4696 | break; |
| 4697 | } |
| 4698 | |
| 4699 | default: |
| 4700 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4701 | } |
| 4702 | } |
| 4703 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4704 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 4705 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 4706 | switch (minmax->GetResultType()) { |
| 4707 | case DataType::Type::kInt32: |
| 4708 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4709 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4710 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4711 | break; |
| 4712 | case DataType::Type::kInt64: |
| 4713 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4714 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4715 | locations->SetOut(Location::SameAsFirstInput()); |
| 4716 | break; |
| 4717 | case DataType::Type::kFloat32: |
| 4718 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4719 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4720 | locations->SetOut(Location::SameAsFirstInput()); |
| 4721 | locations->AddTemp(Location::RequiresRegister()); |
| 4722 | break; |
| 4723 | case DataType::Type::kFloat64: |
| 4724 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4725 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4726 | locations->SetOut(Location::SameAsFirstInput()); |
| 4727 | break; |
| 4728 | default: |
| 4729 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 4730 | } |
| 4731 | } |
| 4732 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4733 | void InstructionCodeGeneratorARMVIXL::GenerateMinMaxInt(LocationSummary* locations, bool is_min) { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4734 | Location op1_loc = locations->InAt(0); |
| 4735 | Location op2_loc = locations->InAt(1); |
| 4736 | Location out_loc = locations->Out(); |
| 4737 | |
| 4738 | vixl32::Register op1 = RegisterFrom(op1_loc); |
| 4739 | vixl32::Register op2 = RegisterFrom(op2_loc); |
| 4740 | vixl32::Register out = RegisterFrom(out_loc); |
| 4741 | |
| 4742 | __ Cmp(op1, op2); |
| 4743 | |
| 4744 | { |
| 4745 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 4746 | 3 * kMaxInstructionSizeInBytes, |
| 4747 | CodeBufferCheckScope::kMaximumSize); |
| 4748 | |
| 4749 | __ ite(is_min ? lt : gt); |
| 4750 | __ mov(is_min ? lt : gt, out, op1); |
| 4751 | __ mov(is_min ? ge : le, out, op2); |
| 4752 | } |
| 4753 | } |
| 4754 | |
| 4755 | void InstructionCodeGeneratorARMVIXL::GenerateMinMaxLong(LocationSummary* locations, bool is_min) { |
| 4756 | Location op1_loc = locations->InAt(0); |
| 4757 | Location op2_loc = locations->InAt(1); |
| 4758 | Location out_loc = locations->Out(); |
| 4759 | |
| 4760 | // Optimization: don't generate any code if inputs are the same. |
| 4761 | if (op1_loc.Equals(op2_loc)) { |
| 4762 | DCHECK(out_loc.Equals(op1_loc)); // out_loc is set as SameAsFirstInput() in location builder. |
| 4763 | return; |
| 4764 | } |
| 4765 | |
| 4766 | vixl32::Register op1_lo = LowRegisterFrom(op1_loc); |
| 4767 | vixl32::Register op1_hi = HighRegisterFrom(op1_loc); |
| 4768 | vixl32::Register op2_lo = LowRegisterFrom(op2_loc); |
| 4769 | vixl32::Register op2_hi = HighRegisterFrom(op2_loc); |
| 4770 | vixl32::Register out_lo = LowRegisterFrom(out_loc); |
| 4771 | vixl32::Register out_hi = HighRegisterFrom(out_loc); |
| 4772 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4773 | const vixl32::Register temp = temps.Acquire(); |
| 4774 | |
| 4775 | DCHECK(op1_lo.Is(out_lo)); |
| 4776 | DCHECK(op1_hi.Is(out_hi)); |
| 4777 | |
| 4778 | // Compare op1 >= op2, or op1 < op2. |
| 4779 | __ Cmp(out_lo, op2_lo); |
| 4780 | __ Sbcs(temp, out_hi, op2_hi); |
| 4781 | |
| 4782 | // Now GE/LT condition code is correct for the long comparison. |
| 4783 | { |
| 4784 | vixl32::ConditionType cond = is_min ? ge : lt; |
| 4785 | ExactAssemblyScope it_scope(GetVIXLAssembler(), |
| 4786 | 3 * kMaxInstructionSizeInBytes, |
| 4787 | CodeBufferCheckScope::kMaximumSize); |
| 4788 | __ itt(cond); |
| 4789 | __ mov(cond, out_lo, op2_lo); |
| 4790 | __ mov(cond, out_hi, op2_hi); |
| 4791 | } |
| 4792 | } |
| 4793 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4794 | void InstructionCodeGeneratorARMVIXL::GenerateMinMaxFloat(HInstruction* minmax, bool is_min) { |
| 4795 | LocationSummary* locations = minmax->GetLocations(); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4796 | Location op1_loc = locations->InAt(0); |
| 4797 | Location op2_loc = locations->InAt(1); |
| 4798 | Location out_loc = locations->Out(); |
| 4799 | |
| 4800 | // Optimization: don't generate any code if inputs are the same. |
| 4801 | if (op1_loc.Equals(op2_loc)) { |
| 4802 | DCHECK(out_loc.Equals(op1_loc)); // out_loc is set as SameAsFirstInput() in location builder. |
| 4803 | return; |
| 4804 | } |
| 4805 | |
| 4806 | vixl32::SRegister op1 = SRegisterFrom(op1_loc); |
| 4807 | vixl32::SRegister op2 = SRegisterFrom(op2_loc); |
| 4808 | vixl32::SRegister out = SRegisterFrom(out_loc); |
| 4809 | |
| 4810 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4811 | const vixl32::Register temp1 = temps.Acquire(); |
| 4812 | vixl32::Register temp2 = RegisterFrom(locations->GetTemp(0)); |
| 4813 | vixl32::Label nan, done; |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4814 | vixl32::Label* final_label = codegen_->GetFinalLabel(minmax, &done); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4815 | |
| 4816 | DCHECK(op1.Is(out)); |
| 4817 | |
| 4818 | __ Vcmp(op1, op2); |
| 4819 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4820 | __ B(vs, &nan, /* is_far_target= */ false); // if un-ordered, go to NaN handling. |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4821 | |
| 4822 | // op1 <> op2 |
| 4823 | vixl32::ConditionType cond = is_min ? gt : lt; |
| 4824 | { |
| 4825 | ExactAssemblyScope it_scope(GetVIXLAssembler(), |
| 4826 | 2 * kMaxInstructionSizeInBytes, |
| 4827 | CodeBufferCheckScope::kMaximumSize); |
| 4828 | __ it(cond); |
| 4829 | __ vmov(cond, F32, out, op2); |
| 4830 | } |
| 4831 | // for <>(not equal), we've done min/max calculation. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4832 | __ B(ne, final_label, /* is_far_target= */ false); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4833 | |
| 4834 | // handle op1 == op2, max(+0.0,-0.0), min(+0.0,-0.0). |
| 4835 | __ Vmov(temp1, op1); |
| 4836 | __ Vmov(temp2, op2); |
| 4837 | if (is_min) { |
| 4838 | __ Orr(temp1, temp1, temp2); |
| 4839 | } else { |
| 4840 | __ And(temp1, temp1, temp2); |
| 4841 | } |
| 4842 | __ Vmov(out, temp1); |
| 4843 | __ B(final_label); |
| 4844 | |
| 4845 | // handle NaN input. |
| 4846 | __ Bind(&nan); |
| 4847 | __ Movt(temp1, High16Bits(kNanFloat)); // 0x7FC0xxxx is a NaN. |
| 4848 | __ Vmov(out, temp1); |
| 4849 | |
| 4850 | if (done.IsReferenced()) { |
| 4851 | __ Bind(&done); |
| 4852 | } |
| 4853 | } |
| 4854 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4855 | void InstructionCodeGeneratorARMVIXL::GenerateMinMaxDouble(HInstruction* minmax, bool is_min) { |
| 4856 | LocationSummary* locations = minmax->GetLocations(); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4857 | Location op1_loc = locations->InAt(0); |
| 4858 | Location op2_loc = locations->InAt(1); |
| 4859 | Location out_loc = locations->Out(); |
| 4860 | |
| 4861 | // Optimization: don't generate any code if inputs are the same. |
| 4862 | if (op1_loc.Equals(op2_loc)) { |
| 4863 | DCHECK(out_loc.Equals(op1_loc)); // out_loc is set as SameAsFirstInput() in. |
| 4864 | return; |
| 4865 | } |
| 4866 | |
| 4867 | vixl32::DRegister op1 = DRegisterFrom(op1_loc); |
| 4868 | vixl32::DRegister op2 = DRegisterFrom(op2_loc); |
| 4869 | vixl32::DRegister out = DRegisterFrom(out_loc); |
| 4870 | vixl32::Label handle_nan_eq, done; |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4871 | vixl32::Label* final_label = codegen_->GetFinalLabel(minmax, &done); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4872 | |
| 4873 | DCHECK(op1.Is(out)); |
| 4874 | |
| 4875 | __ Vcmp(op1, op2); |
| 4876 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4877 | __ B(vs, &handle_nan_eq, /* is_far_target= */ false); // if un-ordered, go to NaN handling. |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4878 | |
| 4879 | // op1 <> op2 |
| 4880 | vixl32::ConditionType cond = is_min ? gt : lt; |
| 4881 | { |
| 4882 | ExactAssemblyScope it_scope(GetVIXLAssembler(), |
| 4883 | 2 * kMaxInstructionSizeInBytes, |
| 4884 | CodeBufferCheckScope::kMaximumSize); |
| 4885 | __ it(cond); |
| 4886 | __ vmov(cond, F64, out, op2); |
| 4887 | } |
| 4888 | // for <>(not equal), we've done min/max calculation. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4889 | __ B(ne, final_label, /* is_far_target= */ false); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4890 | |
| 4891 | // handle op1 == op2, max(+0.0,-0.0). |
| 4892 | if (!is_min) { |
| 4893 | __ Vand(F64, out, op1, op2); |
| 4894 | __ B(final_label); |
| 4895 | } |
| 4896 | |
| 4897 | // handle op1 == op2, min(+0.0,-0.0), NaN input. |
| 4898 | __ Bind(&handle_nan_eq); |
| 4899 | __ Vorr(F64, out, op1, op2); // assemble op1/-0.0/NaN. |
| 4900 | |
| 4901 | if (done.IsReferenced()) { |
| 4902 | __ Bind(&done); |
| 4903 | } |
| 4904 | } |
| 4905 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4906 | void InstructionCodeGeneratorARMVIXL::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 4907 | DataType::Type type = minmax->GetResultType(); |
| 4908 | switch (type) { |
| 4909 | case DataType::Type::kInt32: |
| 4910 | GenerateMinMaxInt(minmax->GetLocations(), is_min); |
| 4911 | break; |
| 4912 | case DataType::Type::kInt64: |
| 4913 | GenerateMinMaxLong(minmax->GetLocations(), is_min); |
| 4914 | break; |
| 4915 | case DataType::Type::kFloat32: |
| 4916 | GenerateMinMaxFloat(minmax, is_min); |
| 4917 | break; |
| 4918 | case DataType::Type::kFloat64: |
| 4919 | GenerateMinMaxDouble(minmax, is_min); |
| 4920 | break; |
| 4921 | default: |
| 4922 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 4923 | } |
| 4924 | } |
| 4925 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4926 | void LocationsBuilderARMVIXL::VisitMin(HMin* min) { |
| 4927 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 4928 | } |
| 4929 | |
| 4930 | void InstructionCodeGeneratorARMVIXL::VisitMin(HMin* min) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4931 | GenerateMinMax(min, /*is_min*/ true); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4932 | } |
| 4933 | |
| 4934 | void LocationsBuilderARMVIXL::VisitMax(HMax* max) { |
| 4935 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 4936 | } |
| 4937 | |
| 4938 | void InstructionCodeGeneratorARMVIXL::VisitMax(HMax* max) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4939 | GenerateMinMax(max, /*is_min*/ false); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4940 | } |
| 4941 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 4942 | void LocationsBuilderARMVIXL::VisitAbs(HAbs* abs) { |
| 4943 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 4944 | switch (abs->GetResultType()) { |
| 4945 | case DataType::Type::kInt32: |
| 4946 | case DataType::Type::kInt64: |
| 4947 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4948 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4949 | locations->AddTemp(Location::RequiresRegister()); |
| 4950 | break; |
| 4951 | case DataType::Type::kFloat32: |
| 4952 | case DataType::Type::kFloat64: |
| 4953 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4954 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4955 | break; |
| 4956 | default: |
| 4957 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 4958 | } |
| 4959 | } |
| 4960 | |
| 4961 | void InstructionCodeGeneratorARMVIXL::VisitAbs(HAbs* abs) { |
| 4962 | LocationSummary* locations = abs->GetLocations(); |
| 4963 | switch (abs->GetResultType()) { |
| 4964 | case DataType::Type::kInt32: { |
| 4965 | vixl32::Register in_reg = RegisterFrom(locations->InAt(0)); |
| 4966 | vixl32::Register out_reg = RegisterFrom(locations->Out()); |
| 4967 | vixl32::Register mask = RegisterFrom(locations->GetTemp(0)); |
| 4968 | __ Asr(mask, in_reg, 31); |
| 4969 | __ Add(out_reg, in_reg, mask); |
| 4970 | __ Eor(out_reg, out_reg, mask); |
| 4971 | break; |
| 4972 | } |
| 4973 | case DataType::Type::kInt64: { |
| 4974 | Location in = locations->InAt(0); |
| 4975 | vixl32::Register in_reg_lo = LowRegisterFrom(in); |
| 4976 | vixl32::Register in_reg_hi = HighRegisterFrom(in); |
| 4977 | Location output = locations->Out(); |
| 4978 | vixl32::Register out_reg_lo = LowRegisterFrom(output); |
| 4979 | vixl32::Register out_reg_hi = HighRegisterFrom(output); |
| 4980 | DCHECK(!out_reg_lo.Is(in_reg_hi)) << "Diagonal overlap unexpected."; |
| 4981 | vixl32::Register mask = RegisterFrom(locations->GetTemp(0)); |
| 4982 | __ Asr(mask, in_reg_hi, 31); |
| 4983 | __ Adds(out_reg_lo, in_reg_lo, mask); |
| 4984 | __ Adc(out_reg_hi, in_reg_hi, mask); |
| 4985 | __ Eor(out_reg_lo, out_reg_lo, mask); |
| 4986 | __ Eor(out_reg_hi, out_reg_hi, mask); |
| 4987 | break; |
| 4988 | } |
| 4989 | case DataType::Type::kFloat32: |
| 4990 | case DataType::Type::kFloat64: |
| 4991 | __ Vabs(OutputVRegister(abs), InputVRegisterAt(abs, 0)); |
| 4992 | break; |
| 4993 | default: |
| 4994 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 4995 | } |
| 4996 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4997 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4998 | void LocationsBuilderARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 4999 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5000 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5001 | } |
| 5002 | |
| 5003 | void InstructionCodeGeneratorARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 5004 | DivZeroCheckSlowPathARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5005 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathARMVIXL(instruction); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5006 | codegen_->AddSlowPath(slow_path); |
| 5007 | |
| 5008 | LocationSummary* locations = instruction->GetLocations(); |
| 5009 | Location value = locations->InAt(0); |
| 5010 | |
| 5011 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5012 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5013 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5014 | case DataType::Type::kInt8: |
| 5015 | case DataType::Type::kUint16: |
| 5016 | case DataType::Type::kInt16: |
| 5017 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5018 | if (value.IsRegister()) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5019 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5020 | } else { |
| 5021 | DCHECK(value.IsConstant()) << value; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5022 | if (Int32ConstantFrom(value) == 0) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5023 | __ B(slow_path->GetEntryLabel()); |
| 5024 | } |
| 5025 | } |
| 5026 | break; |
| 5027 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5028 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5029 | if (value.IsRegisterPair()) { |
| 5030 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5031 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5032 | __ Orrs(temp, LowRegisterFrom(value), HighRegisterFrom(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5033 | __ B(eq, slow_path->GetEntryLabel()); |
| 5034 | } else { |
| 5035 | DCHECK(value.IsConstant()) << value; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5036 | if (Int64ConstantFrom(value) == 0) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5037 | __ B(slow_path->GetEntryLabel()); |
| 5038 | } |
| 5039 | } |
| 5040 | break; |
| 5041 | } |
| 5042 | default: |
| 5043 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 5044 | } |
| 5045 | } |
| 5046 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5047 | void InstructionCodeGeneratorARMVIXL::HandleIntegerRotate(HRor* ror) { |
| 5048 | LocationSummary* locations = ror->GetLocations(); |
| 5049 | vixl32::Register in = InputRegisterAt(ror, 0); |
| 5050 | Location rhs = locations->InAt(1); |
| 5051 | vixl32::Register out = OutputRegister(ror); |
| 5052 | |
| 5053 | if (rhs.IsConstant()) { |
| 5054 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 5055 | // so map all rotations to a +ve. equivalent in that range. |
| 5056 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 5057 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 5058 | if (rot) { |
| 5059 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 5060 | // (e.g. left by 2 bits == right by 30.) |
| 5061 | __ Ror(out, in, rot); |
| 5062 | } else if (!out.Is(in)) { |
| 5063 | __ Mov(out, in); |
| 5064 | } |
| 5065 | } else { |
| 5066 | __ Ror(out, in, RegisterFrom(rhs)); |
| 5067 | } |
| 5068 | } |
| 5069 | |
| 5070 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 5071 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 5072 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 5073 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 5074 | void InstructionCodeGeneratorARMVIXL::HandleLongRotate(HRor* ror) { |
| 5075 | LocationSummary* locations = ror->GetLocations(); |
| 5076 | vixl32::Register in_reg_lo = LowRegisterFrom(locations->InAt(0)); |
| 5077 | vixl32::Register in_reg_hi = HighRegisterFrom(locations->InAt(0)); |
| 5078 | Location rhs = locations->InAt(1); |
| 5079 | vixl32::Register out_reg_lo = LowRegisterFrom(locations->Out()); |
| 5080 | vixl32::Register out_reg_hi = HighRegisterFrom(locations->Out()); |
| 5081 | |
| 5082 | if (rhs.IsConstant()) { |
| 5083 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 5084 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
| 5085 | rot &= kMaxLongShiftDistance; |
| 5086 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 5087 | // logic below to a simple pair of binary orr. |
| 5088 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 5089 | if (rot >= kArmBitsPerWord) { |
| 5090 | rot -= kArmBitsPerWord; |
| 5091 | std::swap(in_reg_hi, in_reg_lo); |
| 5092 | } |
| 5093 | // Rotate, or mov to out for zero or word size rotations. |
| 5094 | if (rot != 0u) { |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5095 | __ Lsr(out_reg_hi, in_reg_hi, Operand::From(rot)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5096 | __ Orr(out_reg_hi, out_reg_hi, Operand(in_reg_lo, ShiftType::LSL, kArmBitsPerWord - rot)); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5097 | __ Lsr(out_reg_lo, in_reg_lo, Operand::From(rot)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5098 | __ Orr(out_reg_lo, out_reg_lo, Operand(in_reg_hi, ShiftType::LSL, kArmBitsPerWord - rot)); |
| 5099 | } else { |
| 5100 | __ Mov(out_reg_lo, in_reg_lo); |
| 5101 | __ Mov(out_reg_hi, in_reg_hi); |
| 5102 | } |
| 5103 | } else { |
| 5104 | vixl32::Register shift_right = RegisterFrom(locations->GetTemp(0)); |
| 5105 | vixl32::Register shift_left = RegisterFrom(locations->GetTemp(1)); |
| 5106 | vixl32::Label end; |
| 5107 | vixl32::Label shift_by_32_plus_shift_right; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5108 | vixl32::Label* final_label = codegen_->GetFinalLabel(ror, &end); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5109 | |
| 5110 | __ And(shift_right, RegisterFrom(rhs), 0x1F); |
| 5111 | __ Lsrs(shift_left, RegisterFrom(rhs), 6); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 5112 | __ Rsb(LeaveFlags, shift_left, shift_right, Operand::From(kArmBitsPerWord)); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5113 | __ B(cc, &shift_by_32_plus_shift_right, /* is_far_target= */ false); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5114 | |
| 5115 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 5116 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 5117 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 5118 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 5119 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 5120 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 5121 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 5122 | __ Add(out_reg_lo, out_reg_lo, shift_left); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5123 | __ B(final_label); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5124 | |
| 5125 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 5126 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 5127 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 5128 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 5129 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 5130 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 5131 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 5132 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 5133 | __ Add(out_reg_lo, out_reg_lo, shift_right); |
| 5134 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5135 | if (end.IsReferenced()) { |
| 5136 | __ Bind(&end); |
| 5137 | } |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5138 | } |
| 5139 | } |
| 5140 | |
| 5141 | void LocationsBuilderARMVIXL::VisitRor(HRor* ror) { |
| 5142 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5143 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5144 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5145 | case DataType::Type::kInt32: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5146 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5147 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 5148 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5149 | break; |
| 5150 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5151 | case DataType::Type::kInt64: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5152 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5153 | if (ror->InputAt(1)->IsConstant()) { |
| 5154 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 5155 | } else { |
| 5156 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5157 | locations->AddTemp(Location::RequiresRegister()); |
| 5158 | locations->AddTemp(Location::RequiresRegister()); |
| 5159 | } |
| 5160 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5161 | break; |
| 5162 | } |
| 5163 | default: |
| 5164 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 5165 | } |
| 5166 | } |
| 5167 | |
| 5168 | void InstructionCodeGeneratorARMVIXL::VisitRor(HRor* ror) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5169 | DataType::Type type = ror->GetResultType(); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5170 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5171 | case DataType::Type::kInt32: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5172 | HandleIntegerRotate(ror); |
| 5173 | break; |
| 5174 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5175 | case DataType::Type::kInt64: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5176 | HandleLongRotate(ror); |
| 5177 | break; |
| 5178 | } |
| 5179 | default: |
| 5180 | LOG(FATAL) << "Unexpected operation type " << type; |
| 5181 | UNREACHABLE(); |
| 5182 | } |
| 5183 | } |
| 5184 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5185 | void LocationsBuilderARMVIXL::HandleShift(HBinaryOperation* op) { |
| 5186 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 5187 | |
| 5188 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5189 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5190 | |
| 5191 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5192 | case DataType::Type::kInt32: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5193 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5194 | if (op->InputAt(1)->IsConstant()) { |
| 5195 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 5196 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5197 | } else { |
| 5198 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5199 | // Make the output overlap, as it will be used to hold the masked |
| 5200 | // second input. |
| 5201 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5202 | } |
| 5203 | break; |
| 5204 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5205 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5206 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5207 | if (op->InputAt(1)->IsConstant()) { |
| 5208 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 5209 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 5210 | // don't clash with high registers which the register allocator currently guarantees. |
| 5211 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5212 | } else { |
| 5213 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5214 | locations->AddTemp(Location::RequiresRegister()); |
| 5215 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5216 | } |
| 5217 | break; |
| 5218 | } |
| 5219 | default: |
| 5220 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 5221 | } |
| 5222 | } |
| 5223 | |
| 5224 | void InstructionCodeGeneratorARMVIXL::HandleShift(HBinaryOperation* op) { |
| 5225 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 5226 | |
| 5227 | LocationSummary* locations = op->GetLocations(); |
| 5228 | Location out = locations->Out(); |
| 5229 | Location first = locations->InAt(0); |
| 5230 | Location second = locations->InAt(1); |
| 5231 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5232 | DataType::Type type = op->GetResultType(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5233 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5234 | case DataType::Type::kInt32: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5235 | vixl32::Register out_reg = OutputRegister(op); |
| 5236 | vixl32::Register first_reg = InputRegisterAt(op, 0); |
| 5237 | if (second.IsRegister()) { |
| 5238 | vixl32::Register second_reg = RegisterFrom(second); |
| 5239 | // ARM doesn't mask the shift count so we need to do it ourselves. |
| 5240 | __ And(out_reg, second_reg, kMaxIntShiftDistance); |
| 5241 | if (op->IsShl()) { |
| 5242 | __ Lsl(out_reg, first_reg, out_reg); |
| 5243 | } else if (op->IsShr()) { |
| 5244 | __ Asr(out_reg, first_reg, out_reg); |
| 5245 | } else { |
| 5246 | __ Lsr(out_reg, first_reg, out_reg); |
| 5247 | } |
| 5248 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5249 | int32_t cst = Int32ConstantFrom(second); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5250 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
| 5251 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
| 5252 | __ Mov(out_reg, first_reg); |
| 5253 | } else if (op->IsShl()) { |
| 5254 | __ Lsl(out_reg, first_reg, shift_value); |
| 5255 | } else if (op->IsShr()) { |
| 5256 | __ Asr(out_reg, first_reg, shift_value); |
| 5257 | } else { |
| 5258 | __ Lsr(out_reg, first_reg, shift_value); |
| 5259 | } |
| 5260 | } |
| 5261 | break; |
| 5262 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5263 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5264 | vixl32::Register o_h = HighRegisterFrom(out); |
| 5265 | vixl32::Register o_l = LowRegisterFrom(out); |
| 5266 | |
| 5267 | vixl32::Register high = HighRegisterFrom(first); |
| 5268 | vixl32::Register low = LowRegisterFrom(first); |
| 5269 | |
| 5270 | if (second.IsRegister()) { |
| 5271 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5272 | |
| 5273 | vixl32::Register second_reg = RegisterFrom(second); |
| 5274 | |
| 5275 | if (op->IsShl()) { |
| 5276 | __ And(o_l, second_reg, kMaxLongShiftDistance); |
| 5277 | // Shift the high part |
| 5278 | __ Lsl(o_h, high, o_l); |
| 5279 | // Shift the low part and `or` what overflew on the high part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5280 | __ Rsb(temp, o_l, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5281 | __ Lsr(temp, low, temp); |
| 5282 | __ Orr(o_h, o_h, temp); |
| 5283 | // If the shift is > 32 bits, override the high part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5284 | __ Subs(temp, o_l, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5285 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5286 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5287 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5288 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5289 | __ it(pl); |
| 5290 | __ lsl(pl, o_h, low, temp); |
| 5291 | } |
| 5292 | // Shift the low part |
| 5293 | __ Lsl(o_l, low, o_l); |
| 5294 | } else if (op->IsShr()) { |
| 5295 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 5296 | // Shift the low part |
| 5297 | __ Lsr(o_l, low, o_h); |
| 5298 | // Shift the high part and `or` what underflew on the low part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5299 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5300 | __ Lsl(temp, high, temp); |
| 5301 | __ Orr(o_l, o_l, temp); |
| 5302 | // If the shift is > 32 bits, override the low part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5303 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5304 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5305 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5306 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5307 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5308 | __ it(pl); |
| 5309 | __ asr(pl, o_l, high, temp); |
| 5310 | } |
| 5311 | // Shift the high part |
| 5312 | __ Asr(o_h, high, o_h); |
| 5313 | } else { |
| 5314 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 5315 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 5316 | __ Lsr(o_l, low, o_h); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5317 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5318 | __ Lsl(temp, high, temp); |
| 5319 | __ Orr(o_l, o_l, temp); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5320 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5321 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5322 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5323 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5324 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5325 | __ it(pl); |
| 5326 | __ lsr(pl, o_l, high, temp); |
| 5327 | } |
| 5328 | __ Lsr(o_h, high, o_h); |
| 5329 | } |
| 5330 | } else { |
| 5331 | // Register allocator doesn't create partial overlap. |
| 5332 | DCHECK(!o_l.Is(high)); |
| 5333 | DCHECK(!o_h.Is(low)); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5334 | int32_t cst = Int32ConstantFrom(second); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5335 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
| 5336 | if (shift_value > 32) { |
| 5337 | if (op->IsShl()) { |
| 5338 | __ Lsl(o_h, low, shift_value - 32); |
| 5339 | __ Mov(o_l, 0); |
| 5340 | } else if (op->IsShr()) { |
| 5341 | __ Asr(o_l, high, shift_value - 32); |
| 5342 | __ Asr(o_h, high, 31); |
| 5343 | } else { |
| 5344 | __ Lsr(o_l, high, shift_value - 32); |
| 5345 | __ Mov(o_h, 0); |
| 5346 | } |
| 5347 | } else if (shift_value == 32) { |
| 5348 | if (op->IsShl()) { |
| 5349 | __ Mov(o_h, low); |
| 5350 | __ Mov(o_l, 0); |
| 5351 | } else if (op->IsShr()) { |
| 5352 | __ Mov(o_l, high); |
| 5353 | __ Asr(o_h, high, 31); |
| 5354 | } else { |
| 5355 | __ Mov(o_l, high); |
| 5356 | __ Mov(o_h, 0); |
| 5357 | } |
| 5358 | } else if (shift_value == 1) { |
| 5359 | if (op->IsShl()) { |
| 5360 | __ Lsls(o_l, low, 1); |
| 5361 | __ Adc(o_h, high, high); |
| 5362 | } else if (op->IsShr()) { |
| 5363 | __ Asrs(o_h, high, 1); |
| 5364 | __ Rrx(o_l, low); |
| 5365 | } else { |
| 5366 | __ Lsrs(o_h, high, 1); |
| 5367 | __ Rrx(o_l, low); |
| 5368 | } |
Nicolas Geoffray | 9b195cc | 2019-04-02 08:29:00 +0100 | [diff] [blame] | 5369 | } else if (shift_value == 0) { |
| 5370 | __ Mov(o_l, low); |
| 5371 | __ Mov(o_h, high); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5372 | } else { |
Nicolas Geoffray | 9b195cc | 2019-04-02 08:29:00 +0100 | [diff] [blame] | 5373 | DCHECK(0 < shift_value && shift_value < 32) << shift_value; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5374 | if (op->IsShl()) { |
| 5375 | __ Lsl(o_h, high, shift_value); |
| 5376 | __ Orr(o_h, o_h, Operand(low, ShiftType::LSR, 32 - shift_value)); |
| 5377 | __ Lsl(o_l, low, shift_value); |
| 5378 | } else if (op->IsShr()) { |
| 5379 | __ Lsr(o_l, low, shift_value); |
| 5380 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 5381 | __ Asr(o_h, high, shift_value); |
| 5382 | } else { |
| 5383 | __ Lsr(o_l, low, shift_value); |
| 5384 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 5385 | __ Lsr(o_h, high, shift_value); |
| 5386 | } |
| 5387 | } |
| 5388 | } |
| 5389 | break; |
| 5390 | } |
| 5391 | default: |
| 5392 | LOG(FATAL) << "Unexpected operation type " << type; |
| 5393 | UNREACHABLE(); |
| 5394 | } |
| 5395 | } |
| 5396 | |
| 5397 | void LocationsBuilderARMVIXL::VisitShl(HShl* shl) { |
| 5398 | HandleShift(shl); |
| 5399 | } |
| 5400 | |
| 5401 | void InstructionCodeGeneratorARMVIXL::VisitShl(HShl* shl) { |
| 5402 | HandleShift(shl); |
| 5403 | } |
| 5404 | |
| 5405 | void LocationsBuilderARMVIXL::VisitShr(HShr* shr) { |
| 5406 | HandleShift(shr); |
| 5407 | } |
| 5408 | |
| 5409 | void InstructionCodeGeneratorARMVIXL::VisitShr(HShr* shr) { |
| 5410 | HandleShift(shr); |
| 5411 | } |
| 5412 | |
| 5413 | void LocationsBuilderARMVIXL::VisitUShr(HUShr* ushr) { |
| 5414 | HandleShift(ushr); |
| 5415 | } |
| 5416 | |
| 5417 | void InstructionCodeGeneratorARMVIXL::VisitUShr(HUShr* ushr) { |
| 5418 | HandleShift(ushr); |
| 5419 | } |
| 5420 | |
| 5421 | void LocationsBuilderARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5422 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5423 | instruction, LocationSummary::kCallOnMainOnly); |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5424 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 5425 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5426 | locations->SetOut(LocationFrom(r0)); |
| 5427 | } |
| 5428 | |
| 5429 | void InstructionCodeGeneratorARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5430 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 5431 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 5432 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 12); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5433 | } |
| 5434 | |
| 5435 | void LocationsBuilderARMVIXL::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5436 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5437 | instruction, LocationSummary::kCallOnMainOnly); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5438 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5439 | locations->SetOut(LocationFrom(r0)); |
Nicolas Geoffray | 8c7c4f1 | 2017-01-26 10:13:11 +0000 | [diff] [blame] | 5440 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5441 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5442 | } |
| 5443 | |
| 5444 | void InstructionCodeGeneratorARMVIXL::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5445 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 5446 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 5447 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5448 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 5449 | DCHECK(!codegen_->IsLeafMethod()); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 5450 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 13); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5451 | } |
| 5452 | |
| 5453 | void LocationsBuilderARMVIXL::VisitParameterValue(HParameterValue* instruction) { |
| 5454 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5455 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5456 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5457 | if (location.IsStackSlot()) { |
| 5458 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5459 | } else if (location.IsDoubleStackSlot()) { |
| 5460 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5461 | } |
| 5462 | locations->SetOut(location); |
| 5463 | } |
| 5464 | |
| 5465 | void InstructionCodeGeneratorARMVIXL::VisitParameterValue( |
| 5466 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 5467 | // Nothing to do, the parameter is already at its location. |
| 5468 | } |
| 5469 | |
| 5470 | void LocationsBuilderARMVIXL::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5471 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5472 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5473 | locations->SetOut(LocationFrom(kMethodRegister)); |
| 5474 | } |
| 5475 | |
| 5476 | void InstructionCodeGeneratorARMVIXL::VisitCurrentMethod( |
| 5477 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5478 | // Nothing to do, the method is already at its location. |
| 5479 | } |
| 5480 | |
| 5481 | void LocationsBuilderARMVIXL::VisitNot(HNot* not_) { |
| 5482 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5483 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5484 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5485 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5486 | } |
| 5487 | |
| 5488 | void InstructionCodeGeneratorARMVIXL::VisitNot(HNot* not_) { |
| 5489 | LocationSummary* locations = not_->GetLocations(); |
| 5490 | Location out = locations->Out(); |
| 5491 | Location in = locations->InAt(0); |
| 5492 | switch (not_->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5493 | case DataType::Type::kInt32: |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5494 | __ Mvn(OutputRegister(not_), InputRegisterAt(not_, 0)); |
| 5495 | break; |
| 5496 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5497 | case DataType::Type::kInt64: |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5498 | __ Mvn(LowRegisterFrom(out), LowRegisterFrom(in)); |
| 5499 | __ Mvn(HighRegisterFrom(out), HighRegisterFrom(in)); |
| 5500 | break; |
| 5501 | |
| 5502 | default: |
| 5503 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 5504 | } |
| 5505 | } |
| 5506 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5507 | void LocationsBuilderARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5508 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5509 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5510 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5511 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5512 | } |
| 5513 | |
| 5514 | void InstructionCodeGeneratorARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5515 | __ Eor(OutputRegister(bool_not), InputRegister(bool_not), 1); |
| 5516 | } |
| 5517 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5518 | void LocationsBuilderARMVIXL::VisitCompare(HCompare* compare) { |
| 5519 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5520 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5521 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5522 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5523 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5524 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5525 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5526 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5527 | case DataType::Type::kInt32: |
| 5528 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5529 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5530 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5531 | // Output overlaps because it is written before doing the low comparison. |
| 5532 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5533 | break; |
| 5534 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5535 | case DataType::Type::kFloat32: |
| 5536 | case DataType::Type::kFloat64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5537 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5538 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
| 5539 | locations->SetOut(Location::RequiresRegister()); |
| 5540 | break; |
| 5541 | } |
| 5542 | default: |
| 5543 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 5544 | } |
| 5545 | } |
| 5546 | |
| 5547 | void InstructionCodeGeneratorARMVIXL::VisitCompare(HCompare* compare) { |
| 5548 | LocationSummary* locations = compare->GetLocations(); |
| 5549 | vixl32::Register out = OutputRegister(compare); |
| 5550 | Location left = locations->InAt(0); |
| 5551 | Location right = locations->InAt(1); |
| 5552 | |
| 5553 | vixl32::Label less, greater, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5554 | vixl32::Label* final_label = codegen_->GetFinalLabel(compare, &done); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5555 | DataType::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 5556 | vixl32::Condition less_cond = vixl32::Condition::None(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5557 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5558 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5559 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5560 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5561 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5562 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5563 | case DataType::Type::kInt32: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5564 | // Emit move to `out` before the `Cmp`, as `Mov` might affect the status flags. |
| 5565 | __ Mov(out, 0); |
| 5566 | __ Cmp(RegisterFrom(left), RegisterFrom(right)); // Signed compare. |
| 5567 | less_cond = lt; |
| 5568 | break; |
| 5569 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5570 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5571 | __ Cmp(HighRegisterFrom(left), HighRegisterFrom(right)); // Signed compare. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5572 | __ B(lt, &less, /* is_far_target= */ false); |
| 5573 | __ B(gt, &greater, /* is_far_target= */ false); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5574 | // Emit move to `out` before the last `Cmp`, as `Mov` might affect the status flags. |
| 5575 | __ Mov(out, 0); |
| 5576 | __ Cmp(LowRegisterFrom(left), LowRegisterFrom(right)); // Unsigned compare. |
| 5577 | less_cond = lo; |
| 5578 | break; |
| 5579 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5580 | case DataType::Type::kFloat32: |
| 5581 | case DataType::Type::kFloat64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5582 | __ Mov(out, 0); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 5583 | GenerateVcmp(compare, codegen_); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5584 | // To branch on the FP compare result we transfer FPSCR to APSR (encoded as PC in VMRS). |
| 5585 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 5586 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
| 5587 | break; |
| 5588 | } |
| 5589 | default: |
| 5590 | LOG(FATAL) << "Unexpected compare type " << type; |
| 5591 | UNREACHABLE(); |
| 5592 | } |
| 5593 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5594 | __ B(eq, final_label, /* is_far_target= */ false); |
| 5595 | __ B(less_cond, &less, /* is_far_target= */ false); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5596 | |
| 5597 | __ Bind(&greater); |
| 5598 | __ Mov(out, 1); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5599 | __ B(final_label); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5600 | |
| 5601 | __ Bind(&less); |
| 5602 | __ Mov(out, -1); |
| 5603 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5604 | if (done.IsReferenced()) { |
| 5605 | __ Bind(&done); |
| 5606 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5607 | } |
| 5608 | |
| 5609 | void LocationsBuilderARMVIXL::VisitPhi(HPhi* instruction) { |
| 5610 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5611 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5612 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| 5613 | locations->SetInAt(i, Location::Any()); |
| 5614 | } |
| 5615 | locations->SetOut(Location::Any()); |
| 5616 | } |
| 5617 | |
| 5618 | void InstructionCodeGeneratorARMVIXL::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 5619 | LOG(FATAL) << "Unreachable"; |
| 5620 | } |
| 5621 | |
| 5622 | void CodeGeneratorARMVIXL::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 5623 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 5624 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
| 5625 | switch (kind) { |
| 5626 | case MemBarrierKind::kAnyStore: |
| 5627 | case MemBarrierKind::kLoadAny: |
| 5628 | case MemBarrierKind::kAnyAny: { |
| 5629 | flavor = DmbOptions::ISH; |
| 5630 | break; |
| 5631 | } |
| 5632 | case MemBarrierKind::kStoreStore: { |
| 5633 | flavor = DmbOptions::ISHST; |
| 5634 | break; |
| 5635 | } |
| 5636 | default: |
| 5637 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 5638 | } |
| 5639 | __ Dmb(flavor); |
| 5640 | } |
| 5641 | |
| 5642 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicLoad(vixl32::Register addr, |
| 5643 | uint32_t offset, |
| 5644 | vixl32::Register out_lo, |
| 5645 | vixl32::Register out_hi) { |
| 5646 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5647 | if (offset != 0) { |
| 5648 | vixl32::Register temp = temps.Acquire(); |
| 5649 | __ Add(temp, addr, offset); |
| 5650 | addr = temp; |
| 5651 | } |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5652 | __ Ldrexd(out_lo, out_hi, MemOperand(addr)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5653 | } |
| 5654 | |
| 5655 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicStore(vixl32::Register addr, |
| 5656 | uint32_t offset, |
| 5657 | vixl32::Register value_lo, |
| 5658 | vixl32::Register value_hi, |
| 5659 | vixl32::Register temp1, |
| 5660 | vixl32::Register temp2, |
| 5661 | HInstruction* instruction) { |
| 5662 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5663 | vixl32::Label fail; |
| 5664 | if (offset != 0) { |
| 5665 | vixl32::Register temp = temps.Acquire(); |
| 5666 | __ Add(temp, addr, offset); |
| 5667 | addr = temp; |
| 5668 | } |
| 5669 | __ Bind(&fail); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5670 | { |
| 5671 | // Ensure the pc position is recorded immediately after the `ldrexd` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5672 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5673 | vixl32::kMaxInstructionSizeInBytes, |
| 5674 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5675 | // We need a load followed by store. (The address used in a STREX instruction must |
| 5676 | // be the same as the address in the most recently executed LDREX instruction.) |
| 5677 | __ ldrexd(temp1, temp2, MemOperand(addr)); |
| 5678 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5679 | } |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5680 | __ Strexd(temp1, value_lo, value_hi, MemOperand(addr)); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5681 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5682 | } |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5683 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5684 | void LocationsBuilderARMVIXL::HandleFieldSet( |
| 5685 | HInstruction* instruction, const FieldInfo& field_info) { |
| 5686 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5687 | |
| 5688 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5689 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5690 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5691 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5692 | DataType::Type field_type = field_info.GetFieldType(); |
| 5693 | if (DataType::IsFloatingPointType(field_type)) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5694 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5695 | } else { |
| 5696 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5697 | } |
| 5698 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5699 | bool is_wide = field_type == DataType::Type::kInt64 || field_type == DataType::Type::kFloat64; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5700 | bool generate_volatile = field_info.IsVolatile() |
| 5701 | && is_wide |
| 5702 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5703 | bool needs_write_barrier = |
| 5704 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 5705 | // Temporary registers for the write barrier. |
| 5706 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
| 5707 | if (needs_write_barrier) { |
| 5708 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
| 5709 | locations->AddTemp(Location::RequiresRegister()); |
| 5710 | } else if (generate_volatile) { |
| 5711 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 5712 | // - registers need to be consecutive |
| 5713 | // - the first register should be even but not R14. |
| 5714 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5715 | // revisit this if we ever enable ARM encoding. |
| 5716 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5717 | |
| 5718 | locations->AddTemp(Location::RequiresRegister()); |
| 5719 | locations->AddTemp(Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5720 | if (field_type == DataType::Type::kFloat64) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5721 | // For doubles we need two more registers to copy the value. |
| 5722 | locations->AddTemp(LocationFrom(r2)); |
| 5723 | locations->AddTemp(LocationFrom(r3)); |
| 5724 | } |
| 5725 | } |
| 5726 | } |
| 5727 | |
| 5728 | void InstructionCodeGeneratorARMVIXL::HandleFieldSet(HInstruction* instruction, |
| 5729 | const FieldInfo& field_info, |
| 5730 | bool value_can_be_null) { |
| 5731 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5732 | |
| 5733 | LocationSummary* locations = instruction->GetLocations(); |
| 5734 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 5735 | Location value = locations->InAt(1); |
| 5736 | |
| 5737 | bool is_volatile = field_info.IsVolatile(); |
| 5738 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5739 | DataType::Type field_type = field_info.GetFieldType(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5740 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5741 | bool needs_write_barrier = |
| 5742 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 5743 | |
| 5744 | if (is_volatile) { |
| 5745 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 5746 | } |
| 5747 | |
| 5748 | switch (field_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5749 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5750 | case DataType::Type::kUint8: |
| 5751 | case DataType::Type::kInt8: |
| 5752 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5753 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5754 | case DataType::Type::kInt32: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5755 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5756 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5757 | StoreOperandType operand_type = GetStoreOperandType(field_type); |
| 5758 | GetAssembler()->StoreToOffset(operand_type, RegisterFrom(value), base, offset); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5759 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5760 | break; |
| 5761 | } |
| 5762 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5763 | case DataType::Type::kReference: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5764 | vixl32::Register value_reg = RegisterFrom(value); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5765 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5766 | // Note that in the case where `value` is a null reference, |
| 5767 | // we do not enter this block, as a null reference does not |
| 5768 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5769 | DCHECK_EQ(field_type, DataType::Type::kReference); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5770 | value_reg = RegisterFrom(locations->GetTemp(0)); |
| 5771 | __ Mov(value_reg, RegisterFrom(value)); |
| 5772 | GetAssembler()->PoisonHeapReference(value_reg); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5773 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5774 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5775 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5776 | GetAssembler()->StoreToOffset(kStoreWord, value_reg, base, offset); |
| 5777 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5778 | break; |
| 5779 | } |
| 5780 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5781 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5782 | if (is_volatile && !atomic_ldrd_strd) { |
| 5783 | GenerateWideAtomicStore(base, |
| 5784 | offset, |
| 5785 | LowRegisterFrom(value), |
| 5786 | HighRegisterFrom(value), |
| 5787 | RegisterFrom(locations->GetTemp(0)), |
| 5788 | RegisterFrom(locations->GetTemp(1)), |
| 5789 | instruction); |
| 5790 | } else { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5791 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5792 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5793 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), base, offset); |
| 5794 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5795 | } |
| 5796 | break; |
| 5797 | } |
| 5798 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5799 | case DataType::Type::kFloat32: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5800 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5801 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5802 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), base, offset); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5803 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5804 | break; |
| 5805 | } |
| 5806 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5807 | case DataType::Type::kFloat64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5808 | vixl32::DRegister value_reg = DRegisterFrom(value); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5809 | if (is_volatile && !atomic_ldrd_strd) { |
| 5810 | vixl32::Register value_reg_lo = RegisterFrom(locations->GetTemp(0)); |
| 5811 | vixl32::Register value_reg_hi = RegisterFrom(locations->GetTemp(1)); |
| 5812 | |
| 5813 | __ Vmov(value_reg_lo, value_reg_hi, value_reg); |
| 5814 | |
| 5815 | GenerateWideAtomicStore(base, |
| 5816 | offset, |
| 5817 | value_reg_lo, |
| 5818 | value_reg_hi, |
| 5819 | RegisterFrom(locations->GetTemp(2)), |
| 5820 | RegisterFrom(locations->GetTemp(3)), |
| 5821 | instruction); |
| 5822 | } else { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5823 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5824 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5825 | GetAssembler()->StoreDToOffset(value_reg, base, offset); |
| 5826 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5827 | } |
| 5828 | break; |
| 5829 | } |
| 5830 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5831 | case DataType::Type::kUint32: |
| 5832 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5833 | case DataType::Type::kVoid: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5834 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5835 | UNREACHABLE(); |
| 5836 | } |
| 5837 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5838 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5839 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5840 | vixl32::Register card = RegisterFrom(locations->GetTemp(1)); |
| 5841 | codegen_->MarkGCCard(temp, card, base, RegisterFrom(value), value_can_be_null); |
| 5842 | } |
| 5843 | |
| 5844 | if (is_volatile) { |
| 5845 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 5846 | } |
| 5847 | } |
| 5848 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5849 | void LocationsBuilderARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 5850 | const FieldInfo& field_info) { |
Nicolas Geoffray | 791df7a | 2021-01-23 13:28:56 +0000 | [diff] [blame] | 5851 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5852 | |
| 5853 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5854 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == DataType::Type::kReference); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5855 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5856 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5857 | object_field_get_with_read_barrier |
| 5858 | ? LocationSummary::kCallOnSlowPath |
| 5859 | : LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5860 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5861 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 5862 | } |
Nicolas Geoffray | 791df7a | 2021-01-23 13:28:56 +0000 | [diff] [blame] | 5863 | locations->SetInAt(0, Location::RequiresRegister()); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5864 | |
| 5865 | bool volatile_for_double = field_info.IsVolatile() |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5866 | && (field_info.GetFieldType() == DataType::Type::kFloat64) |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5867 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5868 | // The output overlaps in case of volatile long: we don't want the |
| 5869 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 5870 | // object's location. Likewise, in the case of an object field get |
| 5871 | // with read barriers enabled, we do not want the load to overwrite |
| 5872 | // the object's location, as we need it to emit the read barrier. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5873 | bool overlap = |
| 5874 | (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) || |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5875 | object_field_get_with_read_barrier; |
| 5876 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5877 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Nicolas Geoffray | 791df7a | 2021-01-23 13:28:56 +0000 | [diff] [blame] | 5878 | locations->SetOut(Location::RequiresFpuRegister()); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5879 | } else { |
Nicolas Geoffray | 791df7a | 2021-01-23 13:28:56 +0000 | [diff] [blame] | 5880 | locations->SetOut(Location::RequiresRegister(), |
| 5881 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5882 | } |
| 5883 | if (volatile_for_double) { |
| 5884 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 5885 | // - registers need to be consecutive |
| 5886 | // - the first register should be even but not R14. |
| 5887 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5888 | // revisit this if we ever enable ARM encoding. |
| 5889 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5890 | locations->AddTemp(Location::RequiresRegister()); |
| 5891 | locations->AddTemp(Location::RequiresRegister()); |
| 5892 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 5893 | // We need a temporary register for the read barrier load in |
| 5894 | // CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier() |
| 5895 | // only if the offset is too big. |
| 5896 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 5897 | locations->AddTemp(Location::RequiresRegister()); |
| 5898 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5899 | } |
| 5900 | } |
| 5901 | |
| 5902 | Location LocationsBuilderARMVIXL::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5903 | DCHECK(DataType::IsFloatingPointType(input->GetType())) << input->GetType(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5904 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 5905 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 5906 | return Location::ConstantLocation(input->AsConstant()); |
| 5907 | } else { |
| 5908 | return Location::RequiresFpuRegister(); |
| 5909 | } |
| 5910 | } |
| 5911 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5912 | Location LocationsBuilderARMVIXL::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 5913 | Opcode opcode) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5914 | DCHECK(!DataType::IsFloatingPointType(constant->GetType())); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5915 | if (constant->IsConstant() && |
| 5916 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 5917 | return Location::ConstantLocation(constant->AsConstant()); |
| 5918 | } |
| 5919 | return Location::RequiresRegister(); |
| 5920 | } |
| 5921 | |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 5922 | static bool CanEncode32BitConstantAsImmediate( |
| 5923 | CodeGeneratorARMVIXL* codegen, |
| 5924 | uint32_t value, |
| 5925 | Opcode opcode, |
| 5926 | vixl32::FlagsUpdate flags_update = vixl32::FlagsUpdate::DontCare) { |
| 5927 | ArmVIXLAssembler* assembler = codegen->GetAssembler(); |
| 5928 | if (assembler->ShifterOperandCanHold(opcode, value, flags_update)) { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5929 | return true; |
| 5930 | } |
| 5931 | Opcode neg_opcode = kNoOperand; |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5932 | uint32_t neg_value = 0; |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5933 | switch (opcode) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5934 | case AND: neg_opcode = BIC; neg_value = ~value; break; |
| 5935 | case ORR: neg_opcode = ORN; neg_value = ~value; break; |
| 5936 | case ADD: neg_opcode = SUB; neg_value = -value; break; |
| 5937 | case ADC: neg_opcode = SBC; neg_value = ~value; break; |
| 5938 | case SUB: neg_opcode = ADD; neg_value = -value; break; |
| 5939 | case SBC: neg_opcode = ADC; neg_value = ~value; break; |
| 5940 | case MOV: neg_opcode = MVN; neg_value = ~value; break; |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5941 | default: |
| 5942 | return false; |
| 5943 | } |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5944 | |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 5945 | if (assembler->ShifterOperandCanHold(neg_opcode, neg_value, flags_update)) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5946 | return true; |
| 5947 | } |
| 5948 | |
| 5949 | return opcode == AND && IsPowerOfTwo(value + 1); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5950 | } |
| 5951 | |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 5952 | bool LocationsBuilderARMVIXL::CanEncodeConstantAsImmediate(HConstant* input_cst, Opcode opcode) { |
| 5953 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 5954 | if (DataType::Is64BitType(input_cst->GetType())) { |
| 5955 | Opcode high_opcode = opcode; |
| 5956 | vixl32::FlagsUpdate low_flags_update = vixl32::FlagsUpdate::DontCare; |
| 5957 | switch (opcode) { |
| 5958 | case SUB: |
| 5959 | // Flip the operation to an ADD. |
| 5960 | value = -value; |
| 5961 | opcode = ADD; |
| 5962 | FALLTHROUGH_INTENDED; |
| 5963 | case ADD: |
| 5964 | if (Low32Bits(value) == 0u) { |
| 5965 | return CanEncode32BitConstantAsImmediate(codegen_, High32Bits(value), opcode); |
| 5966 | } |
| 5967 | high_opcode = ADC; |
| 5968 | low_flags_update = vixl32::FlagsUpdate::SetFlags; |
| 5969 | break; |
| 5970 | default: |
| 5971 | break; |
| 5972 | } |
| 5973 | return CanEncode32BitConstantAsImmediate(codegen_, High32Bits(value), high_opcode) && |
| 5974 | CanEncode32BitConstantAsImmediate(codegen_, Low32Bits(value), opcode, low_flags_update); |
| 5975 | } else { |
| 5976 | return CanEncode32BitConstantAsImmediate(codegen_, Low32Bits(value), opcode); |
| 5977 | } |
| 5978 | } |
| 5979 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5980 | void InstructionCodeGeneratorARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 5981 | const FieldInfo& field_info) { |
Nicolas Geoffray | 791df7a | 2021-01-23 13:28:56 +0000 | [diff] [blame] | 5982 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5983 | |
| 5984 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 791df7a | 2021-01-23 13:28:56 +0000 | [diff] [blame] | 5985 | vixl32::Register base = InputRegisterAt(instruction, 0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5986 | Location out = locations->Out(); |
| 5987 | bool is_volatile = field_info.IsVolatile(); |
| 5988 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5989 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 5990 | DataType::Type load_type = instruction->GetType(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5991 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5992 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5993 | switch (load_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5994 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5995 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5996 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5997 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5998 | case DataType::Type::kInt16: |
| 5999 | case DataType::Type::kInt32: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6000 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6001 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6002 | LoadOperandType operand_type = GetLoadOperandType(load_type); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6003 | GetAssembler()->LoadFromOffset(operand_type, RegisterFrom(out), base, offset); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6004 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6005 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6006 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6007 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6008 | case DataType::Type::kReference: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6009 | // /* HeapReference<Object> */ out = *(base + offset) |
| 6010 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 6011 | Location maybe_temp = (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location(); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6012 | // Note that a potential implicit null check is handled in this |
| 6013 | // CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier call. |
| 6014 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6015 | instruction, out, base, offset, maybe_temp, /* needs_null_check= */ true); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6016 | if (is_volatile) { |
| 6017 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6018 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6019 | } else { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6020 | { |
| 6021 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6022 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6023 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(out), base, offset); |
| 6024 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6025 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6026 | if (is_volatile) { |
| 6027 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6028 | } |
| 6029 | // If read barriers are enabled, emit read barriers other than |
| 6030 | // Baker's using a slow path (and also unpoison the loaded |
| 6031 | // reference, if heap poisoning is enabled). |
Nicolas Geoffray | 791df7a | 2021-01-23 13:28:56 +0000 | [diff] [blame] | 6032 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, locations->InAt(0), offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6033 | } |
| 6034 | break; |
| 6035 | } |
| 6036 | |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6037 | case DataType::Type::kInt64: { |
| 6038 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6039 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6040 | if (is_volatile && !atomic_ldrd_strd) { |
| 6041 | GenerateWideAtomicLoad(base, offset, LowRegisterFrom(out), HighRegisterFrom(out)); |
| 6042 | } else { |
| 6043 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out), base, offset); |
| 6044 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6045 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6046 | break; |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6047 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6048 | |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6049 | case DataType::Type::kFloat32: { |
| 6050 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6051 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6052 | GetAssembler()->LoadSFromOffset(SRegisterFrom(out), base, offset); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6053 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6054 | break; |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6055 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6056 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6057 | case DataType::Type::kFloat64: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6058 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6059 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6060 | vixl32::DRegister out_dreg = DRegisterFrom(out); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6061 | if (is_volatile && !atomic_ldrd_strd) { |
| 6062 | vixl32::Register lo = RegisterFrom(locations->GetTemp(0)); |
| 6063 | vixl32::Register hi = RegisterFrom(locations->GetTemp(1)); |
| 6064 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6065 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6066 | __ Vmov(out_dreg, lo, hi); |
| 6067 | } else { |
| 6068 | GetAssembler()->LoadDFromOffset(out_dreg, base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6069 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6070 | } |
| 6071 | break; |
| 6072 | } |
| 6073 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6074 | case DataType::Type::kUint32: |
| 6075 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6076 | case DataType::Type::kVoid: |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6077 | LOG(FATAL) << "Unreachable type " << load_type; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6078 | UNREACHABLE(); |
| 6079 | } |
| 6080 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6081 | if (is_volatile) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6082 | if (load_type == DataType::Type::kReference) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6083 | // Memory barriers, in the case of references, are also handled |
| 6084 | // in the previous switch statement. |
| 6085 | } else { |
| 6086 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6087 | } |
| 6088 | } |
| 6089 | } |
| 6090 | |
| 6091 | void LocationsBuilderARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 6092 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6093 | } |
| 6094 | |
| 6095 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 6096 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 6097 | } |
| 6098 | |
| 6099 | void LocationsBuilderARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6100 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6101 | } |
| 6102 | |
| 6103 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6104 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6105 | } |
| 6106 | |
| 6107 | void LocationsBuilderARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6108 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6109 | } |
| 6110 | |
| 6111 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6112 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6113 | } |
| 6114 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6115 | void LocationsBuilderARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 6116 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6117 | } |
| 6118 | |
| 6119 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 6120 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 6121 | } |
| 6122 | |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 6123 | void LocationsBuilderARMVIXL::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 6124 | codegen_->CreateStringBuilderAppendLocations(instruction, LocationFrom(r0)); |
| 6125 | } |
| 6126 | |
| 6127 | void InstructionCodeGeneratorARMVIXL::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 6128 | __ Mov(r0, instruction->GetFormat()->GetValue()); |
| 6129 | codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc()); |
| 6130 | } |
| 6131 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6132 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 6133 | HUnresolvedInstanceFieldGet* instruction) { |
| 6134 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6135 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6136 | instruction, instruction->GetFieldType(), calling_convention); |
| 6137 | } |
| 6138 | |
| 6139 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 6140 | HUnresolvedInstanceFieldGet* instruction) { |
| 6141 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6142 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6143 | instruction->GetFieldType(), |
| 6144 | instruction->GetFieldIndex(), |
| 6145 | instruction->GetDexPc(), |
| 6146 | calling_convention); |
| 6147 | } |
| 6148 | |
| 6149 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 6150 | HUnresolvedInstanceFieldSet* instruction) { |
| 6151 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6152 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6153 | instruction, instruction->GetFieldType(), calling_convention); |
| 6154 | } |
| 6155 | |
| 6156 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 6157 | HUnresolvedInstanceFieldSet* instruction) { |
| 6158 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6159 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6160 | instruction->GetFieldType(), |
| 6161 | instruction->GetFieldIndex(), |
| 6162 | instruction->GetDexPc(), |
| 6163 | calling_convention); |
| 6164 | } |
| 6165 | |
| 6166 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldGet( |
| 6167 | HUnresolvedStaticFieldGet* instruction) { |
| 6168 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6169 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6170 | instruction, instruction->GetFieldType(), calling_convention); |
| 6171 | } |
| 6172 | |
| 6173 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldGet( |
| 6174 | HUnresolvedStaticFieldGet* instruction) { |
| 6175 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6176 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6177 | instruction->GetFieldType(), |
| 6178 | instruction->GetFieldIndex(), |
| 6179 | instruction->GetDexPc(), |
| 6180 | calling_convention); |
| 6181 | } |
| 6182 | |
| 6183 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldSet( |
| 6184 | HUnresolvedStaticFieldSet* instruction) { |
| 6185 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6186 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6187 | instruction, instruction->GetFieldType(), calling_convention); |
| 6188 | } |
| 6189 | |
| 6190 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldSet( |
| 6191 | HUnresolvedStaticFieldSet* instruction) { |
| 6192 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6193 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6194 | instruction->GetFieldType(), |
| 6195 | instruction->GetFieldIndex(), |
| 6196 | instruction->GetDexPc(), |
| 6197 | calling_convention); |
| 6198 | } |
| 6199 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6200 | void LocationsBuilderARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6201 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6202 | locations->SetInAt(0, Location::RequiresRegister()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6203 | } |
| 6204 | |
| 6205 | void CodeGeneratorARMVIXL::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 6206 | if (CanMoveNullCheckToUser(instruction)) { |
| 6207 | return; |
| 6208 | } |
| 6209 | |
| 6210 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6211 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6212 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6213 | vixl32::kMaxInstructionSizeInBytes, |
| 6214 | CodeBufferCheckScope::kMaximumSize); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6215 | __ ldr(temps.Acquire(), MemOperand(InputRegisterAt(instruction, 0))); |
| 6216 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 6217 | } |
| 6218 | |
| 6219 | void CodeGeneratorARMVIXL::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| 6220 | NullCheckSlowPathARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6221 | new (GetScopedAllocator()) NullCheckSlowPathARMVIXL(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6222 | AddSlowPath(slow_path); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6223 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6224 | } |
| 6225 | |
| 6226 | void InstructionCodeGeneratorARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
| 6227 | codegen_->GenerateNullCheck(instruction); |
| 6228 | } |
| 6229 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6230 | void CodeGeneratorARMVIXL::LoadFromShiftedRegOffset(DataType::Type type, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6231 | Location out_loc, |
| 6232 | vixl32::Register base, |
| 6233 | vixl32::Register reg_index, |
| 6234 | vixl32::Condition cond) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6235 | uint32_t shift_count = DataType::SizeShift(type); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6236 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 6237 | |
| 6238 | switch (type) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6239 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6240 | case DataType::Type::kUint8: |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6241 | __ Ldrb(cond, RegisterFrom(out_loc), mem_address); |
| 6242 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6243 | case DataType::Type::kInt8: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6244 | __ Ldrsb(cond, RegisterFrom(out_loc), mem_address); |
| 6245 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6246 | case DataType::Type::kUint16: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6247 | __ Ldrh(cond, RegisterFrom(out_loc), mem_address); |
| 6248 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6249 | case DataType::Type::kInt16: |
| 6250 | __ Ldrsh(cond, RegisterFrom(out_loc), mem_address); |
| 6251 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6252 | case DataType::Type::kReference: |
| 6253 | case DataType::Type::kInt32: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6254 | __ Ldr(cond, RegisterFrom(out_loc), mem_address); |
| 6255 | break; |
| 6256 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6257 | case DataType::Type::kInt64: |
| 6258 | case DataType::Type::kFloat32: |
| 6259 | case DataType::Type::kFloat64: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6260 | default: |
| 6261 | LOG(FATAL) << "Unreachable type " << type; |
| 6262 | UNREACHABLE(); |
| 6263 | } |
| 6264 | } |
| 6265 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6266 | void CodeGeneratorARMVIXL::StoreToShiftedRegOffset(DataType::Type type, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6267 | Location loc, |
| 6268 | vixl32::Register base, |
| 6269 | vixl32::Register reg_index, |
| 6270 | vixl32::Condition cond) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6271 | uint32_t shift_count = DataType::SizeShift(type); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6272 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 6273 | |
| 6274 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6275 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6276 | case DataType::Type::kUint8: |
| 6277 | case DataType::Type::kInt8: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6278 | __ Strb(cond, RegisterFrom(loc), mem_address); |
| 6279 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6280 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6281 | case DataType::Type::kInt16: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6282 | __ Strh(cond, RegisterFrom(loc), mem_address); |
| 6283 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6284 | case DataType::Type::kReference: |
| 6285 | case DataType::Type::kInt32: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6286 | __ Str(cond, RegisterFrom(loc), mem_address); |
| 6287 | break; |
| 6288 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6289 | case DataType::Type::kInt64: |
| 6290 | case DataType::Type::kFloat32: |
| 6291 | case DataType::Type::kFloat64: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6292 | default: |
| 6293 | LOG(FATAL) << "Unreachable type " << type; |
| 6294 | UNREACHABLE(); |
| 6295 | } |
| 6296 | } |
| 6297 | |
| 6298 | void LocationsBuilderARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
| 6299 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6300 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6301 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6302 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 6303 | object_array_get_with_read_barrier |
| 6304 | ? LocationSummary::kCallOnSlowPath |
| 6305 | : LocationSummary::kNoCall); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6306 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6307 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6308 | } |
| 6309 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6310 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6311 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6312 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6313 | } else { |
| 6314 | // The output overlaps in the case of an object array get with |
| 6315 | // read barriers enabled: we do not want the move to overwrite the |
| 6316 | // array's location, as we need it to emit the read barrier. |
| 6317 | locations->SetOut( |
| 6318 | Location::RequiresRegister(), |
| 6319 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 6320 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6321 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6322 | if (instruction->GetIndex()->IsConstant()) { |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6323 | // Array loads with constant index are treated as field loads. |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6324 | // We need a temporary register for the read barrier load in |
| 6325 | // CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier() |
| 6326 | // only if the offset is too big. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6327 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 6328 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6329 | offset += index << DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6330 | if (offset >= kReferenceLoadMinFarOffset) { |
| 6331 | locations->AddTemp(Location::RequiresRegister()); |
| 6332 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6333 | } else { |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6334 | // We need a non-scratch temporary for the array data pointer in |
| 6335 | // CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier(). |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6336 | locations->AddTemp(Location::RequiresRegister()); |
| 6337 | } |
| 6338 | } else if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 6339 | // Also need a temporary for String compression feature. |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6340 | locations->AddTemp(Location::RequiresRegister()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6341 | } |
| 6342 | } |
| 6343 | |
| 6344 | void InstructionCodeGeneratorARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6345 | LocationSummary* locations = instruction->GetLocations(); |
| 6346 | Location obj_loc = locations->InAt(0); |
| 6347 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 6348 | Location index = locations->InAt(1); |
| 6349 | Location out_loc = locations->Out(); |
| 6350 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6351 | DataType::Type type = instruction->GetType(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6352 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 6353 | instruction->IsStringCharAt(); |
| 6354 | HInstruction* array_instr = instruction->GetArray(); |
| 6355 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6356 | |
| 6357 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6358 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6359 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6360 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6361 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6362 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6363 | case DataType::Type::kInt32: { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6364 | vixl32::Register length; |
| 6365 | if (maybe_compressed_char_at) { |
| 6366 | length = RegisterFrom(locations->GetTemp(0)); |
| 6367 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6368 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6369 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6370 | GetAssembler()->LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 6371 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6372 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6373 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6374 | int32_t const_index = Int32ConstantFrom(index); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6375 | if (maybe_compressed_char_at) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6376 | vixl32::Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6377 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6378 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 6379 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6380 | "Expecting 0=compressed, 1=uncompressed"); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6381 | __ B(cs, &uncompressed_load, /* is_far_target= */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6382 | GetAssembler()->LoadFromOffset(kLoadUnsignedByte, |
| 6383 | RegisterFrom(out_loc), |
| 6384 | obj, |
| 6385 | data_offset + const_index); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6386 | __ B(final_label); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6387 | __ Bind(&uncompressed_load); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6388 | GetAssembler()->LoadFromOffset(GetLoadOperandType(DataType::Type::kUint16), |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6389 | RegisterFrom(out_loc), |
| 6390 | obj, |
| 6391 | data_offset + (const_index << 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6392 | if (done.IsReferenced()) { |
| 6393 | __ Bind(&done); |
| 6394 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6395 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6396 | uint32_t full_offset = data_offset + (const_index << DataType::SizeShift(type)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6397 | |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6398 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6399 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6400 | LoadOperandType load_type = GetLoadOperandType(type); |
| 6401 | GetAssembler()->LoadFromOffset(load_type, RegisterFrom(out_loc), obj, full_offset); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6402 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6403 | } |
| 6404 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6405 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6406 | vixl32::Register temp = temps.Acquire(); |
| 6407 | |
| 6408 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6409 | // We do not need to compute the intermediate address from the array: the |
| 6410 | // input instruction has done it already. See the comment in |
| 6411 | // `TryExtractArrayAccessAddress()`. |
| 6412 | if (kIsDebugBuild) { |
| 6413 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6414 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6415 | } |
| 6416 | temp = obj; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6417 | } else { |
| 6418 | __ Add(temp, obj, data_offset); |
| 6419 | } |
| 6420 | if (maybe_compressed_char_at) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6421 | vixl32::Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6422 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6423 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 6424 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6425 | "Expecting 0=compressed, 1=uncompressed"); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6426 | __ B(cs, &uncompressed_load, /* is_far_target= */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6427 | __ Ldrb(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 0)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6428 | __ B(final_label); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6429 | __ Bind(&uncompressed_load); |
| 6430 | __ Ldrh(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6431 | if (done.IsReferenced()) { |
| 6432 | __ Bind(&done); |
| 6433 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6434 | } else { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6435 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6436 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6437 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6438 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6439 | } |
| 6440 | } |
| 6441 | break; |
| 6442 | } |
| 6443 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6444 | case DataType::Type::kReference: { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6445 | // The read barrier instrumentation of object ArrayGet |
| 6446 | // instructions does not support the HIntermediateAddress |
| 6447 | // instruction. |
| 6448 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 6449 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6450 | static_assert( |
| 6451 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6452 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 6453 | // /* HeapReference<Object> */ out = |
| 6454 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6455 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6456 | // Note that a potential implicit null check is handled in this |
| 6457 | // CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6458 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 6459 | if (index.IsConstant()) { |
| 6460 | // Array load with a constant index can be treated as a field load. |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 6461 | Location maybe_temp = |
| 6462 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6463 | data_offset += Int32ConstantFrom(index) << DataType::SizeShift(type); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6464 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6465 | out_loc, |
| 6466 | obj, |
| 6467 | data_offset, |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 6468 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6469 | /* needs_null_check= */ false); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6470 | } else { |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 6471 | Location temp = locations->GetTemp(0); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6472 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6473 | out_loc, obj, data_offset, index, temp, /* needs_null_check= */ false); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6474 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6475 | } else { |
| 6476 | vixl32::Register out = OutputRegister(instruction); |
| 6477 | if (index.IsConstant()) { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6478 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
| 6479 | { |
| 6480 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6481 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6482 | GetAssembler()->LoadFromOffset(kLoadWord, out, obj, offset); |
| 6483 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6484 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6485 | // If read barriers are enabled, emit read barriers other than |
| 6486 | // Baker's using a slow path (and also unpoison the loaded |
| 6487 | // reference, if heap poisoning is enabled). |
| 6488 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 6489 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6490 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6491 | vixl32::Register temp = temps.Acquire(); |
| 6492 | |
| 6493 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6494 | // We do not need to compute the intermediate address from the array: the |
| 6495 | // input instruction has done it already. See the comment in |
| 6496 | // `TryExtractArrayAccessAddress()`. |
| 6497 | if (kIsDebugBuild) { |
| 6498 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6499 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6500 | } |
| 6501 | temp = obj; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6502 | } else { |
| 6503 | __ Add(temp, obj, data_offset); |
| 6504 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6505 | { |
| 6506 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6507 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6508 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
| 6509 | temps.Close(); |
| 6510 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6511 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6512 | // If read barriers are enabled, emit read barriers other than |
| 6513 | // Baker's using a slow path (and also unpoison the loaded |
| 6514 | // reference, if heap poisoning is enabled). |
| 6515 | codegen_->MaybeGenerateReadBarrierSlow( |
| 6516 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 6517 | } |
| 6518 | } |
| 6519 | break; |
| 6520 | } |
| 6521 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6522 | case DataType::Type::kInt64: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6523 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6524 | // As two macro instructions can be emitted the max size is doubled. |
| 6525 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6526 | if (index.IsConstant()) { |
| 6527 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6528 | (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6529 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), obj, offset); |
| 6530 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6531 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6532 | vixl32::Register temp = temps.Acquire(); |
| 6533 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6534 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), temp, data_offset); |
| 6535 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6536 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6537 | break; |
| 6538 | } |
| 6539 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6540 | case DataType::Type::kFloat32: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6541 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6542 | // As two macro instructions can be emitted the max size is doubled. |
| 6543 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6544 | vixl32::SRegister out = SRegisterFrom(out_loc); |
| 6545 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6546 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6547 | GetAssembler()->LoadSFromOffset(out, obj, offset); |
| 6548 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6549 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6550 | vixl32::Register temp = temps.Acquire(); |
| 6551 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 6552 | GetAssembler()->LoadSFromOffset(out, temp, data_offset); |
| 6553 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6554 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6555 | break; |
| 6556 | } |
| 6557 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6558 | case DataType::Type::kFloat64: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6559 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6560 | // As two macro instructions can be emitted the max size is doubled. |
| 6561 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6562 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6563 | size_t offset = (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6564 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), obj, offset); |
| 6565 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6566 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6567 | vixl32::Register temp = temps.Acquire(); |
| 6568 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6569 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), temp, data_offset); |
| 6570 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6571 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6572 | break; |
| 6573 | } |
| 6574 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6575 | case DataType::Type::kUint32: |
| 6576 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6577 | case DataType::Type::kVoid: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6578 | LOG(FATAL) << "Unreachable type " << type; |
| 6579 | UNREACHABLE(); |
| 6580 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6581 | } |
| 6582 | |
| 6583 | void LocationsBuilderARMVIXL::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6584 | DataType::Type value_type = instruction->GetComponentType(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6585 | |
| 6586 | bool needs_write_barrier = |
| 6587 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6588 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6589 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6590 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6591 | instruction, |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6592 | needs_type_check ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6593 | |
| 6594 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6595 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6596 | if (DataType::IsFloatingPointType(value_type)) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6597 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 6598 | } else { |
| 6599 | locations->SetInAt(2, Location::RequiresRegister()); |
| 6600 | } |
| 6601 | if (needs_write_barrier) { |
| 6602 | // Temporary registers for the write barrier. |
| 6603 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 6604 | locations->AddTemp(Location::RequiresRegister()); |
| 6605 | } |
| 6606 | } |
| 6607 | |
| 6608 | void InstructionCodeGeneratorARMVIXL::VisitArraySet(HArraySet* instruction) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6609 | LocationSummary* locations = instruction->GetLocations(); |
| 6610 | vixl32::Register array = InputRegisterAt(instruction, 0); |
| 6611 | Location index = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6612 | DataType::Type value_type = instruction->GetComponentType(); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6613 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6614 | bool needs_write_barrier = |
| 6615 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 6616 | uint32_t data_offset = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6617 | mirror::Array::DataOffset(DataType::Size(value_type)).Uint32Value(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6618 | Location value_loc = locations->InAt(2); |
| 6619 | HInstruction* array_instr = instruction->GetArray(); |
| 6620 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6621 | |
| 6622 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6623 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6624 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6625 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6626 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6627 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6628 | case DataType::Type::kInt32: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6629 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6630 | int32_t const_index = Int32ConstantFrom(index); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6631 | uint32_t full_offset = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6632 | data_offset + (const_index << DataType::SizeShift(value_type)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6633 | StoreOperandType store_type = GetStoreOperandType(value_type); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6634 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6635 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6636 | GetAssembler()->StoreToOffset(store_type, RegisterFrom(value_loc), array, full_offset); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6637 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6638 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6639 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6640 | vixl32::Register temp = temps.Acquire(); |
| 6641 | |
| 6642 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6643 | // We do not need to compute the intermediate address from the array: the |
| 6644 | // input instruction has done it already. See the comment in |
| 6645 | // `TryExtractArrayAccessAddress()`. |
| 6646 | if (kIsDebugBuild) { |
| 6647 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6648 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6649 | } |
| 6650 | temp = array; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6651 | } else { |
| 6652 | __ Add(temp, array, data_offset); |
| 6653 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6654 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6655 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6656 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6657 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6658 | } |
| 6659 | break; |
| 6660 | } |
| 6661 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6662 | case DataType::Type::kReference: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6663 | vixl32::Register value = RegisterFrom(value_loc); |
| 6664 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 6665 | // See the comment in instruction_simplifier_shared.cc. |
| 6666 | DCHECK(!has_intermediate_address); |
| 6667 | |
| 6668 | if (instruction->InputAt(2)->IsNullConstant()) { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6669 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6670 | // As two macro instructions can be emitted the max size is doubled. |
| 6671 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6672 | // Just setting null. |
| 6673 | if (index.IsConstant()) { |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6674 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6675 | GetAssembler()->StoreToOffset(kStoreWord, value, array, offset); |
| 6676 | } else { |
| 6677 | DCHECK(index.IsRegister()) << index; |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6678 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6679 | vixl32::Register temp = temps.Acquire(); |
| 6680 | __ Add(temp, array, data_offset); |
| 6681 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 6682 | } |
| 6683 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6684 | DCHECK(!needs_write_barrier); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6685 | DCHECK(!needs_type_check); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6686 | break; |
| 6687 | } |
| 6688 | |
| 6689 | DCHECK(needs_write_barrier); |
| 6690 | Location temp1_loc = locations->GetTemp(0); |
| 6691 | vixl32::Register temp1 = RegisterFrom(temp1_loc); |
| 6692 | Location temp2_loc = locations->GetTemp(1); |
| 6693 | vixl32::Register temp2 = RegisterFrom(temp2_loc); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6694 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6695 | bool can_value_be_null = instruction->GetValueCanBeNull(); |
| 6696 | vixl32::Label do_store; |
| 6697 | if (can_value_be_null) { |
| 6698 | __ CompareAndBranchIfZero(value, &do_store, /* is_far_target= */ false); |
| 6699 | } |
| 6700 | |
| 6701 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 6702 | if (needs_type_check) { |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6703 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathARMVIXL(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6704 | codegen_->AddSlowPath(slow_path); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6705 | |
| 6706 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6707 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6708 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6709 | |
| 6710 | // Note that when read barriers are enabled, the type checks |
| 6711 | // are performed without read barriers. This is fine, even in |
| 6712 | // the case where a class object is in the from-space after |
| 6713 | // the flip, as a comparison involving such a type would not |
| 6714 | // produce a false positive; it may of course produce a false |
| 6715 | // negative, in which case we would take the ArraySet slow |
| 6716 | // path. |
| 6717 | |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6718 | { |
| 6719 | // Ensure we record the pc position immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6720 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6721 | vixl32::kMaxInstructionSizeInBytes, |
| 6722 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6723 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 6724 | __ ldr(temp1, MemOperand(array, class_offset)); |
| 6725 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6726 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6727 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 6728 | |
| 6729 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 6730 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 6731 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 6732 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 6733 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 6734 | // nor `temp2`, as we are comparing two poisoned references. |
| 6735 | __ Cmp(temp1, temp2); |
| 6736 | |
| 6737 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6738 | vixl32::Label do_put; |
| 6739 | __ B(eq, &do_put, /* is_far_target= */ false); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6740 | // If heap poisoning is enabled, the `temp1` reference has |
| 6741 | // not been unpoisoned yet; unpoison it now. |
| 6742 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 6743 | |
| 6744 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 6745 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 6746 | // If heap poisoning is enabled, no need to unpoison |
| 6747 | // `temp1`, as we are comparing against null below. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6748 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6749 | __ Bind(&do_put); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6750 | } else { |
| 6751 | __ B(ne, slow_path->GetEntryLabel()); |
| 6752 | } |
| 6753 | } |
| 6754 | |
Vladimir Marko | ac3fcff | 2020-11-17 12:17:58 +0000 | [diff] [blame] | 6755 | codegen_->MarkGCCard(temp1, temp2, array, value, /* value_can_be_null= */ false); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6756 | |
| 6757 | if (can_value_be_null) { |
| 6758 | DCHECK(do_store.IsReferenced()); |
| 6759 | __ Bind(&do_store); |
| 6760 | } |
| 6761 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6762 | vixl32::Register source = value; |
| 6763 | if (kPoisonHeapReferences) { |
| 6764 | // Note that in the case where `value` is a null reference, |
| 6765 | // we do not enter this block, as a null reference does not |
| 6766 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6767 | DCHECK_EQ(value_type, DataType::Type::kReference); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6768 | __ Mov(temp1, value); |
| 6769 | GetAssembler()->PoisonHeapReference(temp1); |
| 6770 | source = temp1; |
| 6771 | } |
| 6772 | |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6773 | { |
| 6774 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6775 | // As two macro instructions can be emitted the max size is doubled. |
| 6776 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
| 6777 | if (index.IsConstant()) { |
| 6778 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
| 6779 | GetAssembler()->StoreToOffset(kStoreWord, source, array, offset); |
| 6780 | } else { |
| 6781 | DCHECK(index.IsRegister()) << index; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6782 | |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6783 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6784 | vixl32::Register temp = temps.Acquire(); |
| 6785 | __ Add(temp, array, data_offset); |
| 6786 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6787 | LocationFrom(source), |
| 6788 | temp, |
| 6789 | RegisterFrom(index)); |
| 6790 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6791 | |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6792 | if (can_value_be_null || !needs_type_check) { |
| 6793 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6794 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6795 | } |
| 6796 | |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6797 | if (slow_path != nullptr) { |
| 6798 | __ Bind(slow_path->GetExitLabel()); |
| 6799 | } |
| 6800 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6801 | break; |
| 6802 | } |
| 6803 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6804 | case DataType::Type::kInt64: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6805 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6806 | // As two macro instructions can be emitted the max size is doubled. |
| 6807 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6808 | Location value = locations->InAt(2); |
| 6809 | if (index.IsConstant()) { |
| 6810 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6811 | (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6812 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), array, offset); |
| 6813 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6814 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6815 | vixl32::Register temp = temps.Acquire(); |
| 6816 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6817 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), temp, data_offset); |
| 6818 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6819 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6820 | break; |
| 6821 | } |
| 6822 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6823 | case DataType::Type::kFloat32: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6824 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6825 | // As two macro instructions can be emitted the max size is doubled. |
| 6826 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6827 | Location value = locations->InAt(2); |
| 6828 | DCHECK(value.IsFpuRegister()); |
| 6829 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6830 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6831 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), array, offset); |
| 6832 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6833 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6834 | vixl32::Register temp = temps.Acquire(); |
| 6835 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 6836 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), temp, data_offset); |
| 6837 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6838 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6839 | break; |
| 6840 | } |
| 6841 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6842 | case DataType::Type::kFloat64: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6843 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6844 | // As two macro instructions can be emitted the max size is doubled. |
| 6845 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6846 | Location value = locations->InAt(2); |
| 6847 | DCHECK(value.IsFpuRegisterPair()); |
| 6848 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6849 | size_t offset = (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6850 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), array, offset); |
| 6851 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6852 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6853 | vixl32::Register temp = temps.Acquire(); |
| 6854 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6855 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), temp, data_offset); |
| 6856 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6857 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6858 | break; |
| 6859 | } |
| 6860 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6861 | case DataType::Type::kUint32: |
| 6862 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6863 | case DataType::Type::kVoid: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6864 | LOG(FATAL) << "Unreachable type " << value_type; |
| 6865 | UNREACHABLE(); |
| 6866 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6867 | } |
| 6868 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6869 | void LocationsBuilderARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 6870 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6871 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6872 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6873 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6874 | } |
| 6875 | |
| 6876 | void InstructionCodeGeneratorARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 6877 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| 6878 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 6879 | vixl32::Register out = OutputRegister(instruction); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6880 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6881 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6882 | vixl32::kMaxInstructionSizeInBytes, |
| 6883 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6884 | __ ldr(out, MemOperand(obj, offset)); |
| 6885 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6886 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6887 | // Mask out compression flag from String's array length. |
| 6888 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6889 | __ Lsr(out, out, 1u); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6890 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6891 | } |
| 6892 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6893 | void LocationsBuilderARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6894 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6895 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6896 | |
| 6897 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6898 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 6899 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6900 | } |
| 6901 | |
| 6902 | void InstructionCodeGeneratorARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 6903 | vixl32::Register out = OutputRegister(instruction); |
| 6904 | vixl32::Register first = InputRegisterAt(instruction, 0); |
| 6905 | Location second = instruction->GetLocations()->InAt(1); |
| 6906 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6907 | if (second.IsRegister()) { |
| 6908 | __ Add(out, first, RegisterFrom(second)); |
| 6909 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6910 | __ Add(out, first, Int32ConstantFrom(second)); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6911 | } |
| 6912 | } |
| 6913 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 6914 | void LocationsBuilderARMVIXL::VisitIntermediateAddressIndex( |
| 6915 | HIntermediateAddressIndex* instruction) { |
| 6916 | LOG(FATAL) << "Unreachable " << instruction->GetId(); |
| 6917 | } |
| 6918 | |
| 6919 | void InstructionCodeGeneratorARMVIXL::VisitIntermediateAddressIndex( |
| 6920 | HIntermediateAddressIndex* instruction) { |
| 6921 | LOG(FATAL) << "Unreachable " << instruction->GetId(); |
| 6922 | } |
| 6923 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6924 | void LocationsBuilderARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 6925 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6926 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 6927 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 6928 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(1))); |
| 6929 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6930 | |
| 6931 | HInstruction* index = instruction->InputAt(0); |
| 6932 | HInstruction* length = instruction->InputAt(1); |
| 6933 | // If both index and length are constants we can statically check the bounds. But if at least one |
| 6934 | // of them is not encodable ArmEncodableConstantOrRegister will create |
| 6935 | // Location::RequiresRegister() which is not desired to happen. Instead we create constant |
| 6936 | // locations. |
| 6937 | bool both_const = index->IsConstant() && length->IsConstant(); |
| 6938 | locations->SetInAt(0, both_const |
| 6939 | ? Location::ConstantLocation(index->AsConstant()) |
| 6940 | : ArmEncodableConstantOrRegister(index, CMP)); |
| 6941 | locations->SetInAt(1, both_const |
| 6942 | ? Location::ConstantLocation(length->AsConstant()) |
| 6943 | : ArmEncodableConstantOrRegister(length, CMP)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6944 | } |
| 6945 | |
| 6946 | void InstructionCodeGeneratorARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6947 | LocationSummary* locations = instruction->GetLocations(); |
| 6948 | Location index_loc = locations->InAt(0); |
| 6949 | Location length_loc = locations->InAt(1); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6950 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6951 | if (length_loc.IsConstant()) { |
| 6952 | int32_t length = Int32ConstantFrom(length_loc); |
| 6953 | if (index_loc.IsConstant()) { |
| 6954 | // BCE will remove the bounds check if we are guaranteed to pass. |
| 6955 | int32_t index = Int32ConstantFrom(index_loc); |
| 6956 | if (index < 0 || index >= length) { |
| 6957 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6958 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARMVIXL(instruction); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6959 | codegen_->AddSlowPath(slow_path); |
| 6960 | __ B(slow_path->GetEntryLabel()); |
| 6961 | } else { |
| 6962 | // Some optimization after BCE may have generated this, and we should not |
| 6963 | // generate a bounds check if it is a valid range. |
| 6964 | } |
| 6965 | return; |
| 6966 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6967 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6968 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6969 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARMVIXL(instruction); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6970 | __ Cmp(RegisterFrom(index_loc), length); |
| 6971 | codegen_->AddSlowPath(slow_path); |
| 6972 | __ B(hs, slow_path->GetEntryLabel()); |
| 6973 | } else { |
| 6974 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6975 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARMVIXL(instruction); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6976 | __ Cmp(RegisterFrom(length_loc), InputOperandAt(instruction, 0)); |
| 6977 | codegen_->AddSlowPath(slow_path); |
| 6978 | __ B(ls, slow_path->GetEntryLabel()); |
| 6979 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6980 | } |
| 6981 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6982 | void CodeGeneratorARMVIXL::MarkGCCard(vixl32::Register temp, |
| 6983 | vixl32::Register card, |
| 6984 | vixl32::Register object, |
| 6985 | vixl32::Register value, |
Vladimir Marko | ac3fcff | 2020-11-17 12:17:58 +0000 | [diff] [blame] | 6986 | bool value_can_be_null) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6987 | vixl32::Label is_null; |
Vladimir Marko | ac3fcff | 2020-11-17 12:17:58 +0000 | [diff] [blame] | 6988 | if (value_can_be_null) { |
| 6989 | __ CompareAndBranchIfZero(value, &is_null, /* is_far_target=*/ false); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6990 | } |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 6991 | // Load the address of the card table into `card`. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6992 | GetAssembler()->LoadFromOffset( |
| 6993 | kLoadWord, card, tr, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 6994 | // Calculate the offset (in the card table) of the card corresponding to |
| 6995 | // `object`. |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 6996 | __ Lsr(temp, object, Operand::From(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 6997 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 6998 | // `object`'s card. |
| 6999 | // |
| 7000 | // Register `card` contains the address of the card table. Note that the card |
| 7001 | // table's base is biased during its creation so that it always starts at an |
| 7002 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 7003 | // art::gc::accounting::CardTable::Create). Therefore the STRB instruction |
| 7004 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 7005 | // (located at `card + object >> kCardShift`). |
| 7006 | // |
| 7007 | // This dual use of the value in register `card` (1. to calculate the location |
| 7008 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 7009 | // (no need to explicitly load `kCardDirty` as an immediate value). |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7010 | __ Strb(card, MemOperand(card, temp)); |
Vladimir Marko | ac3fcff | 2020-11-17 12:17:58 +0000 | [diff] [blame] | 7011 | if (value_can_be_null) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7012 | __ Bind(&is_null); |
| 7013 | } |
| 7014 | } |
| 7015 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7016 | void LocationsBuilderARMVIXL::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 7017 | LOG(FATAL) << "Unreachable"; |
| 7018 | } |
| 7019 | |
| 7020 | void InstructionCodeGeneratorARMVIXL::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 7021 | if (instruction->GetNext()->IsSuspendCheck() && |
| 7022 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 7023 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 7024 | // The back edge will generate the suspend check. |
| 7025 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 7026 | } |
| 7027 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7028 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 7029 | } |
| 7030 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7031 | void LocationsBuilderARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7032 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7033 | instruction, LocationSummary::kCallOnSlowPath); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7034 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7035 | } |
| 7036 | |
| 7037 | void InstructionCodeGeneratorARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 7038 | HBasicBlock* block = instruction->GetBlock(); |
| 7039 | if (block->GetLoopInformation() != nullptr) { |
| 7040 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 7041 | // The back edge will generate the suspend check. |
| 7042 | return; |
| 7043 | } |
| 7044 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 7045 | // The goto will generate the suspend check. |
| 7046 | return; |
| 7047 | } |
| 7048 | GenerateSuspendCheck(instruction, nullptr); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 7049 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 14); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7050 | } |
| 7051 | |
| 7052 | void InstructionCodeGeneratorARMVIXL::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 7053 | HBasicBlock* successor) { |
| 7054 | SuspendCheckSlowPathARMVIXL* slow_path = |
| 7055 | down_cast<SuspendCheckSlowPathARMVIXL*>(instruction->GetSlowPath()); |
| 7056 | if (slow_path == nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7057 | slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7058 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathARMVIXL(instruction, successor); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7059 | instruction->SetSlowPath(slow_path); |
| 7060 | codegen_->AddSlowPath(slow_path); |
| 7061 | if (successor != nullptr) { |
| 7062 | DCHECK(successor->IsLoopHeader()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7063 | } |
| 7064 | } else { |
| 7065 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 7066 | } |
| 7067 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7068 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7069 | vixl32::Register temp = temps.Acquire(); |
| 7070 | GetAssembler()->LoadFromOffset( |
| 7071 | kLoadUnsignedHalfword, temp, tr, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
| 7072 | if (successor == nullptr) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7073 | __ CompareAndBranchIfNonZero(temp, slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7074 | __ Bind(slow_path->GetReturnLabel()); |
| 7075 | } else { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7076 | __ CompareAndBranchIfZero(temp, codegen_->GetLabelOf(successor)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7077 | __ B(slow_path->GetEntryLabel()); |
| 7078 | } |
| 7079 | } |
| 7080 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7081 | ArmVIXLAssembler* ParallelMoveResolverARMVIXL::GetAssembler() const { |
| 7082 | return codegen_->GetAssembler(); |
| 7083 | } |
| 7084 | |
| 7085 | void ParallelMoveResolverARMVIXL::EmitMove(size_t index) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7086 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7087 | MoveOperands* move = moves_[index]; |
| 7088 | Location source = move->GetSource(); |
| 7089 | Location destination = move->GetDestination(); |
| 7090 | |
| 7091 | if (source.IsRegister()) { |
| 7092 | if (destination.IsRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7093 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7094 | } else if (destination.IsFpuRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7095 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7096 | } else { |
| 7097 | DCHECK(destination.IsStackSlot()); |
| 7098 | GetAssembler()->StoreToOffset(kStoreWord, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7099 | RegisterFrom(source), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7100 | sp, |
| 7101 | destination.GetStackIndex()); |
| 7102 | } |
| 7103 | } else if (source.IsStackSlot()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7104 | if (destination.IsRegister()) { |
| 7105 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 7106 | RegisterFrom(destination), |
| 7107 | sp, |
| 7108 | source.GetStackIndex()); |
| 7109 | } else if (destination.IsFpuRegister()) { |
| 7110 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 7111 | } else { |
| 7112 | DCHECK(destination.IsStackSlot()); |
| 7113 | vixl32::Register temp = temps.Acquire(); |
| 7114 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 7115 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 7116 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7117 | } else if (source.IsFpuRegister()) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7118 | if (destination.IsRegister()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7119 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7120 | } else if (destination.IsFpuRegister()) { |
| 7121 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 7122 | } else { |
| 7123 | DCHECK(destination.IsStackSlot()); |
| 7124 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 7125 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7126 | } else if (source.IsDoubleStackSlot()) { |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7127 | if (destination.IsDoubleStackSlot()) { |
| 7128 | vixl32::DRegister temp = temps.AcquireD(); |
| 7129 | GetAssembler()->LoadDFromOffset(temp, sp, source.GetStackIndex()); |
| 7130 | GetAssembler()->StoreDToOffset(temp, sp, destination.GetStackIndex()); |
| 7131 | } else if (destination.IsRegisterPair()) { |
| 7132 | DCHECK(ExpectedPairLayout(destination)); |
| 7133 | GetAssembler()->LoadFromOffset( |
| 7134 | kLoadWordPair, LowRegisterFrom(destination), sp, source.GetStackIndex()); |
| 7135 | } else { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7136 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 7137 | GetAssembler()->LoadDFromOffset(DRegisterFrom(destination), sp, source.GetStackIndex()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7138 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7139 | } else if (source.IsRegisterPair()) { |
| 7140 | if (destination.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7141 | __ Mov(LowRegisterFrom(destination), LowRegisterFrom(source)); |
| 7142 | __ Mov(HighRegisterFrom(destination), HighRegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7143 | } else if (destination.IsFpuRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7144 | __ Vmov(DRegisterFrom(destination), LowRegisterFrom(source), HighRegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7145 | } else { |
| 7146 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 7147 | DCHECK(ExpectedPairLayout(source)); |
| 7148 | GetAssembler()->StoreToOffset(kStoreWordPair, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7149 | LowRegisterFrom(source), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7150 | sp, |
| 7151 | destination.GetStackIndex()); |
| 7152 | } |
| 7153 | } else if (source.IsFpuRegisterPair()) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7154 | if (destination.IsRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7155 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), DRegisterFrom(source)); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7156 | } else if (destination.IsFpuRegisterPair()) { |
| 7157 | __ Vmov(DRegisterFrom(destination), DRegisterFrom(source)); |
| 7158 | } else { |
| 7159 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 7160 | GetAssembler()->StoreDToOffset(DRegisterFrom(source), sp, destination.GetStackIndex()); |
| 7161 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7162 | } else { |
| 7163 | DCHECK(source.IsConstant()) << source; |
| 7164 | HConstant* constant = source.GetConstant(); |
| 7165 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 7166 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
| 7167 | if (destination.IsRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7168 | __ Mov(RegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7169 | } else { |
| 7170 | DCHECK(destination.IsStackSlot()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7171 | vixl32::Register temp = temps.Acquire(); |
| 7172 | __ Mov(temp, value); |
| 7173 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 7174 | } |
| 7175 | } else if (constant->IsLongConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 7176 | int64_t value = Int64ConstantFrom(source); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7177 | if (destination.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7178 | __ Mov(LowRegisterFrom(destination), Low32Bits(value)); |
| 7179 | __ Mov(HighRegisterFrom(destination), High32Bits(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7180 | } else { |
| 7181 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7182 | vixl32::Register temp = temps.Acquire(); |
| 7183 | __ Mov(temp, Low32Bits(value)); |
| 7184 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 7185 | __ Mov(temp, High32Bits(value)); |
| 7186 | GetAssembler()->StoreToOffset(kStoreWord, |
| 7187 | temp, |
| 7188 | sp, |
| 7189 | destination.GetHighStackIndex(kArmWordSize)); |
| 7190 | } |
| 7191 | } else if (constant->IsDoubleConstant()) { |
| 7192 | double value = constant->AsDoubleConstant()->GetValue(); |
| 7193 | if (destination.IsFpuRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7194 | __ Vmov(DRegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7195 | } else { |
| 7196 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 7197 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7198 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7199 | __ Mov(temp, Low32Bits(int_value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7200 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7201 | __ Mov(temp, High32Bits(int_value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7202 | GetAssembler()->StoreToOffset(kStoreWord, |
| 7203 | temp, |
| 7204 | sp, |
| 7205 | destination.GetHighStackIndex(kArmWordSize)); |
| 7206 | } |
| 7207 | } else { |
| 7208 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
| 7209 | float value = constant->AsFloatConstant()->GetValue(); |
| 7210 | if (destination.IsFpuRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7211 | __ Vmov(SRegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7212 | } else { |
| 7213 | DCHECK(destination.IsStackSlot()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7214 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7215 | __ Mov(temp, bit_cast<int32_t, float>(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7216 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 7217 | } |
| 7218 | } |
| 7219 | } |
| 7220 | } |
| 7221 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7222 | void ParallelMoveResolverARMVIXL::Exchange(vixl32::Register reg, int mem) { |
| 7223 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 7224 | vixl32::Register temp = temps.Acquire(); |
| 7225 | __ Mov(temp, reg); |
| 7226 | GetAssembler()->LoadFromOffset(kLoadWord, reg, sp, mem); |
| 7227 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7228 | } |
| 7229 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7230 | void ParallelMoveResolverARMVIXL::Exchange(int mem1, int mem2) { |
| 7231 | // TODO(VIXL32): Double check the performance of this implementation. |
| 7232 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7233 | vixl32::Register temp1 = temps.Acquire(); |
| 7234 | ScratchRegisterScope ensure_scratch( |
| 7235 | this, temp1.GetCode(), r0.GetCode(), codegen_->GetNumberOfCoreRegisters()); |
| 7236 | vixl32::Register temp2(ensure_scratch.GetRegister()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7237 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7238 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 7239 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, sp, mem1 + stack_offset); |
| 7240 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, sp, mem2 + stack_offset); |
| 7241 | GetAssembler()->StoreToOffset(kStoreWord, temp1, sp, mem2 + stack_offset); |
| 7242 | GetAssembler()->StoreToOffset(kStoreWord, temp2, sp, mem1 + stack_offset); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7243 | } |
| 7244 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7245 | void ParallelMoveResolverARMVIXL::EmitSwap(size_t index) { |
| 7246 | MoveOperands* move = moves_[index]; |
| 7247 | Location source = move->GetSource(); |
| 7248 | Location destination = move->GetDestination(); |
| 7249 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 7250 | |
| 7251 | if (source.IsRegister() && destination.IsRegister()) { |
| 7252 | vixl32::Register temp = temps.Acquire(); |
| 7253 | DCHECK(!RegisterFrom(source).Is(temp)); |
| 7254 | DCHECK(!RegisterFrom(destination).Is(temp)); |
| 7255 | __ Mov(temp, RegisterFrom(destination)); |
| 7256 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 7257 | __ Mov(RegisterFrom(source), temp); |
| 7258 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| 7259 | Exchange(RegisterFrom(source), destination.GetStackIndex()); |
| 7260 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| 7261 | Exchange(RegisterFrom(destination), source.GetStackIndex()); |
| 7262 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7263 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7264 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7265 | vixl32::Register temp = temps.Acquire(); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7266 | __ Vmov(temp, SRegisterFrom(source)); |
| 7267 | __ Vmov(SRegisterFrom(source), SRegisterFrom(destination)); |
| 7268 | __ Vmov(SRegisterFrom(destination), temp); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7269 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
| 7270 | vixl32::DRegister temp = temps.AcquireD(); |
| 7271 | __ Vmov(temp, LowRegisterFrom(source), HighRegisterFrom(source)); |
| 7272 | __ Mov(LowRegisterFrom(source), LowRegisterFrom(destination)); |
| 7273 | __ Mov(HighRegisterFrom(source), HighRegisterFrom(destination)); |
| 7274 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), temp); |
| 7275 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
| 7276 | vixl32::Register low_reg = LowRegisterFrom(source.IsRegisterPair() ? source : destination); |
| 7277 | int mem = source.IsRegisterPair() ? destination.GetStackIndex() : source.GetStackIndex(); |
| 7278 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
| 7279 | vixl32::DRegister temp = temps.AcquireD(); |
| 7280 | __ Vmov(temp, low_reg, vixl32::Register(low_reg.GetCode() + 1)); |
| 7281 | GetAssembler()->LoadFromOffset(kLoadWordPair, low_reg, sp, mem); |
| 7282 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
| 7283 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7284 | vixl32::DRegister first = DRegisterFrom(source); |
| 7285 | vixl32::DRegister second = DRegisterFrom(destination); |
| 7286 | vixl32::DRegister temp = temps.AcquireD(); |
| 7287 | __ Vmov(temp, first); |
| 7288 | __ Vmov(first, second); |
| 7289 | __ Vmov(second, temp); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7290 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7291 | vixl32::DRegister reg = source.IsFpuRegisterPair() |
| 7292 | ? DRegisterFrom(source) |
| 7293 | : DRegisterFrom(destination); |
| 7294 | int mem = source.IsFpuRegisterPair() |
| 7295 | ? destination.GetStackIndex() |
| 7296 | : source.GetStackIndex(); |
| 7297 | vixl32::DRegister temp = temps.AcquireD(); |
| 7298 | __ Vmov(temp, reg); |
| 7299 | GetAssembler()->LoadDFromOffset(reg, sp, mem); |
| 7300 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7301 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7302 | vixl32::SRegister reg = source.IsFpuRegister() |
| 7303 | ? SRegisterFrom(source) |
| 7304 | : SRegisterFrom(destination); |
| 7305 | int mem = source.IsFpuRegister() |
| 7306 | ? destination.GetStackIndex() |
| 7307 | : source.GetStackIndex(); |
| 7308 | vixl32::Register temp = temps.Acquire(); |
| 7309 | __ Vmov(temp, reg); |
| 7310 | GetAssembler()->LoadSFromOffset(reg, sp, mem); |
| 7311 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7312 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 7313 | vixl32::DRegister temp1 = temps.AcquireD(); |
| 7314 | vixl32::DRegister temp2 = temps.AcquireD(); |
| 7315 | __ Vldr(temp1, MemOperand(sp, source.GetStackIndex())); |
| 7316 | __ Vldr(temp2, MemOperand(sp, destination.GetStackIndex())); |
| 7317 | __ Vstr(temp1, MemOperand(sp, destination.GetStackIndex())); |
| 7318 | __ Vstr(temp2, MemOperand(sp, source.GetStackIndex())); |
| 7319 | } else { |
| 7320 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
| 7321 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7322 | } |
| 7323 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7324 | void ParallelMoveResolverARMVIXL::SpillScratch(int reg) { |
| 7325 | __ Push(vixl32::Register(reg)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7326 | } |
| 7327 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7328 | void ParallelMoveResolverARMVIXL::RestoreScratch(int reg) { |
| 7329 | __ Pop(vixl32::Register(reg)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7330 | } |
| 7331 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7332 | HLoadClass::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadClassKind( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7333 | HLoadClass::LoadKind desired_class_load_kind) { |
| 7334 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7335 | case HLoadClass::LoadKind::kInvalid: |
| 7336 | LOG(FATAL) << "UNREACHABLE"; |
| 7337 | UNREACHABLE(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7338 | case HLoadClass::LoadKind::kReferrersClass: |
| 7339 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7340 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7341 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7342 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7343 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 7344 | case HLoadClass::LoadKind::kBssEntryPackage: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7345 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7346 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7347 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7348 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7349 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7350 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7351 | case HLoadClass::LoadKind::kRuntimeCall: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7352 | break; |
| 7353 | } |
| 7354 | return desired_class_load_kind; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7355 | } |
| 7356 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7357 | void LocationsBuilderARMVIXL::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7358 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7359 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7360 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7361 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7362 | cls, |
| 7363 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7364 | LocationFrom(r0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7365 | DCHECK(calling_convention.GetRegisterAt(0).Is(r0)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7366 | return; |
| 7367 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7368 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 7369 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 7370 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7371 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7372 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 7373 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7374 | ? LocationSummary::kCallOnSlowPath |
| 7375 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7376 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7377 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7378 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7379 | } |
| 7380 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7381 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7382 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7383 | } |
| 7384 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7385 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 7386 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 7387 | // Rely on the type resolution or initialization and marking to save everything we need. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 7388 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7389 | } else { |
| 7390 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7391 | } |
| 7392 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7393 | } |
| 7394 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7395 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7396 | // move. |
| 7397 | void InstructionCodeGeneratorARMVIXL::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7398 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7399 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7400 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 7401 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 15); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7402 | return; |
| 7403 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7404 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 7405 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 7406 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7407 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7408 | LocationSummary* locations = cls->GetLocations(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7409 | Location out_loc = locations->Out(); |
| 7410 | vixl32::Register out = OutputRegister(cls); |
| 7411 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7412 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 7413 | ? kWithoutReadBarrier |
| 7414 | : kCompilerReadBarrierOption; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7415 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7416 | switch (load_kind) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7417 | case HLoadClass::LoadKind::kReferrersClass: { |
| 7418 | DCHECK(!cls->CanCallRuntime()); |
| 7419 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 7420 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 7421 | vixl32::Register current_method = InputRegisterAt(cls, 0); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7422 | codegen_->GenerateGcRootFieldLoad(cls, |
| 7423 | out_loc, |
| 7424 | current_method, |
| 7425 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 7426 | read_barrier_option); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7427 | break; |
| 7428 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7429 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 7430 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 7431 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7432 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 7433 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7434 | codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7435 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 7436 | break; |
| 7437 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7438 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7439 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7440 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 7441 | codegen_->NewBootImageRelRoPatch(CodeGenerator::GetBootImageOffset(cls)); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7442 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7443 | __ Ldr(out, MemOperand(out, /* offset= */ 0)); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7444 | break; |
| 7445 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7446 | case HLoadClass::LoadKind::kBssEntry: |
| 7447 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 7448 | case HLoadClass::LoadKind::kBssEntryPackage: { |
| 7449 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = codegen_->NewTypeBssEntryPatch(cls); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 7450 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 7451 | // All aligned loads are implicitly atomic consume operations on ARM. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7452 | codegen_->GenerateGcRootFieldLoad(cls, out_loc, out, /* offset= */ 0, read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7453 | generate_null_check = true; |
| 7454 | break; |
| 7455 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7456 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 7457 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 7458 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 7459 | DCHECK_NE(address, 0u); |
| 7460 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 7461 | break; |
| 7462 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7463 | case HLoadClass::LoadKind::kJitTableAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7464 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 7465 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7466 | cls->GetClass())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7467 | // /* GcRoot<mirror::Class> */ out = *out |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7468 | codegen_->GenerateGcRootFieldLoad(cls, out_loc, out, /* offset= */ 0, read_barrier_option); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7469 | break; |
| 7470 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7471 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7472 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7473 | LOG(FATAL) << "UNREACHABLE"; |
| 7474 | UNREACHABLE(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7475 | } |
| 7476 | |
| 7477 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 7478 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7479 | LoadClassSlowPathARMVIXL* slow_path = |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 7480 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARMVIXL(cls, cls); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7481 | codegen_->AddSlowPath(slow_path); |
| 7482 | if (generate_null_check) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7483 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7484 | } |
| 7485 | if (cls->MustGenerateClinitCheck()) { |
| 7486 | GenerateClassInitializationCheck(slow_path, out); |
| 7487 | } else { |
| 7488 | __ Bind(slow_path->GetExitLabel()); |
| 7489 | } |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 7490 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 16); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7491 | } |
| 7492 | } |
| 7493 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 7494 | void LocationsBuilderARMVIXL::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 7495 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7496 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 7497 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 7498 | } |
| 7499 | |
| 7500 | void InstructionCodeGeneratorARMVIXL::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 7501 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 7502 | } |
| 7503 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 7504 | void LocationsBuilderARMVIXL::VisitLoadMethodType(HLoadMethodType* load) { |
| 7505 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7506 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 7507 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 7508 | } |
| 7509 | |
| 7510 | void InstructionCodeGeneratorARMVIXL::VisitLoadMethodType(HLoadMethodType* load) { |
| 7511 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 7512 | } |
| 7513 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7514 | void LocationsBuilderARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 7515 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7516 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7517 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7518 | if (check->HasUses()) { |
| 7519 | locations->SetOut(Location::SameAsFirstInput()); |
| 7520 | } |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 7521 | // Rely on the type initialization to save everything we need. |
| 7522 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7523 | } |
| 7524 | |
| 7525 | void InstructionCodeGeneratorARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 7526 | // We assume the class is not null. |
| 7527 | LoadClassSlowPathARMVIXL* slow_path = |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 7528 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARMVIXL(check->GetLoadClass(), check); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7529 | codegen_->AddSlowPath(slow_path); |
| 7530 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 7531 | } |
| 7532 | |
| 7533 | void InstructionCodeGeneratorARMVIXL::GenerateClassInitializationCheck( |
| 7534 | LoadClassSlowPathARMVIXL* slow_path, vixl32::Register class_reg) { |
| 7535 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 7536 | vixl32::Register temp = temps.Acquire(); |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 7537 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 7538 | constexpr uint32_t shifted_visibly_initialized_value = |
| 7539 | enum_cast<uint32_t>(ClassStatus::kVisiblyInitialized) << status_lsb_position; |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 7540 | |
Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 7541 | const size_t status_offset = mirror::Class::StatusOffset().SizeValue(); |
| 7542 | GetAssembler()->LoadFromOffset(kLoadWord, temp, class_reg, status_offset); |
| 7543 | __ Cmp(temp, shifted_visibly_initialized_value); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 7544 | __ B(lo, slow_path->GetEntryLabel()); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7545 | __ Bind(slow_path->GetExitLabel()); |
| 7546 | } |
| 7547 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7548 | void InstructionCodeGeneratorARMVIXL::GenerateBitstringTypeCheckCompare( |
| 7549 | HTypeCheckInstruction* check, |
| 7550 | vixl32::Register temp, |
| 7551 | vixl32::FlagsUpdate flags_update) { |
| 7552 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 7553 | uint32_t mask = check->GetBitstringMask(); |
| 7554 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 7555 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 7556 | |
| 7557 | // Note that HInstanceOf shall check for zero value in `temp` but HCheckCast needs |
| 7558 | // the Z flag for BNE. This is indicated by the `flags_update` parameter. |
| 7559 | if (mask_bits == 16u) { |
| 7560 | // Load only the bitstring part of the status word. |
| 7561 | __ Ldrh(temp, MemOperand(temp, mirror::Class::StatusOffset().Int32Value())); |
| 7562 | // Check if the bitstring bits are equal to `path_to_root`. |
| 7563 | if (flags_update == SetFlags) { |
| 7564 | __ Cmp(temp, path_to_root); |
| 7565 | } else { |
| 7566 | __ Sub(temp, temp, path_to_root); |
| 7567 | } |
| 7568 | } else { |
| 7569 | // /* uint32_t */ temp = temp->status_ |
| 7570 | __ Ldr(temp, MemOperand(temp, mirror::Class::StatusOffset().Int32Value())); |
| 7571 | if (GetAssembler()->ShifterOperandCanHold(SUB, path_to_root)) { |
| 7572 | // Compare the bitstring bits using SUB. |
| 7573 | __ Sub(temp, temp, path_to_root); |
| 7574 | // Shift out bits that do not contribute to the comparison. |
| 7575 | __ Lsl(flags_update, temp, temp, dchecked_integral_cast<uint32_t>(32u - mask_bits)); |
| 7576 | } else if (IsUint<16>(path_to_root)) { |
| 7577 | if (temp.IsLow()) { |
| 7578 | // Note: Optimized for size but contains one more dependent instruction than necessary. |
| 7579 | // MOVW+SUB(register) would be 8 bytes unless we find a low-reg temporary but the |
| 7580 | // macro assembler would use the high reg IP for the constant by default. |
| 7581 | // Compare the bitstring bits using SUB. |
| 7582 | __ Sub(temp, temp, path_to_root & 0x00ffu); // 16-bit SUB (immediate) T2 |
| 7583 | __ Sub(temp, temp, path_to_root & 0xff00u); // 32-bit SUB (immediate) T3 |
| 7584 | // Shift out bits that do not contribute to the comparison. |
| 7585 | __ Lsl(flags_update, temp, temp, dchecked_integral_cast<uint32_t>(32u - mask_bits)); |
| 7586 | } else { |
| 7587 | // Extract the bitstring bits. |
| 7588 | __ Ubfx(temp, temp, 0, mask_bits); |
| 7589 | // Check if the bitstring bits are equal to `path_to_root`. |
| 7590 | if (flags_update == SetFlags) { |
| 7591 | __ Cmp(temp, path_to_root); |
| 7592 | } else { |
| 7593 | __ Sub(temp, temp, path_to_root); |
| 7594 | } |
| 7595 | } |
| 7596 | } else { |
| 7597 | // Shift out bits that do not contribute to the comparison. |
| 7598 | __ Lsl(temp, temp, dchecked_integral_cast<uint32_t>(32u - mask_bits)); |
| 7599 | // Check if the shifted bitstring bits are equal to `path_to_root << (32u - mask_bits)`. |
| 7600 | if (flags_update == SetFlags) { |
| 7601 | __ Cmp(temp, path_to_root << (32u - mask_bits)); |
| 7602 | } else { |
| 7603 | __ Sub(temp, temp, path_to_root << (32u - mask_bits)); |
| 7604 | } |
| 7605 | } |
| 7606 | } |
| 7607 | } |
| 7608 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7609 | HLoadString::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadStringKind( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7610 | HLoadString::LoadKind desired_string_load_kind) { |
| 7611 | switch (desired_string_load_kind) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7612 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7613 | case HLoadString::LoadKind::kBootImageRelRo: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7614 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7615 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7616 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7617 | case HLoadString::LoadKind::kJitBootImageAddress: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7618 | case HLoadString::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7619 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7620 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7621 | case HLoadString::LoadKind::kRuntimeCall: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7622 | break; |
| 7623 | } |
| 7624 | return desired_string_load_kind; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7625 | } |
| 7626 | |
| 7627 | void LocationsBuilderARMVIXL::VisitLoadString(HLoadString* load) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7628 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7629 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7630 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7631 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7632 | locations->SetOut(LocationFrom(r0)); |
| 7633 | } else { |
| 7634 | locations->SetOut(Location::RequiresRegister()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7635 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 7636 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7637 | // Rely on the pResolveString and marking to save everything we need, including temps. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 7638 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7639 | } else { |
| 7640 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7641 | } |
| 7642 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7643 | } |
| 7644 | } |
| 7645 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7646 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7647 | // move. |
| 7648 | void InstructionCodeGeneratorARMVIXL::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7649 | LocationSummary* locations = load->GetLocations(); |
| 7650 | Location out_loc = locations->Out(); |
| 7651 | vixl32::Register out = OutputRegister(load); |
| 7652 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 7653 | |
| 7654 | switch (load_kind) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7655 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 7656 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 7657 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7658 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7659 | codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7660 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7661 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7662 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7663 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7664 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7665 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 7666 | codegen_->NewBootImageRelRoPatch(CodeGenerator::GetBootImageOffset(load)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7667 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7668 | __ Ldr(out, MemOperand(out, /* offset= */ 0)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7669 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7670 | } |
| 7671 | case HLoadString::LoadKind::kBssEntry: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7672 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7673 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 7674 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 7675 | // All aligned loads are implicitly atomic consume operations on ARM. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7676 | codegen_->GenerateGcRootFieldLoad( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7677 | load, out_loc, out, /* offset= */ 0, kCompilerReadBarrierOption); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7678 | LoadStringSlowPathARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7679 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathARMVIXL(load); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7680 | codegen_->AddSlowPath(slow_path); |
| 7681 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 7682 | __ Bind(slow_path->GetExitLabel()); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 7683 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 17); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7684 | return; |
| 7685 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7686 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 7687 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 7688 | DCHECK_NE(address, 0u); |
| 7689 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 7690 | return; |
| 7691 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7692 | case HLoadString::LoadKind::kJitTableAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7693 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7694 | load->GetStringIndex(), |
| 7695 | load->GetString())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7696 | // /* GcRoot<mirror::String> */ out = *out |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7697 | codegen_->GenerateGcRootFieldLoad( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7698 | load, out_loc, out, /* offset= */ 0, kCompilerReadBarrierOption); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7699 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7700 | } |
| 7701 | default: |
| 7702 | break; |
| 7703 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7704 | |
| 7705 | // TODO: Re-add the compiler code to do string dex cache lookup again. |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7706 | DCHECK_EQ(load->GetLoadKind(), HLoadString::LoadKind::kRuntimeCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7707 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7708 | __ Mov(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7709 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 7710 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 7711 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 18); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7712 | } |
| 7713 | |
| 7714 | static int32_t GetExceptionTlsOffset() { |
| 7715 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
| 7716 | } |
| 7717 | |
| 7718 | void LocationsBuilderARMVIXL::VisitLoadException(HLoadException* load) { |
| 7719 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7720 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7721 | locations->SetOut(Location::RequiresRegister()); |
| 7722 | } |
| 7723 | |
| 7724 | void InstructionCodeGeneratorARMVIXL::VisitLoadException(HLoadException* load) { |
| 7725 | vixl32::Register out = OutputRegister(load); |
| 7726 | GetAssembler()->LoadFromOffset(kLoadWord, out, tr, GetExceptionTlsOffset()); |
| 7727 | } |
| 7728 | |
| 7729 | |
| 7730 | void LocationsBuilderARMVIXL::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7731 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7732 | } |
| 7733 | |
| 7734 | void InstructionCodeGeneratorARMVIXL::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 7735 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 7736 | vixl32::Register temp = temps.Acquire(); |
| 7737 | __ Mov(temp, 0); |
| 7738 | GetAssembler()->StoreToOffset(kStoreWord, temp, tr, GetExceptionTlsOffset()); |
| 7739 | } |
| 7740 | |
| 7741 | void LocationsBuilderARMVIXL::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7742 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7743 | instruction, LocationSummary::kCallOnMainOnly); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7744 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7745 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7746 | } |
| 7747 | |
| 7748 | void InstructionCodeGeneratorARMVIXL::VisitThrow(HThrow* instruction) { |
| 7749 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| 7750 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 7751 | } |
| 7752 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7753 | // Temp is used for read barrier. |
| 7754 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 7755 | if (kEmitCompilerReadBarrier && |
| 7756 | (kUseBakerReadBarrier || |
| 7757 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7758 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7759 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 7760 | return 1; |
| 7761 | } |
| 7762 | return 0; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7763 | } |
| 7764 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7765 | // Interface case has 3 temps, one for holding the number of interfaces, one for the current |
| 7766 | // interface pointer, one for loading the current interface. |
| 7767 | // The other checks have one temp for loading the object's class. |
| 7768 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 7769 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7770 | return 3; |
| 7771 | } |
| 7772 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 7773 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7774 | |
| 7775 | void LocationsBuilderARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 7776 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7777 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7778 | bool baker_read_barrier_slow_path = false; |
| 7779 | switch (type_check_kind) { |
| 7780 | case TypeCheckKind::kExactCheck: |
| 7781 | case TypeCheckKind::kAbstractClassCheck: |
| 7782 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7783 | case TypeCheckKind::kArrayObjectCheck: { |
| 7784 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 7785 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 7786 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7787 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7788 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7789 | case TypeCheckKind::kArrayCheck: |
| 7790 | case TypeCheckKind::kUnresolvedCheck: |
| 7791 | case TypeCheckKind::kInterfaceCheck: |
| 7792 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7793 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7794 | case TypeCheckKind::kBitstringCheck: |
| 7795 | break; |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7796 | } |
| 7797 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7798 | LocationSummary* locations = |
| 7799 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7800 | if (baker_read_barrier_slow_path) { |
| 7801 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 7802 | } |
| 7803 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7804 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7805 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7806 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7807 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 7808 | } else { |
| 7809 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7810 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7811 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 7812 | // Note that TypeCheckSlowPathARM uses this register too. |
| 7813 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7814 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7815 | } |
| 7816 | |
| 7817 | void InstructionCodeGeneratorARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 7818 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7819 | LocationSummary* locations = instruction->GetLocations(); |
| 7820 | Location obj_loc = locations->InAt(0); |
| 7821 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7822 | vixl32::Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 7823 | ? vixl32::Register() |
| 7824 | : InputRegisterAt(instruction, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7825 | Location out_loc = locations->Out(); |
| 7826 | vixl32::Register out = OutputRegister(instruction); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7827 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7828 | DCHECK_LE(num_temps, 1u); |
| 7829 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7830 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7831 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7832 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7833 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7834 | vixl32::Label done; |
| 7835 | vixl32::Label* const final_label = codegen_->GetFinalLabel(instruction, &done); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7836 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 7837 | |
| 7838 | // Return 0 if `obj` is null. |
| 7839 | // avoid null check if we know obj is not null. |
| 7840 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7841 | DCHECK(!out.Is(obj)); |
| 7842 | __ Mov(out, 0); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7843 | __ CompareAndBranchIfZero(obj, final_label, /* is_far_target= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7844 | } |
| 7845 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7846 | switch (type_check_kind) { |
| 7847 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7848 | ReadBarrierOption read_barrier_option = |
| 7849 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7850 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7851 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7852 | out_loc, |
| 7853 | obj_loc, |
| 7854 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7855 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7856 | read_barrier_option); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7857 | // Classes must be equal for the instanceof to succeed. |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7858 | __ Cmp(out, cls); |
| 7859 | // We speculatively set the result to false without changing the condition |
| 7860 | // flags, which allows us to avoid some branching later. |
| 7861 | __ Mov(LeaveFlags, out, 0); |
| 7862 | |
| 7863 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7864 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7865 | // encoding can be used. |
| 7866 | if (out.IsLow()) { |
| 7867 | // We use the scope because of the IT block that follows. |
| 7868 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7869 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7870 | CodeBufferCheckScope::kExactSize); |
| 7871 | |
| 7872 | __ it(eq); |
| 7873 | __ mov(eq, out, 1); |
| 7874 | } else { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7875 | __ B(ne, final_label, /* is_far_target= */ false); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7876 | __ Mov(out, 1); |
| 7877 | } |
| 7878 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7879 | break; |
| 7880 | } |
| 7881 | |
| 7882 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7883 | ReadBarrierOption read_barrier_option = |
| 7884 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7885 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7886 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7887 | out_loc, |
| 7888 | obj_loc, |
| 7889 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7890 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7891 | read_barrier_option); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7892 | // If the class is abstract, we eagerly fetch the super class of the |
| 7893 | // object to avoid doing a comparison we know will fail. |
| 7894 | vixl32::Label loop; |
| 7895 | __ Bind(&loop); |
| 7896 | // /* HeapReference<Class> */ out = out->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7897 | GenerateReferenceLoadOneRegister(instruction, |
| 7898 | out_loc, |
| 7899 | super_offset, |
| 7900 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7901 | read_barrier_option); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7902 | // If `out` is null, we use it for the result, and jump to the final label. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7903 | __ CompareAndBranchIfZero(out, final_label, /* is_far_target= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7904 | __ Cmp(out, cls); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7905 | __ B(ne, &loop, /* is_far_target= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7906 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7907 | break; |
| 7908 | } |
| 7909 | |
| 7910 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7911 | ReadBarrierOption read_barrier_option = |
| 7912 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7913 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7914 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7915 | out_loc, |
| 7916 | obj_loc, |
| 7917 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7918 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7919 | read_barrier_option); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7920 | // Walk over the class hierarchy to find a match. |
| 7921 | vixl32::Label loop, success; |
| 7922 | __ Bind(&loop); |
| 7923 | __ Cmp(out, cls); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7924 | __ B(eq, &success, /* is_far_target= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7925 | // /* HeapReference<Class> */ out = out->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7926 | GenerateReferenceLoadOneRegister(instruction, |
| 7927 | out_loc, |
| 7928 | super_offset, |
| 7929 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7930 | read_barrier_option); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7931 | // This is essentially a null check, but it sets the condition flags to the |
| 7932 | // proper value for the code that follows the loop, i.e. not `eq`. |
| 7933 | __ Cmp(out, 1); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7934 | __ B(hs, &loop, /* is_far_target= */ false); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7935 | |
| 7936 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7937 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7938 | // encoding can be used. |
| 7939 | if (out.IsLow()) { |
| 7940 | // If `out` is null, we use it for the result, and the condition flags |
| 7941 | // have already been set to `ne`, so the IT block that comes afterwards |
| 7942 | // (and which handles the successful case) turns into a NOP (instead of |
| 7943 | // overwriting `out`). |
| 7944 | __ Bind(&success); |
| 7945 | |
| 7946 | // We use the scope because of the IT block that follows. |
| 7947 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7948 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7949 | CodeBufferCheckScope::kExactSize); |
| 7950 | |
| 7951 | // There is only one branch to the `success` label (which is bound to this |
| 7952 | // IT block), and it has the same condition, `eq`, so in that case the MOV |
| 7953 | // is executed. |
| 7954 | __ it(eq); |
| 7955 | __ mov(eq, out, 1); |
| 7956 | } else { |
| 7957 | // If `out` is null, we use it for the result, and jump to the final label. |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7958 | __ B(final_label); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7959 | __ Bind(&success); |
| 7960 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7961 | } |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7962 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7963 | break; |
| 7964 | } |
| 7965 | |
| 7966 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7967 | ReadBarrierOption read_barrier_option = |
| 7968 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7969 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7970 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7971 | out_loc, |
| 7972 | obj_loc, |
| 7973 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7974 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7975 | read_barrier_option); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7976 | // Do an exact check. |
| 7977 | vixl32::Label exact_check; |
| 7978 | __ Cmp(out, cls); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7979 | __ B(eq, &exact_check, /* is_far_target= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7980 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 7981 | // /* HeapReference<Class> */ out = out->component_type_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7982 | GenerateReferenceLoadOneRegister(instruction, |
| 7983 | out_loc, |
| 7984 | component_offset, |
| 7985 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7986 | read_barrier_option); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7987 | // If `out` is null, we use it for the result, and jump to the final label. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7988 | __ CompareAndBranchIfZero(out, final_label, /* is_far_target= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7989 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 7990 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7991 | __ Cmp(out, 0); |
| 7992 | // We speculatively set the result to false without changing the condition |
| 7993 | // flags, which allows us to avoid some branching later. |
| 7994 | __ Mov(LeaveFlags, out, 0); |
| 7995 | |
| 7996 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7997 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7998 | // encoding can be used. |
| 7999 | if (out.IsLow()) { |
| 8000 | __ Bind(&exact_check); |
| 8001 | |
| 8002 | // We use the scope because of the IT block that follows. |
| 8003 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 8004 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 8005 | CodeBufferCheckScope::kExactSize); |
| 8006 | |
| 8007 | __ it(eq); |
| 8008 | __ mov(eq, out, 1); |
| 8009 | } else { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8010 | __ B(ne, final_label, /* is_far_target= */ false); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 8011 | __ Bind(&exact_check); |
| 8012 | __ Mov(out, 1); |
| 8013 | } |
| 8014 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8015 | break; |
| 8016 | } |
| 8017 | |
| 8018 | case TypeCheckKind::kArrayCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8019 | // No read barrier since the slow path will retry upon failure. |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 8020 | // /* HeapReference<Class> */ out = obj->klass_ |
| 8021 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8022 | out_loc, |
| 8023 | obj_loc, |
| 8024 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8025 | maybe_temp_loc, |
| 8026 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8027 | __ Cmp(out, cls); |
| 8028 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8029 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8030 | instruction, /* is_fatal= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8031 | codegen_->AddSlowPath(slow_path); |
| 8032 | __ B(ne, slow_path->GetEntryLabel()); |
| 8033 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8034 | break; |
| 8035 | } |
| 8036 | |
| 8037 | case TypeCheckKind::kUnresolvedCheck: |
| 8038 | case TypeCheckKind::kInterfaceCheck: { |
| 8039 | // Note that we indeed only call on slow path, but we always go |
| 8040 | // into the slow path for the unresolved and interface check |
| 8041 | // cases. |
| 8042 | // |
| 8043 | // We cannot directly call the InstanceofNonTrivial runtime |
| 8044 | // entry point without resorting to a type checking slow path |
| 8045 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 8046 | // require to assign fixed registers for the inputs of this |
| 8047 | // HInstanceOf instruction (following the runtime calling |
| 8048 | // convention), which might be cluttered by the potential first |
| 8049 | // read barrier emission at the beginning of this method. |
| 8050 | // |
| 8051 | // TODO: Introduce a new runtime entry point taking the object |
| 8052 | // to test (instead of its class) as argument, and let it deal |
| 8053 | // with the read barrier issues. This will let us refactor this |
| 8054 | // case of the `switch` code as it was previously (with a direct |
| 8055 | // call to the runtime not using a type checking slow path). |
| 8056 | // This should also be beneficial for the other cases above. |
| 8057 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8058 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8059 | instruction, /* is_fatal= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8060 | codegen_->AddSlowPath(slow_path); |
| 8061 | __ B(slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8062 | break; |
| 8063 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 8064 | |
| 8065 | case TypeCheckKind::kBitstringCheck: { |
| 8066 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8067 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8068 | out_loc, |
| 8069 | obj_loc, |
| 8070 | class_offset, |
| 8071 | maybe_temp_loc, |
| 8072 | kWithoutReadBarrier); |
| 8073 | |
| 8074 | GenerateBitstringTypeCheckCompare(instruction, out, DontCare); |
| 8075 | // If `out` is a low reg and we would have another low reg temp, we could |
| 8076 | // optimize this as RSBS+ADC, see GenerateConditionWithZero(). |
| 8077 | // |
| 8078 | // Also, in some cases when `out` is a low reg and we're loading a constant to IP |
| 8079 | // it would make sense to use CMP+MOV+IT+MOV instead of SUB+CLZ+LSR as the code size |
| 8080 | // would be the same and we would have fewer direct data dependencies. |
| 8081 | codegen_->GenerateConditionWithZero(kCondEQ, out, out); // CLZ+LSR |
| 8082 | break; |
| 8083 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8084 | } |
| 8085 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8086 | if (done.IsReferenced()) { |
| 8087 | __ Bind(&done); |
| 8088 | } |
| 8089 | |
| 8090 | if (slow_path != nullptr) { |
| 8091 | __ Bind(slow_path->GetExitLabel()); |
| 8092 | } |
| 8093 | } |
| 8094 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8095 | void LocationsBuilderARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8096 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 8097 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8098 | LocationSummary* locations = |
| 8099 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8100 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 8101 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 8102 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 8103 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 8104 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 8105 | } else { |
| 8106 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8107 | } |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8108 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8109 | } |
| 8110 | |
| 8111 | void InstructionCodeGeneratorARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
| 8112 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 8113 | LocationSummary* locations = instruction->GetLocations(); |
| 8114 | Location obj_loc = locations->InAt(0); |
| 8115 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 8116 | vixl32::Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 8117 | ? vixl32::Register() |
| 8118 | : InputRegisterAt(instruction, 1); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8119 | Location temp_loc = locations->GetTemp(0); |
| 8120 | vixl32::Register temp = RegisterFrom(temp_loc); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8121 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 8122 | DCHECK_LE(num_temps, 3u); |
| 8123 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 8124 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 8125 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 8126 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 8127 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 8128 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 8129 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 8130 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 8131 | const uint32_t object_array_data_offset = |
| 8132 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8133 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 8134 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8135 | SlowPathCodeARMVIXL* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8136 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
| 8137 | instruction, is_type_check_slow_path_fatal); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8138 | codegen_->AddSlowPath(type_check_slow_path); |
| 8139 | |
| 8140 | vixl32::Label done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 8141 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8142 | // Avoid null check if we know obj is not null. |
| 8143 | if (instruction->MustDoNullCheck()) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8144 | __ CompareAndBranchIfZero(obj, final_label, /* is_far_target= */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8145 | } |
| 8146 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8147 | switch (type_check_kind) { |
| 8148 | case TypeCheckKind::kExactCheck: |
| 8149 | case TypeCheckKind::kArrayCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8150 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8151 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8152 | temp_loc, |
| 8153 | obj_loc, |
| 8154 | class_offset, |
| 8155 | maybe_temp2_loc, |
| 8156 | kWithoutReadBarrier); |
| 8157 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8158 | __ Cmp(temp, cls); |
| 8159 | // Jump to slow path for throwing the exception or doing a |
| 8160 | // more involved array check. |
| 8161 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 8162 | break; |
| 8163 | } |
| 8164 | |
| 8165 | case TypeCheckKind::kAbstractClassCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8166 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8167 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8168 | temp_loc, |
| 8169 | obj_loc, |
| 8170 | class_offset, |
| 8171 | maybe_temp2_loc, |
| 8172 | kWithoutReadBarrier); |
| 8173 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8174 | // If the class is abstract, we eagerly fetch the super class of the |
| 8175 | // object to avoid doing a comparison we know will fail. |
| 8176 | vixl32::Label loop; |
| 8177 | __ Bind(&loop); |
| 8178 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8179 | GenerateReferenceLoadOneRegister(instruction, |
| 8180 | temp_loc, |
| 8181 | super_offset, |
| 8182 | maybe_temp2_loc, |
| 8183 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8184 | |
| 8185 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 8186 | // exception. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 8187 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8188 | |
| 8189 | // Otherwise, compare the classes. |
| 8190 | __ Cmp(temp, cls); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8191 | __ B(ne, &loop, /* is_far_target= */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8192 | break; |
| 8193 | } |
| 8194 | |
| 8195 | case TypeCheckKind::kClassHierarchyCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8196 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8197 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8198 | temp_loc, |
| 8199 | obj_loc, |
| 8200 | class_offset, |
| 8201 | maybe_temp2_loc, |
| 8202 | kWithoutReadBarrier); |
| 8203 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8204 | // Walk over the class hierarchy to find a match. |
| 8205 | vixl32::Label loop; |
| 8206 | __ Bind(&loop); |
| 8207 | __ Cmp(temp, cls); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8208 | __ B(eq, final_label, /* is_far_target= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8209 | |
| 8210 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8211 | GenerateReferenceLoadOneRegister(instruction, |
| 8212 | temp_loc, |
| 8213 | super_offset, |
| 8214 | maybe_temp2_loc, |
| 8215 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8216 | |
| 8217 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 8218 | // exception. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 8219 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8220 | // Otherwise, jump to the beginning of the loop. |
| 8221 | __ B(&loop); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8222 | break; |
| 8223 | } |
| 8224 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8225 | case TypeCheckKind::kArrayObjectCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8226 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8227 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8228 | temp_loc, |
| 8229 | obj_loc, |
| 8230 | class_offset, |
| 8231 | maybe_temp2_loc, |
| 8232 | kWithoutReadBarrier); |
| 8233 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8234 | // Do an exact check. |
| 8235 | __ Cmp(temp, cls); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8236 | __ B(eq, final_label, /* is_far_target= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8237 | |
| 8238 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 8239 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8240 | GenerateReferenceLoadOneRegister(instruction, |
| 8241 | temp_loc, |
| 8242 | component_offset, |
| 8243 | maybe_temp2_loc, |
| 8244 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8245 | // If the component type is null, jump to the slow path to throw the exception. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 8246 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8247 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 8248 | // to further check that this component type is not a primitive type. |
| 8249 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8250 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 8251 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8252 | break; |
| 8253 | } |
| 8254 | |
| 8255 | case TypeCheckKind::kUnresolvedCheck: |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8256 | // We always go into the type check slow path for the unresolved check case. |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8257 | // We cannot directly call the CheckCast runtime entry point |
| 8258 | // without resorting to a type checking slow path here (i.e. by |
| 8259 | // calling InvokeRuntime directly), as it would require to |
| 8260 | // assign fixed registers for the inputs of this HInstanceOf |
| 8261 | // instruction (following the runtime calling convention), which |
| 8262 | // might be cluttered by the potential first read barrier |
| 8263 | // emission at the beginning of this method. |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8264 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8265 | __ B(type_check_slow_path->GetEntryLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8266 | break; |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8267 | |
| 8268 | case TypeCheckKind::kInterfaceCheck: { |
| 8269 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 8270 | // positives by doing this. |
| 8271 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8272 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8273 | temp_loc, |
| 8274 | obj_loc, |
| 8275 | class_offset, |
| 8276 | maybe_temp2_loc, |
| 8277 | kWithoutReadBarrier); |
| 8278 | |
| 8279 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 8280 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8281 | temp_loc, |
| 8282 | temp_loc, |
| 8283 | iftable_offset, |
| 8284 | maybe_temp2_loc, |
| 8285 | kWithoutReadBarrier); |
| 8286 | // Iftable is never null. |
| 8287 | __ Ldr(RegisterFrom(maybe_temp2_loc), MemOperand(temp, array_length_offset)); |
| 8288 | // Loop through the iftable and check if any class matches. |
| 8289 | vixl32::Label start_loop; |
| 8290 | __ Bind(&start_loop); |
| 8291 | __ CompareAndBranchIfZero(RegisterFrom(maybe_temp2_loc), |
| 8292 | type_check_slow_path->GetEntryLabel()); |
| 8293 | __ Ldr(RegisterFrom(maybe_temp3_loc), MemOperand(temp, object_array_data_offset)); |
| 8294 | GetAssembler()->MaybeUnpoisonHeapReference(RegisterFrom(maybe_temp3_loc)); |
| 8295 | // Go to next interface. |
| 8296 | __ Add(temp, temp, Operand::From(2 * kHeapReferenceSize)); |
| 8297 | __ Sub(RegisterFrom(maybe_temp2_loc), RegisterFrom(maybe_temp2_loc), 2); |
| 8298 | // Compare the classes and continue the loop if they do not match. |
| 8299 | __ Cmp(cls, RegisterFrom(maybe_temp3_loc)); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8300 | __ B(ne, &start_loop, /* is_far_target= */ false); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8301 | break; |
| 8302 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 8303 | |
| 8304 | case TypeCheckKind::kBitstringCheck: { |
| 8305 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8306 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8307 | temp_loc, |
| 8308 | obj_loc, |
| 8309 | class_offset, |
| 8310 | maybe_temp2_loc, |
| 8311 | kWithoutReadBarrier); |
| 8312 | |
| 8313 | GenerateBitstringTypeCheckCompare(instruction, temp, SetFlags); |
| 8314 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 8315 | break; |
| 8316 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8317 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 8318 | if (done.IsReferenced()) { |
| 8319 | __ Bind(&done); |
| 8320 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8321 | |
| 8322 | __ Bind(type_check_slow_path->GetExitLabel()); |
| 8323 | } |
| 8324 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8325 | void LocationsBuilderARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8326 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8327 | instruction, LocationSummary::kCallOnMainOnly); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8328 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 8329 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 8330 | } |
| 8331 | |
| 8332 | void InstructionCodeGeneratorARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 8333 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 8334 | instruction, |
| 8335 | instruction->GetDexPc()); |
| 8336 | if (instruction->IsEnter()) { |
| 8337 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 8338 | } else { |
| 8339 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 8340 | } |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 8341 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 19); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8342 | } |
| 8343 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8344 | void LocationsBuilderARMVIXL::VisitAnd(HAnd* instruction) { |
| 8345 | HandleBitwiseOperation(instruction, AND); |
| 8346 | } |
| 8347 | |
| 8348 | void LocationsBuilderARMVIXL::VisitOr(HOr* instruction) { |
| 8349 | HandleBitwiseOperation(instruction, ORR); |
| 8350 | } |
| 8351 | |
| 8352 | void LocationsBuilderARMVIXL::VisitXor(HXor* instruction) { |
| 8353 | HandleBitwiseOperation(instruction, EOR); |
| 8354 | } |
| 8355 | |
| 8356 | void LocationsBuilderARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
| 8357 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8358 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8359 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 8360 | || instruction->GetResultType() == DataType::Type::kInt64); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8361 | // Note: GVN reorders commutative operations to have the constant on the right hand side. |
| 8362 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8363 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
| 8364 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8365 | } |
| 8366 | |
| 8367 | void InstructionCodeGeneratorARMVIXL::VisitAnd(HAnd* instruction) { |
| 8368 | HandleBitwiseOperation(instruction); |
| 8369 | } |
| 8370 | |
| 8371 | void InstructionCodeGeneratorARMVIXL::VisitOr(HOr* instruction) { |
| 8372 | HandleBitwiseOperation(instruction); |
| 8373 | } |
| 8374 | |
| 8375 | void InstructionCodeGeneratorARMVIXL::VisitXor(HXor* instruction) { |
| 8376 | HandleBitwiseOperation(instruction); |
| 8377 | } |
| 8378 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8379 | void LocationsBuilderARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 8380 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8381 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8382 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 8383 | || instruction->GetResultType() == DataType::Type::kInt64); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8384 | |
| 8385 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8386 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8387 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8388 | } |
| 8389 | |
| 8390 | void InstructionCodeGeneratorARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 8391 | LocationSummary* locations = instruction->GetLocations(); |
| 8392 | Location first = locations->InAt(0); |
| 8393 | Location second = locations->InAt(1); |
| 8394 | Location out = locations->Out(); |
| 8395 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8396 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8397 | vixl32::Register first_reg = RegisterFrom(first); |
| 8398 | vixl32::Register second_reg = RegisterFrom(second); |
| 8399 | vixl32::Register out_reg = RegisterFrom(out); |
| 8400 | |
| 8401 | switch (instruction->GetOpKind()) { |
| 8402 | case HInstruction::kAnd: |
| 8403 | __ Bic(out_reg, first_reg, second_reg); |
| 8404 | break; |
| 8405 | case HInstruction::kOr: |
| 8406 | __ Orn(out_reg, first_reg, second_reg); |
| 8407 | break; |
| 8408 | // There is no EON on arm. |
| 8409 | case HInstruction::kXor: |
| 8410 | default: |
| 8411 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 8412 | UNREACHABLE(); |
| 8413 | } |
| 8414 | return; |
| 8415 | |
| 8416 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8417 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8418 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8419 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8420 | vixl32::Register second_low = LowRegisterFrom(second); |
| 8421 | vixl32::Register second_high = HighRegisterFrom(second); |
| 8422 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8423 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8424 | |
| 8425 | switch (instruction->GetOpKind()) { |
| 8426 | case HInstruction::kAnd: |
| 8427 | __ Bic(out_low, first_low, second_low); |
| 8428 | __ Bic(out_high, first_high, second_high); |
| 8429 | break; |
| 8430 | case HInstruction::kOr: |
| 8431 | __ Orn(out_low, first_low, second_low); |
| 8432 | __ Orn(out_high, first_high, second_high); |
| 8433 | break; |
| 8434 | // There is no EON on arm. |
| 8435 | case HInstruction::kXor: |
| 8436 | default: |
| 8437 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 8438 | UNREACHABLE(); |
| 8439 | } |
| 8440 | } |
| 8441 | } |
| 8442 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8443 | void LocationsBuilderARMVIXL::VisitDataProcWithShifterOp( |
| 8444 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8445 | DCHECK(instruction->GetType() == DataType::Type::kInt32 || |
| 8446 | instruction->GetType() == DataType::Type::kInt64); |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8447 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8448 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8449 | const bool overlap = instruction->GetType() == DataType::Type::kInt64 && |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8450 | HDataProcWithShifterOp::IsExtensionOp(instruction->GetOpKind()); |
| 8451 | |
| 8452 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8453 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8454 | locations->SetOut(Location::RequiresRegister(), |
| 8455 | overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 8456 | } |
| 8457 | |
| 8458 | void InstructionCodeGeneratorARMVIXL::VisitDataProcWithShifterOp( |
| 8459 | HDataProcWithShifterOp* instruction) { |
| 8460 | const LocationSummary* const locations = instruction->GetLocations(); |
| 8461 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 8462 | const HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 8463 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8464 | if (instruction->GetType() == DataType::Type::kInt32) { |
Anton Kirilov | 420ee30 | 2017-02-21 18:10:26 +0000 | [diff] [blame] | 8465 | const vixl32::Register first = InputRegisterAt(instruction, 0); |
| 8466 | const vixl32::Register output = OutputRegister(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8467 | const vixl32::Register second = instruction->InputAt(1)->GetType() == DataType::Type::kInt64 |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8468 | ? LowRegisterFrom(locations->InAt(1)) |
| 8469 | : InputRegisterAt(instruction, 1); |
| 8470 | |
Anton Kirilov | 420ee30 | 2017-02-21 18:10:26 +0000 | [diff] [blame] | 8471 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 8472 | DCHECK_EQ(kind, HInstruction::kAdd); |
| 8473 | |
| 8474 | switch (op_kind) { |
| 8475 | case HDataProcWithShifterOp::kUXTB: |
| 8476 | __ Uxtab(output, first, second); |
| 8477 | break; |
| 8478 | case HDataProcWithShifterOp::kUXTH: |
| 8479 | __ Uxtah(output, first, second); |
| 8480 | break; |
| 8481 | case HDataProcWithShifterOp::kSXTB: |
| 8482 | __ Sxtab(output, first, second); |
| 8483 | break; |
| 8484 | case HDataProcWithShifterOp::kSXTH: |
| 8485 | __ Sxtah(output, first, second); |
| 8486 | break; |
| 8487 | default: |
| 8488 | LOG(FATAL) << "Unexpected operation kind: " << op_kind; |
| 8489 | UNREACHABLE(); |
| 8490 | } |
| 8491 | } else { |
| 8492 | GenerateDataProcInstruction(kind, |
| 8493 | output, |
| 8494 | first, |
| 8495 | Operand(second, |
| 8496 | ShiftFromOpKind(op_kind), |
| 8497 | instruction->GetShiftAmount()), |
| 8498 | codegen_); |
| 8499 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8500 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8501 | DCHECK_EQ(instruction->GetType(), DataType::Type::kInt64); |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8502 | |
| 8503 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 8504 | const vixl32::Register second = InputRegisterAt(instruction, 1); |
| 8505 | |
| 8506 | DCHECK(!LowRegisterFrom(locations->Out()).Is(second)); |
| 8507 | GenerateDataProc(kind, |
| 8508 | locations->Out(), |
| 8509 | locations->InAt(0), |
| 8510 | second, |
| 8511 | Operand(second, ShiftType::ASR, 31), |
| 8512 | codegen_); |
| 8513 | } else { |
| 8514 | GenerateLongDataProc(instruction, codegen_); |
| 8515 | } |
| 8516 | } |
| 8517 | } |
| 8518 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8519 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8520 | void InstructionCodeGeneratorARMVIXL::GenerateAndConst(vixl32::Register out, |
| 8521 | vixl32::Register first, |
| 8522 | uint32_t value) { |
| 8523 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 8524 | if (value == 0xffffffffu) { |
| 8525 | if (!out.Is(first)) { |
| 8526 | __ Mov(out, first); |
| 8527 | } |
| 8528 | return; |
| 8529 | } |
| 8530 | if (value == 0u) { |
| 8531 | __ Mov(out, 0); |
| 8532 | return; |
| 8533 | } |
| 8534 | if (GetAssembler()->ShifterOperandCanHold(AND, value)) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 8535 | __ And(out, first, value); |
| 8536 | } else if (GetAssembler()->ShifterOperandCanHold(BIC, ~value)) { |
| 8537 | __ Bic(out, first, ~value); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8538 | } else { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 8539 | DCHECK(IsPowerOfTwo(value + 1)); |
| 8540 | __ Ubfx(out, first, 0, WhichPowerOf2(value + 1)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8541 | } |
| 8542 | } |
| 8543 | |
| 8544 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8545 | void InstructionCodeGeneratorARMVIXL::GenerateOrrConst(vixl32::Register out, |
| 8546 | vixl32::Register first, |
| 8547 | uint32_t value) { |
| 8548 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 8549 | if (value == 0u) { |
| 8550 | if (!out.Is(first)) { |
| 8551 | __ Mov(out, first); |
| 8552 | } |
| 8553 | return; |
| 8554 | } |
| 8555 | if (value == 0xffffffffu) { |
| 8556 | __ Mvn(out, 0); |
| 8557 | return; |
| 8558 | } |
| 8559 | if (GetAssembler()->ShifterOperandCanHold(ORR, value)) { |
| 8560 | __ Orr(out, first, value); |
| 8561 | } else { |
| 8562 | DCHECK(GetAssembler()->ShifterOperandCanHold(ORN, ~value)); |
| 8563 | __ Orn(out, first, ~value); |
| 8564 | } |
| 8565 | } |
| 8566 | |
| 8567 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8568 | void InstructionCodeGeneratorARMVIXL::GenerateEorConst(vixl32::Register out, |
| 8569 | vixl32::Register first, |
| 8570 | uint32_t value) { |
| 8571 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 8572 | if (value == 0u) { |
| 8573 | if (!out.Is(first)) { |
| 8574 | __ Mov(out, first); |
| 8575 | } |
| 8576 | return; |
| 8577 | } |
| 8578 | __ Eor(out, first, value); |
| 8579 | } |
| 8580 | |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8581 | void InstructionCodeGeneratorARMVIXL::GenerateAddLongConst(Location out, |
| 8582 | Location first, |
| 8583 | uint64_t value) { |
| 8584 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8585 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8586 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8587 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8588 | uint32_t value_low = Low32Bits(value); |
| 8589 | uint32_t value_high = High32Bits(value); |
| 8590 | if (value_low == 0u) { |
| 8591 | if (!out_low.Is(first_low)) { |
| 8592 | __ Mov(out_low, first_low); |
| 8593 | } |
| 8594 | __ Add(out_high, first_high, value_high); |
| 8595 | return; |
| 8596 | } |
| 8597 | __ Adds(out_low, first_low, value_low); |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 8598 | if (GetAssembler()->ShifterOperandCanHold(ADC, value_high)) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8599 | __ Adc(out_high, first_high, value_high); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8600 | } else { |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 8601 | DCHECK(GetAssembler()->ShifterOperandCanHold(SBC, ~value_high)); |
| 8602 | __ Sbc(out_high, first_high, ~value_high); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8603 | } |
| 8604 | } |
| 8605 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8606 | void InstructionCodeGeneratorARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 8607 | LocationSummary* locations = instruction->GetLocations(); |
| 8608 | Location first = locations->InAt(0); |
| 8609 | Location second = locations->InAt(1); |
| 8610 | Location out = locations->Out(); |
| 8611 | |
| 8612 | if (second.IsConstant()) { |
| 8613 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 8614 | uint32_t value_low = Low32Bits(value); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8615 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8616 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 8617 | vixl32::Register out_reg = OutputRegister(instruction); |
| 8618 | if (instruction->IsAnd()) { |
| 8619 | GenerateAndConst(out_reg, first_reg, value_low); |
| 8620 | } else if (instruction->IsOr()) { |
| 8621 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 8622 | } else { |
| 8623 | DCHECK(instruction->IsXor()); |
| 8624 | GenerateEorConst(out_reg, first_reg, value_low); |
| 8625 | } |
| 8626 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8627 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8628 | uint32_t value_high = High32Bits(value); |
| 8629 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8630 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8631 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8632 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8633 | if (instruction->IsAnd()) { |
| 8634 | GenerateAndConst(out_low, first_low, value_low); |
| 8635 | GenerateAndConst(out_high, first_high, value_high); |
| 8636 | } else if (instruction->IsOr()) { |
| 8637 | GenerateOrrConst(out_low, first_low, value_low); |
| 8638 | GenerateOrrConst(out_high, first_high, value_high); |
| 8639 | } else { |
| 8640 | DCHECK(instruction->IsXor()); |
| 8641 | GenerateEorConst(out_low, first_low, value_low); |
| 8642 | GenerateEorConst(out_high, first_high, value_high); |
| 8643 | } |
| 8644 | } |
| 8645 | return; |
| 8646 | } |
| 8647 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8648 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8649 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 8650 | vixl32::Register second_reg = InputRegisterAt(instruction, 1); |
| 8651 | vixl32::Register out_reg = OutputRegister(instruction); |
| 8652 | if (instruction->IsAnd()) { |
| 8653 | __ And(out_reg, first_reg, second_reg); |
| 8654 | } else if (instruction->IsOr()) { |
| 8655 | __ Orr(out_reg, first_reg, second_reg); |
| 8656 | } else { |
| 8657 | DCHECK(instruction->IsXor()); |
| 8658 | __ Eor(out_reg, first_reg, second_reg); |
| 8659 | } |
| 8660 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8661 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8662 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8663 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8664 | vixl32::Register second_low = LowRegisterFrom(second); |
| 8665 | vixl32::Register second_high = HighRegisterFrom(second); |
| 8666 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8667 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8668 | if (instruction->IsAnd()) { |
| 8669 | __ And(out_low, first_low, second_low); |
| 8670 | __ And(out_high, first_high, second_high); |
| 8671 | } else if (instruction->IsOr()) { |
| 8672 | __ Orr(out_low, first_low, second_low); |
| 8673 | __ Orr(out_high, first_high, second_high); |
| 8674 | } else { |
| 8675 | DCHECK(instruction->IsXor()); |
| 8676 | __ Eor(out_low, first_low, second_low); |
| 8677 | __ Eor(out_high, first_high, second_high); |
| 8678 | } |
| 8679 | } |
| 8680 | } |
| 8681 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8682 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadOneRegister( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8683 | HInstruction* instruction, |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8684 | Location out, |
| 8685 | uint32_t offset, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8686 | Location maybe_temp, |
| 8687 | ReadBarrierOption read_barrier_option) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8688 | vixl32::Register out_reg = RegisterFrom(out); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8689 | if (read_barrier_option == kWithReadBarrier) { |
| 8690 | CHECK(kEmitCompilerReadBarrier); |
| 8691 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 8692 | if (kUseBakerReadBarrier) { |
| 8693 | // Load with fast path based Baker's read barrier. |
| 8694 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8695 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8696 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check= */ false); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8697 | } else { |
| 8698 | // Load with slow path based read barrier. |
| 8699 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 8700 | // in the following move operation, as we will need it for the |
| 8701 | // read barrier below. |
| 8702 | __ Mov(RegisterFrom(maybe_temp), out_reg); |
| 8703 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8704 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 8705 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 8706 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8707 | } else { |
| 8708 | // Plain load with no read barrier. |
| 8709 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8710 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 8711 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 8712 | } |
| 8713 | } |
| 8714 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8715 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadTwoRegisters( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8716 | HInstruction* instruction, |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8717 | Location out, |
| 8718 | Location obj, |
| 8719 | uint32_t offset, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8720 | Location maybe_temp, |
| 8721 | ReadBarrierOption read_barrier_option) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8722 | vixl32::Register out_reg = RegisterFrom(out); |
| 8723 | vixl32::Register obj_reg = RegisterFrom(obj); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8724 | if (read_barrier_option == kWithReadBarrier) { |
| 8725 | CHECK(kEmitCompilerReadBarrier); |
| 8726 | if (kUseBakerReadBarrier) { |
| 8727 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 8728 | // Load with fast path based Baker's read barrier. |
| 8729 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8730 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8731 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check= */ false); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8732 | } else { |
| 8733 | // Load with slow path based read barrier. |
| 8734 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8735 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8736 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 8737 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8738 | } else { |
| 8739 | // Plain load with no read barrier. |
| 8740 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8741 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8742 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 8743 | } |
| 8744 | } |
| 8745 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 8746 | void CodeGeneratorARMVIXL::GenerateGcRootFieldLoad( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8747 | HInstruction* instruction, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8748 | Location root, |
| 8749 | vixl32::Register obj, |
| 8750 | uint32_t offset, |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8751 | ReadBarrierOption read_barrier_option) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8752 | vixl32::Register root_reg = RegisterFrom(root); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8753 | if (read_barrier_option == kWithReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8754 | DCHECK(kEmitCompilerReadBarrier); |
| 8755 | if (kUseBakerReadBarrier) { |
| 8756 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8757 | // Baker's read barrier are used. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8758 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8759 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 8760 | // the Marking Register) to decide whether we need to enter |
| 8761 | // the slow path to mark the GC root. |
| 8762 | // |
| 8763 | // We use shared thunks for the slow path; shared within the method |
| 8764 | // for JIT, across methods for AOT. That thunk checks the reference |
| 8765 | // and jumps to the entrypoint if needed. |
| 8766 | // |
| 8767 | // lr = &return_address; |
| 8768 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 8769 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8770 | // goto gc_root_thunk<root_reg>(lr) |
| 8771 | // } |
| 8772 | // return_address: |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8773 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8774 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8775 | temps.Exclude(ip); |
| 8776 | bool narrow = CanEmitNarrowLdr(root_reg, obj, offset); |
| 8777 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(root_reg.GetCode(), narrow); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8778 | |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8779 | size_t narrow_instructions = /* CMP */ (mr.IsLow() ? 1u : 0u) + /* LDR */ (narrow ? 1u : 0u); |
| 8780 | size_t wide_instructions = /* ADR+CMP+LDR+BNE */ 4u - narrow_instructions; |
| 8781 | size_t exact_size = wide_instructions * vixl32::k32BitT32InstructionSizeInBytes + |
| 8782 | narrow_instructions * vixl32::k16BitT32InstructionSizeInBytes; |
| 8783 | ExactAssemblyScope guard(GetVIXLAssembler(), exact_size); |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8784 | vixl32::Label return_address; |
| 8785 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8786 | __ cmp(mr, Operand(0)); |
| 8787 | // Currently the offset is always within range. If that changes, |
| 8788 | // we shall have to split the load the same way as for fields. |
| 8789 | DCHECK_LT(offset, kReferenceLoadMinFarOffset); |
| 8790 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8791 | __ ldr(EncodingSize(narrow ? Narrow : Wide), root_reg, MemOperand(obj, offset)); |
| 8792 | EmitBakerReadBarrierBne(custom_data); |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8793 | __ bind(&return_address); |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8794 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8795 | narrow ? BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_OFFSET |
| 8796 | : BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_OFFSET); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8797 | } else { |
| 8798 | // GC root loaded through a slow path for read barriers other |
| 8799 | // than Baker's. |
| 8800 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 8801 | __ Add(root_reg, obj, offset); |
| 8802 | // /* mirror::Object* */ root = root->Read() |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 8803 | GenerateReadBarrierForRootSlow(instruction, root, root); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8804 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8805 | } else { |
| 8806 | // Plain GC root load with no read barrier. |
| 8807 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8808 | GetAssembler()->LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8809 | // Note that GC roots are not affected by heap poisoning, thus we |
| 8810 | // do not have to unpoison `root_reg` here. |
| 8811 | } |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 8812 | MaybeGenerateMarkingRegisterCheck(/* code= */ 20); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8813 | } |
| 8814 | |
Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 8815 | void CodeGeneratorARMVIXL::GenerateIntrinsicCasMoveWithBakerReadBarrier( |
| 8816 | vixl::aarch32::Register marked_old_value, |
| 8817 | vixl::aarch32::Register old_value) { |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8818 | DCHECK(kEmitCompilerReadBarrier); |
| 8819 | DCHECK(kUseBakerReadBarrier); |
| 8820 | |
Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 8821 | // Similar to the Baker RB path in GenerateGcRootFieldLoad(), with a MOV instead of LDR. |
| 8822 | // For low registers, we can reuse the GC root narrow entrypoint, for high registers |
| 8823 | // we use a specialized entrypoint because the register bits are 8-11 instead of 12-15. |
| 8824 | bool narrow_mov = marked_old_value.IsLow(); |
| 8825 | uint32_t custom_data = narrow_mov |
| 8826 | ? EncodeBakerReadBarrierGcRootData(marked_old_value.GetCode(), /*narrow=*/ true) |
| 8827 | : EncodeBakerReadBarrierIntrinsicCasData(marked_old_value.GetCode()); |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8828 | |
Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 8829 | size_t narrow_instructions = /* CMP */ (mr.IsLow() ? 1u : 0u) + /* MOV */ (narrow_mov ? 1u : 0u); |
| 8830 | size_t wide_instructions = /* ADR+CMP+MOV+BNE */ 4u - narrow_instructions; |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8831 | size_t exact_size = wide_instructions * vixl32::k32BitT32InstructionSizeInBytes + |
| 8832 | narrow_instructions * vixl32::k16BitT32InstructionSizeInBytes; |
| 8833 | ExactAssemblyScope guard(GetVIXLAssembler(), exact_size); |
| 8834 | vixl32::Label return_address; |
| 8835 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8836 | __ cmp(mr, Operand(0)); |
| 8837 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 8838 | __ mov(EncodingSize(narrow_mov ? Narrow : Wide), marked_old_value, old_value); |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8839 | EmitBakerReadBarrierBne(custom_data); |
| 8840 | __ bind(&return_address); |
| 8841 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 8842 | narrow_mov |
| 8843 | ? BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_OFFSET |
| 8844 | : BAKER_MARK_INTROSPECTION_INTRINSIC_CAS_MOV_OFFSET); |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8845 | } |
| 8846 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8847 | void CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8848 | Location ref, |
| 8849 | vixl32::Register obj, |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8850 | const vixl32::MemOperand& src, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8851 | bool needs_null_check) { |
| 8852 | DCHECK(kEmitCompilerReadBarrier); |
| 8853 | DCHECK(kUseBakerReadBarrier); |
| 8854 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8855 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 8856 | // Marking Register) to decide whether we need to enter the slow |
| 8857 | // path to mark the reference. Then, in the slow path, check the |
| 8858 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 8859 | // decide whether to mark `ref` or not. |
| 8860 | // |
| 8861 | // We use shared thunks for the slow path; shared within the method |
| 8862 | // for JIT, across methods for AOT. That thunk checks the holder |
| 8863 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 8864 | // it creates a fake dependency and returns to the LDR instruction. |
| 8865 | // |
| 8866 | // lr = &gray_return_address; |
| 8867 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8868 | // goto field_thunk<holder_reg, base_reg>(lr) |
| 8869 | // } |
| 8870 | // not_gray_return_address: |
| 8871 | // // Original reference load. If the offset is too large to fit |
| 8872 | // // into LDR, we use an adjusted base register here. |
| 8873 | // HeapReference<mirror::Object> reference = *(obj+offset); |
| 8874 | // gray_return_address: |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8875 | |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8876 | DCHECK(src.GetAddrMode() == vixl32::Offset); |
| 8877 | DCHECK_ALIGNED(src.GetOffsetImmediate(), sizeof(mirror::HeapReference<mirror::Object>)); |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8878 | vixl32::Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8879 | bool narrow = CanEmitNarrowLdr(ref_reg, src.GetBaseRegister(), src.GetOffsetImmediate()); |
| 8880 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8881 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8882 | temps.Exclude(ip); |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8883 | uint32_t custom_data = |
| 8884 | EncodeBakerReadBarrierFieldData(src.GetBaseRegister().GetCode(), obj.GetCode(), narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8885 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8886 | { |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8887 | size_t narrow_instructions = |
| 8888 | /* CMP */ (mr.IsLow() ? 1u : 0u) + |
| 8889 | /* LDR+unpoison? */ (narrow ? (kPoisonHeapReferences ? 2u : 1u) : 0u); |
| 8890 | size_t wide_instructions = |
| 8891 | /* ADR+CMP+LDR+BNE+unpoison? */ (kPoisonHeapReferences ? 5u : 4u) - narrow_instructions; |
| 8892 | size_t exact_size = wide_instructions * vixl32::k32BitT32InstructionSizeInBytes + |
| 8893 | narrow_instructions * vixl32::k16BitT32InstructionSizeInBytes; |
| 8894 | ExactAssemblyScope guard(GetVIXLAssembler(), exact_size); |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8895 | vixl32::Label return_address; |
| 8896 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8897 | __ cmp(mr, Operand(0)); |
| 8898 | EmitBakerReadBarrierBne(custom_data); |
| 8899 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8900 | __ ldr(EncodingSize(narrow ? Narrow : Wide), ref_reg, src); |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8901 | if (needs_null_check) { |
| 8902 | MaybeRecordImplicitNullCheck(instruction); |
| 8903 | } |
| 8904 | // Note: We need a specific width for the unpoisoning NEG. |
| 8905 | if (kPoisonHeapReferences) { |
| 8906 | if (narrow) { |
| 8907 | // The only 16-bit encoding is T1 which sets flags outside IT block (i.e. RSBS, not RSB). |
| 8908 | __ rsbs(EncodingSize(Narrow), ref_reg, ref_reg, Operand(0)); |
| 8909 | } else { |
| 8910 | __ rsb(EncodingSize(Wide), ref_reg, ref_reg, Operand(0)); |
| 8911 | } |
| 8912 | } |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8913 | __ bind(&return_address); |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8914 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8915 | narrow ? BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_OFFSET |
| 8916 | : BAKER_MARK_INTROSPECTION_FIELD_LDR_WIDE_OFFSET); |
| 8917 | } |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 8918 | MaybeGenerateMarkingRegisterCheck(/* code= */ 21, /* temp_loc= */ LocationFrom(ip)); |
Roland Levillain | 6070e88 | 2016-11-03 17:51:58 +0000 | [diff] [blame] | 8919 | } |
| 8920 | |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8921 | void CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8922 | Location ref, |
| 8923 | vixl32::Register obj, |
| 8924 | uint32_t offset, |
Vladimir Marko | 01b6552 | 2020-10-28 15:43:54 +0000 | [diff] [blame] | 8925 | Location maybe_temp, |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8926 | bool needs_null_check) { |
| 8927 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 8928 | vixl32::Register base = obj; |
| 8929 | if (offset >= kReferenceLoadMinFarOffset) { |
Vladimir Marko | 01b6552 | 2020-10-28 15:43:54 +0000 | [diff] [blame] | 8930 | base = RegisterFrom(maybe_temp); |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8931 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 8932 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 8933 | offset &= (kReferenceLoadMinFarOffset - 1u); |
| 8934 | } |
| 8935 | GenerateFieldLoadWithBakerReadBarrier( |
| 8936 | instruction, ref, obj, MemOperand(base, offset), needs_null_check); |
| 8937 | } |
| 8938 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8939 | void CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier(Location ref, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8940 | vixl32::Register obj, |
| 8941 | uint32_t data_offset, |
| 8942 | Location index, |
| 8943 | Location temp, |
| 8944 | bool needs_null_check) { |
| 8945 | DCHECK(kEmitCompilerReadBarrier); |
| 8946 | DCHECK(kUseBakerReadBarrier); |
| 8947 | |
| 8948 | static_assert( |
| 8949 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 8950 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8951 | ScaleFactor scale_factor = TIMES_4; |
| 8952 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8953 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 8954 | // Marking Register) to decide whether we need to enter the slow |
| 8955 | // path to mark the reference. Then, in the slow path, check the |
| 8956 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 8957 | // decide whether to mark `ref` or not. |
| 8958 | // |
| 8959 | // We use shared thunks for the slow path; shared within the method |
| 8960 | // for JIT, across methods for AOT. That thunk checks the holder |
| 8961 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 8962 | // it creates a fake dependency and returns to the LDR instruction. |
| 8963 | // |
| 8964 | // lr = &gray_return_address; |
| 8965 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8966 | // goto array_thunk<base_reg>(lr) |
| 8967 | // } |
| 8968 | // not_gray_return_address: |
| 8969 | // // Original reference load. If the offset is too large to fit |
| 8970 | // // into LDR, we use an adjusted base register here. |
| 8971 | // HeapReference<mirror::Object> reference = data[index]; |
| 8972 | // gray_return_address: |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8973 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8974 | DCHECK(index.IsValid()); |
| 8975 | vixl32::Register index_reg = RegisterFrom(index, DataType::Type::kInt32); |
| 8976 | vixl32::Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
| 8977 | vixl32::Register data_reg = RegisterFrom(temp, DataType::Type::kInt32); // Raw pointer. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8978 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8979 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8980 | temps.Exclude(ip); |
| 8981 | uint32_t custom_data = EncodeBakerReadBarrierArrayData(data_reg.GetCode()); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8982 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8983 | __ Add(data_reg, obj, Operand(data_offset)); |
| 8984 | { |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8985 | size_t narrow_instructions = /* CMP */ (mr.IsLow() ? 1u : 0u); |
| 8986 | size_t wide_instructions = |
| 8987 | /* ADR+CMP+BNE+LDR+unpoison? */ (kPoisonHeapReferences ? 5u : 4u) - narrow_instructions; |
| 8988 | size_t exact_size = wide_instructions * vixl32::k32BitT32InstructionSizeInBytes + |
| 8989 | narrow_instructions * vixl32::k16BitT32InstructionSizeInBytes; |
| 8990 | ExactAssemblyScope guard(GetVIXLAssembler(), exact_size); |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8991 | vixl32::Label return_address; |
| 8992 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8993 | __ cmp(mr, Operand(0)); |
| 8994 | EmitBakerReadBarrierBne(custom_data); |
| 8995 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8996 | __ ldr(ref_reg, MemOperand(data_reg, index_reg, vixl32::LSL, scale_factor)); |
| 8997 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 8998 | // Note: We need a Wide NEG for the unpoisoning. |
| 8999 | if (kPoisonHeapReferences) { |
| 9000 | __ rsb(EncodingSize(Wide), ref_reg, ref_reg, Operand(0)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9001 | } |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 9002 | __ bind(&return_address); |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 9003 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 9004 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9005 | } |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 9006 | MaybeGenerateMarkingRegisterCheck(/* code= */ 22, /* temp_loc= */ LocationFrom(ip)); |
Roland Levillain | 6070e88 | 2016-11-03 17:51:58 +0000 | [diff] [blame] | 9007 | } |
| 9008 | |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 9009 | void CodeGeneratorARMVIXL::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 9010 | // The following condition is a compile-time one, so it does not have a run-time cost. |
| 9011 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && kIsDebugBuild) { |
| 9012 | // The following condition is a run-time one; it is executed after the |
| 9013 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 9014 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 9015 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 9016 | vixl32::Register temp = temp_loc.IsValid() ? RegisterFrom(temp_loc) : temps.Acquire(); |
| 9017 | GetAssembler()->GenerateMarkingRegisterCheck(temp, |
| 9018 | kMarkingRegisterCheckBreakCodeBaseCode + code); |
| 9019 | } |
| 9020 | } |
| 9021 | } |
| 9022 | |
Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 9023 | SlowPathCodeARMVIXL* CodeGeneratorARMVIXL::AddReadBarrierSlowPath(HInstruction* instruction, |
| 9024 | Location out, |
| 9025 | Location ref, |
| 9026 | Location obj, |
| 9027 | uint32_t offset, |
| 9028 | Location index) { |
| 9029 | SlowPathCodeARMVIXL* slow_path = new (GetScopedAllocator()) |
| 9030 | ReadBarrierForHeapReferenceSlowPathARMVIXL(instruction, out, ref, obj, offset, index); |
| 9031 | AddSlowPath(slow_path); |
| 9032 | return slow_path; |
| 9033 | } |
| 9034 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9035 | void CodeGeneratorARMVIXL::GenerateReadBarrierSlow(HInstruction* instruction, |
| 9036 | Location out, |
| 9037 | Location ref, |
| 9038 | Location obj, |
| 9039 | uint32_t offset, |
| 9040 | Location index) { |
| 9041 | DCHECK(kEmitCompilerReadBarrier); |
| 9042 | |
| 9043 | // Insert a slow path based read barrier *after* the reference load. |
| 9044 | // |
| 9045 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 9046 | // reference will be carried out by the runtime within the slow |
| 9047 | // path. |
| 9048 | // |
| 9049 | // Note that `ref` currently does not get unpoisoned (when heap |
| 9050 | // poisoning is enabled), which is alright as the `ref` argument is |
| 9051 | // not used by the artReadBarrierSlow entry point. |
| 9052 | // |
| 9053 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 9054 | SlowPathCodeARMVIXL* slow_path = |
| 9055 | AddReadBarrierSlowPath(instruction, out, ref, obj, offset, index); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9056 | |
| 9057 | __ B(slow_path->GetEntryLabel()); |
| 9058 | __ Bind(slow_path->GetExitLabel()); |
| 9059 | } |
| 9060 | |
| 9061 | void CodeGeneratorARMVIXL::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9062 | Location out, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9063 | Location ref, |
| 9064 | Location obj, |
| 9065 | uint32_t offset, |
| 9066 | Location index) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9067 | if (kEmitCompilerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9068 | // Baker's read barriers shall be handled by the fast path |
Roland Levillain | 9983e30 | 2017-07-14 14:34:22 +0100 | [diff] [blame] | 9069 | // (CodeGeneratorARMVIXL::GenerateReferenceLoadWithBakerReadBarrier). |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9070 | DCHECK(!kUseBakerReadBarrier); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9071 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 9072 | // by the runtime within the slow path. |
| 9073 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9074 | } else if (kPoisonHeapReferences) { |
| 9075 | GetAssembler()->UnpoisonHeapReference(RegisterFrom(out)); |
| 9076 | } |
| 9077 | } |
| 9078 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9079 | void CodeGeneratorARMVIXL::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 9080 | Location out, |
| 9081 | Location root) { |
| 9082 | DCHECK(kEmitCompilerReadBarrier); |
| 9083 | |
| 9084 | // Insert a slow path based read barrier *after* the GC root load. |
| 9085 | // |
| 9086 | // Note that GC roots are not affected by heap poisoning, so we do |
| 9087 | // not need to do anything special for this here. |
| 9088 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9089 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathARMVIXL(instruction, out, root); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9090 | AddSlowPath(slow_path); |
| 9091 | |
| 9092 | __ B(slow_path->GetEntryLabel()); |
| 9093 | __ Bind(slow_path->GetExitLabel()); |
| 9094 | } |
| 9095 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9096 | // Check if the desired_dispatch_info is supported. If it is, return it, |
| 9097 | // otherwise return a fall-back info that should be used instead. |
| 9098 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARMVIXL::GetSupportedInvokeStaticOrDirectDispatch( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9099 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9100 | ArtMethod* method) { |
Vladimir Marko | d3e9c62 | 2020-08-05 12:20:28 +0100 | [diff] [blame] | 9101 | if (method->IsIntrinsic() && |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9102 | desired_dispatch_info.code_ptr_location == CodePtrLocation::kCallCriticalNative) { |
Vladimir Marko | d3e9c62 | 2020-08-05 12:20:28 +0100 | [diff] [blame] | 9103 | // As a work-around for soft-float native ABI interfering with type checks, we are |
| 9104 | // inserting fake calls to Float.floatToRawIntBits() or Double.doubleToRawLongBits() |
| 9105 | // when a float or double argument is passed in core registers but we cannot do that |
| 9106 | // for actual intrinsic implementations that expect them in FP registers. Therefore |
| 9107 | // we do not use `kCallCriticalNative` for intrinsics with FP arguments; if they are |
| 9108 | // properly intrinsified, the dispatch type does not matter anyway. |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9109 | ScopedObjectAccess soa(Thread::Current()); |
| 9110 | uint32_t shorty_len; |
| 9111 | const char* shorty = method->GetShorty(&shorty_len); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9112 | for (uint32_t i = 1; i != shorty_len; ++i) { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9113 | if (shorty[i] == 'D' || shorty[i] == 'F') { |
| 9114 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9115 | dispatch_info.code_ptr_location = CodePtrLocation::kCallArtMethod; |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9116 | return dispatch_info; |
| 9117 | } |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9118 | } |
| 9119 | } |
Nicolas Geoffray | e807ff7 | 2017-01-23 09:03:12 +0000 | [diff] [blame] | 9120 | return desired_dispatch_info; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9121 | } |
| 9122 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 9123 | |
| 9124 | void CodeGeneratorARMVIXL::LoadMethod(MethodLoadKind load_kind, Location temp, HInvoke* invoke) { |
| 9125 | switch (load_kind) { |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9126 | case MethodLoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 9127 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 9128 | PcRelativePatchInfo* labels = NewBootImageMethodPatch(invoke->GetResolvedMethodReference()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9129 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 9130 | EmitMovwMovtPlaceholder(labels, temp_reg); |
| 9131 | break; |
| 9132 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9133 | case MethodLoadKind::kBootImageRelRo: { |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 9134 | uint32_t boot_image_offset = GetBootImageOffset(invoke); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 9135 | PcRelativePatchInfo* labels = NewBootImageRelRoPatch(boot_image_offset); |
| 9136 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 9137 | EmitMovwMovtPlaceholder(labels, temp_reg); |
| 9138 | GetAssembler()->LoadFromOffset(kLoadWord, temp_reg, temp_reg, /* offset*/ 0); |
| 9139 | break; |
| 9140 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9141 | case MethodLoadKind::kBssEntry: { |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 9142 | PcRelativePatchInfo* labels = NewMethodBssEntryPatch(invoke->GetMethodReference()); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9143 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 9144 | EmitMovwMovtPlaceholder(labels, temp_reg); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 9145 | // All aligned loads are implicitly atomic consume operations on ARM. |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9146 | GetAssembler()->LoadFromOffset(kLoadWord, temp_reg, temp_reg, /* offset*/ 0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9147 | break; |
| 9148 | } |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 9149 | case MethodLoadKind::kJitDirectAddress: { |
| 9150 | __ Mov(RegisterFrom(temp), Operand::From(invoke->GetResolvedMethod())); |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 9151 | break; |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 9152 | } |
| 9153 | case MethodLoadKind::kRuntimeCall: { |
| 9154 | // Test situation, don't do anything. |
| 9155 | break; |
| 9156 | } |
| 9157 | default: { |
| 9158 | LOG(FATAL) << "Load kind should have already been handled " << load_kind; |
| 9159 | UNREACHABLE(); |
| 9160 | } |
| 9161 | } |
| 9162 | } |
| 9163 | |
| 9164 | void CodeGeneratorARMVIXL::GenerateStaticOrDirectCall( |
| 9165 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
| 9166 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 9167 | switch (invoke->GetMethodLoadKind()) { |
| 9168 | case MethodLoadKind::kStringInit: { |
| 9169 | uint32_t offset = |
| 9170 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 9171 | // temp = thread->string_init_entrypoint |
| 9172 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp), tr, offset); |
| 9173 | break; |
| 9174 | } |
| 9175 | case MethodLoadKind::kRecursive: { |
| 9176 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodIndex()); |
| 9177 | break; |
| 9178 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9179 | case MethodLoadKind::kRuntimeCall: { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9180 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 9181 | return; // No code pointer retrieval; the runtime performs the call directly. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9182 | } |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 9183 | case MethodLoadKind::kBootImageLinkTimePcRelative: |
| 9184 | // Note: Unlike arm64, x86 and x86-64, we do not avoid the materialization of method |
| 9185 | // pointer for kCallCriticalNative because it would not save us an instruction from |
| 9186 | // the current sequence MOVW+MOVT+ADD(pc)+LDR+BL. The ADD(pc) separates the patched |
| 9187 | // offset instructions MOVW+MOVT from the entrypoint load, so they cannot be fused. |
| 9188 | FALLTHROUGH_INTENDED; |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 9189 | default: { |
| 9190 | LoadMethod(invoke->GetMethodLoadKind(), temp, invoke); |
| 9191 | break; |
| 9192 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9193 | } |
| 9194 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9195 | auto call_code_pointer_member = [&](MemberOffset offset) { |
| 9196 | // LR = callee_method->member; |
| 9197 | GetAssembler()->LoadFromOffset(kLoadWord, lr, RegisterFrom(callee_method), offset.Int32Value()); |
| 9198 | { |
| 9199 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 9200 | // blx in T32 has only 16bit encoding that's why a stricter check for the scope is used. |
| 9201 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9202 | vixl32::k16BitT32InstructionSizeInBytes, |
| 9203 | CodeBufferCheckScope::kExactSize); |
| 9204 | // LR() |
| 9205 | __ blx(lr); |
| 9206 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 9207 | } |
| 9208 | }; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9209 | switch (invoke->GetCodePtrLocation()) { |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9210 | case CodePtrLocation::kCallSelf: |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9211 | { |
| 9212 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 9213 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9214 | vixl32::k32BitT32InstructionSizeInBytes, |
| 9215 | CodeBufferCheckScope::kMaximumSize); |
| 9216 | __ bl(GetFrameEntryLabel()); |
| 9217 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 9218 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9219 | break; |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9220 | case CodePtrLocation::kCallCriticalNative: { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9221 | size_t out_frame_size = |
| 9222 | PrepareCriticalNativeCall<CriticalNativeCallingConventionVisitorARMVIXL, |
| 9223 | kAapcsStackAlignment, |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 9224 | GetCriticalNativeDirectCallFrameSize>(invoke); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9225 | call_code_pointer_member(ArtMethod::EntryPointFromJniOffset(kArmPointerSize)); |
| 9226 | // Move the result when needed due to native and managed ABI mismatch. |
| 9227 | switch (invoke->GetType()) { |
| 9228 | case DataType::Type::kFloat32: |
| 9229 | __ Vmov(s0, r0); |
| 9230 | break; |
| 9231 | case DataType::Type::kFloat64: |
| 9232 | __ Vmov(d0, r0, r1); |
| 9233 | break; |
| 9234 | case DataType::Type::kBool: |
| 9235 | case DataType::Type::kInt8: |
| 9236 | case DataType::Type::kUint16: |
| 9237 | case DataType::Type::kInt16: |
| 9238 | case DataType::Type::kInt32: |
| 9239 | case DataType::Type::kInt64: |
| 9240 | case DataType::Type::kVoid: |
| 9241 | break; |
| 9242 | default: |
| 9243 | DCHECK(false) << invoke->GetType(); |
| 9244 | break; |
| 9245 | } |
| 9246 | if (out_frame_size != 0u) { |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 9247 | DecreaseFrame(out_frame_size); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9248 | } |
| 9249 | break; |
| 9250 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9251 | case CodePtrLocation::kCallArtMethod: |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9252 | call_code_pointer_member(ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize)); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9253 | break; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9254 | } |
| 9255 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9256 | DCHECK(!IsLeafMethod()); |
| 9257 | } |
| 9258 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9259 | void CodeGeneratorARMVIXL::GenerateVirtualCall( |
| 9260 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9261 | vixl32::Register temp = RegisterFrom(temp_location); |
| 9262 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 9263 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
| 9264 | |
| 9265 | // Use the calling convention instead of the location of the receiver, as |
| 9266 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 9267 | // slow path, the arguments have been moved to the right place, so here we are |
| 9268 | // guaranteed that the receiver is the first register of the calling convention. |
| 9269 | InvokeDexCallingConventionARMVIXL calling_convention; |
| 9270 | vixl32::Register receiver = calling_convention.GetRegisterAt(0); |
| 9271 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9272 | { |
| 9273 | // Make sure the pc is recorded immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 9274 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9275 | vixl32::kMaxInstructionSizeInBytes, |
| 9276 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9277 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 9278 | __ ldr(temp, MemOperand(receiver, class_offset)); |
| 9279 | MaybeRecordImplicitNullCheck(invoke); |
| 9280 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9281 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 9282 | // emit a read barrier for the previous class reference load. |
| 9283 | // However this is not required in practice, as this is an |
| 9284 | // intermediate/temporary reference and because the current |
| 9285 | // concurrent copying collector keeps the from-space memory |
| 9286 | // intact/accessible until the end of the marking phase (the |
| 9287 | // concurrent copying collector may not in the future). |
| 9288 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 9289 | |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 9290 | // If we're compiling baseline, update the inline cache. |
| 9291 | MaybeGenerateInlineCacheCheck(invoke, temp); |
| 9292 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9293 | // temp = temp->GetMethodAt(method_offset); |
| 9294 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 9295 | kArmPointerSize).Int32Value(); |
| 9296 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 9297 | // LR = temp->GetEntryPoint(); |
| 9298 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9299 | { |
| 9300 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 9301 | // blx in T32 has only 16bit encoding that's why a stricter check for the scope is used. |
| 9302 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9303 | vixl32::k16BitT32InstructionSizeInBytes, |
| 9304 | CodeBufferCheckScope::kExactSize); |
| 9305 | // LR(); |
| 9306 | __ blx(lr); |
| 9307 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 9308 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9309 | } |
| 9310 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9311 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageIntrinsicPatch( |
| 9312 | uint32_t intrinsic_data) { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 9313 | return NewPcRelativePatch(/* dex_file= */ nullptr, intrinsic_data, &boot_image_other_patches_); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9314 | } |
| 9315 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 9316 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageRelRoPatch( |
| 9317 | uint32_t boot_image_offset) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9318 | return NewPcRelativePatch(/* dex_file= */ nullptr, |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 9319 | boot_image_offset, |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 9320 | &boot_image_other_patches_); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 9321 | } |
| 9322 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9323 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageMethodPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9324 | MethodReference target_method) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9325 | return NewPcRelativePatch( |
| 9326 | target_method.dex_file, target_method.index, &boot_image_method_patches_); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9327 | } |
| 9328 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9329 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewMethodBssEntryPatch( |
| 9330 | MethodReference target_method) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9331 | return NewPcRelativePatch( |
| 9332 | target_method.dex_file, target_method.index, &method_bss_entry_patches_); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9333 | } |
| 9334 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9335 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageTypePatch( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9336 | const DexFile& dex_file, dex::TypeIndex type_index) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9337 | return NewPcRelativePatch(&dex_file, type_index.index_, &boot_image_type_patches_); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9338 | } |
| 9339 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9340 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewTypeBssEntryPatch( |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 9341 | HLoadClass* load_class) { |
| 9342 | const DexFile& dex_file = load_class->GetDexFile(); |
| 9343 | dex::TypeIndex type_index = load_class->GetTypeIndex(); |
| 9344 | ArenaDeque<PcRelativePatchInfo>* patches = nullptr; |
| 9345 | switch (load_class->GetLoadKind()) { |
| 9346 | case HLoadClass::LoadKind::kBssEntry: |
| 9347 | patches = &type_bss_entry_patches_; |
| 9348 | break; |
| 9349 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 9350 | patches = &public_type_bss_entry_patches_; |
| 9351 | break; |
| 9352 | case HLoadClass::LoadKind::kBssEntryPackage: |
| 9353 | patches = &package_type_bss_entry_patches_; |
| 9354 | break; |
| 9355 | default: |
| 9356 | LOG(FATAL) << "Unexpected load kind: " << load_class->GetLoadKind(); |
| 9357 | UNREACHABLE(); |
| 9358 | } |
Vladimir Marko | baade40 | 2020-09-30 14:45:39 +0000 | [diff] [blame] | 9359 | return NewPcRelativePatch(&dex_file, type_index.index_, patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9360 | } |
| 9361 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9362 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageStringPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9363 | const DexFile& dex_file, dex::StringIndex string_index) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9364 | return NewPcRelativePatch(&dex_file, string_index.index_, &boot_image_string_patches_); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9365 | } |
| 9366 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 9367 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewStringBssEntryPatch( |
| 9368 | const DexFile& dex_file, dex::StringIndex string_index) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9369 | return NewPcRelativePatch(&dex_file, string_index.index_, &string_bss_entry_patches_); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 9370 | } |
| 9371 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9372 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativePatch( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9373 | const DexFile* dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9374 | patches->emplace_back(dex_file, offset_or_index); |
| 9375 | return &patches->back(); |
| 9376 | } |
| 9377 | |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9378 | void CodeGeneratorARMVIXL::EmitEntrypointThunkCall(ThreadOffset32 entrypoint_offset) { |
| 9379 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 9380 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9381 | call_entrypoint_patches_.emplace_back(/*dex_file*/ nullptr, entrypoint_offset.Uint32Value()); |
| 9382 | vixl::aarch32::Label* bl_label = &call_entrypoint_patches_.back().label; |
| 9383 | __ bind(bl_label); |
| 9384 | vixl32::Label placeholder_label; |
| 9385 | __ bl(&placeholder_label); // Placeholder, patched at link-time. |
| 9386 | __ bind(&placeholder_label); |
| 9387 | } |
| 9388 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 9389 | void CodeGeneratorARMVIXL::EmitBakerReadBarrierBne(uint32_t custom_data) { |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 9390 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 9391 | if (GetCompilerOptions().IsJitCompiler()) { |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 9392 | auto it = jit_baker_read_barrier_slow_paths_.FindOrAdd(custom_data); |
| 9393 | vixl::aarch32::Label* slow_path_entry = &it->second.label; |
| 9394 | __ b(ne, EncodingSize(Wide), slow_path_entry); |
| 9395 | } else { |
| 9396 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 9397 | vixl::aarch32::Label* patch_label = &baker_read_barrier_patches_.back().label; |
| 9398 | __ bind(patch_label); |
| 9399 | vixl32::Label placeholder_label; |
| 9400 | __ b(ne, EncodingSize(Wide), &placeholder_label); // Placeholder, patched at link-time. |
| 9401 | __ bind(&placeholder_label); |
| 9402 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9403 | } |
| 9404 | |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9405 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateBootImageAddressLiteral(uint32_t address) { |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 9406 | return DeduplicateUint32Literal(address, &uint32_literals_); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9407 | } |
| 9408 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 9409 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitStringLiteral( |
| 9410 | const DexFile& dex_file, |
| 9411 | dex::StringIndex string_index, |
| 9412 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9413 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9414 | return jit_string_patches_.GetOrCreate( |
| 9415 | StringReference(&dex_file, string_index), |
| 9416 | [this]() { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9417 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ 0u); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9418 | }); |
| 9419 | } |
| 9420 | |
| 9421 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 9422 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 9423 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9424 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9425 | return jit_class_patches_.GetOrCreate( |
| 9426 | TypeReference(&dex_file, type_index), |
| 9427 | [this]() { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9428 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ 0u); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9429 | }); |
| 9430 | } |
| 9431 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9432 | void CodeGeneratorARMVIXL::LoadBootImageAddress(vixl32::Register reg, |
| 9433 | uint32_t boot_image_reference) { |
| 9434 | if (GetCompilerOptions().IsBootImage()) { |
| 9435 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 9436 | NewBootImageIntrinsicPatch(boot_image_reference); |
| 9437 | EmitMovwMovtPlaceholder(labels, reg); |
Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 9438 | } else if (GetCompilerOptions().GetCompilePic()) { |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9439 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 9440 | NewBootImageRelRoPatch(boot_image_reference); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 9441 | EmitMovwMovtPlaceholder(labels, reg); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9442 | __ Ldr(reg, MemOperand(reg, /* offset= */ 0)); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 9443 | } else { |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 9444 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 9445 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 9446 | DCHECK(!heap->GetBootImageSpaces().empty()); |
| 9447 | uintptr_t address = |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9448 | reinterpret_cast<uintptr_t>(heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 9449 | __ Ldr(reg, DeduplicateBootImageAddressLiteral(dchecked_integral_cast<uint32_t>(address))); |
| 9450 | } |
| 9451 | } |
| 9452 | |
Vladimir Marko | 7968cae | 2021-01-19 12:02:35 +0000 | [diff] [blame] | 9453 | void CodeGeneratorARMVIXL::LoadTypeForBootImageIntrinsic(vixl::aarch32::Register reg, |
| 9454 | TypeReference target_type) { |
| 9455 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
| 9456 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 9457 | PcRelativePatchInfo* labels = |
| 9458 | NewBootImageTypePatch(*target_type.dex_file, target_type.TypeIndex()); |
| 9459 | EmitMovwMovtPlaceholder(labels, reg); |
| 9460 | } |
| 9461 | |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 9462 | void CodeGeneratorARMVIXL::LoadIntrinsicDeclaringClass(vixl32::Register reg, HInvoke* invoke) { |
| 9463 | DCHECK_NE(invoke->GetIntrinsic(), Intrinsics::kNone); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9464 | if (GetCompilerOptions().IsBootImage()) { |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 9465 | MethodReference target_method = invoke->GetResolvedMethodReference(); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9466 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
Vladimir Marko | 7968cae | 2021-01-19 12:02:35 +0000 | [diff] [blame] | 9467 | LoadTypeForBootImageIntrinsic(reg, TypeReference(target_method.dex_file, type_idx)); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9468 | } else { |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 9469 | uint32_t boot_image_offset = GetBootImageOffsetOfIntrinsicDeclaringClass(invoke); |
| 9470 | LoadBootImageAddress(reg, boot_image_offset); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9471 | } |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9472 | } |
| 9473 | |
Vladimir Marko | 7968cae | 2021-01-19 12:02:35 +0000 | [diff] [blame] | 9474 | void CodeGeneratorARMVIXL::LoadClassRootForIntrinsic(vixl::aarch32::Register reg, |
| 9475 | ClassRoot class_root) { |
| 9476 | if (GetCompilerOptions().IsBootImage()) { |
| 9477 | ScopedObjectAccess soa(Thread::Current()); |
| 9478 | ObjPtr<mirror::Class> klass = GetClassRoot(class_root); |
| 9479 | TypeReference target_type(&klass->GetDexFile(), klass->GetDexTypeIndex()); |
| 9480 | LoadTypeForBootImageIntrinsic(reg, target_type); |
| 9481 | } else { |
| 9482 | uint32_t boot_image_offset = GetBootImageOffset(class_root); |
| 9483 | LoadBootImageAddress(reg, boot_image_offset); |
| 9484 | } |
| 9485 | } |
| 9486 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9487 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9488 | inline void CodeGeneratorARMVIXL::EmitPcRelativeLinkerPatches( |
| 9489 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9490 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9491 | for (const PcRelativePatchInfo& info : infos) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9492 | const DexFile* dex_file = info.target_dex_file; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9493 | size_t offset_or_index = info.offset_or_index; |
| 9494 | DCHECK(info.add_pc_label.IsBound()); |
| 9495 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.GetLocation()); |
| 9496 | // Add MOVW patch. |
| 9497 | DCHECK(info.movw_label.IsBound()); |
| 9498 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.GetLocation()); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9499 | linker_patches->push_back(Factory(movw_offset, dex_file, add_pc_offset, offset_or_index)); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9500 | // Add MOVT patch. |
| 9501 | DCHECK(info.movt_label.IsBound()); |
| 9502 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.GetLocation()); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9503 | linker_patches->push_back(Factory(movt_offset, dex_file, add_pc_offset, offset_or_index)); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9504 | } |
| 9505 | } |
| 9506 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9507 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 9508 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 9509 | const DexFile* target_dex_file, |
| 9510 | uint32_t pc_insn_offset, |
| 9511 | uint32_t boot_image_offset) { |
| 9512 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 9513 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 9514 | } |
| 9515 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9516 | void CodeGeneratorARMVIXL::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9517 | DCHECK(linker_patches->empty()); |
| 9518 | size_t size = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9519 | /* MOVW+MOVT for each entry */ 2u * boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9520 | /* MOVW+MOVT for each entry */ 2u * method_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9521 | /* MOVW+MOVT for each entry */ 2u * boot_image_type_patches_.size() + |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9522 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size() + |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 9523 | /* MOVW+MOVT for each entry */ 2u * public_type_bss_entry_patches_.size() + |
| 9524 | /* MOVW+MOVT for each entry */ 2u * package_type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9525 | /* MOVW+MOVT for each entry */ 2u * boot_image_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 9526 | /* MOVW+MOVT for each entry */ 2u * string_bss_entry_patches_.size() + |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 9527 | /* MOVW+MOVT for each entry */ 2u * boot_image_other_patches_.size() + |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9528 | call_entrypoint_patches_.size() + |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9529 | baker_read_barrier_patches_.size(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9530 | linker_patches->reserve(size); |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 9531 | if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9532 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9533 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9534 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9535 | boot_image_type_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9536 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9537 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9538 | } else { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 9539 | DCHECK(boot_image_method_patches_.empty()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 9540 | DCHECK(boot_image_type_patches_.empty()); |
| 9541 | DCHECK(boot_image_string_patches_.empty()); |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 9542 | } |
| 9543 | if (GetCompilerOptions().IsBootImage()) { |
| 9544 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 9545 | boot_image_other_patches_, linker_patches); |
| 9546 | } else { |
| 9547 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| 9548 | boot_image_other_patches_, linker_patches); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9549 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9550 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 9551 | method_bss_entry_patches_, linker_patches); |
| 9552 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 9553 | type_bss_entry_patches_, linker_patches); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 9554 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PublicTypeBssEntryPatch>( |
| 9555 | public_type_bss_entry_patches_, linker_patches); |
| 9556 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PackageTypeBssEntryPatch>( |
| 9557 | package_type_bss_entry_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9558 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 9559 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9560 | for (const PatchInfo<vixl32::Label>& info : call_entrypoint_patches_) { |
| 9561 | DCHECK(info.target_dex_file == nullptr); |
| 9562 | linker_patches->push_back(linker::LinkerPatch::CallEntrypointPatch( |
| 9563 | info.label.GetLocation(), info.offset_or_index)); |
| 9564 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9565 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9566 | linker_patches->push_back(linker::LinkerPatch::BakerReadBarrierBranchPatch( |
| 9567 | info.label.GetLocation(), info.custom_data)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9568 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9569 | DCHECK_EQ(size, linker_patches->size()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9570 | } |
| 9571 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9572 | bool CodeGeneratorARMVIXL::NeedsThunkCode(const linker::LinkerPatch& patch) const { |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9573 | return patch.GetType() == linker::LinkerPatch::Type::kCallEntrypoint || |
| 9574 | patch.GetType() == linker::LinkerPatch::Type::kBakerReadBarrierBranch || |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9575 | patch.GetType() == linker::LinkerPatch::Type::kCallRelative; |
| 9576 | } |
| 9577 | |
| 9578 | void CodeGeneratorARMVIXL::EmitThunkCode(const linker::LinkerPatch& patch, |
| 9579 | /*out*/ ArenaVector<uint8_t>* code, |
| 9580 | /*out*/ std::string* debug_name) { |
| 9581 | arm::ArmVIXLAssembler assembler(GetGraph()->GetAllocator()); |
| 9582 | switch (patch.GetType()) { |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9583 | case linker::LinkerPatch::Type::kCallRelative: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9584 | // The thunk just uses the entry point in the ArtMethod. This works even for calls |
| 9585 | // to the generic JNI and interpreter trampolines. |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9586 | MemberOffset offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
| 9587 | assembler.LoadFromOffset(arm::kLoadWord, vixl32::pc, vixl32::r0, offset.Int32Value()); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9588 | assembler.GetVIXLAssembler()->Bkpt(0); |
| 9589 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 9590 | *debug_name = "MethodCallThunk"; |
| 9591 | } |
| 9592 | break; |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9593 | } |
| 9594 | case linker::LinkerPatch::Type::kCallEntrypoint: { |
| 9595 | assembler.LoadFromOffset(arm::kLoadWord, vixl32::pc, tr, patch.EntrypointOffset()); |
| 9596 | assembler.GetVIXLAssembler()->Bkpt(0); |
| 9597 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 9598 | *debug_name = "EntrypointCallThunk_" + std::to_string(patch.EntrypointOffset()); |
| 9599 | } |
| 9600 | break; |
| 9601 | } |
| 9602 | case linker::LinkerPatch::Type::kBakerReadBarrierBranch: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9603 | DCHECK_EQ(patch.GetBakerCustomValue2(), 0u); |
| 9604 | CompileBakerReadBarrierThunk(assembler, patch.GetBakerCustomValue1(), debug_name); |
| 9605 | break; |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9606 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9607 | default: |
| 9608 | LOG(FATAL) << "Unexpected patch type " << patch.GetType(); |
| 9609 | UNREACHABLE(); |
| 9610 | } |
| 9611 | |
| 9612 | // Ensure we emit the literal pool if any. |
| 9613 | assembler.FinalizeCode(); |
| 9614 | code->resize(assembler.CodeSize()); |
| 9615 | MemoryRegion code_region(code->data(), code->size()); |
| 9616 | assembler.FinalizeInstructions(code_region); |
| 9617 | } |
| 9618 | |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9619 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateUint32Literal( |
| 9620 | uint32_t value, |
| 9621 | Uint32ToLiteralMap* map) { |
| 9622 | return map->GetOrCreate( |
| 9623 | value, |
| 9624 | [this, value]() { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9625 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ value); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9626 | }); |
| 9627 | } |
| 9628 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 9629 | void LocationsBuilderARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 9630 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9631 | new (GetGraph()->GetAllocator()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 9632 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 9633 | Location::RequiresRegister()); |
| 9634 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 9635 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 9636 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 9637 | } |
| 9638 | |
| 9639 | void InstructionCodeGeneratorARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 9640 | vixl32::Register res = OutputRegister(instr); |
| 9641 | vixl32::Register accumulator = |
| 9642 | InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 9643 | vixl32::Register mul_left = |
| 9644 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 9645 | vixl32::Register mul_right = |
| 9646 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
| 9647 | |
| 9648 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 9649 | __ Mla(res, mul_left, mul_right, accumulator); |
| 9650 | } else { |
| 9651 | __ Mls(res, mul_left, mul_right, accumulator); |
| 9652 | } |
| 9653 | } |
| 9654 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9655 | void LocationsBuilderARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9656 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9657 | LOG(FATAL) << "Unreachable"; |
| 9658 | } |
| 9659 | |
| 9660 | void InstructionCodeGeneratorARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9661 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9662 | LOG(FATAL) << "Unreachable"; |
| 9663 | } |
| 9664 | |
| 9665 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 9666 | void LocationsBuilderARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9667 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9668 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9669 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9670 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
| 9671 | codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 9672 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 9673 | if (switch_instr->GetStartValue() != 0) { |
| 9674 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 9675 | } |
| 9676 | } |
| 9677 | } |
| 9678 | |
| 9679 | // TODO(VIXL): Investigate and reach the parity with old arm codegen. |
| 9680 | void InstructionCodeGeneratorARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9681 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 9682 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9683 | LocationSummary* locations = switch_instr->GetLocations(); |
| 9684 | vixl32::Register value_reg = InputRegisterAt(switch_instr, 0); |
| 9685 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 9686 | |
| 9687 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
| 9688 | !codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 9689 | // Create a series of compare/jumps. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9690 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9691 | vixl32::Register temp_reg = temps.Acquire(); |
| 9692 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 9693 | // the immediate, because IP is used as the destination register. For the other |
| 9694 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 9695 | // and they can be encoded in the instruction without making use of IP register. |
| 9696 | __ Adds(temp_reg, value_reg, -lower_bound); |
| 9697 | |
| 9698 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 9699 | // Jump to successors[0] if value == lower_bound. |
| 9700 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 9701 | int32_t last_index = 0; |
| 9702 | for (; num_entries - last_index > 2; last_index += 2) { |
| 9703 | __ Adds(temp_reg, temp_reg, -2); |
| 9704 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 9705 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9706 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 9707 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 9708 | } |
| 9709 | if (num_entries - last_index == 2) { |
| 9710 | // The last missing case_value. |
| 9711 | __ Cmp(temp_reg, 1); |
| 9712 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9713 | } |
| 9714 | |
| 9715 | // And the default for any other value. |
| 9716 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 9717 | __ B(codegen_->GetLabelOf(default_block)); |
| 9718 | } |
| 9719 | } else { |
| 9720 | // Create a table lookup. |
| 9721 | vixl32::Register table_base = RegisterFrom(locations->GetTemp(0)); |
| 9722 | |
| 9723 | JumpTableARMVIXL* jump_table = codegen_->CreateJumpTable(switch_instr); |
| 9724 | |
| 9725 | // Remove the bias. |
| 9726 | vixl32::Register key_reg; |
| 9727 | if (lower_bound != 0) { |
| 9728 | key_reg = RegisterFrom(locations->GetTemp(1)); |
| 9729 | __ Sub(key_reg, value_reg, lower_bound); |
| 9730 | } else { |
| 9731 | key_reg = value_reg; |
| 9732 | } |
| 9733 | |
| 9734 | // Check whether the value is in the table, jump to default block if not. |
| 9735 | __ Cmp(key_reg, num_entries - 1); |
| 9736 | __ B(hi, codegen_->GetLabelOf(default_block)); |
| 9737 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9738 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9739 | vixl32::Register jump_offset = temps.Acquire(); |
| 9740 | |
| 9741 | // Load jump offset from the table. |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9742 | { |
| 9743 | const size_t jump_size = switch_instr->GetNumEntries() * sizeof(int32_t); |
| 9744 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9745 | (vixl32::kMaxInstructionSizeInBytes * 4) + jump_size, |
| 9746 | CodeBufferCheckScope::kMaximumSize); |
| 9747 | __ adr(table_base, jump_table->GetTableStartLabel()); |
| 9748 | __ ldr(jump_offset, MemOperand(table_base, key_reg, vixl32::LSL, 2)); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9749 | |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9750 | // Jump to target block by branching to table_base(pc related) + offset. |
| 9751 | vixl32::Register target_address = table_base; |
| 9752 | __ add(target_address, table_base, jump_offset); |
| 9753 | __ bx(target_address); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 9754 | |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9755 | jump_table->EmitTable(codegen_); |
| 9756 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9757 | } |
| 9758 | } |
| 9759 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9760 | // Copy the result of a call into the given target. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9761 | void CodeGeneratorARMVIXL::MoveFromReturnRegister(Location trg, DataType::Type type) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9762 | if (!trg.IsValid()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9763 | DCHECK_EQ(type, DataType::Type::kVoid); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9764 | return; |
| 9765 | } |
| 9766 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9767 | DCHECK_NE(type, DataType::Type::kVoid); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9768 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9769 | Location return_loc = InvokeDexCallingConventionVisitorARMVIXL().GetReturnLocation(type); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9770 | if (return_loc.Equals(trg)) { |
| 9771 | return; |
| 9772 | } |
| 9773 | |
Vladimir Marko | ac3fcff | 2020-11-17 12:17:58 +0000 | [diff] [blame] | 9774 | // Let the parallel move resolver take care of all of this. |
| 9775 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
| 9776 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 9777 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9778 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9779 | |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9780 | void LocationsBuilderARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 9781 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9782 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9783 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9784 | locations->SetOut(Location::RequiresRegister()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9785 | } |
| 9786 | |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9787 | void InstructionCodeGeneratorARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 9788 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| 9789 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 9790 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
| 9791 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9792 | OutputRegister(instruction), |
| 9793 | InputRegisterAt(instruction, 0), |
| 9794 | method_offset); |
| 9795 | } else { |
| 9796 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 9797 | instruction->GetIndex(), kArmPointerSize)); |
| 9798 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9799 | OutputRegister(instruction), |
| 9800 | InputRegisterAt(instruction, 0), |
| 9801 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 9802 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9803 | OutputRegister(instruction), |
| 9804 | OutputRegister(instruction), |
| 9805 | method_offset); |
| 9806 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9807 | } |
| 9808 | |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9809 | static void PatchJitRootUse(uint8_t* code, |
| 9810 | const uint8_t* roots_data, |
| 9811 | VIXLUInt32Literal* literal, |
| 9812 | uint64_t index_in_table) { |
| 9813 | DCHECK(literal->IsBound()); |
| 9814 | uint32_t literal_offset = literal->GetLocation(); |
| 9815 | uintptr_t address = |
| 9816 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 9817 | uint8_t* data = code + literal_offset; |
| 9818 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 9819 | } |
| 9820 | |
| 9821 | void CodeGeneratorARMVIXL::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 9822 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9823 | const StringReference& string_reference = entry.first; |
| 9824 | VIXLUInt32Literal* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9825 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9826 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9827 | } |
| 9828 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9829 | const TypeReference& type_reference = entry.first; |
| 9830 | VIXLUInt32Literal* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9831 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9832 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9833 | } |
| 9834 | } |
| 9835 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9836 | void CodeGeneratorARMVIXL::EmitMovwMovtPlaceholder( |
| 9837 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels, |
| 9838 | vixl32::Register out) { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 9839 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9840 | 3 * vixl32::kMaxInstructionSizeInBytes, |
| 9841 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9842 | // TODO(VIXL): Think about using mov instead of movw. |
| 9843 | __ bind(&labels->movw_label); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9844 | __ movw(out, /* operand= */ 0u); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9845 | __ bind(&labels->movt_label); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9846 | __ movt(out, /* operand= */ 0u); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9847 | __ bind(&labels->add_pc_label); |
| 9848 | __ add(out, out, pc); |
| 9849 | } |
| 9850 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9851 | #undef __ |
| 9852 | #undef QUICK_ENTRY_POINT |
| 9853 | #undef TODO_VIXL32 |
| 9854 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9855 | #define __ assembler.GetVIXLAssembler()-> |
| 9856 | |
| 9857 | static void EmitGrayCheckAndFastPath(ArmVIXLAssembler& assembler, |
| 9858 | vixl32::Register base_reg, |
| 9859 | vixl32::MemOperand& lock_word, |
| 9860 | vixl32::Label* slow_path, |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9861 | int32_t raw_ldr_offset, |
| 9862 | vixl32::Label* throw_npe = nullptr) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9863 | // Load the lock word containing the rb_state. |
| 9864 | __ Ldr(ip, lock_word); |
| 9865 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
Roland Levillain | 14e5a29 | 2018-06-28 12:00:56 +0100 | [diff] [blame] | 9866 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9867 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 9868 | __ Tst(ip, Operand(LockWord::kReadBarrierStateMaskShifted)); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9869 | __ B(ne, slow_path, /* is_far_target= */ false); |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9870 | // To throw NPE, we return to the fast path; the artificial dependence below does not matter. |
| 9871 | if (throw_npe != nullptr) { |
| 9872 | __ Bind(throw_npe); |
| 9873 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9874 | __ Add(lr, lr, raw_ldr_offset); |
| 9875 | // Introduce a dependency on the lock_word including rb_state, |
| 9876 | // to prevent load-load reordering, and without using |
| 9877 | // a memory barrier (which would be more expensive). |
| 9878 | __ Add(base_reg, base_reg, Operand(ip, LSR, 32)); |
| 9879 | __ Bx(lr); // And return back to the function. |
| 9880 | // Note: The fake dependency is unnecessary for the slow path. |
| 9881 | } |
| 9882 | |
| 9883 | // Load the read barrier introspection entrypoint in register `entrypoint` |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 9884 | static vixl32::Register LoadReadBarrierMarkIntrospectionEntrypoint(ArmVIXLAssembler& assembler) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9885 | // The register where the read barrier introspection entrypoint is loaded |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 9886 | // is the marking register. We clobber it here and the entrypoint restores it to 1. |
| 9887 | vixl32::Register entrypoint = mr; |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9888 | // entrypoint = Thread::Current()->pReadBarrierMarkReg12, i.e. pReadBarrierMarkIntrospection. |
| 9889 | DCHECK_EQ(ip.GetCode(), 12u); |
| 9890 | const int32_t entry_point_offset = |
| 9891 | Thread::ReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ip.GetCode()); |
| 9892 | __ Ldr(entrypoint, MemOperand(tr, entry_point_offset)); |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 9893 | return entrypoint; |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9894 | } |
| 9895 | |
| 9896 | void CodeGeneratorARMVIXL::CompileBakerReadBarrierThunk(ArmVIXLAssembler& assembler, |
| 9897 | uint32_t encoded_data, |
| 9898 | /*out*/ std::string* debug_name) { |
| 9899 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 9900 | switch (kind) { |
| 9901 | case BakerReadBarrierKind::kField: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9902 | vixl32::Register base_reg(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 9903 | CheckValidReg(base_reg.GetCode()); |
| 9904 | vixl32::Register holder_reg(BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 9905 | CheckValidReg(holder_reg.GetCode()); |
| 9906 | BakerReadBarrierWidth width = BakerReadBarrierWidthField::Decode(encoded_data); |
| 9907 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 9908 | temps.Exclude(ip); |
Roland Levillain | 988c391 | 2019-09-25 19:33:35 +0100 | [diff] [blame] | 9909 | // In the case of a field load, if `base_reg` differs from |
| 9910 | // `holder_reg`, the offset was too large and we must have emitted (during the construction |
| 9911 | // of the HIR graph, see `art::HInstructionBuilder::BuildInstanceFieldAccess`) and preserved |
| 9912 | // (see `art::PrepareForRegisterAllocation::VisitNullCheck`) an explicit null check before |
| 9913 | // the load. Otherwise, for implicit null checks, we need to null-check the holder as we do |
| 9914 | // not necessarily do that check before going to the thunk. |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9915 | vixl32::Label throw_npe_label; |
| 9916 | vixl32::Label* throw_npe = nullptr; |
| 9917 | if (GetCompilerOptions().GetImplicitNullChecks() && holder_reg.Is(base_reg)) { |
| 9918 | throw_npe = &throw_npe_label; |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9919 | __ CompareAndBranchIfZero(holder_reg, throw_npe, /* is_far_target= */ false); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9920 | } |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9921 | // Check if the holder is gray and, if not, add fake dependency to the base register |
| 9922 | // and return to the LDR instruction to load the reference. Otherwise, use introspection |
| 9923 | // to load the reference and call the entrypoint that performs further checks on the |
| 9924 | // reference and marks it if needed. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9925 | vixl32::Label slow_path; |
| 9926 | MemOperand lock_word(holder_reg, mirror::Object::MonitorOffset().Int32Value()); |
| 9927 | const int32_t raw_ldr_offset = (width == BakerReadBarrierWidth::kWide) |
| 9928 | ? BAKER_MARK_INTROSPECTION_FIELD_LDR_WIDE_OFFSET |
| 9929 | : BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_OFFSET; |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9930 | EmitGrayCheckAndFastPath( |
| 9931 | assembler, base_reg, lock_word, &slow_path, raw_ldr_offset, throw_npe); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9932 | __ Bind(&slow_path); |
| 9933 | const int32_t ldr_offset = /* Thumb state adjustment (LR contains Thumb state). */ -1 + |
| 9934 | raw_ldr_offset; |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 9935 | vixl32::Register ep_reg = LoadReadBarrierMarkIntrospectionEntrypoint(assembler); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9936 | if (width == BakerReadBarrierWidth::kWide) { |
| 9937 | MemOperand ldr_half_address(lr, ldr_offset + 2); |
| 9938 | __ Ldrh(ip, ldr_half_address); // Load the LDR immediate half-word with "Rt | imm12". |
| 9939 | __ Ubfx(ip, ip, 0, 12); // Extract the offset imm12. |
| 9940 | __ Ldr(ip, MemOperand(base_reg, ip)); // Load the reference. |
| 9941 | } else { |
| 9942 | MemOperand ldr_address(lr, ldr_offset); |
| 9943 | __ Ldrh(ip, ldr_address); // Load the LDR immediate, encoding T1. |
| 9944 | __ Add(ep_reg, // Adjust the entrypoint address to the entrypoint |
| 9945 | ep_reg, // for narrow LDR. |
| 9946 | Operand(BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_ENTRYPOINT_OFFSET)); |
| 9947 | __ Ubfx(ip, ip, 6, 5); // Extract the imm5, i.e. offset / 4. |
| 9948 | __ Ldr(ip, MemOperand(base_reg, ip, LSL, 2)); // Load the reference. |
| 9949 | } |
| 9950 | // Do not unpoison. With heap poisoning enabled, the entrypoint expects a poisoned reference. |
| 9951 | __ Bx(ep_reg); // Jump to the entrypoint. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9952 | break; |
| 9953 | } |
| 9954 | case BakerReadBarrierKind::kArray: { |
| 9955 | vixl32::Register base_reg(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 9956 | CheckValidReg(base_reg.GetCode()); |
| 9957 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 9958 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 9959 | DCHECK(BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide); |
| 9960 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 9961 | temps.Exclude(ip); |
| 9962 | vixl32::Label slow_path; |
| 9963 | int32_t data_offset = |
| 9964 | mirror::Array::DataOffset(Primitive::ComponentSize(Primitive::kPrimNot)).Int32Value(); |
| 9965 | MemOperand lock_word(base_reg, mirror::Object::MonitorOffset().Int32Value() - data_offset); |
| 9966 | DCHECK_LT(lock_word.GetOffsetImmediate(), 0); |
| 9967 | const int32_t raw_ldr_offset = BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET; |
| 9968 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path, raw_ldr_offset); |
| 9969 | __ Bind(&slow_path); |
| 9970 | const int32_t ldr_offset = /* Thumb state adjustment (LR contains Thumb state). */ -1 + |
| 9971 | raw_ldr_offset; |
| 9972 | MemOperand ldr_address(lr, ldr_offset + 2); |
| 9973 | __ Ldrb(ip, ldr_address); // Load the LDR (register) byte with "00 | imm2 | Rm", |
| 9974 | // i.e. Rm+32 because the scale in imm2 is 2. |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 9975 | vixl32::Register ep_reg = LoadReadBarrierMarkIntrospectionEntrypoint(assembler); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9976 | __ Bfi(ep_reg, ip, 3, 6); // Insert ip to the entrypoint address to create |
| 9977 | // a switch case target based on the index register. |
| 9978 | __ Mov(ip, base_reg); // Move the base register to ip0. |
| 9979 | __ Bx(ep_reg); // Jump to the entrypoint's array switch case. |
| 9980 | break; |
| 9981 | } |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 9982 | case BakerReadBarrierKind::kGcRoot: |
Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 9983 | case BakerReadBarrierKind::kIntrinsicCas: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9984 | // Check if the reference needs to be marked and if so (i.e. not null, not marked yet |
| 9985 | // and it does not have a forwarding address), call the correct introspection entrypoint; |
| 9986 | // otherwise return the reference (or the extracted forwarding address). |
| 9987 | // There is no gray bit check for GC roots. |
| 9988 | vixl32::Register root_reg(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 9989 | CheckValidReg(root_reg.GetCode()); |
| 9990 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 9991 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 9992 | BakerReadBarrierWidth width = BakerReadBarrierWidthField::Decode(encoded_data); |
| 9993 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 9994 | temps.Exclude(ip); |
| 9995 | vixl32::Label return_label, not_marked, forwarding_address; |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9996 | __ CompareAndBranchIfZero(root_reg, &return_label, /* is_far_target= */ false); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9997 | MemOperand lock_word(root_reg, mirror::Object::MonitorOffset().Int32Value()); |
| 9998 | __ Ldr(ip, lock_word); |
| 9999 | __ Tst(ip, LockWord::kMarkBitStateMaskShifted); |
| 10000 | __ B(eq, ¬_marked); |
| 10001 | __ Bind(&return_label); |
| 10002 | __ Bx(lr); |
| 10003 | __ Bind(¬_marked); |
| 10004 | static_assert(LockWord::kStateShift == 30 && LockWord::kStateForwardingAddress == 3, |
| 10005 | "To use 'CMP ip, #modified-immediate; BHS', we need the lock word state in " |
| 10006 | " the highest bits and the 'forwarding address' state to have all bits set"); |
| 10007 | __ Cmp(ip, Operand(0xc0000000)); |
| 10008 | __ B(hs, &forwarding_address); |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 10009 | vixl32::Register ep_reg = LoadReadBarrierMarkIntrospectionEntrypoint(assembler); |
Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 10010 | // Adjust the art_quick_read_barrier_mark_introspection address |
| 10011 | // in kBakerCcEntrypointRegister to one of |
| 10012 | // art_quick_read_barrier_mark_introspection_{gc_roots_{wide,narrow},intrinsic_cas}. |
| 10013 | if (kind == BakerReadBarrierKind::kIntrinsicCas) { |
| 10014 | DCHECK(width == BakerReadBarrierWidth::kWide); |
| 10015 | DCHECK(!root_reg.IsLow()); |
| 10016 | } |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 10017 | int32_t entrypoint_offset = |
| 10018 | (kind == BakerReadBarrierKind::kGcRoot) |
| 10019 | ? (width == BakerReadBarrierWidth::kWide) |
| 10020 | ? BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_ENTRYPOINT_OFFSET |
| 10021 | : BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_ENTRYPOINT_OFFSET |
Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 10022 | : BAKER_MARK_INTROSPECTION_INTRINSIC_CAS_ENTRYPOINT_OFFSET; |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 10023 | __ Add(ep_reg, ep_reg, Operand(entrypoint_offset)); |
| 10024 | __ Mov(ip, root_reg); |
| 10025 | __ Bx(ep_reg); |
| 10026 | __ Bind(&forwarding_address); |
| 10027 | __ Lsl(root_reg, ip, LockWord::kForwardingAddressShift); |
| 10028 | __ Bx(lr); |
| 10029 | break; |
| 10030 | } |
| 10031 | default: |
| 10032 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 10033 | UNREACHABLE(); |
| 10034 | } |
| 10035 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 10036 | // For JIT, the slow path is considered part of the compiled method, |
Vladimir Marko | f91fc12 | 2020-05-13 09:21:00 +0100 | [diff] [blame] | 10037 | // so JIT should pass null as `debug_name`. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 10038 | DCHECK(!GetCompilerOptions().IsJitCompiler() || debug_name == nullptr); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 10039 | if (debug_name != nullptr && GetCompilerOptions().GenerateAnyDebugInfo()) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 10040 | std::ostringstream oss; |
| 10041 | oss << "BakerReadBarrierThunk"; |
| 10042 | switch (kind) { |
| 10043 | case BakerReadBarrierKind::kField: |
| 10044 | oss << "Field"; |
| 10045 | if (BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide) { |
| 10046 | oss << "Wide"; |
| 10047 | } |
| 10048 | oss << "_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 10049 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 10050 | break; |
| 10051 | case BakerReadBarrierKind::kArray: |
| 10052 | oss << "Array_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 10053 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 10054 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 10055 | DCHECK(BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide); |
| 10056 | break; |
| 10057 | case BakerReadBarrierKind::kGcRoot: |
| 10058 | oss << "GcRoot"; |
| 10059 | if (BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide) { |
| 10060 | oss << "Wide"; |
| 10061 | } |
| 10062 | oss << "_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 10063 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 10064 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 10065 | break; |
Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 10066 | case BakerReadBarrierKind::kIntrinsicCas: |
| 10067 | oss << "IntrinsicCas_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 10068 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 10069 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 10070 | DCHECK(BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide); |
| 10071 | break; |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 10072 | } |
| 10073 | *debug_name = oss.str(); |
| 10074 | } |
| 10075 | } |
| 10076 | |
| 10077 | #undef __ |
| 10078 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 10079 | } // namespace arm |
| 10080 | } // namespace art |