| 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() || |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 764 | instruction_->IsPredicatedInstanceFieldGet() || |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 765 | instruction_->IsStaticFieldGet() || |
| 766 | instruction_->IsArrayGet() || |
| 767 | instruction_->IsInstanceOf() || |
| 768 | instruction_->IsCheckCast() || |
| Vladimir Marko | 94d2c81 | 2020-11-05 10:04:45 +0000 | [diff] [blame] | 769 | (instruction_->IsInvoke() && instruction_->GetLocations()->Intrinsified())) |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 770 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 771 | << instruction_->DebugName(); |
| 772 | // The read barrier instrumentation of object ArrayGet |
| 773 | // instructions does not support the HIntermediateAddress |
| 774 | // instruction. |
| 775 | DCHECK(!(instruction_->IsArrayGet() && |
| 776 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 777 | |
| 778 | __ Bind(GetEntryLabel()); |
| 779 | SaveLiveRegisters(codegen, locations); |
| 780 | |
| 781 | // We may have to change the index's value, but as `index_` is a |
| 782 | // constant member (like other "inputs" of this slow path), |
| 783 | // introduce a copy of it, `index`. |
| 784 | Location index = index_; |
| 785 | if (index_.IsValid()) { |
| 786 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 787 | if (instruction_->IsArrayGet()) { |
| 788 | // Compute the actual memory offset and store it in `index`. |
| 789 | vixl32::Register index_reg = RegisterFrom(index_); |
| 790 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg.GetCode())); |
| 791 | if (codegen->IsCoreCalleeSaveRegister(index_reg.GetCode())) { |
| 792 | // We are about to change the value of `index_reg` (see the |
| Roland Levillain | 9983e30 | 2017-07-14 14:34:22 +0100 | [diff] [blame] | 793 | // calls to art::arm::ArmVIXLMacroAssembler::Lsl and |
| 794 | // art::arm::ArmVIXLMacroAssembler::Add below), but it has |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 795 | // not been saved by the previous call to |
| 796 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 797 | // callee-save register -- |
| 798 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 799 | // callee-save registers, as it has been designed with the |
| 800 | // assumption that callee-save registers are supposed to be |
| 801 | // handled by the called function. So, as a callee-save |
| 802 | // register, `index_reg` _would_ eventually be saved onto |
| 803 | // the stack, but it would be too late: we would have |
| 804 | // changed its value earlier. Therefore, we manually save |
| 805 | // it here into another freely available register, |
| 806 | // `free_reg`, chosen of course among the caller-save |
| 807 | // registers (as a callee-save `free_reg` register would |
| 808 | // exhibit the same problem). |
| 809 | // |
| 810 | // Note we could have requested a temporary register from |
| 811 | // the register allocator instead; but we prefer not to, as |
| 812 | // this is a slow path, and we know we can find a |
| 813 | // caller-save register that is available. |
| 814 | vixl32::Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 815 | __ Mov(free_reg, index_reg); |
| 816 | index_reg = free_reg; |
| 817 | index = LocationFrom(index_reg); |
| 818 | } else { |
| 819 | // The initial register stored in `index_` has already been |
| 820 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 821 | // (as it is not a callee-save register), so we can freely |
| 822 | // use it. |
| 823 | } |
| 824 | // Shifting the index value contained in `index_reg` by the scale |
| 825 | // factor (2) cannot overflow in practice, as the runtime is |
| 826 | // unable to allocate object arrays with a size larger than |
| 827 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 828 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 829 | static_assert( |
| 830 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 831 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 832 | __ Add(index_reg, index_reg, offset_); |
| 833 | } else { |
| 834 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 835 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 836 | // (as in the case of ArrayGet), as it is actually an offset |
| 837 | // to an object field within an object. |
| 838 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| 839 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| Vladimir Marko | ac3fcff | 2020-11-17 12:17:58 +0000 | [diff] [blame] | 840 | Intrinsics intrinsic = instruction_->AsInvoke()->GetIntrinsic(); |
| 841 | DCHECK(intrinsic == Intrinsics::kUnsafeGetObject || |
| 842 | intrinsic == Intrinsics::kUnsafeGetObjectVolatile || |
| Sorin Basca | 2f01e8e | 2021-06-18 06:44:07 +0000 | [diff] [blame] | 843 | intrinsic == Intrinsics::kJdkUnsafeGetObject || |
| 844 | intrinsic == Intrinsics::kJdkUnsafeGetObjectVolatile || |
| Sorin Basca | 4a4696a | 2021-10-09 07:14:40 +0000 | [diff] [blame] | 845 | intrinsic == Intrinsics::kJdkUnsafeGetObjectAcquire || |
| Vladimir Marko | ac3fcff | 2020-11-17 12:17:58 +0000 | [diff] [blame] | 846 | mirror::VarHandle::GetAccessModeTemplateByIntrinsic(intrinsic) == |
| Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 847 | mirror::VarHandle::AccessModeTemplate::kGet || |
| 848 | mirror::VarHandle::GetAccessModeTemplateByIntrinsic(intrinsic) == |
| 849 | mirror::VarHandle::AccessModeTemplate::kCompareAndSet || |
| 850 | mirror::VarHandle::GetAccessModeTemplateByIntrinsic(intrinsic) == |
| Vladimir Marko | 526569a | 2020-11-30 15:48:38 +0000 | [diff] [blame] | 851 | mirror::VarHandle::AccessModeTemplate::kCompareAndExchange || |
| 852 | mirror::VarHandle::GetAccessModeTemplateByIntrinsic(intrinsic) == |
| 853 | mirror::VarHandle::AccessModeTemplate::kGetAndUpdate) |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 854 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 855 | DCHECK_EQ(offset_, 0U); |
| Vladimir Marko | ac3fcff | 2020-11-17 12:17:58 +0000 | [diff] [blame] | 856 | // Though UnsafeGet's offset location is a register pair, we only pass the low |
| 857 | // part (high part is irrelevant for 32-bit addresses) to the slow path. |
| 858 | // For VarHandle intrinsics, the index is always just a register. |
| 859 | DCHECK(index_.IsRegister()); |
| 860 | index = index_; |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 861 | } |
| 862 | } |
| 863 | |
| 864 | // We're moving two or three locations to locations that could |
| 865 | // overlap, so we need a parallel move resolver. |
| 866 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 867 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 868 | parallel_move.AddMove(ref_, |
| 869 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 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 | parallel_move.AddMove(obj_, |
| 873 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 874 | DataType::Type::kReference, |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 875 | nullptr); |
| 876 | if (index.IsValid()) { |
| 877 | parallel_move.AddMove(index, |
| 878 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 879 | DataType::Type::kInt32, |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 880 | nullptr); |
| 881 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 882 | } else { |
| 883 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 884 | __ Mov(calling_convention.GetRegisterAt(2), offset_); |
| 885 | } |
| 886 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
| 887 | CheckEntrypointTypes< |
| 888 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 889 | arm_codegen->Move32(out_, LocationFrom(r0)); |
| 890 | |
| 891 | RestoreLiveRegisters(codegen, locations); |
| 892 | __ B(GetExitLabel()); |
| 893 | } |
| 894 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 895 | const char* GetDescription() const override { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 896 | return "ReadBarrierForHeapReferenceSlowPathARMVIXL"; |
| 897 | } |
| 898 | |
| 899 | private: |
| 900 | vixl32::Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 901 | uint32_t ref = RegisterFrom(ref_).GetCode(); |
| 902 | uint32_t obj = RegisterFrom(obj_).GetCode(); |
| 903 | for (uint32_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 904 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 905 | return vixl32::Register(i); |
| 906 | } |
| 907 | } |
| 908 | // We shall never fail to find a free caller-save register, as |
| 909 | // there are more than two core caller-save registers on ARM |
| 910 | // (meaning it is possible to find one which is different from |
| 911 | // `ref` and `obj`). |
| 912 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 913 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 914 | UNREACHABLE(); |
| 915 | } |
| 916 | |
| 917 | const Location out_; |
| 918 | const Location ref_; |
| 919 | const Location obj_; |
| 920 | const uint32_t offset_; |
| 921 | // An additional location containing an index to an array. |
| 922 | // Only used for HArrayGet and the UnsafeGetObject & |
| 923 | // UnsafeGetObjectVolatile intrinsics. |
| 924 | const Location index_; |
| 925 | |
| 926 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARMVIXL); |
| 927 | }; |
| 928 | |
| 929 | // Slow path generating a read barrier for a GC root. |
| 930 | class ReadBarrierForRootSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 931 | public: |
| 932 | ReadBarrierForRootSlowPathARMVIXL(HInstruction* instruction, Location out, Location root) |
| 933 | : SlowPathCodeARMVIXL(instruction), out_(out), root_(root) { |
| 934 | DCHECK(kEmitCompilerReadBarrier); |
| 935 | } |
| 936 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 937 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 938 | LocationSummary* locations = instruction_->GetLocations(); |
| 939 | vixl32::Register reg_out = RegisterFrom(out_); |
| 940 | DCHECK(locations->CanCall()); |
| 941 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.GetCode())); |
| Vladimir Marko | ac3fcff | 2020-11-17 12:17:58 +0000 | [diff] [blame] | 942 | DCHECK(instruction_->IsLoadClass() || |
| 943 | instruction_->IsLoadString() || |
| 944 | (instruction_->IsInvoke() && instruction_->GetLocations()->Intrinsified())) |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 945 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 946 | << instruction_->DebugName(); |
| 947 | |
| 948 | __ Bind(GetEntryLabel()); |
| 949 | SaveLiveRegisters(codegen, locations); |
| 950 | |
| 951 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 952 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 953 | arm_codegen->Move32(LocationFrom(calling_convention.GetRegisterAt(0)), root_); |
| 954 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| 955 | instruction_, |
| 956 | instruction_->GetDexPc(), |
| 957 | this); |
| 958 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 959 | arm_codegen->Move32(out_, LocationFrom(r0)); |
| 960 | |
| 961 | RestoreLiveRegisters(codegen, locations); |
| 962 | __ B(GetExitLabel()); |
| 963 | } |
| 964 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 965 | const char* GetDescription() const override { return "ReadBarrierForRootSlowPathARMVIXL"; } |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 966 | |
| 967 | private: |
| 968 | const Location out_; |
| 969 | const Location root_; |
| 970 | |
| 971 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARMVIXL); |
| 972 | }; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 973 | |
| Mythri Alle | 2d4feeb | 2021-10-13 15:39:37 +0000 | [diff] [blame^] | 974 | class MethodEntryExitHooksSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 975 | public: |
| 976 | explicit MethodEntryExitHooksSlowPathARMVIXL(HInstruction* instruction) |
| 977 | : SlowPathCodeARMVIXL(instruction) {} |
| 978 | |
| 979 | void EmitNativeCode(CodeGenerator* codegen) override { |
| 980 | LocationSummary* locations = instruction_->GetLocations(); |
| 981 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 982 | QuickEntrypointEnum entry_point = |
| 983 | (instruction_->IsMethodEntryHook()) ? kQuickMethodEntryHook : kQuickMethodExitHook; |
| 984 | __ Bind(GetEntryLabel()); |
| 985 | SaveLiveRegisters(codegen, locations); |
| 986 | arm_codegen->InvokeRuntime(entry_point, instruction_, instruction_->GetDexPc(), this); |
| 987 | RestoreLiveRegisters(codegen, locations); |
| 988 | __ B(GetExitLabel()); |
| 989 | } |
| 990 | |
| 991 | const char* GetDescription() const override { |
| 992 | return "MethodEntryExitHooksSlowPath"; |
| 993 | } |
| 994 | |
| 995 | private: |
| 996 | DISALLOW_COPY_AND_ASSIGN(MethodEntryExitHooksSlowPathARMVIXL); |
| 997 | }; |
| 998 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 999 | inline vixl32::Condition ARMCondition(IfCondition cond) { |
| 1000 | switch (cond) { |
| 1001 | case kCondEQ: return eq; |
| 1002 | case kCondNE: return ne; |
| 1003 | case kCondLT: return lt; |
| 1004 | case kCondLE: return le; |
| 1005 | case kCondGT: return gt; |
| 1006 | case kCondGE: return ge; |
| 1007 | case kCondB: return lo; |
| 1008 | case kCondBE: return ls; |
| 1009 | case kCondA: return hi; |
| 1010 | case kCondAE: return hs; |
| 1011 | } |
| 1012 | LOG(FATAL) << "Unreachable"; |
| 1013 | UNREACHABLE(); |
| 1014 | } |
| 1015 | |
| 1016 | // Maps signed condition to unsigned condition. |
| 1017 | inline vixl32::Condition ARMUnsignedCondition(IfCondition cond) { |
| 1018 | switch (cond) { |
| 1019 | case kCondEQ: return eq; |
| 1020 | case kCondNE: return ne; |
| 1021 | // Signed to unsigned. |
| 1022 | case kCondLT: return lo; |
| 1023 | case kCondLE: return ls; |
| 1024 | case kCondGT: return hi; |
| 1025 | case kCondGE: return hs; |
| 1026 | // Unsigned remain unchanged. |
| 1027 | case kCondB: return lo; |
| 1028 | case kCondBE: return ls; |
| 1029 | case kCondA: return hi; |
| 1030 | case kCondAE: return hs; |
| 1031 | } |
| 1032 | LOG(FATAL) << "Unreachable"; |
| 1033 | UNREACHABLE(); |
| 1034 | } |
| 1035 | |
| 1036 | inline vixl32::Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 1037 | // The ARM condition codes can express all the necessary branches, see the |
| 1038 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 1039 | // There is no dex instruction or HIR that would need the missing conditions |
| 1040 | // "equal or unordered" or "not equal". |
| 1041 | switch (cond) { |
| 1042 | case kCondEQ: return eq; |
| 1043 | case kCondNE: return ne /* unordered */; |
| 1044 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 1045 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 1046 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 1047 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 1048 | default: |
| 1049 | LOG(FATAL) << "UNREACHABLE"; |
| 1050 | UNREACHABLE(); |
| 1051 | } |
| 1052 | } |
| 1053 | |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1054 | inline ShiftType ShiftFromOpKind(HDataProcWithShifterOp::OpKind op_kind) { |
| 1055 | switch (op_kind) { |
| 1056 | case HDataProcWithShifterOp::kASR: return ShiftType::ASR; |
| 1057 | case HDataProcWithShifterOp::kLSL: return ShiftType::LSL; |
| 1058 | case HDataProcWithShifterOp::kLSR: return ShiftType::LSR; |
| 1059 | default: |
| 1060 | LOG(FATAL) << "Unexpected op kind " << op_kind; |
| 1061 | UNREACHABLE(); |
| 1062 | } |
| 1063 | } |
| 1064 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1065 | void CodeGeneratorARMVIXL::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 1066 | stream << vixl32::Register(reg); |
| 1067 | } |
| 1068 | |
| 1069 | void CodeGeneratorARMVIXL::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| 1070 | stream << vixl32::SRegister(reg); |
| 1071 | } |
| 1072 | |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1073 | const ArmInstructionSetFeatures& CodeGeneratorARMVIXL::GetInstructionSetFeatures() const { |
| 1074 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsArmInstructionSetFeatures(); |
| 1075 | } |
| 1076 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1077 | static uint32_t ComputeSRegisterListMask(const SRegisterList& regs) { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1078 | uint32_t mask = 0; |
| 1079 | for (uint32_t i = regs.GetFirstSRegister().GetCode(); |
| 1080 | i <= regs.GetLastSRegister().GetCode(); |
| 1081 | ++i) { |
| 1082 | mask |= (1 << i); |
| 1083 | } |
| 1084 | return mask; |
| 1085 | } |
| 1086 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1087 | // Saves the register in the stack. Returns the size taken on stack. |
| 1088 | size_t CodeGeneratorARMVIXL::SaveCoreRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1089 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1090 | TODO_VIXL32(FATAL); |
| Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 1091 | UNREACHABLE(); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | // Restores the register from the stack. Returns the size taken on stack. |
| 1095 | size_t CodeGeneratorARMVIXL::RestoreCoreRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1096 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1097 | TODO_VIXL32(FATAL); |
| Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 1098 | UNREACHABLE(); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1099 | } |
| 1100 | |
| 1101 | size_t CodeGeneratorARMVIXL::SaveFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1102 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1103 | TODO_VIXL32(FATAL); |
| Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 1104 | UNREACHABLE(); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | size_t CodeGeneratorARMVIXL::RestoreFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1108 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1109 | TODO_VIXL32(FATAL); |
| Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 1110 | UNREACHABLE(); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 1111 | } |
| 1112 | |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1113 | static void GenerateDataProcInstruction(HInstruction::InstructionKind kind, |
| 1114 | vixl32::Register out, |
| 1115 | vixl32::Register first, |
| 1116 | const Operand& second, |
| 1117 | CodeGeneratorARMVIXL* codegen) { |
| 1118 | if (second.IsImmediate() && second.GetImmediate() == 0) { |
| 1119 | const Operand in = kind == HInstruction::kAnd |
| 1120 | ? Operand(0) |
| 1121 | : Operand(first); |
| 1122 | |
| 1123 | __ Mov(out, in); |
| 1124 | } else { |
| 1125 | switch (kind) { |
| 1126 | case HInstruction::kAdd: |
| 1127 | __ Add(out, first, second); |
| 1128 | break; |
| 1129 | case HInstruction::kAnd: |
| 1130 | __ And(out, first, second); |
| 1131 | break; |
| 1132 | case HInstruction::kOr: |
| 1133 | __ Orr(out, first, second); |
| 1134 | break; |
| 1135 | case HInstruction::kSub: |
| 1136 | __ Sub(out, first, second); |
| 1137 | break; |
| 1138 | case HInstruction::kXor: |
| 1139 | __ Eor(out, first, second); |
| 1140 | break; |
| 1141 | default: |
| 1142 | LOG(FATAL) << "Unexpected instruction kind: " << kind; |
| 1143 | UNREACHABLE(); |
| 1144 | } |
| 1145 | } |
| 1146 | } |
| 1147 | |
| 1148 | static void GenerateDataProc(HInstruction::InstructionKind kind, |
| 1149 | const Location& out, |
| 1150 | const Location& first, |
| 1151 | const Operand& second_lo, |
| 1152 | const Operand& second_hi, |
| 1153 | CodeGeneratorARMVIXL* codegen) { |
| 1154 | const vixl32::Register first_hi = HighRegisterFrom(first); |
| 1155 | const vixl32::Register first_lo = LowRegisterFrom(first); |
| 1156 | const vixl32::Register out_hi = HighRegisterFrom(out); |
| 1157 | const vixl32::Register out_lo = LowRegisterFrom(out); |
| 1158 | |
| 1159 | if (kind == HInstruction::kAdd) { |
| 1160 | __ Adds(out_lo, first_lo, second_lo); |
| 1161 | __ Adc(out_hi, first_hi, second_hi); |
| 1162 | } else if (kind == HInstruction::kSub) { |
| 1163 | __ Subs(out_lo, first_lo, second_lo); |
| 1164 | __ Sbc(out_hi, first_hi, second_hi); |
| 1165 | } else { |
| 1166 | GenerateDataProcInstruction(kind, out_lo, first_lo, second_lo, codegen); |
| 1167 | GenerateDataProcInstruction(kind, out_hi, first_hi, second_hi, codegen); |
| 1168 | } |
| 1169 | } |
| 1170 | |
| 1171 | static Operand GetShifterOperand(vixl32::Register rm, ShiftType shift, uint32_t shift_imm) { |
| 1172 | return shift_imm == 0 ? Operand(rm) : Operand(rm, shift, shift_imm); |
| 1173 | } |
| 1174 | |
| 1175 | static void GenerateLongDataProc(HDataProcWithShifterOp* instruction, |
| 1176 | CodeGeneratorARMVIXL* codegen) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1177 | DCHECK_EQ(instruction->GetType(), DataType::Type::kInt64); |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1178 | DCHECK(HDataProcWithShifterOp::IsShiftOp(instruction->GetOpKind())); |
| 1179 | |
| 1180 | const LocationSummary* const locations = instruction->GetLocations(); |
| 1181 | const uint32_t shift_value = instruction->GetShiftAmount(); |
| 1182 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 1183 | const Location first = locations->InAt(0); |
| 1184 | const Location second = locations->InAt(1); |
| 1185 | const Location out = locations->Out(); |
| 1186 | const vixl32::Register first_hi = HighRegisterFrom(first); |
| 1187 | const vixl32::Register first_lo = LowRegisterFrom(first); |
| 1188 | const vixl32::Register out_hi = HighRegisterFrom(out); |
| 1189 | const vixl32::Register out_lo = LowRegisterFrom(out); |
| 1190 | const vixl32::Register second_hi = HighRegisterFrom(second); |
| 1191 | const vixl32::Register second_lo = LowRegisterFrom(second); |
| 1192 | const ShiftType shift = ShiftFromOpKind(instruction->GetOpKind()); |
| 1193 | |
| 1194 | if (shift_value >= 32) { |
| 1195 | if (shift == ShiftType::LSL) { |
| 1196 | GenerateDataProcInstruction(kind, |
| 1197 | out_hi, |
| 1198 | first_hi, |
| 1199 | Operand(second_lo, ShiftType::LSL, shift_value - 32), |
| 1200 | codegen); |
| 1201 | GenerateDataProcInstruction(kind, out_lo, first_lo, 0, codegen); |
| 1202 | } else if (shift == ShiftType::ASR) { |
| 1203 | GenerateDataProc(kind, |
| 1204 | out, |
| 1205 | first, |
| 1206 | GetShifterOperand(second_hi, ShiftType::ASR, shift_value - 32), |
| 1207 | Operand(second_hi, ShiftType::ASR, 31), |
| 1208 | codegen); |
| 1209 | } else { |
| 1210 | DCHECK_EQ(shift, ShiftType::LSR); |
| 1211 | GenerateDataProc(kind, |
| 1212 | out, |
| 1213 | first, |
| 1214 | GetShifterOperand(second_hi, ShiftType::LSR, shift_value - 32), |
| 1215 | 0, |
| 1216 | codegen); |
| 1217 | } |
| 1218 | } else { |
| 1219 | DCHECK_GT(shift_value, 1U); |
| 1220 | DCHECK_LT(shift_value, 32U); |
| 1221 | |
| 1222 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1223 | |
| 1224 | if (shift == ShiftType::LSL) { |
| 1225 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1226 | // Location::kOutputOverlap; not applicable to other cases. |
| 1227 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1228 | GenerateDataProcInstruction(kind, |
| 1229 | out_hi, |
| 1230 | first_hi, |
| 1231 | Operand(second_hi, ShiftType::LSL, shift_value), |
| 1232 | codegen); |
| 1233 | GenerateDataProcInstruction(kind, |
| 1234 | out_hi, |
| 1235 | out_hi, |
| 1236 | Operand(second_lo, ShiftType::LSR, 32 - shift_value), |
| 1237 | codegen); |
| 1238 | GenerateDataProcInstruction(kind, |
| 1239 | out_lo, |
| 1240 | first_lo, |
| 1241 | Operand(second_lo, ShiftType::LSL, shift_value), |
| 1242 | codegen); |
| 1243 | } else { |
| 1244 | const vixl32::Register temp = temps.Acquire(); |
| 1245 | |
| 1246 | __ Lsl(temp, second_hi, shift_value); |
| 1247 | __ Orr(temp, temp, Operand(second_lo, ShiftType::LSR, 32 - shift_value)); |
| 1248 | GenerateDataProc(kind, |
| 1249 | out, |
| 1250 | first, |
| 1251 | Operand(second_lo, ShiftType::LSL, shift_value), |
| 1252 | temp, |
| 1253 | codegen); |
| 1254 | } |
| 1255 | } else { |
| 1256 | DCHECK(shift == ShiftType::ASR || shift == ShiftType::LSR); |
| 1257 | |
| 1258 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1259 | // Location::kOutputOverlap; not applicable to other cases. |
| 1260 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1261 | GenerateDataProcInstruction(kind, |
| 1262 | out_lo, |
| 1263 | first_lo, |
| 1264 | Operand(second_lo, ShiftType::LSR, shift_value), |
| 1265 | codegen); |
| 1266 | GenerateDataProcInstruction(kind, |
| 1267 | out_lo, |
| 1268 | out_lo, |
| 1269 | Operand(second_hi, ShiftType::LSL, 32 - shift_value), |
| 1270 | codegen); |
| 1271 | GenerateDataProcInstruction(kind, |
| 1272 | out_hi, |
| 1273 | first_hi, |
| 1274 | Operand(second_hi, shift, shift_value), |
| 1275 | codegen); |
| 1276 | } else { |
| 1277 | const vixl32::Register temp = temps.Acquire(); |
| 1278 | |
| 1279 | __ Lsr(temp, second_lo, shift_value); |
| 1280 | __ Orr(temp, temp, Operand(second_hi, ShiftType::LSL, 32 - shift_value)); |
| 1281 | GenerateDataProc(kind, |
| 1282 | out, |
| 1283 | first, |
| 1284 | temp, |
| 1285 | Operand(second_hi, shift, shift_value), |
| 1286 | codegen); |
| 1287 | } |
| 1288 | } |
| 1289 | } |
| 1290 | } |
| 1291 | |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1292 | static void GenerateVcmp(HInstruction* instruction, CodeGeneratorARMVIXL* codegen) { |
| 1293 | const Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1294 | if (rhs_loc.IsConstant()) { |
| 1295 | // 0.0 is the only immediate that can be encoded directly in |
| 1296 | // a VCMP instruction. |
| 1297 | // |
| 1298 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1299 | // specify that in a floating-point comparison, positive zero |
| 1300 | // and negative zero are considered equal, so we can use the |
| 1301 | // literal 0.0 for both cases here. |
| 1302 | // |
| 1303 | // Note however that some methods (Float.equal, Float.compare, |
| 1304 | // Float.compareTo, Double.equal, Double.compare, |
| 1305 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1306 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1307 | // -0.0. So if we ever translate calls to these methods into a |
| 1308 | // HCompare instruction, we must handle the -0.0 case with |
| 1309 | // care here. |
| 1310 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1311 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1312 | const DataType::Type type = instruction->InputAt(0)->GetType(); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1313 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1314 | if (type == DataType::Type::kFloat32) { |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1315 | __ Vcmp(F32, InputSRegisterAt(instruction, 0), 0.0); |
| 1316 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1317 | DCHECK_EQ(type, DataType::Type::kFloat64); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1318 | __ Vcmp(F64, InputDRegisterAt(instruction, 0), 0.0); |
| 1319 | } |
| 1320 | } else { |
| 1321 | __ Vcmp(InputVRegisterAt(instruction, 0), InputVRegisterAt(instruction, 1)); |
| 1322 | } |
| 1323 | } |
| 1324 | |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1325 | static int64_t AdjustConstantForCondition(int64_t value, |
| 1326 | IfCondition* condition, |
| 1327 | IfCondition* opposite) { |
| 1328 | if (value == 1) { |
| 1329 | if (*condition == kCondB) { |
| 1330 | value = 0; |
| 1331 | *condition = kCondEQ; |
| 1332 | *opposite = kCondNE; |
| 1333 | } else if (*condition == kCondAE) { |
| 1334 | value = 0; |
| 1335 | *condition = kCondNE; |
| 1336 | *opposite = kCondEQ; |
| 1337 | } |
| 1338 | } else if (value == -1) { |
| 1339 | if (*condition == kCondGT) { |
| 1340 | value = 0; |
| 1341 | *condition = kCondGE; |
| 1342 | *opposite = kCondLT; |
| 1343 | } else if (*condition == kCondLE) { |
| 1344 | value = 0; |
| 1345 | *condition = kCondLT; |
| 1346 | *opposite = kCondGE; |
| 1347 | } |
| 1348 | } |
| 1349 | |
| 1350 | return value; |
| 1351 | } |
| 1352 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1353 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateLongTestConstant( |
| 1354 | HCondition* condition, |
| 1355 | bool invert, |
| 1356 | CodeGeneratorARMVIXL* codegen) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1357 | DCHECK_EQ(condition->GetLeft()->GetType(), DataType::Type::kInt64); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1358 | |
| 1359 | const LocationSummary* const locations = condition->GetLocations(); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1360 | IfCondition cond = condition->GetCondition(); |
| 1361 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1362 | |
| 1363 | if (invert) { |
| 1364 | std::swap(cond, opposite); |
| 1365 | } |
| 1366 | |
| 1367 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1368 | const Location left = locations->InAt(0); |
| 1369 | const Location right = locations->InAt(1); |
| 1370 | |
| 1371 | DCHECK(right.IsConstant()); |
| 1372 | |
| 1373 | const vixl32::Register left_high = HighRegisterFrom(left); |
| 1374 | const vixl32::Register left_low = LowRegisterFrom(left); |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1375 | int64_t value = AdjustConstantForCondition(Int64ConstantFrom(right), &cond, &opposite); |
| 1376 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1377 | |
| 1378 | // Comparisons against 0 are common enough to deserve special attention. |
| 1379 | if (value == 0) { |
| 1380 | switch (cond) { |
| 1381 | case kCondNE: |
| 1382 | // x > 0 iff x != 0 when the comparison is unsigned. |
| 1383 | case kCondA: |
| 1384 | ret = std::make_pair(ne, eq); |
| 1385 | FALLTHROUGH_INTENDED; |
| 1386 | case kCondEQ: |
| 1387 | // x <= 0 iff x == 0 when the comparison is unsigned. |
| 1388 | case kCondBE: |
| 1389 | __ Orrs(temps.Acquire(), left_low, left_high); |
| 1390 | return ret; |
| 1391 | case kCondLT: |
| 1392 | case kCondGE: |
| 1393 | __ Cmp(left_high, 0); |
| 1394 | return std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
| 1395 | // Trivially true or false. |
| 1396 | case kCondB: |
| 1397 | ret = std::make_pair(ne, eq); |
| 1398 | FALLTHROUGH_INTENDED; |
| 1399 | case kCondAE: |
| 1400 | __ Cmp(left_low, left_low); |
| 1401 | return ret; |
| 1402 | default: |
| 1403 | break; |
| 1404 | } |
| 1405 | } |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1406 | |
| 1407 | switch (cond) { |
| 1408 | case kCondEQ: |
| 1409 | case kCondNE: |
| 1410 | case kCondB: |
| 1411 | case kCondBE: |
| 1412 | case kCondA: |
| 1413 | case kCondAE: { |
| Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1414 | const uint32_t value_low = Low32Bits(value); |
| 1415 | Operand operand_low(value_low); |
| 1416 | |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1417 | __ Cmp(left_high, High32Bits(value)); |
| 1418 | |
| Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1419 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1420 | // we must ensure that the operands corresponding to the least significant |
| 1421 | // halves of the inputs fit into a 16-bit CMP encoding. |
| 1422 | if (!left_low.IsLow() || !IsUint<8>(value_low)) { |
| 1423 | operand_low = Operand(temps.Acquire()); |
| 1424 | __ Mov(LeaveFlags, operand_low.GetBaseRegister(), value_low); |
| 1425 | } |
| 1426 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1427 | // We use the scope because of the IT block that follows. |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1428 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1429 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1430 | CodeBufferCheckScope::kExactSize); |
| 1431 | |
| 1432 | __ it(eq); |
| Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1433 | __ cmp(eq, left_low, operand_low); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1434 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1435 | break; |
| 1436 | } |
| 1437 | case kCondLE: |
| 1438 | case kCondGT: |
| 1439 | // Trivially true or false. |
| 1440 | if (value == std::numeric_limits<int64_t>::max()) { |
| 1441 | __ Cmp(left_low, left_low); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1442 | 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] | 1443 | break; |
| 1444 | } |
| 1445 | |
| 1446 | if (cond == kCondLE) { |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1447 | DCHECK_EQ(opposite, kCondGT); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1448 | cond = kCondLT; |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1449 | opposite = kCondGE; |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1450 | } else { |
| 1451 | DCHECK_EQ(cond, kCondGT); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1452 | DCHECK_EQ(opposite, kCondLE); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1453 | cond = kCondGE; |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1454 | opposite = kCondLT; |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | value++; |
| 1458 | FALLTHROUGH_INTENDED; |
| 1459 | case kCondGE: |
| 1460 | case kCondLT: { |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1461 | __ Cmp(left_low, Low32Bits(value)); |
| 1462 | __ Sbcs(temps.Acquire(), left_high, High32Bits(value)); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1463 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1464 | break; |
| 1465 | } |
| 1466 | default: |
| 1467 | LOG(FATAL) << "Unreachable"; |
| 1468 | UNREACHABLE(); |
| 1469 | } |
| 1470 | |
| 1471 | return ret; |
| 1472 | } |
| 1473 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1474 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateLongTest( |
| 1475 | HCondition* condition, |
| 1476 | bool invert, |
| 1477 | CodeGeneratorARMVIXL* codegen) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1478 | DCHECK_EQ(condition->GetLeft()->GetType(), DataType::Type::kInt64); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1479 | |
| 1480 | const LocationSummary* const locations = condition->GetLocations(); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1481 | IfCondition cond = condition->GetCondition(); |
| 1482 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1483 | |
| 1484 | if (invert) { |
| 1485 | std::swap(cond, opposite); |
| 1486 | } |
| 1487 | |
| 1488 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1489 | Location left = locations->InAt(0); |
| 1490 | Location right = locations->InAt(1); |
| 1491 | |
| 1492 | DCHECK(right.IsRegisterPair()); |
| 1493 | |
| 1494 | switch (cond) { |
| 1495 | case kCondEQ: |
| 1496 | case kCondNE: |
| 1497 | case kCondB: |
| 1498 | case kCondBE: |
| 1499 | case kCondA: |
| 1500 | case kCondAE: { |
| 1501 | __ Cmp(HighRegisterFrom(left), HighRegisterFrom(right)); |
| 1502 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1503 | // We use the scope because of the IT block that follows. |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1504 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1505 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1506 | CodeBufferCheckScope::kExactSize); |
| 1507 | |
| 1508 | __ it(eq); |
| 1509 | __ cmp(eq, LowRegisterFrom(left), LowRegisterFrom(right)); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1510 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1511 | break; |
| 1512 | } |
| 1513 | case kCondLE: |
| 1514 | case kCondGT: |
| 1515 | if (cond == kCondLE) { |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1516 | DCHECK_EQ(opposite, kCondGT); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1517 | cond = kCondGE; |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1518 | opposite = kCondLT; |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1519 | } else { |
| 1520 | DCHECK_EQ(cond, kCondGT); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1521 | DCHECK_EQ(opposite, kCondLE); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1522 | cond = kCondLT; |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1523 | opposite = kCondGE; |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1524 | } |
| 1525 | |
| 1526 | std::swap(left, right); |
| 1527 | FALLTHROUGH_INTENDED; |
| 1528 | case kCondGE: |
| 1529 | case kCondLT: { |
| 1530 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1531 | |
| 1532 | __ Cmp(LowRegisterFrom(left), LowRegisterFrom(right)); |
| 1533 | __ Sbcs(temps.Acquire(), HighRegisterFrom(left), HighRegisterFrom(right)); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1534 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1535 | break; |
| 1536 | } |
| 1537 | default: |
| 1538 | LOG(FATAL) << "Unreachable"; |
| 1539 | UNREACHABLE(); |
| 1540 | } |
| 1541 | |
| 1542 | return ret; |
| 1543 | } |
| 1544 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1545 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateTest(HCondition* condition, |
| 1546 | bool invert, |
| 1547 | CodeGeneratorARMVIXL* codegen) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1548 | const DataType::Type type = condition->GetLeft()->GetType(); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1549 | IfCondition cond = condition->GetCondition(); |
| 1550 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1551 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1552 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1553 | if (invert) { |
| 1554 | std::swap(cond, opposite); |
| 1555 | } |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1556 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1557 | if (type == DataType::Type::kInt64) { |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1558 | ret = condition->GetLocations()->InAt(1).IsConstant() |
| 1559 | ? GenerateLongTestConstant(condition, invert, codegen) |
| 1560 | : GenerateLongTest(condition, invert, codegen); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1561 | } else if (DataType::IsFloatingPointType(type)) { |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1562 | GenerateVcmp(condition, codegen); |
| 1563 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 1564 | ret = std::make_pair(ARMFPCondition(cond, condition->IsGtBias()), |
| 1565 | ARMFPCondition(opposite, condition->IsGtBias())); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1566 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1567 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1568 | __ Cmp(InputRegisterAt(condition, 0), InputOperandAt(condition, 1)); |
| 1569 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | return ret; |
| 1573 | } |
| 1574 | |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1575 | static void GenerateConditionGeneric(HCondition* cond, CodeGeneratorARMVIXL* codegen) { |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1576 | const vixl32::Register out = OutputRegister(cond); |
| 1577 | const auto condition = GenerateTest(cond, false, codegen); |
| 1578 | |
| 1579 | __ Mov(LeaveFlags, out, 0); |
| 1580 | |
| 1581 | if (out.IsLow()) { |
| 1582 | // We use the scope because of the IT block that follows. |
| 1583 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1584 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1585 | CodeBufferCheckScope::kExactSize); |
| 1586 | |
| 1587 | __ it(condition.first); |
| 1588 | __ mov(condition.first, out, 1); |
| 1589 | } else { |
| 1590 | vixl32::Label done_label; |
| 1591 | vixl32::Label* const final_label = codegen->GetFinalLabel(cond, &done_label); |
| 1592 | |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1593 | __ B(condition.second, final_label, /* is_far_target= */ false); |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1594 | __ Mov(out, 1); |
| 1595 | |
| 1596 | if (done_label.IsReferenced()) { |
| 1597 | __ Bind(&done_label); |
| 1598 | } |
| 1599 | } |
| 1600 | } |
| 1601 | |
| 1602 | static void GenerateEqualLong(HCondition* cond, CodeGeneratorARMVIXL* codegen) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1603 | DCHECK_EQ(cond->GetLeft()->GetType(), DataType::Type::kInt64); |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1604 | |
| 1605 | const LocationSummary* const locations = cond->GetLocations(); |
| 1606 | IfCondition condition = cond->GetCondition(); |
| 1607 | const vixl32::Register out = OutputRegister(cond); |
| 1608 | const Location left = locations->InAt(0); |
| 1609 | const Location right = locations->InAt(1); |
| 1610 | vixl32::Register left_high = HighRegisterFrom(left); |
| 1611 | vixl32::Register left_low = LowRegisterFrom(left); |
| 1612 | vixl32::Register temp; |
| 1613 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1614 | |
| 1615 | if (right.IsConstant()) { |
| 1616 | IfCondition opposite = cond->GetOppositeCondition(); |
| 1617 | const int64_t value = AdjustConstantForCondition(Int64ConstantFrom(right), |
| 1618 | &condition, |
| 1619 | &opposite); |
| 1620 | Operand right_high = High32Bits(value); |
| 1621 | Operand right_low = Low32Bits(value); |
| 1622 | |
| 1623 | // The output uses Location::kNoOutputOverlap. |
| 1624 | if (out.Is(left_high)) { |
| 1625 | std::swap(left_low, left_high); |
| 1626 | std::swap(right_low, right_high); |
| 1627 | } |
| 1628 | |
| 1629 | __ Sub(out, left_low, right_low); |
| 1630 | temp = temps.Acquire(); |
| 1631 | __ Sub(temp, left_high, right_high); |
| 1632 | } else { |
| 1633 | DCHECK(right.IsRegisterPair()); |
| 1634 | temp = temps.Acquire(); |
| 1635 | __ Sub(temp, left_high, HighRegisterFrom(right)); |
| 1636 | __ Sub(out, left_low, LowRegisterFrom(right)); |
| 1637 | } |
| 1638 | |
| 1639 | // Need to check after calling AdjustConstantForCondition(). |
| 1640 | DCHECK(condition == kCondEQ || condition == kCondNE) << condition; |
| 1641 | |
| 1642 | if (condition == kCondNE && out.IsLow()) { |
| 1643 | __ Orrs(out, out, temp); |
| 1644 | |
| 1645 | // We use the scope because of the IT block that follows. |
| 1646 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1647 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1648 | CodeBufferCheckScope::kExactSize); |
| 1649 | |
| 1650 | __ it(ne); |
| 1651 | __ mov(ne, out, 1); |
| 1652 | } else { |
| 1653 | __ Orr(out, out, temp); |
| 1654 | codegen->GenerateConditionWithZero(condition, out, out, temp); |
| 1655 | } |
| 1656 | } |
| 1657 | |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1658 | static void GenerateConditionLong(HCondition* cond, CodeGeneratorARMVIXL* codegen) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1659 | DCHECK_EQ(cond->GetLeft()->GetType(), DataType::Type::kInt64); |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1660 | |
| 1661 | const LocationSummary* const locations = cond->GetLocations(); |
| 1662 | IfCondition condition = cond->GetCondition(); |
| 1663 | const vixl32::Register out = OutputRegister(cond); |
| 1664 | const Location left = locations->InAt(0); |
| 1665 | const Location right = locations->InAt(1); |
| 1666 | |
| 1667 | if (right.IsConstant()) { |
| 1668 | IfCondition opposite = cond->GetOppositeCondition(); |
| 1669 | |
| 1670 | // Comparisons against 0 are common enough to deserve special attention. |
| 1671 | if (AdjustConstantForCondition(Int64ConstantFrom(right), &condition, &opposite) == 0) { |
| 1672 | switch (condition) { |
| 1673 | case kCondNE: |
| 1674 | case kCondA: |
| 1675 | if (out.IsLow()) { |
| 1676 | // We only care if both input registers are 0 or not. |
| 1677 | __ Orrs(out, LowRegisterFrom(left), HighRegisterFrom(left)); |
| 1678 | |
| 1679 | // We use the scope because of the IT block that follows. |
| 1680 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1681 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1682 | CodeBufferCheckScope::kExactSize); |
| 1683 | |
| 1684 | __ it(ne); |
| 1685 | __ mov(ne, out, 1); |
| 1686 | return; |
| 1687 | } |
| 1688 | |
| 1689 | FALLTHROUGH_INTENDED; |
| 1690 | case kCondEQ: |
| 1691 | case kCondBE: |
| 1692 | // We only care if both input registers are 0 or not. |
| 1693 | __ Orr(out, LowRegisterFrom(left), HighRegisterFrom(left)); |
| 1694 | codegen->GenerateConditionWithZero(condition, out, out); |
| 1695 | return; |
| 1696 | case kCondLT: |
| 1697 | case kCondGE: |
| 1698 | // We only care about the sign bit. |
| 1699 | FALLTHROUGH_INTENDED; |
| 1700 | case kCondAE: |
| 1701 | case kCondB: |
| 1702 | codegen->GenerateConditionWithZero(condition, out, HighRegisterFrom(left)); |
| 1703 | return; |
| 1704 | case kCondLE: |
| 1705 | case kCondGT: |
| 1706 | default: |
| 1707 | break; |
| 1708 | } |
| 1709 | } |
| 1710 | } |
| 1711 | |
| Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1712 | // If `out` is a low register, then the GenerateConditionGeneric() |
| 1713 | // function generates a shorter code sequence that is still branchless. |
| 1714 | if ((condition == kCondEQ || condition == kCondNE) && !out.IsLow()) { |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1715 | GenerateEqualLong(cond, codegen); |
| 1716 | return; |
| 1717 | } |
| 1718 | |
| Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1719 | GenerateConditionGeneric(cond, codegen); |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1720 | } |
| 1721 | |
| Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 1722 | static void GenerateConditionIntegralOrNonPrimitive(HCondition* cond, |
| 1723 | CodeGeneratorARMVIXL* codegen) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1724 | const DataType::Type type = cond->GetLeft()->GetType(); |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1725 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1726 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1727 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1728 | if (type == DataType::Type::kInt64) { |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1729 | GenerateConditionLong(cond, codegen); |
| 1730 | return; |
| 1731 | } |
| 1732 | |
| 1733 | IfCondition condition = cond->GetCondition(); |
| 1734 | vixl32::Register in = InputRegisterAt(cond, 0); |
| 1735 | const vixl32::Register out = OutputRegister(cond); |
| 1736 | const Location right = cond->GetLocations()->InAt(1); |
| 1737 | int64_t value; |
| 1738 | |
| 1739 | if (right.IsConstant()) { |
| 1740 | IfCondition opposite = cond->GetOppositeCondition(); |
| 1741 | |
| 1742 | value = AdjustConstantForCondition(Int64ConstantFrom(right), &condition, &opposite); |
| 1743 | |
| 1744 | // Comparisons against 0 are common enough to deserve special attention. |
| 1745 | if (value == 0) { |
| 1746 | switch (condition) { |
| 1747 | case kCondNE: |
| 1748 | case kCondA: |
| 1749 | if (out.IsLow() && out.Is(in)) { |
| 1750 | __ Cmp(out, 0); |
| 1751 | |
| 1752 | // We use the scope because of the IT block that follows. |
| 1753 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1754 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1755 | CodeBufferCheckScope::kExactSize); |
| 1756 | |
| 1757 | __ it(ne); |
| 1758 | __ mov(ne, out, 1); |
| 1759 | return; |
| 1760 | } |
| 1761 | |
| 1762 | FALLTHROUGH_INTENDED; |
| 1763 | case kCondEQ: |
| 1764 | case kCondBE: |
| 1765 | case kCondLT: |
| 1766 | case kCondGE: |
| 1767 | case kCondAE: |
| 1768 | case kCondB: |
| 1769 | codegen->GenerateConditionWithZero(condition, out, in); |
| 1770 | return; |
| 1771 | case kCondLE: |
| 1772 | case kCondGT: |
| 1773 | default: |
| 1774 | break; |
| 1775 | } |
| 1776 | } |
| 1777 | } |
| 1778 | |
| 1779 | if (condition == kCondEQ || condition == kCondNE) { |
| 1780 | Operand operand(0); |
| 1781 | |
| 1782 | if (right.IsConstant()) { |
| 1783 | operand = Operand::From(value); |
| 1784 | } else if (out.Is(RegisterFrom(right))) { |
| 1785 | // Avoid 32-bit instructions if possible. |
| 1786 | operand = InputOperandAt(cond, 0); |
| 1787 | in = RegisterFrom(right); |
| 1788 | } else { |
| 1789 | operand = InputOperandAt(cond, 1); |
| 1790 | } |
| 1791 | |
| 1792 | if (condition == kCondNE && out.IsLow()) { |
| 1793 | __ Subs(out, in, operand); |
| 1794 | |
| 1795 | // We use the scope because of the IT block that follows. |
| 1796 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1797 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1798 | CodeBufferCheckScope::kExactSize); |
| 1799 | |
| 1800 | __ it(ne); |
| 1801 | __ mov(ne, out, 1); |
| 1802 | } else { |
| 1803 | __ Sub(out, in, operand); |
| 1804 | codegen->GenerateConditionWithZero(condition, out, out); |
| 1805 | } |
| 1806 | |
| 1807 | return; |
| 1808 | } |
| 1809 | |
| 1810 | GenerateConditionGeneric(cond, codegen); |
| 1811 | } |
| 1812 | |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1813 | static bool CanEncodeConstantAs8BitImmediate(HConstant* constant) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1814 | const DataType::Type type = constant->GetType(); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1815 | bool ret = false; |
| 1816 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1817 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1818 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1819 | if (type == DataType::Type::kInt64) { |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1820 | const uint64_t value = Uint64ConstantFrom(constant); |
| 1821 | |
| 1822 | ret = IsUint<8>(Low32Bits(value)) && IsUint<8>(High32Bits(value)); |
| 1823 | } else { |
| 1824 | ret = IsUint<8>(Int32ConstantFrom(constant)); |
| 1825 | } |
| 1826 | |
| 1827 | return ret; |
| 1828 | } |
| 1829 | |
| 1830 | static Location Arm8BitEncodableConstantOrRegister(HInstruction* constant) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1831 | DCHECK(!DataType::IsFloatingPointType(constant->GetType())); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1832 | |
| 1833 | if (constant->IsConstant() && CanEncodeConstantAs8BitImmediate(constant->AsConstant())) { |
| 1834 | return Location::ConstantLocation(constant->AsConstant()); |
| 1835 | } |
| 1836 | |
| 1837 | return Location::RequiresRegister(); |
| 1838 | } |
| 1839 | |
| 1840 | static bool CanGenerateConditionalMove(const Location& out, const Location& src) { |
| 1841 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1842 | // we check that we are not dealing with floating-point output (there is no |
| 1843 | // 16-bit VMOV encoding). |
| 1844 | if (!out.IsRegister() && !out.IsRegisterPair()) { |
| 1845 | return false; |
| 1846 | } |
| 1847 | |
| 1848 | // For constants, we also check that the output is in one or two low registers, |
| 1849 | // and that the constants fit in an 8-bit unsigned integer, so that a 16-bit |
| 1850 | // MOV encoding can be used. |
| 1851 | if (src.IsConstant()) { |
| 1852 | if (!CanEncodeConstantAs8BitImmediate(src.GetConstant())) { |
| 1853 | return false; |
| 1854 | } |
| 1855 | |
| 1856 | if (out.IsRegister()) { |
| 1857 | if (!RegisterFrom(out).IsLow()) { |
| 1858 | return false; |
| 1859 | } |
| 1860 | } else { |
| 1861 | DCHECK(out.IsRegisterPair()); |
| 1862 | |
| 1863 | if (!HighRegisterFrom(out).IsLow()) { |
| 1864 | return false; |
| 1865 | } |
| 1866 | } |
| 1867 | } |
| 1868 | |
| 1869 | return true; |
| 1870 | } |
| 1871 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1872 | #undef __ |
| 1873 | |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1874 | vixl32::Label* CodeGeneratorARMVIXL::GetFinalLabel(HInstruction* instruction, |
| 1875 | vixl32::Label* final_label) { |
| 1876 | DCHECK(!instruction->IsControlFlow() && !instruction->IsSuspendCheck()); |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 1877 | DCHECK(!instruction->IsInvoke() || !instruction->GetLocations()->CanCall()); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1878 | |
| 1879 | const HBasicBlock* const block = instruction->GetBlock(); |
| 1880 | const HLoopInformation* const info = block->GetLoopInformation(); |
| 1881 | HInstruction* const next = instruction->GetNext(); |
| 1882 | |
| 1883 | // Avoid a branch to a branch. |
| 1884 | if (next->IsGoto() && (info == nullptr || |
| 1885 | !info->IsBackEdge(*block) || |
| 1886 | !info->HasSuspendCheck())) { |
| 1887 | final_label = GetLabelOf(next->AsGoto()->GetSuccessor()); |
| 1888 | } |
| 1889 | |
| 1890 | return final_label; |
| 1891 | } |
| 1892 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1893 | CodeGeneratorARMVIXL::CodeGeneratorARMVIXL(HGraph* graph, |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1894 | const CompilerOptions& compiler_options, |
| 1895 | OptimizingCompilerStats* stats) |
| 1896 | : CodeGenerator(graph, |
| 1897 | kNumberOfCoreRegisters, |
| 1898 | kNumberOfSRegisters, |
| 1899 | kNumberOfRegisterPairs, |
| 1900 | kCoreCalleeSaves.GetList(), |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1901 | ComputeSRegisterListMask(kFpuCalleeSaves), |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1902 | compiler_options, |
| 1903 | stats), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1904 | block_labels_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1905 | jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1906 | location_builder_(graph, this), |
| 1907 | instruction_visitor_(graph, this), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1908 | move_resolver_(graph->GetAllocator(), this), |
| 1909 | assembler_(graph->GetAllocator()), |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1910 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1911 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1912 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1913 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 1914 | public_type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1915 | package_type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1916 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1917 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1918 | boot_image_other_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1919 | call_entrypoint_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1920 | baker_read_barrier_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1921 | uint32_literals_(std::less<uint32_t>(), |
| 1922 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 1923 | jit_string_patches_(StringReferenceValueComparator(), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1924 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 1925 | jit_class_patches_(TypeReferenceValueComparator(), |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1926 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1927 | jit_baker_read_barrier_slow_paths_(std::less<uint32_t>(), |
| 1928 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1929 | // Always save the LR register to mimic Quick. |
| 1930 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
| Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 1931 | // Give D30 and D31 as scratch register to VIXL. The register allocator only works on |
| 1932 | // S0-S31, which alias to D0-D15. |
| 1933 | GetVIXLAssembler()->GetScratchVRegisterList()->Combine(d31); |
| 1934 | GetVIXLAssembler()->GetScratchVRegisterList()->Combine(d30); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1935 | } |
| 1936 | |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1937 | void JumpTableARMVIXL::EmitTable(CodeGeneratorARMVIXL* codegen) { |
| 1938 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| 1939 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| 1940 | |
| 1941 | // 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] | 1942 | // underlying code buffer and we have generated a jump table of the right size, using |
| 1943 | // codegen->GetVIXLAssembler()->GetBuffer().Align(); |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 1944 | ExactAssemblyScope aas(codegen->GetVIXLAssembler(), |
| 1945 | num_entries * sizeof(int32_t), |
| 1946 | CodeBufferCheckScope::kMaximumSize); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1947 | // TODO(VIXL): Check that using lower case bind is fine here. |
| 1948 | codegen->GetVIXLAssembler()->bind(&table_start_); |
| Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1949 | for (uint32_t i = 0; i < num_entries; i++) { |
| 1950 | codegen->GetVIXLAssembler()->place(bb_addresses_[i].get()); |
| 1951 | } |
| 1952 | } |
| 1953 | |
| 1954 | void JumpTableARMVIXL::FixTable(CodeGeneratorARMVIXL* codegen) { |
| 1955 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| 1956 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| 1957 | |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1958 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 1959 | for (uint32_t i = 0; i < num_entries; i++) { |
| 1960 | vixl32::Label* target_label = codegen->GetLabelOf(successors[i]); |
| 1961 | DCHECK(target_label->IsBound()); |
| 1962 | int32_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
| 1963 | // When doing BX to address we need to have lower bit set to 1 in T32. |
| 1964 | if (codegen->GetVIXLAssembler()->IsUsingT32()) { |
| 1965 | jump_offset++; |
| 1966 | } |
| 1967 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 1968 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1969 | |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 1970 | bb_addresses_[i].get()->UpdateValue(jump_offset, codegen->GetVIXLAssembler()->GetBuffer()); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1971 | } |
| 1972 | } |
| 1973 | |
| Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1974 | void CodeGeneratorARMVIXL::FixJumpTables() { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1975 | for (auto&& jump_table : jump_tables_) { |
| Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1976 | jump_table->FixTable(this); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1977 | } |
| 1978 | } |
| 1979 | |
| Andreas Gampe | ca620d7 | 2016-11-08 08:09:33 -0800 | [diff] [blame] | 1980 | #define __ reinterpret_cast<ArmVIXLAssembler*>(GetAssembler())->GetVIXLAssembler()-> // NOLINT |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1981 | |
| 1982 | void CodeGeneratorARMVIXL::Finalize(CodeAllocator* allocator) { |
| Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1983 | FixJumpTables(); |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1984 | |
| 1985 | // Emit JIT baker read barrier slow paths. |
| Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 1986 | DCHECK(GetCompilerOptions().IsJitCompiler() || jit_baker_read_barrier_slow_paths_.empty()); |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1987 | for (auto& entry : jit_baker_read_barrier_slow_paths_) { |
| 1988 | uint32_t encoded_data = entry.first; |
| 1989 | vixl::aarch32::Label* slow_path_entry = &entry.second.label; |
| 1990 | __ Bind(slow_path_entry); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1991 | CompileBakerReadBarrierThunk(*GetAssembler(), encoded_data, /* debug_name= */ nullptr); |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1992 | } |
| 1993 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1994 | GetAssembler()->FinalizeCode(); |
| 1995 | CodeGenerator::Finalize(allocator); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1996 | |
| 1997 | // Verify Baker read barrier linker patches. |
| 1998 | if (kIsDebugBuild) { |
| 1999 | ArrayRef<const uint8_t> code = allocator->GetMemory(); |
| 2000 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 2001 | DCHECK(info.label.IsBound()); |
| 2002 | uint32_t literal_offset = info.label.GetLocation(); |
| 2003 | DCHECK_ALIGNED(literal_offset, 2u); |
| 2004 | |
| 2005 | auto GetInsn16 = [&code](uint32_t offset) { |
| 2006 | DCHECK_ALIGNED(offset, 2u); |
| 2007 | return (static_cast<uint32_t>(code[offset + 0]) << 0) + |
| 2008 | (static_cast<uint32_t>(code[offset + 1]) << 8); |
| 2009 | }; |
| 2010 | auto GetInsn32 = [=](uint32_t offset) { |
| 2011 | return (GetInsn16(offset) << 16) + (GetInsn16(offset + 2u) << 0); |
| 2012 | }; |
| 2013 | |
| 2014 | uint32_t encoded_data = info.custom_data; |
| 2015 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 2016 | // Check that the next instruction matches the expected LDR. |
| 2017 | switch (kind) { |
| 2018 | case BakerReadBarrierKind::kField: { |
| 2019 | BakerReadBarrierWidth width = BakerReadBarrierWidthField::Decode(encoded_data); |
| 2020 | if (width == BakerReadBarrierWidth::kWide) { |
| 2021 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 2022 | uint32_t next_insn = GetInsn32(literal_offset + 4u); |
| 2023 | // LDR (immediate), encoding T3, with correct base_reg. |
| 2024 | CheckValidReg((next_insn >> 12) & 0xfu); // Check destination register. |
| 2025 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 2026 | CHECK_EQ(next_insn & 0xffff0000u, 0xf8d00000u | (base_reg << 16)); |
| 2027 | } else { |
| 2028 | DCHECK_GE(code.size() - literal_offset, 6u); |
| 2029 | uint32_t next_insn = GetInsn16(literal_offset + 4u); |
| 2030 | // LDR (immediate), encoding T1, with correct base_reg. |
| 2031 | CheckValidReg(next_insn & 0x7u); // Check destination register. |
| 2032 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 2033 | CHECK_EQ(next_insn & 0xf838u, 0x6800u | (base_reg << 3)); |
| 2034 | } |
| 2035 | break; |
| 2036 | } |
| 2037 | case BakerReadBarrierKind::kArray: { |
| 2038 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 2039 | uint32_t next_insn = GetInsn32(literal_offset + 4u); |
| 2040 | // LDR (register) with correct base_reg, S=1 and option=011 (LDR Wt, [Xn, Xm, LSL #2]). |
| 2041 | CheckValidReg((next_insn >> 12) & 0xfu); // Check destination register. |
| 2042 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 2043 | CHECK_EQ(next_insn & 0xffff0ff0u, 0xf8500020u | (base_reg << 16)); |
| 2044 | CheckValidReg(next_insn & 0xf); // Check index register |
| 2045 | break; |
| 2046 | } |
| 2047 | case BakerReadBarrierKind::kGcRoot: { |
| 2048 | BakerReadBarrierWidth width = BakerReadBarrierWidthField::Decode(encoded_data); |
| 2049 | if (width == BakerReadBarrierWidth::kWide) { |
| 2050 | DCHECK_GE(literal_offset, 4u); |
| 2051 | uint32_t prev_insn = GetInsn32(literal_offset - 4u); |
| Vladimir Marko | f28be43 | 2018-08-14 12:20:51 +0000 | [diff] [blame] | 2052 | // LDR (immediate), encoding T3, with correct root_reg. |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 2053 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| Vladimir Marko | f28be43 | 2018-08-14 12:20:51 +0000 | [diff] [blame] | 2054 | CHECK_EQ(prev_insn & 0xfff0f000u, 0xf8d00000u | (root_reg << 12)); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 2055 | } else { |
| 2056 | DCHECK_GE(literal_offset, 2u); |
| 2057 | uint32_t prev_insn = GetInsn16(literal_offset - 2u); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 2058 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 2059 | // Usually LDR (immediate), encoding T1, with correct root_reg but we may have |
| 2060 | // a `MOV marked, old_value` for intrinsic CAS where `marked` is a low register. |
| 2061 | if ((prev_insn & 0xff87u) != (0x4600 | root_reg)) { |
| 2062 | CHECK_EQ(prev_insn & 0xf807u, 0x6800u | root_reg); |
| 2063 | } |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 2064 | } |
| 2065 | break; |
| 2066 | } |
| Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 2067 | case BakerReadBarrierKind::kIntrinsicCas: { |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 2068 | DCHECK_GE(literal_offset, 4u); |
| 2069 | uint32_t prev_insn = GetInsn32(literal_offset - 4u); |
| Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 2070 | // MOV (register), encoding T3, with correct root_reg. |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 2071 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 2072 | DCHECK_GE(root_reg, 8u); // Used only for high registers. |
| 2073 | CHECK_EQ(prev_insn & 0xfffffff0u, 0xea4f0000u | (root_reg << 8)); |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 2074 | break; |
| 2075 | } |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 2076 | default: |
| 2077 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 2078 | UNREACHABLE(); |
| 2079 | } |
| 2080 | } |
| 2081 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2082 | } |
| 2083 | |
| 2084 | void CodeGeneratorARMVIXL::SetupBlockedRegisters() const { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2085 | // Stack register, LR and PC are always reserved. |
| 2086 | blocked_core_registers_[SP] = true; |
| 2087 | blocked_core_registers_[LR] = true; |
| 2088 | blocked_core_registers_[PC] = true; |
| 2089 | |
| Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 2090 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2091 | // Reserve marking register. |
| 2092 | blocked_core_registers_[MR] = true; |
| 2093 | } |
| 2094 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2095 | // Reserve thread register. |
| 2096 | blocked_core_registers_[TR] = true; |
| 2097 | |
| 2098 | // Reserve temp register. |
| 2099 | blocked_core_registers_[IP] = true; |
| 2100 | |
| 2101 | if (GetGraph()->IsDebuggable()) { |
| 2102 | // Stubs do not save callee-save floating point registers. If the graph |
| 2103 | // is debuggable, we need to deal with these registers differently. For |
| 2104 | // now, just block them. |
| 2105 | for (uint32_t i = kFpuCalleeSaves.GetFirstSRegister().GetCode(); |
| 2106 | i <= kFpuCalleeSaves.GetLastSRegister().GetCode(); |
| 2107 | ++i) { |
| 2108 | blocked_fpu_registers_[i] = true; |
| 2109 | } |
| 2110 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2111 | } |
| 2112 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2113 | InstructionCodeGeneratorARMVIXL::InstructionCodeGeneratorARMVIXL(HGraph* graph, |
| 2114 | CodeGeneratorARMVIXL* codegen) |
| 2115 | : InstructionCodeGenerator(graph, codegen), |
| 2116 | assembler_(codegen->GetAssembler()), |
| 2117 | codegen_(codegen) {} |
| 2118 | |
| 2119 | void CodeGeneratorARMVIXL::ComputeSpillMask() { |
| 2120 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| Vladimir Marko | 460f054 | 2019-07-04 14:02:08 +0100 | [diff] [blame] | 2121 | DCHECK_NE(core_spill_mask_ & (1u << kLrCode), 0u) |
| 2122 | << "At least the return address register must be saved"; |
| 2123 | // 16-bit PUSH/POP (T1) can save/restore just the LR/PC. |
| 2124 | DCHECK(GetVIXLAssembler()->IsUsingT32()); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2125 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 2126 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 2127 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 2128 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 2129 | // but in the range. |
| 2130 | if (fpu_spill_mask_ != 0) { |
| 2131 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 2132 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 2133 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 2134 | fpu_spill_mask_ |= (1 << i); |
| 2135 | } |
| 2136 | } |
| 2137 | } |
| 2138 | |
| Mythri Alle | 2d4feeb | 2021-10-13 15:39:37 +0000 | [diff] [blame^] | 2139 | void LocationsBuilderARMVIXL::VisitMethodExitHook(HMethodExitHook* method_hook) { |
| 2140 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| 2141 | LocationSummary(method_hook, LocationSummary::kCallOnSlowPath); |
| 2142 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(method_hook->InputAt(0)->GetType())); |
| 2143 | } |
| 2144 | |
| 2145 | void InstructionCodeGeneratorARMVIXL::GenerateMethodEntryExitHook(HInstruction* instruction) { |
| 2146 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2147 | vixl32::Register temp = temps.Acquire(); |
| 2148 | |
| 2149 | SlowPathCodeARMVIXL* slow_path = |
| 2150 | new (codegen_->GetScopedAllocator()) MethodEntryExitHooksSlowPathARMVIXL(instruction); |
| 2151 | codegen_->AddSlowPath(slow_path); |
| 2152 | |
| 2153 | int offset = instrumentation::Instrumentation::NeedsEntryExitHooksOffset().Int32Value(); |
| 2154 | uint32_t address = reinterpret_cast32<uint32_t>(Runtime::Current()->GetInstrumentation()); |
| 2155 | __ Mov(temp, address + offset); |
| 2156 | __ Ldrh(temp, MemOperand(temp, 0)); |
| 2157 | __ CompareAndBranchIfNonZero(temp, slow_path->GetEntryLabel()); |
| 2158 | __ Bind(slow_path->GetExitLabel()); |
| 2159 | } |
| 2160 | |
| 2161 | void InstructionCodeGeneratorARMVIXL::VisitMethodExitHook(HMethodExitHook* instruction) { |
| 2162 | DCHECK(codegen_->GetCompilerOptions().IsJitCompiler() && GetGraph()->IsDebuggable()); |
| 2163 | DCHECK(codegen_->RequiresCurrentMethod()); |
| 2164 | GenerateMethodEntryExitHook(instruction); |
| 2165 | } |
| 2166 | |
| 2167 | void LocationsBuilderARMVIXL::VisitMethodEntryHook(HMethodEntryHook* method_hook) { |
| 2168 | new (GetGraph()->GetAllocator()) LocationSummary(method_hook, LocationSummary::kCallOnSlowPath); |
| 2169 | } |
| 2170 | |
| 2171 | void InstructionCodeGeneratorARMVIXL::VisitMethodEntryHook(HMethodEntryHook* instruction) { |
| 2172 | DCHECK(codegen_->GetCompilerOptions().IsJitCompiler() && GetGraph()->IsDebuggable()); |
| 2173 | DCHECK(codegen_->RequiresCurrentMethod()); |
| 2174 | GenerateMethodEntryExitHook(instruction); |
| 2175 | } |
| 2176 | |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2177 | void CodeGeneratorARMVIXL::MaybeIncrementHotness(bool is_frame_entry) { |
| 2178 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 2179 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2180 | vixl32::Register temp = temps.Acquire(); |
| 2181 | static_assert(ArtMethod::MaxCounter() == 0xFFFF, "asm is probably wrong"); |
| 2182 | if (!is_frame_entry) { |
| 2183 | __ Push(vixl32::Register(kMethodRegister)); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2184 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize); |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2185 | GetAssembler()->LoadFromOffset(kLoadWord, kMethodRegister, sp, kArmWordSize); |
| 2186 | } |
| 2187 | // Load with zero extend to clear the high bits for integer overflow check. |
| 2188 | __ Ldrh(temp, MemOperand(kMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); |
| Vladimir Marko | ce131fe | 2021-10-26 20:03:35 +0000 | [diff] [blame] | 2189 | __ Add(temp, temp, 1); |
| 2190 | // Subtract one if the counter would overflow. |
| 2191 | __ Sub(temp, temp, Operand(temp, ShiftType::LSR, 16)); |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2192 | __ Strh(temp, MemOperand(kMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); |
| 2193 | if (!is_frame_entry) { |
| 2194 | __ Pop(vixl32::Register(kMethodRegister)); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2195 | GetAssembler()->cfi().AdjustCFAOffset(-static_cast<int>(kArmWordSize)); |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2196 | } |
| 2197 | } |
| 2198 | |
| 2199 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
| Nicolas Geoffray | 095dc46 | 2020-08-17 16:40:28 +0100 | [diff] [blame] | 2200 | ScopedProfilingInfoUse spiu( |
| 2201 | Runtime::Current()->GetJit(), GetGraph()->GetArtMethod(), Thread::Current()); |
| 2202 | ProfilingInfo* info = spiu.GetProfilingInfo(); |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 2203 | if (info != nullptr) { |
| 2204 | uint32_t address = reinterpret_cast32<uint32_t>(info); |
| 2205 | vixl::aarch32::Label done; |
| 2206 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2207 | temps.Exclude(ip); |
| 2208 | if (!is_frame_entry) { |
| 2209 | __ 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] | 2210 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize); |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 2211 | } |
| 2212 | __ Mov(r4, address); |
| 2213 | __ Ldrh(ip, MemOperand(r4, ProfilingInfo::BaselineHotnessCountOffset().Int32Value())); |
| 2214 | __ Add(ip, ip, 1); |
| Nicolas Geoffray | 8b8d93d | 2020-09-17 14:30:01 +0100 | [diff] [blame] | 2215 | instruction_visitor_.GenerateAndConst(ip, ip, interpreter::kTieredHotnessMask); |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 2216 | __ Strh(ip, MemOperand(r4, ProfilingInfo::BaselineHotnessCountOffset().Int32Value())); |
| 2217 | if (!is_frame_entry) { |
| 2218 | __ Pop(r4); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2219 | GetAssembler()->cfi().AdjustCFAOffset(-static_cast<int>(kArmWordSize)); |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 2220 | } |
| 2221 | __ Lsls(ip, ip, 16); |
| 2222 | __ B(ne, &done); |
| 2223 | uint32_t entry_point_offset = |
| 2224 | GetThreadOffset<kArmPointerSize>(kQuickCompileOptimized).Int32Value(); |
| 2225 | if (HasEmptyFrame()) { |
| 2226 | CHECK(is_frame_entry); |
| 2227 | // For leaf methods, we need to spill lr and r0. Also spill r1 and r2 for |
| 2228 | // alignment. |
| 2229 | uint32_t core_spill_mask = |
| 2230 | (1 << lr.GetCode()) | (1 << r0.GetCode()) | (1 << r1.GetCode()) | (1 << r2.GetCode()); |
| 2231 | __ Push(RegisterList(core_spill_mask)); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2232 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask)); |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 2233 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 2234 | __ Blx(lr); |
| 2235 | __ Pop(RegisterList(core_spill_mask)); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2236 | GetAssembler()->cfi().AdjustCFAOffset( |
| 2237 | -static_cast<int>(kArmWordSize) * POPCOUNT(core_spill_mask)); |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 2238 | } else { |
| 2239 | if (!RequiresCurrentMethod()) { |
| 2240 | CHECK(is_frame_entry); |
| 2241 | GetAssembler()->StoreToOffset(kStoreWord, kMethodRegister, sp, 0); |
| 2242 | } |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2243 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 2244 | __ Blx(lr); |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2245 | } |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 2246 | __ Bind(&done); |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2247 | } |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2248 | } |
| 2249 | } |
| 2250 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2251 | void CodeGeneratorARMVIXL::GenerateFrameEntry() { |
| 2252 | bool skip_overflow_check = |
| 2253 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
| 2254 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
| 2255 | __ Bind(&frame_entry_label_); |
| 2256 | |
| 2257 | if (HasEmptyFrame()) { |
| David Srbecky | 3002184 | 2019-02-13 14:19:36 +0000 | [diff] [blame] | 2258 | // Ensure that the CFI opcode list is not empty. |
| 2259 | GetAssembler()->cfi().Nop(); |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2260 | MaybeIncrementHotness(/* is_frame_entry= */ true); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2261 | return; |
| 2262 | } |
| 2263 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2264 | if (!skip_overflow_check) { |
| xueliang.zhong | 1004955 | 2018-01-31 17:10:36 +0000 | [diff] [blame] | 2265 | // Using r4 instead of IP saves 2 bytes. |
| Nicolas Geoffray | 1a4f3ca | 2018-01-25 14:07:15 +0000 | [diff] [blame] | 2266 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| xueliang.zhong | 1004955 | 2018-01-31 17:10:36 +0000 | [diff] [blame] | 2267 | vixl32::Register temp; |
| 2268 | // TODO: Remove this check when R4 is made a callee-save register |
| 2269 | // in ART compiled code (b/72801708). Currently we need to make |
| 2270 | // sure r4 is not blocked, e.g. in special purpose |
| 2271 | // TestCodeGeneratorARMVIXL; also asserting that r4 is available |
| 2272 | // here. |
| 2273 | if (!blocked_core_registers_[R4]) { |
| 2274 | for (vixl32::Register reg : kParameterCoreRegistersVIXL) { |
| 2275 | DCHECK(!reg.Is(r4)); |
| 2276 | } |
| 2277 | DCHECK(!kCoreCalleeSaves.Includes(r4)); |
| 2278 | temp = r4; |
| 2279 | } else { |
| 2280 | temp = temps.Acquire(); |
| 2281 | } |
| Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 2282 | __ Sub(temp, sp, Operand::From(GetStackOverflowReservedBytes(InstructionSet::kArm))); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2283 | // The load must immediately precede RecordPcInfo. |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 2284 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2285 | vixl32::kMaxInstructionSizeInBytes, |
| 2286 | CodeBufferCheckScope::kMaximumSize); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2287 | __ ldr(temp, MemOperand(temp)); |
| 2288 | RecordPcInfo(nullptr, 0); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2289 | } |
| 2290 | |
| Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 2291 | uint32_t frame_size = GetFrameSize(); |
| 2292 | uint32_t core_spills_offset = frame_size - GetCoreSpillSize(); |
| 2293 | uint32_t fp_spills_offset = frame_size - FrameEntrySpillSize(); |
| 2294 | if ((fpu_spill_mask_ == 0u || IsPowerOfTwo(fpu_spill_mask_)) && |
| 2295 | core_spills_offset <= 3u * kArmWordSize) { |
| 2296 | // Do a single PUSH for core registers including the method and up to two |
| 2297 | // filler registers. Then store the single FP spill if any. |
| 2298 | // (The worst case is when the method is not required and we actually |
| 2299 | // store 3 extra registers but they are stored in the same properly |
| 2300 | // aligned 16-byte chunk where we're already writing anyway.) |
| 2301 | DCHECK_EQ(kMethodRegister.GetCode(), 0u); |
| 2302 | uint32_t extra_regs = MaxInt<uint32_t>(core_spills_offset / kArmWordSize); |
| 2303 | DCHECK_LT(MostSignificantBit(extra_regs), LeastSignificantBit(core_spill_mask_)); |
| 2304 | __ Push(RegisterList(core_spill_mask_ | extra_regs)); |
| 2305 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
| 2306 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(kMethodRegister), |
| 2307 | core_spills_offset, |
| 2308 | core_spill_mask_, |
| 2309 | kArmWordSize); |
| 2310 | if (fpu_spill_mask_ != 0u) { |
| 2311 | DCHECK(IsPowerOfTwo(fpu_spill_mask_)); |
| 2312 | vixl::aarch32::SRegister sreg(LeastSignificantBit(fpu_spill_mask_)); |
| 2313 | GetAssembler()->StoreSToOffset(sreg, sp, fp_spills_offset); |
| 2314 | GetAssembler()->cfi().RelOffset(DWARFReg(sreg), /*offset=*/ fp_spills_offset); |
| 2315 | } |
| 2316 | } else { |
| 2317 | __ Push(RegisterList(core_spill_mask_)); |
| 2318 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 2319 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(kMethodRegister), |
| 2320 | /*offset=*/ 0, |
| 2321 | core_spill_mask_, |
| 2322 | kArmWordSize); |
| 2323 | if (fpu_spill_mask_ != 0) { |
| 2324 | uint32_t first = LeastSignificantBit(fpu_spill_mask_); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2325 | |
| Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 2326 | // Check that list is contiguous. |
| 2327 | 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] | 2328 | |
| Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 2329 | __ Vpush(SRegisterList(vixl32::SRegister(first), POPCOUNT(fpu_spill_mask_))); |
| 2330 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
| 2331 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(s0), |
| 2332 | /*offset=*/ 0, |
| 2333 | fpu_spill_mask_, |
| 2334 | kArmWordSize); |
| 2335 | } |
| Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 2336 | |
| Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 2337 | // Adjust SP and save the current method if we need it. Note that we do |
| 2338 | // not save the method in HCurrentMethod, as the instruction might have |
| 2339 | // been removed in the SSA graph. |
| 2340 | if (RequiresCurrentMethod() && fp_spills_offset <= 3 * kArmWordSize) { |
| 2341 | DCHECK_EQ(kMethodRegister.GetCode(), 0u); |
| 2342 | __ Push(RegisterList(MaxInt<uint32_t>(fp_spills_offset / kArmWordSize))); |
| 2343 | GetAssembler()->cfi().AdjustCFAOffset(fp_spills_offset); |
| 2344 | } else { |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2345 | IncreaseFrame(fp_spills_offset); |
| Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 2346 | if (RequiresCurrentMethod()) { |
| 2347 | GetAssembler()->StoreToOffset(kStoreWord, kMethodRegister, sp, 0); |
| 2348 | } |
| 2349 | } |
| Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 2350 | } |
| Nicolas Geoffray | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 2351 | |
| 2352 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 2353 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2354 | vixl32::Register temp = temps.Acquire(); |
| 2355 | // Initialize should_deoptimize flag to 0. |
| 2356 | __ Mov(temp, 0); |
| 2357 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, GetStackOffsetOfShouldDeoptimizeFlag()); |
| 2358 | } |
| Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 2359 | |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2360 | MaybeIncrementHotness(/* is_frame_entry= */ true); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2361 | MaybeGenerateMarkingRegisterCheck(/* code= */ 1); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2362 | } |
| 2363 | |
| 2364 | void CodeGeneratorARMVIXL::GenerateFrameExit() { |
| 2365 | if (HasEmptyFrame()) { |
| 2366 | __ Bx(lr); |
| 2367 | return; |
| 2368 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2369 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2370 | // Pop LR into PC to return. |
| 2371 | DCHECK_NE(core_spill_mask_ & (1 << kLrCode), 0U); |
| 2372 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << kLrCode))) | 1 << kPcCode; |
| Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 2373 | |
| 2374 | uint32_t frame_size = GetFrameSize(); |
| 2375 | uint32_t core_spills_offset = frame_size - GetCoreSpillSize(); |
| 2376 | uint32_t fp_spills_offset = frame_size - FrameEntrySpillSize(); |
| 2377 | if ((fpu_spill_mask_ == 0u || IsPowerOfTwo(fpu_spill_mask_)) && |
| 2378 | // r4 is blocked by TestCodeGeneratorARMVIXL used by some tests. |
| 2379 | core_spills_offset <= (blocked_core_registers_[r4.GetCode()] ? 2u : 3u) * kArmWordSize) { |
| 2380 | // Load the FP spill if any and then do a single POP including the method |
| 2381 | // and up to two filler registers. If we have no FP spills, this also has |
| 2382 | // the advantage that we do not need to emit CFI directives. |
| 2383 | if (fpu_spill_mask_ != 0u) { |
| 2384 | DCHECK(IsPowerOfTwo(fpu_spill_mask_)); |
| 2385 | vixl::aarch32::SRegister sreg(LeastSignificantBit(fpu_spill_mask_)); |
| 2386 | GetAssembler()->cfi().RememberState(); |
| 2387 | GetAssembler()->LoadSFromOffset(sreg, sp, fp_spills_offset); |
| 2388 | GetAssembler()->cfi().Restore(DWARFReg(sreg)); |
| 2389 | } |
| 2390 | // Clobber registers r2-r4 as they are caller-save in ART managed ABI and |
| 2391 | // never hold the return value. |
| 2392 | uint32_t extra_regs = MaxInt<uint32_t>(core_spills_offset / kArmWordSize) << r2.GetCode(); |
| 2393 | DCHECK_EQ(extra_regs & kCoreCalleeSaves.GetList(), 0u); |
| 2394 | DCHECK_LT(MostSignificantBit(extra_regs), LeastSignificantBit(pop_mask)); |
| 2395 | __ Pop(RegisterList(pop_mask | extra_regs)); |
| 2396 | if (fpu_spill_mask_ != 0u) { |
| 2397 | GetAssembler()->cfi().RestoreState(); |
| 2398 | } |
| 2399 | } else { |
| 2400 | GetAssembler()->cfi().RememberState(); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2401 | DecreaseFrame(fp_spills_offset); |
| Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 2402 | if (fpu_spill_mask_ != 0) { |
| 2403 | uint32_t first = LeastSignificantBit(fpu_spill_mask_); |
| 2404 | |
| 2405 | // Check that list is contiguous. |
| 2406 | DCHECK_EQ(fpu_spill_mask_ >> CTZ(fpu_spill_mask_), ~0u >> (32 - POPCOUNT(fpu_spill_mask_))); |
| 2407 | |
| 2408 | __ Vpop(SRegisterList(vixl32::SRegister(first), POPCOUNT(fpu_spill_mask_))); |
| 2409 | GetAssembler()->cfi().AdjustCFAOffset( |
| 2410 | -static_cast<int>(kArmWordSize) * POPCOUNT(fpu_spill_mask_)); |
| 2411 | GetAssembler()->cfi().RestoreMany(DWARFReg(vixl32::SRegister(0)), fpu_spill_mask_); |
| 2412 | } |
| 2413 | __ Pop(RegisterList(pop_mask)); |
| 2414 | GetAssembler()->cfi().RestoreState(); |
| 2415 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
| 2416 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2417 | } |
| 2418 | |
| 2419 | void CodeGeneratorARMVIXL::Bind(HBasicBlock* block) { |
| 2420 | __ Bind(GetLabelOf(block)); |
| 2421 | } |
| 2422 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2423 | Location InvokeDexCallingConventionVisitorARMVIXL::GetNextLocation(DataType::Type type) { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2424 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2425 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2426 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2427 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2428 | case DataType::Type::kInt8: |
| 2429 | case DataType::Type::kUint16: |
| 2430 | case DataType::Type::kInt16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2431 | case DataType::Type::kInt32: { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2432 | uint32_t index = gp_index_++; |
| 2433 | uint32_t stack_index = stack_index_++; |
| 2434 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2435 | return LocationFrom(calling_convention.GetRegisterAt(index)); |
| 2436 | } else { |
| 2437 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2438 | } |
| 2439 | } |
| 2440 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2441 | case DataType::Type::kInt64: { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2442 | uint32_t index = gp_index_; |
| 2443 | uint32_t stack_index = stack_index_; |
| 2444 | gp_index_ += 2; |
| 2445 | stack_index_ += 2; |
| 2446 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2447 | if (calling_convention.GetRegisterAt(index).Is(r1)) { |
| 2448 | // Skip R1, and use R2_R3 instead. |
| 2449 | gp_index_++; |
| 2450 | index++; |
| 2451 | } |
| 2452 | } |
| 2453 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2454 | DCHECK_EQ(calling_convention.GetRegisterAt(index).GetCode() + 1, |
| 2455 | calling_convention.GetRegisterAt(index + 1).GetCode()); |
| 2456 | |
| 2457 | return LocationFrom(calling_convention.GetRegisterAt(index), |
| 2458 | calling_convention.GetRegisterAt(index + 1)); |
| 2459 | } else { |
| 2460 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2461 | } |
| 2462 | } |
| 2463 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2464 | case DataType::Type::kFloat32: { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2465 | uint32_t stack_index = stack_index_++; |
| 2466 | if (float_index_ % 2 == 0) { |
| 2467 | float_index_ = std::max(double_index_, float_index_); |
| 2468 | } |
| 2469 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 2470 | return LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 2471 | } else { |
| 2472 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2473 | } |
| 2474 | } |
| 2475 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2476 | case DataType::Type::kFloat64: { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2477 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 2478 | uint32_t stack_index = stack_index_; |
| 2479 | stack_index_ += 2; |
| 2480 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 2481 | uint32_t index = double_index_; |
| 2482 | double_index_ += 2; |
| 2483 | Location result = LocationFrom( |
| 2484 | calling_convention.GetFpuRegisterAt(index), |
| 2485 | calling_convention.GetFpuRegisterAt(index + 1)); |
| 2486 | DCHECK(ExpectedPairLayout(result)); |
| 2487 | return result; |
| 2488 | } else { |
| 2489 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2490 | } |
| 2491 | } |
| 2492 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2493 | case DataType::Type::kUint32: |
| 2494 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2495 | case DataType::Type::kVoid: |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2496 | LOG(FATAL) << "Unexpected parameter type " << type; |
| Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 2497 | UNREACHABLE(); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2498 | } |
| 2499 | return Location::NoLocation(); |
| 2500 | } |
| 2501 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2502 | Location InvokeDexCallingConventionVisitorARMVIXL::GetReturnLocation(DataType::Type type) const { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2503 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2504 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2505 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2506 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2507 | case DataType::Type::kInt8: |
| 2508 | case DataType::Type::kUint16: |
| 2509 | case DataType::Type::kInt16: |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2510 | case DataType::Type::kUint32: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2511 | case DataType::Type::kInt32: { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2512 | return LocationFrom(r0); |
| 2513 | } |
| 2514 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2515 | case DataType::Type::kFloat32: { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2516 | return LocationFrom(s0); |
| 2517 | } |
| 2518 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2519 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2520 | case DataType::Type::kInt64: { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2521 | return LocationFrom(r0, r1); |
| 2522 | } |
| 2523 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2524 | case DataType::Type::kFloat64: { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2525 | return LocationFrom(s0, s1); |
| 2526 | } |
| 2527 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2528 | case DataType::Type::kVoid: |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2529 | return Location::NoLocation(); |
| 2530 | } |
| 2531 | |
| 2532 | UNREACHABLE(); |
| 2533 | } |
| 2534 | |
| 2535 | Location InvokeDexCallingConventionVisitorARMVIXL::GetMethodLocation() const { |
| 2536 | return LocationFrom(kMethodRegister); |
| 2537 | } |
| 2538 | |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 2539 | Location CriticalNativeCallingConventionVisitorARMVIXL::GetNextLocation(DataType::Type type) { |
| 2540 | DCHECK_NE(type, DataType::Type::kReference); |
| 2541 | |
| 2542 | // Native ABI uses the same registers as managed, except that the method register r0 |
| 2543 | // is a normal argument. |
| 2544 | Location location = Location::NoLocation(); |
| 2545 | if (DataType::Is64BitType(type)) { |
| 2546 | gpr_index_ = RoundUp(gpr_index_, 2u); |
| 2547 | stack_offset_ = RoundUp(stack_offset_, 2 * kFramePointerSize); |
| 2548 | if (gpr_index_ < 1u + kParameterCoreRegistersLengthVIXL) { |
| 2549 | location = LocationFrom(gpr_index_ == 0u ? r0 : kParameterCoreRegistersVIXL[gpr_index_ - 1u], |
| 2550 | kParameterCoreRegistersVIXL[gpr_index_]); |
| 2551 | gpr_index_ += 2u; |
| 2552 | } |
| 2553 | } else { |
| 2554 | if (gpr_index_ < 1u + kParameterCoreRegistersLengthVIXL) { |
| 2555 | location = LocationFrom(gpr_index_ == 0u ? r0 : kParameterCoreRegistersVIXL[gpr_index_ - 1u]); |
| 2556 | ++gpr_index_; |
| 2557 | } |
| 2558 | } |
| 2559 | if (location.IsInvalid()) { |
| 2560 | if (DataType::Is64BitType(type)) { |
| 2561 | location = Location::DoubleStackSlot(stack_offset_); |
| 2562 | stack_offset_ += 2 * kFramePointerSize; |
| 2563 | } else { |
| 2564 | location = Location::StackSlot(stack_offset_); |
| 2565 | stack_offset_ += kFramePointerSize; |
| 2566 | } |
| 2567 | |
| 2568 | if (for_register_allocation_) { |
| 2569 | location = Location::Any(); |
| 2570 | } |
| 2571 | } |
| 2572 | return location; |
| 2573 | } |
| 2574 | |
| 2575 | Location CriticalNativeCallingConventionVisitorARMVIXL::GetReturnLocation(DataType::Type type) |
| 2576 | const { |
| 2577 | // We perform conversion to the managed ABI return register after the call if needed. |
| 2578 | InvokeDexCallingConventionVisitorARMVIXL dex_calling_convention; |
| 2579 | return dex_calling_convention.GetReturnLocation(type); |
| 2580 | } |
| 2581 | |
| 2582 | Location CriticalNativeCallingConventionVisitorARMVIXL::GetMethodLocation() const { |
| 2583 | // Pass the method in the hidden argument R4. |
| 2584 | return Location::RegisterLocation(R4); |
| 2585 | } |
| 2586 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2587 | void CodeGeneratorARMVIXL::Move32(Location destination, Location source) { |
| 2588 | if (source.Equals(destination)) { |
| 2589 | return; |
| 2590 | } |
| 2591 | if (destination.IsRegister()) { |
| 2592 | if (source.IsRegister()) { |
| 2593 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 2594 | } else if (source.IsFpuRegister()) { |
| 2595 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
| 2596 | } else { |
| 2597 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 2598 | RegisterFrom(destination), |
| 2599 | sp, |
| 2600 | source.GetStackIndex()); |
| 2601 | } |
| 2602 | } else if (destination.IsFpuRegister()) { |
| 2603 | if (source.IsRegister()) { |
| 2604 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
| 2605 | } else if (source.IsFpuRegister()) { |
| 2606 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 2607 | } else { |
| 2608 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 2609 | } |
| 2610 | } else { |
| 2611 | DCHECK(destination.IsStackSlot()) << destination; |
| 2612 | if (source.IsRegister()) { |
| 2613 | GetAssembler()->StoreToOffset(kStoreWord, |
| 2614 | RegisterFrom(source), |
| 2615 | sp, |
| 2616 | destination.GetStackIndex()); |
| 2617 | } else if (source.IsFpuRegister()) { |
| 2618 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 2619 | } else { |
| 2620 | DCHECK(source.IsStackSlot()) << source; |
| 2621 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2622 | vixl32::Register temp = temps.Acquire(); |
| 2623 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 2624 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 2625 | } |
| 2626 | } |
| 2627 | } |
| 2628 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2629 | void CodeGeneratorARMVIXL::MoveConstant(Location location, int32_t value) { |
| 2630 | DCHECK(location.IsRegister()); |
| 2631 | __ Mov(RegisterFrom(location), value); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2632 | } |
| 2633 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2634 | void CodeGeneratorARMVIXL::MoveLocation(Location dst, Location src, DataType::Type dst_type) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2635 | // TODO(VIXL): Maybe refactor to have the 'move' implementation here and use it in |
| 2636 | // `ParallelMoveResolverARMVIXL::EmitMove`, as is done in the `arm64` backend. |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2637 | HParallelMove move(GetGraph()->GetAllocator()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2638 | move.AddMove(src, dst, dst_type, nullptr); |
| 2639 | GetMoveResolver()->EmitNativeCode(&move); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2640 | } |
| 2641 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2642 | void CodeGeneratorARMVIXL::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 2643 | if (location.IsRegister()) { |
| 2644 | locations->AddTemp(location); |
| 2645 | } else if (location.IsRegisterPair()) { |
| 2646 | locations->AddTemp(LocationFrom(LowRegisterFrom(location))); |
| 2647 | locations->AddTemp(LocationFrom(HighRegisterFrom(location))); |
| 2648 | } else { |
| 2649 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 2650 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2651 | } |
| 2652 | |
| 2653 | void CodeGeneratorARMVIXL::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2654 | HInstruction* instruction, |
| 2655 | uint32_t dex_pc, |
| 2656 | SlowPathCode* slow_path) { |
| 2657 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 2658 | |
| 2659 | ThreadOffset32 entrypoint_offset = GetThreadOffset<kArmPointerSize>(entrypoint); |
| 2660 | // Reduce code size for AOT by using shared trampolines for slow path runtime calls across the |
| 2661 | // entire oat file. This adds an extra branch and we do not want to slow down the main path. |
| 2662 | // 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] | 2663 | if (slow_path == nullptr || GetCompilerOptions().IsJitCompiler()) { |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 2664 | __ Ldr(lr, MemOperand(tr, entrypoint_offset.Int32Value())); |
| 2665 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 2666 | // blx in T32 has only 16bit encoding that's why a stricter check for the scope is used. |
| 2667 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2668 | vixl32::k16BitT32InstructionSizeInBytes, |
| 2669 | CodeBufferCheckScope::kExactSize); |
| 2670 | __ blx(lr); |
| 2671 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2672 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2673 | } |
| 2674 | } else { |
| 2675 | // Ensure the pc position is recorded immediately after the `bl` instruction. |
| 2676 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2677 | vixl32::k32BitT32InstructionSizeInBytes, |
| 2678 | CodeBufferCheckScope::kExactSize); |
| 2679 | EmitEntrypointThunkCall(entrypoint_offset); |
| 2680 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2681 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2682 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2683 | } |
| 2684 | } |
| 2685 | |
| 2686 | void CodeGeneratorARMVIXL::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2687 | HInstruction* instruction, |
| 2688 | SlowPathCode* slow_path) { |
| 2689 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2690 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2691 | __ Blx(lr); |
| 2692 | } |
| 2693 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2694 | void InstructionCodeGeneratorARMVIXL::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 2695 | if (successor->IsExitBlock()) { |
| 2696 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 2697 | return; // no code needed |
| 2698 | } |
| 2699 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2700 | HBasicBlock* block = got->GetBlock(); |
| 2701 | HInstruction* previous = got->GetPrevious(); |
| 2702 | HLoopInformation* info = block->GetLoopInformation(); |
| 2703 | |
| 2704 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2705 | codegen_->MaybeIncrementHotness(/* is_frame_entry= */ false); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2706 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2707 | return; |
| 2708 | } |
| 2709 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2710 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2711 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 2); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2712 | } |
| 2713 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 2714 | __ B(codegen_->GetLabelOf(successor)); |
| 2715 | } |
| 2716 | } |
| 2717 | |
| 2718 | void LocationsBuilderARMVIXL::VisitGoto(HGoto* got) { |
| 2719 | got->SetLocations(nullptr); |
| 2720 | } |
| 2721 | |
| 2722 | void InstructionCodeGeneratorARMVIXL::VisitGoto(HGoto* got) { |
| 2723 | HandleGoto(got, got->GetSuccessor()); |
| 2724 | } |
| 2725 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2726 | void LocationsBuilderARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2727 | try_boundary->SetLocations(nullptr); |
| 2728 | } |
| 2729 | |
| 2730 | void InstructionCodeGeneratorARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2731 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2732 | if (!successor->IsExitBlock()) { |
| 2733 | HandleGoto(try_boundary, successor); |
| 2734 | } |
| 2735 | } |
| 2736 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2737 | void LocationsBuilderARMVIXL::VisitExit(HExit* exit) { |
| 2738 | exit->SetLocations(nullptr); |
| 2739 | } |
| 2740 | |
| 2741 | void InstructionCodeGeneratorARMVIXL::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 2742 | } |
| 2743 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2744 | void InstructionCodeGeneratorARMVIXL::GenerateCompareTestAndBranch(HCondition* condition, |
| Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2745 | vixl32::Label* true_target, |
| 2746 | vixl32::Label* false_target, |
| Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2747 | bool is_far_target) { |
| Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2748 | if (true_target == false_target) { |
| 2749 | DCHECK(true_target != nullptr); |
| 2750 | __ B(true_target); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2751 | return; |
| 2752 | } |
| 2753 | |
| Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2754 | vixl32::Label* non_fallthrough_target; |
| 2755 | bool invert; |
| 2756 | bool emit_both_branches; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2757 | |
| Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2758 | if (true_target == nullptr) { |
| 2759 | // The true target is fallthrough. |
| 2760 | DCHECK(false_target != nullptr); |
| 2761 | non_fallthrough_target = false_target; |
| 2762 | invert = true; |
| 2763 | emit_both_branches = false; |
| 2764 | } else { |
| 2765 | non_fallthrough_target = true_target; |
| 2766 | invert = false; |
| 2767 | // Either the false target is fallthrough, or there is no fallthrough |
| 2768 | // and both branches must be emitted. |
| 2769 | emit_both_branches = (false_target != nullptr); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2770 | } |
| 2771 | |
| Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2772 | const auto cond = GenerateTest(condition, invert, codegen_); |
| 2773 | |
| 2774 | __ B(cond.first, non_fallthrough_target, is_far_target); |
| 2775 | |
| 2776 | if (emit_both_branches) { |
| 2777 | // No target falls through, we need to branch. |
| 2778 | __ B(false_target); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2779 | } |
| 2780 | } |
| 2781 | |
| 2782 | void InstructionCodeGeneratorARMVIXL::GenerateTestAndBranch(HInstruction* instruction, |
| 2783 | size_t condition_input_index, |
| 2784 | vixl32::Label* true_target, |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2785 | vixl32::Label* false_target, |
| 2786 | bool far_target) { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2787 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 2788 | |
| 2789 | if (true_target == nullptr && false_target == nullptr) { |
| 2790 | // Nothing to do. The code always falls through. |
| 2791 | return; |
| 2792 | } else if (cond->IsIntConstant()) { |
| 2793 | // Constant condition, statically compared against "true" (integer value 1). |
| 2794 | if (cond->AsIntConstant()->IsTrue()) { |
| 2795 | if (true_target != nullptr) { |
| 2796 | __ B(true_target); |
| 2797 | } |
| 2798 | } else { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 2799 | DCHECK(cond->AsIntConstant()->IsFalse()) << Int32ConstantFrom(cond); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2800 | if (false_target != nullptr) { |
| 2801 | __ B(false_target); |
| 2802 | } |
| 2803 | } |
| 2804 | return; |
| 2805 | } |
| 2806 | |
| 2807 | // The following code generates these patterns: |
| 2808 | // (1) true_target == nullptr && false_target != nullptr |
| 2809 | // - opposite condition true => branch to false_target |
| 2810 | // (2) true_target != nullptr && false_target == nullptr |
| 2811 | // - condition true => branch to true_target |
| 2812 | // (3) true_target != nullptr && false_target != nullptr |
| 2813 | // - condition true => branch to true_target |
| 2814 | // - branch to false_target |
| 2815 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 2816 | // Condition has been materialized, compare the output to 0. |
| 2817 | if (kIsDebugBuild) { |
| 2818 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 2819 | DCHECK(cond_val.IsRegister()); |
| 2820 | } |
| 2821 | if (true_target == nullptr) { |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2822 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, condition_input_index), |
| 2823 | false_target, |
| 2824 | far_target); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2825 | } else { |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2826 | __ CompareAndBranchIfNonZero(InputRegisterAt(instruction, condition_input_index), |
| 2827 | true_target, |
| 2828 | far_target); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2829 | } |
| 2830 | } else { |
| 2831 | // Condition has not been materialized. Use its inputs as the comparison and |
| 2832 | // its condition as the branch condition. |
| 2833 | HCondition* condition = cond->AsCondition(); |
| 2834 | |
| 2835 | // If this is a long or FP comparison that has been folded into |
| 2836 | // the HCondition, generate the comparison directly. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2837 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 2838 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
| Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2839 | GenerateCompareTestAndBranch(condition, true_target, false_target, far_target); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2840 | return; |
| 2841 | } |
| 2842 | |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2843 | vixl32::Label* non_fallthrough_target; |
| 2844 | vixl32::Condition arm_cond = vixl32::Condition::None(); |
| 2845 | const vixl32::Register left = InputRegisterAt(cond, 0); |
| 2846 | const Operand right = InputOperandAt(cond, 1); |
| 2847 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2848 | if (true_target == nullptr) { |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2849 | arm_cond = ARMCondition(condition->GetOppositeCondition()); |
| 2850 | non_fallthrough_target = false_target; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2851 | } else { |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2852 | arm_cond = ARMCondition(condition->GetCondition()); |
| 2853 | non_fallthrough_target = true_target; |
| 2854 | } |
| 2855 | |
| 2856 | if (right.IsImmediate() && right.GetImmediate() == 0 && (arm_cond.Is(ne) || arm_cond.Is(eq))) { |
| 2857 | if (arm_cond.Is(eq)) { |
| Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2858 | __ CompareAndBranchIfZero(left, non_fallthrough_target, far_target); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2859 | } else { |
| 2860 | DCHECK(arm_cond.Is(ne)); |
| Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2861 | __ CompareAndBranchIfNonZero(left, non_fallthrough_target, far_target); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2862 | } |
| 2863 | } else { |
| 2864 | __ Cmp(left, right); |
| Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2865 | __ B(arm_cond, non_fallthrough_target, far_target); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2866 | } |
| 2867 | } |
| 2868 | |
| 2869 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 2870 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 2871 | if (true_target != nullptr && false_target != nullptr) { |
| 2872 | __ B(false_target); |
| 2873 | } |
| 2874 | } |
| 2875 | |
| 2876 | void LocationsBuilderARMVIXL::VisitIf(HIf* if_instr) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2877 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2878 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| 2879 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2880 | } |
| 2881 | } |
| 2882 | |
| 2883 | void InstructionCodeGeneratorARMVIXL::VisitIf(HIf* if_instr) { |
| 2884 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 2885 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2886 | vixl32::Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 2887 | nullptr : codegen_->GetLabelOf(true_successor); |
| 2888 | vixl32::Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 2889 | nullptr : codegen_->GetLabelOf(false_successor); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2890 | GenerateTestAndBranch(if_instr, /* condition_input_index= */ 0, true_target, false_target); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2891 | } |
| 2892 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2893 | void LocationsBuilderARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2894 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2895 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 2896 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 2897 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2898 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 2899 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2900 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| 2901 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2902 | } |
| 2903 | } |
| 2904 | |
| 2905 | void InstructionCodeGeneratorARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2906 | SlowPathCodeARMVIXL* slow_path = |
| 2907 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARMVIXL>(deoptimize); |
| 2908 | GenerateTestAndBranch(deoptimize, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2909 | /* condition_input_index= */ 0, |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2910 | slow_path->GetEntryLabel(), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2911 | /* false_target= */ nullptr); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2912 | } |
| 2913 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2914 | void LocationsBuilderARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2915 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2916 | LocationSummary(flag, LocationSummary::kNoCall); |
| 2917 | locations->SetOut(Location::RequiresRegister()); |
| 2918 | } |
| 2919 | |
| 2920 | void InstructionCodeGeneratorARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2921 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 2922 | OutputRegister(flag), |
| 2923 | sp, |
| 2924 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 2925 | } |
| 2926 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2927 | void LocationsBuilderARMVIXL::VisitSelect(HSelect* select) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2928 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2929 | const bool is_floating_point = DataType::IsFloatingPointType(select->GetType()); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2930 | |
| 2931 | if (is_floating_point) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2932 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2933 | locations->SetInAt(1, Location::FpuRegisterOrConstant(select->GetTrueValue())); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2934 | } else { |
| 2935 | locations->SetInAt(0, Location::RequiresRegister()); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2936 | locations->SetInAt(1, Arm8BitEncodableConstantOrRegister(select->GetTrueValue())); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2937 | } |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2938 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2939 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2940 | locations->SetInAt(2, Location::RegisterOrConstant(select->GetCondition())); |
| 2941 | // The code generator handles overlap with the values, but not with the condition. |
| 2942 | locations->SetOut(Location::SameAsFirstInput()); |
| 2943 | } else if (is_floating_point) { |
| 2944 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2945 | } else { |
| 2946 | if (!locations->InAt(1).IsConstant()) { |
| 2947 | locations->SetInAt(0, Arm8BitEncodableConstantOrRegister(select->GetFalseValue())); |
| 2948 | } |
| 2949 | |
| 2950 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2951 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2952 | } |
| 2953 | |
| 2954 | void InstructionCodeGeneratorARMVIXL::VisitSelect(HSelect* select) { |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2955 | HInstruction* const condition = select->GetCondition(); |
| 2956 | const LocationSummary* const locations = select->GetLocations(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2957 | const DataType::Type type = select->GetType(); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2958 | const Location first = locations->InAt(0); |
| 2959 | const Location out = locations->Out(); |
| 2960 | const Location second = locations->InAt(1); |
| Nicolas Geoffray | 7b05c5f | 2018-09-21 11:31:38 +0100 | [diff] [blame] | 2961 | |
| 2962 | // In the unlucky case the output of this instruction overlaps |
| 2963 | // with an input of an "emitted-at-use-site" condition, and |
| 2964 | // the output of this instruction is not one of its inputs, we'll |
| 2965 | // need to fallback to branches instead of conditional ARM instructions. |
| 2966 | bool output_overlaps_with_condition_inputs = |
| 2967 | !IsBooleanValueOrMaterializedCondition(condition) && |
| 2968 | !out.Equals(first) && |
| 2969 | !out.Equals(second) && |
| 2970 | (condition->GetLocations()->InAt(0).Equals(out) || |
| 2971 | condition->GetLocations()->InAt(1).Equals(out)); |
| 2972 | DCHECK(!output_overlaps_with_condition_inputs || condition->IsCondition()); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2973 | Location src; |
| 2974 | |
| 2975 | if (condition->IsIntConstant()) { |
| 2976 | if (condition->AsIntConstant()->IsFalse()) { |
| 2977 | src = first; |
| 2978 | } else { |
| 2979 | src = second; |
| 2980 | } |
| 2981 | |
| 2982 | codegen_->MoveLocation(out, src, type); |
| 2983 | return; |
| 2984 | } |
| 2985 | |
| Nicolas Geoffray | 7b05c5f | 2018-09-21 11:31:38 +0100 | [diff] [blame] | 2986 | if (!DataType::IsFloatingPointType(type) && !output_overlaps_with_condition_inputs) { |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2987 | bool invert = false; |
| 2988 | |
| 2989 | if (out.Equals(second)) { |
| 2990 | src = first; |
| 2991 | invert = true; |
| 2992 | } else if (out.Equals(first)) { |
| 2993 | src = second; |
| 2994 | } else if (second.IsConstant()) { |
| 2995 | DCHECK(CanEncodeConstantAs8BitImmediate(second.GetConstant())); |
| 2996 | src = second; |
| 2997 | } else if (first.IsConstant()) { |
| 2998 | DCHECK(CanEncodeConstantAs8BitImmediate(first.GetConstant())); |
| 2999 | src = first; |
| 3000 | invert = true; |
| 3001 | } else { |
| 3002 | src = second; |
| 3003 | } |
| 3004 | |
| 3005 | if (CanGenerateConditionalMove(out, src)) { |
| 3006 | if (!out.Equals(first) && !out.Equals(second)) { |
| 3007 | codegen_->MoveLocation(out, src.Equals(first) ? second : first, type); |
| 3008 | } |
| 3009 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3010 | std::pair<vixl32::Condition, vixl32::Condition> cond(eq, ne); |
| 3011 | |
| 3012 | if (IsBooleanValueOrMaterializedCondition(condition)) { |
| 3013 | __ Cmp(InputRegisterAt(select, 2), 0); |
| 3014 | cond = invert ? std::make_pair(eq, ne) : std::make_pair(ne, eq); |
| 3015 | } else { |
| 3016 | cond = GenerateTest(condition->AsCondition(), invert, codegen_); |
| 3017 | } |
| 3018 | |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3019 | const size_t instr_count = out.IsRegisterPair() ? 4 : 2; |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3020 | // We use the scope because of the IT block that follows. |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3021 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 3022 | instr_count * vixl32::k16BitT32InstructionSizeInBytes, |
| 3023 | CodeBufferCheckScope::kExactSize); |
| 3024 | |
| 3025 | if (out.IsRegister()) { |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3026 | __ it(cond.first); |
| 3027 | __ mov(cond.first, RegisterFrom(out), OperandFrom(src, type)); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3028 | } else { |
| 3029 | DCHECK(out.IsRegisterPair()); |
| 3030 | |
| 3031 | Operand operand_high(0); |
| 3032 | Operand operand_low(0); |
| 3033 | |
| 3034 | if (src.IsConstant()) { |
| 3035 | const int64_t value = Int64ConstantFrom(src); |
| 3036 | |
| 3037 | operand_high = High32Bits(value); |
| 3038 | operand_low = Low32Bits(value); |
| 3039 | } else { |
| 3040 | DCHECK(src.IsRegisterPair()); |
| 3041 | operand_high = HighRegisterFrom(src); |
| 3042 | operand_low = LowRegisterFrom(src); |
| 3043 | } |
| 3044 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3045 | __ it(cond.first); |
| 3046 | __ mov(cond.first, LowRegisterFrom(out), operand_low); |
| 3047 | __ it(cond.first); |
| 3048 | __ mov(cond.first, HighRegisterFrom(out), operand_high); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3049 | } |
| 3050 | |
| 3051 | return; |
| 3052 | } |
| 3053 | } |
| 3054 | |
| 3055 | vixl32::Label* false_target = nullptr; |
| 3056 | vixl32::Label* true_target = nullptr; |
| 3057 | vixl32::Label select_end; |
| Nicolas Geoffray | 7b05c5f | 2018-09-21 11:31:38 +0100 | [diff] [blame] | 3058 | vixl32::Label other_case; |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3059 | vixl32::Label* const target = codegen_->GetFinalLabel(select, &select_end); |
| 3060 | |
| 3061 | if (out.Equals(second)) { |
| 3062 | true_target = target; |
| 3063 | src = first; |
| 3064 | } else { |
| 3065 | false_target = target; |
| 3066 | src = second; |
| 3067 | |
| 3068 | if (!out.Equals(first)) { |
| Nicolas Geoffray | 7b05c5f | 2018-09-21 11:31:38 +0100 | [diff] [blame] | 3069 | if (output_overlaps_with_condition_inputs) { |
| 3070 | false_target = &other_case; |
| 3071 | } else { |
| 3072 | codegen_->MoveLocation(out, first, type); |
| 3073 | } |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3074 | } |
| 3075 | } |
| 3076 | |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3077 | GenerateTestAndBranch(select, 2, true_target, false_target, /* far_target= */ false); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3078 | codegen_->MoveLocation(out, src, type); |
| Nicolas Geoffray | 7b05c5f | 2018-09-21 11:31:38 +0100 | [diff] [blame] | 3079 | if (output_overlaps_with_condition_inputs) { |
| 3080 | __ B(target); |
| 3081 | __ Bind(&other_case); |
| 3082 | codegen_->MoveLocation(out, first, type); |
| 3083 | } |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3084 | |
| 3085 | if (select_end.IsReferenced()) { |
| 3086 | __ Bind(&select_end); |
| 3087 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3088 | } |
| 3089 | |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 3090 | void LocationsBuilderARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3091 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 3092 | } |
| 3093 | |
| 3094 | void InstructionCodeGeneratorARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3095 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| 3096 | } |
| 3097 | |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3098 | void CodeGeneratorARMVIXL::IncreaseFrame(size_t adjustment) { |
| 3099 | __ Claim(adjustment); |
| 3100 | GetAssembler()->cfi().AdjustCFAOffset(adjustment); |
| 3101 | } |
| 3102 | |
| 3103 | void CodeGeneratorARMVIXL::DecreaseFrame(size_t adjustment) { |
| 3104 | __ Drop(adjustment); |
| 3105 | GetAssembler()->cfi().AdjustCFAOffset(-adjustment); |
| 3106 | } |
| 3107 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3108 | void CodeGeneratorARMVIXL::GenerateNop() { |
| 3109 | __ Nop(); |
| 3110 | } |
| 3111 | |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3112 | // `temp` is an extra temporary register that is used for some conditions; |
| 3113 | // callers may not specify it, in which case the method will use a scratch |
| 3114 | // register instead. |
| 3115 | void CodeGeneratorARMVIXL::GenerateConditionWithZero(IfCondition condition, |
| 3116 | vixl32::Register out, |
| 3117 | vixl32::Register in, |
| 3118 | vixl32::Register temp) { |
| 3119 | switch (condition) { |
| 3120 | case kCondEQ: |
| 3121 | // x <= 0 iff x == 0 when the comparison is unsigned. |
| 3122 | case kCondBE: |
| 3123 | if (!temp.IsValid() || (out.IsLow() && !out.Is(in))) { |
| 3124 | temp = out; |
| 3125 | } |
| 3126 | |
| 3127 | // Avoid 32-bit instructions if possible; note that `in` and `temp` must be |
| 3128 | // different as well. |
| 3129 | if (in.IsLow() && temp.IsLow() && !in.Is(temp)) { |
| 3130 | // temp = - in; only 0 sets the carry flag. |
| 3131 | __ Rsbs(temp, in, 0); |
| 3132 | |
| 3133 | if (out.Is(in)) { |
| 3134 | std::swap(in, temp); |
| 3135 | } |
| 3136 | |
| 3137 | // out = - in + in + carry = carry |
| 3138 | __ Adc(out, temp, in); |
| 3139 | } else { |
| 3140 | // If `in` is 0, then it has 32 leading zeros, and less than that otherwise. |
| 3141 | __ Clz(out, in); |
| 3142 | // Any number less than 32 logically shifted right by 5 bits results in 0; |
| 3143 | // the same operation on 32 yields 1. |
| 3144 | __ Lsr(out, out, 5); |
| 3145 | } |
| 3146 | |
| 3147 | break; |
| 3148 | case kCondNE: |
| 3149 | // x > 0 iff x != 0 when the comparison is unsigned. |
| 3150 | case kCondA: { |
| 3151 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3152 | |
| 3153 | if (out.Is(in)) { |
| 3154 | if (!temp.IsValid() || in.Is(temp)) { |
| 3155 | temp = temps.Acquire(); |
| 3156 | } |
| 3157 | } else if (!temp.IsValid() || !temp.IsLow()) { |
| 3158 | temp = out; |
| 3159 | } |
| 3160 | |
| 3161 | // temp = in - 1; only 0 does not set the carry flag. |
| 3162 | __ Subs(temp, in, 1); |
| 3163 | // out = in + ~temp + carry = in + (-(in - 1) - 1) + carry = in - in + 1 - 1 + carry = carry |
| 3164 | __ Sbc(out, in, temp); |
| 3165 | break; |
| 3166 | } |
| 3167 | case kCondGE: |
| 3168 | __ Mvn(out, in); |
| 3169 | in = out; |
| 3170 | FALLTHROUGH_INTENDED; |
| 3171 | case kCondLT: |
| 3172 | // We only care about the sign bit. |
| 3173 | __ Lsr(out, in, 31); |
| 3174 | break; |
| 3175 | case kCondAE: |
| 3176 | // Trivially true. |
| 3177 | __ Mov(out, 1); |
| 3178 | break; |
| 3179 | case kCondB: |
| 3180 | // Trivially false. |
| 3181 | __ Mov(out, 0); |
| 3182 | break; |
| 3183 | default: |
| 3184 | LOG(FATAL) << "Unexpected condition " << condition; |
| 3185 | UNREACHABLE(); |
| 3186 | } |
| 3187 | } |
| 3188 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3189 | void LocationsBuilderARMVIXL::HandleCondition(HCondition* cond) { |
| 3190 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3191 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
| Nicolas Geoffray | 7b05c5f | 2018-09-21 11:31:38 +0100 | [diff] [blame] | 3192 | const DataType::Type type = cond->InputAt(0)->GetType(); |
| 3193 | if (DataType::IsFloatingPointType(type)) { |
| 3194 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3195 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
| 3196 | } else { |
| 3197 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3198 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 3199 | } |
| 3200 | if (!cond->IsEmittedAtUseSite()) { |
| 3201 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3202 | } |
| 3203 | } |
| 3204 | |
| 3205 | void InstructionCodeGeneratorARMVIXL::HandleCondition(HCondition* cond) { |
| 3206 | if (cond->IsEmittedAtUseSite()) { |
| 3207 | return; |
| 3208 | } |
| 3209 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3210 | const DataType::Type type = cond->GetLeft()->GetType(); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3211 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3212 | if (DataType::IsFloatingPointType(type)) { |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3213 | GenerateConditionGeneric(cond, codegen_); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3214 | return; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3215 | } |
| 3216 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3217 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3218 | |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3219 | const IfCondition condition = cond->GetCondition(); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3220 | |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3221 | // A condition with only one boolean input, or two boolean inputs without being equality or |
| 3222 | // inequality results from transformations done by the instruction simplifier, and is handled |
| 3223 | // as a regular condition with integral inputs. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3224 | if (type == DataType::Type::kBool && |
| 3225 | cond->GetRight()->GetType() == DataType::Type::kBool && |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3226 | (condition == kCondEQ || condition == kCondNE)) { |
| 3227 | vixl32::Register left = InputRegisterAt(cond, 0); |
| 3228 | const vixl32::Register out = OutputRegister(cond); |
| 3229 | const Location right_loc = cond->GetLocations()->InAt(1); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3230 | |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3231 | // The constant case is handled by the instruction simplifier. |
| 3232 | DCHECK(!right_loc.IsConstant()); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3233 | |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3234 | vixl32::Register right = RegisterFrom(right_loc); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3235 | |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3236 | // Avoid 32-bit instructions if possible. |
| 3237 | if (out.Is(right)) { |
| 3238 | std::swap(left, right); |
| 3239 | } |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3240 | |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3241 | __ Eor(out, left, right); |
| 3242 | |
| 3243 | if (condition == kCondEQ) { |
| 3244 | __ Eor(out, out, 1); |
| 3245 | } |
| 3246 | |
| 3247 | return; |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3248 | } |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 3249 | |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3250 | GenerateConditionIntegralOrNonPrimitive(cond, codegen_); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3251 | } |
| 3252 | |
| 3253 | void LocationsBuilderARMVIXL::VisitEqual(HEqual* comp) { |
| 3254 | HandleCondition(comp); |
| 3255 | } |
| 3256 | |
| 3257 | void InstructionCodeGeneratorARMVIXL::VisitEqual(HEqual* comp) { |
| 3258 | HandleCondition(comp); |
| 3259 | } |
| 3260 | |
| 3261 | void LocationsBuilderARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 3262 | HandleCondition(comp); |
| 3263 | } |
| 3264 | |
| 3265 | void InstructionCodeGeneratorARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 3266 | HandleCondition(comp); |
| 3267 | } |
| 3268 | |
| 3269 | void LocationsBuilderARMVIXL::VisitLessThan(HLessThan* comp) { |
| 3270 | HandleCondition(comp); |
| 3271 | } |
| 3272 | |
| 3273 | void InstructionCodeGeneratorARMVIXL::VisitLessThan(HLessThan* comp) { |
| 3274 | HandleCondition(comp); |
| 3275 | } |
| 3276 | |
| 3277 | void LocationsBuilderARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 3278 | HandleCondition(comp); |
| 3279 | } |
| 3280 | |
| 3281 | void InstructionCodeGeneratorARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 3282 | HandleCondition(comp); |
| 3283 | } |
| 3284 | |
| 3285 | void LocationsBuilderARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 3286 | HandleCondition(comp); |
| 3287 | } |
| 3288 | |
| 3289 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 3290 | HandleCondition(comp); |
| 3291 | } |
| 3292 | |
| 3293 | void LocationsBuilderARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 3294 | HandleCondition(comp); |
| 3295 | } |
| 3296 | |
| 3297 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 3298 | HandleCondition(comp); |
| 3299 | } |
| 3300 | |
| 3301 | void LocationsBuilderARMVIXL::VisitBelow(HBelow* comp) { |
| 3302 | HandleCondition(comp); |
| 3303 | } |
| 3304 | |
| 3305 | void InstructionCodeGeneratorARMVIXL::VisitBelow(HBelow* comp) { |
| 3306 | HandleCondition(comp); |
| 3307 | } |
| 3308 | |
| 3309 | void LocationsBuilderARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 3310 | HandleCondition(comp); |
| 3311 | } |
| 3312 | |
| 3313 | void InstructionCodeGeneratorARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 3314 | HandleCondition(comp); |
| 3315 | } |
| 3316 | |
| 3317 | void LocationsBuilderARMVIXL::VisitAbove(HAbove* comp) { |
| 3318 | HandleCondition(comp); |
| 3319 | } |
| 3320 | |
| 3321 | void InstructionCodeGeneratorARMVIXL::VisitAbove(HAbove* comp) { |
| 3322 | HandleCondition(comp); |
| 3323 | } |
| 3324 | |
| 3325 | void LocationsBuilderARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 3326 | HandleCondition(comp); |
| 3327 | } |
| 3328 | |
| 3329 | void InstructionCodeGeneratorARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 3330 | HandleCondition(comp); |
| 3331 | } |
| 3332 | |
| 3333 | void LocationsBuilderARMVIXL::VisitIntConstant(HIntConstant* constant) { |
| 3334 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3335 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3336 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3337 | } |
| 3338 | |
| 3339 | void InstructionCodeGeneratorARMVIXL::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 3340 | // Will be generated at use site. |
| 3341 | } |
| 3342 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3343 | void LocationsBuilderARMVIXL::VisitNullConstant(HNullConstant* constant) { |
| 3344 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3345 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3346 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3347 | } |
| 3348 | |
| 3349 | void InstructionCodeGeneratorARMVIXL::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 3350 | // Will be generated at use site. |
| 3351 | } |
| 3352 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3353 | void LocationsBuilderARMVIXL::VisitLongConstant(HLongConstant* constant) { |
| 3354 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3355 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3356 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3357 | } |
| 3358 | |
| 3359 | void InstructionCodeGeneratorARMVIXL::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 3360 | // Will be generated at use site. |
| 3361 | } |
| 3362 | |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3363 | void LocationsBuilderARMVIXL::VisitFloatConstant(HFloatConstant* constant) { |
| 3364 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3365 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3366 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3367 | } |
| 3368 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3369 | void InstructionCodeGeneratorARMVIXL::VisitFloatConstant( |
| 3370 | HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3371 | // Will be generated at use site. |
| 3372 | } |
| 3373 | |
| 3374 | void LocationsBuilderARMVIXL::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3375 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3376 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3377 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3378 | } |
| 3379 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3380 | void InstructionCodeGeneratorARMVIXL::VisitDoubleConstant( |
| 3381 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3382 | // Will be generated at use site. |
| 3383 | } |
| 3384 | |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 3385 | void LocationsBuilderARMVIXL::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 3386 | constructor_fence->SetLocations(nullptr); |
| 3387 | } |
| 3388 | |
| 3389 | void InstructionCodeGeneratorARMVIXL::VisitConstructorFence( |
| 3390 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 3391 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 3392 | } |
| 3393 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3394 | void LocationsBuilderARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3395 | memory_barrier->SetLocations(nullptr); |
| 3396 | } |
| 3397 | |
| 3398 | void InstructionCodeGeneratorARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3399 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 3400 | } |
| 3401 | |
| 3402 | void LocationsBuilderARMVIXL::VisitReturnVoid(HReturnVoid* ret) { |
| 3403 | ret->SetLocations(nullptr); |
| 3404 | } |
| 3405 | |
| 3406 | void InstructionCodeGeneratorARMVIXL::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 3407 | codegen_->GenerateFrameExit(); |
| 3408 | } |
| 3409 | |
| 3410 | void LocationsBuilderARMVIXL::VisitReturn(HReturn* ret) { |
| 3411 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3412 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3413 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
| 3414 | } |
| 3415 | |
| Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 3416 | void InstructionCodeGeneratorARMVIXL::VisitReturn(HReturn* ret) { |
| 3417 | if (GetGraph()->IsCompilingOsr()) { |
| 3418 | // To simplify callers of an OSR method, we put the return value in both |
| 3419 | // floating point and core registers. |
| 3420 | switch (ret->InputAt(0)->GetType()) { |
| 3421 | case DataType::Type::kFloat32: |
| 3422 | __ Vmov(r0, s0); |
| 3423 | break; |
| 3424 | case DataType::Type::kFloat64: |
| 3425 | __ Vmov(r0, r1, d0); |
| 3426 | break; |
| 3427 | default: |
| 3428 | break; |
| 3429 | } |
| 3430 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3431 | codegen_->GenerateFrameExit(); |
| 3432 | } |
| 3433 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3434 | void LocationsBuilderARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3435 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3436 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3437 | // the method_idx. |
| 3438 | HandleInvoke(invoke); |
| 3439 | } |
| 3440 | |
| 3441 | void InstructionCodeGeneratorARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3442 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3443 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 3); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3444 | } |
| 3445 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3446 | void LocationsBuilderARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3447 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3448 | // art::PrepareForRegisterAllocation. |
| 3449 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 3450 | |
| Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3451 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3452 | if (intrinsic.TryDispatch(invoke)) { |
| Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3453 | return; |
| 3454 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3455 | |
| Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 3456 | if (invoke->GetCodePtrLocation() == CodePtrLocation::kCallCriticalNative) { |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 3457 | CriticalNativeCallingConventionVisitorARMVIXL calling_convention_visitor( |
| 3458 | /*for_register_allocation=*/ true); |
| 3459 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 3460 | } else { |
| 3461 | HandleInvoke(invoke); |
| 3462 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3463 | } |
| 3464 | |
| Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3465 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARMVIXL* codegen) { |
| 3466 | if (invoke->GetLocations()->Intrinsified()) { |
| 3467 | IntrinsicCodeGeneratorARMVIXL intrinsic(codegen); |
| 3468 | intrinsic.Dispatch(invoke); |
| 3469 | return true; |
| 3470 | } |
| 3471 | return false; |
| 3472 | } |
| 3473 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3474 | void InstructionCodeGeneratorARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3475 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3476 | // art::PrepareForRegisterAllocation. |
| 3477 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 3478 | |
| Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3479 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3480 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 4); |
| Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3481 | return; |
| 3482 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3483 | |
| 3484 | LocationSummary* locations = invoke->GetLocations(); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3485 | codegen_->GenerateStaticOrDirectCall( |
| 3486 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
| Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3487 | |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3488 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 5); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3489 | } |
| 3490 | |
| 3491 | void LocationsBuilderARMVIXL::HandleInvoke(HInvoke* invoke) { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3492 | InvokeDexCallingConventionVisitorARMVIXL calling_convention_visitor; |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3493 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 3494 | } |
| 3495 | |
| 3496 | void LocationsBuilderARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3497 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3498 | if (intrinsic.TryDispatch(invoke)) { |
| 3499 | return; |
| 3500 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3501 | |
| 3502 | HandleInvoke(invoke); |
| 3503 | } |
| 3504 | |
| 3505 | void InstructionCodeGeneratorARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3506 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3507 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 6); |
| Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3508 | return; |
| 3509 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3510 | |
| 3511 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3512 | DCHECK(!codegen_->IsLeafMethod()); |
| Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3513 | |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3514 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 7); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3515 | } |
| 3516 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3517 | void LocationsBuilderARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3518 | HandleInvoke(invoke); |
| 3519 | // Add the hidden argument. |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 3520 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRecursive) { |
| 3521 | // We cannot request r12 as it's blocked by the register allocator. |
| 3522 | invoke->GetLocations()->SetInAt(invoke->GetNumberOfArguments() - 1, Location::Any()); |
| 3523 | } |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3524 | } |
| 3525 | |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 3526 | void CodeGeneratorARMVIXL::MaybeGenerateInlineCacheCheck(HInstruction* instruction, |
| 3527 | vixl32::Register klass) { |
| 3528 | DCHECK_EQ(r0.GetCode(), klass.GetCode()); |
| Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 3529 | // We know the destination of an intrinsic, so no need to record inline |
| 3530 | // caches. |
| 3531 | if (!instruction->GetLocations()->Intrinsified() && |
| Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 3532 | GetGraph()->IsCompilingBaseline() && |
| Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 3533 | !Runtime::Current()->IsAotCompiler()) { |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 3534 | DCHECK(!instruction->GetEnvironment()->IsFromInlinedInvoke()); |
| Nicolas Geoffray | 095dc46 | 2020-08-17 16:40:28 +0100 | [diff] [blame] | 3535 | ScopedProfilingInfoUse spiu( |
| 3536 | Runtime::Current()->GetJit(), GetGraph()->GetArtMethod(), Thread::Current()); |
| 3537 | ProfilingInfo* info = spiu.GetProfilingInfo(); |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 3538 | if (info != nullptr) { |
| 3539 | InlineCache* cache = info->GetInlineCache(instruction->GetDexPc()); |
| 3540 | uint32_t address = reinterpret_cast32<uint32_t>(cache); |
| 3541 | vixl32::Label done; |
| 3542 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3543 | temps.Exclude(ip); |
| 3544 | __ Mov(r4, address); |
| 3545 | __ Ldr(ip, MemOperand(r4, InlineCache::ClassesOffset().Int32Value())); |
| 3546 | // Fast path for a monomorphic cache. |
| 3547 | __ Cmp(klass, ip); |
| 3548 | __ B(eq, &done, /* is_far_target= */ false); |
| 3549 | InvokeRuntime(kQuickUpdateInlineCache, instruction, instruction->GetDexPc()); |
| 3550 | __ Bind(&done); |
| 3551 | } |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 3552 | } |
| 3553 | } |
| 3554 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3555 | void InstructionCodeGeneratorARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3556 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 3557 | LocationSummary* locations = invoke->GetLocations(); |
| 3558 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3559 | Location receiver = locations->InAt(0); |
| 3560 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3561 | |
| 3562 | DCHECK(!receiver.IsStackSlot()); |
| 3563 | |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3564 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
| 3565 | { |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 3566 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 3567 | vixl32::kMaxInstructionSizeInBytes, |
| 3568 | CodeBufferCheckScope::kMaximumSize); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3569 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 3570 | __ ldr(temp, MemOperand(RegisterFrom(receiver), class_offset)); |
| 3571 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 3572 | } |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3573 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3574 | // emit a read barrier for the previous class reference load. |
| 3575 | // However this is not required in practice, as this is an |
| 3576 | // intermediate/temporary reference and because the current |
| 3577 | // concurrent copying collector keeps the from-space memory |
| 3578 | // intact/accessible until the end of the marking phase (the |
| 3579 | // concurrent copying collector may not in the future). |
| 3580 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 3581 | |
| 3582 | // If we're compiling baseline, update the inline cache. |
| 3583 | codegen_->MaybeGenerateInlineCacheCheck(invoke, temp); |
| 3584 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3585 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3586 | temp, |
| 3587 | temp, |
| 3588 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 3589 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3590 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 3591 | invoke->GetImtIndex(), kArmPointerSize)); |
| 3592 | // temp = temp->GetImtEntryAt(method_offset); |
| 3593 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 3594 | uint32_t entry_point = |
| 3595 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
| 3596 | // LR = temp->GetEntryPoint(); |
| 3597 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
| 3598 | |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3599 | { |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 3600 | // Set the hidden (in r12) argument. It is done here, right before a BLX to prevent other |
| 3601 | // instruction from clobbering it as they might use r12 as a scratch register. |
| 3602 | Location hidden_reg = Location::RegisterLocation(r12.GetCode()); |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3603 | // The VIXL macro assembler may clobber any of the scratch registers that are available to it, |
| 3604 | // so it checks if the application is using them (by passing them to the macro assembler |
| 3605 | // methods). The following application of UseScratchRegisterScope corrects VIXL's notion of |
| 3606 | // what is available, and is the opposite of the standard usage: Instead of requesting a |
| 3607 | // temporary location, it imposes an external constraint (i.e. a specific register is reserved |
| 3608 | // for the hidden argument). Note that this works even if VIXL needs a scratch register itself |
| 3609 | // (to materialize the constant), since the destination register becomes available for such use |
| 3610 | // internally for the duration of the macro instruction. |
| 3611 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 3612 | temps.Exclude(RegisterFrom(hidden_reg)); |
| 3613 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRecursive) { |
| 3614 | Location current_method = locations->InAt(invoke->GetNumberOfArguments() - 1); |
| 3615 | if (current_method.IsStackSlot()) { |
| 3616 | GetAssembler()->LoadFromOffset( |
| 3617 | kLoadWord, RegisterFrom(hidden_reg), sp, current_method.GetStackIndex()); |
| 3618 | } else { |
| 3619 | __ Mov(RegisterFrom(hidden_reg), RegisterFrom(current_method)); |
| 3620 | } |
| Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame] | 3621 | } else if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRuntimeCall) { |
| 3622 | // We pass the method from the IMT in case of a conflict. This will ensure |
| 3623 | // we go into the runtime to resolve the actual method. |
| 3624 | CHECK_NE(temp.GetCode(), lr.GetCode()); |
| 3625 | __ Mov(RegisterFrom(hidden_reg), temp); |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 3626 | } else { |
| 3627 | codegen_->LoadMethod(invoke->GetHiddenArgumentLoadKind(), hidden_reg, invoke); |
| 3628 | } |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3629 | } |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3630 | { |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3631 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 3632 | // 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] | 3633 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3634 | vixl32::k16BitT32InstructionSizeInBytes, |
| 3635 | CodeBufferCheckScope::kExactSize); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3636 | // LR(); |
| 3637 | __ blx(lr); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3638 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3639 | DCHECK(!codegen_->IsLeafMethod()); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3640 | } |
| Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3641 | |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3642 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 8); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3643 | } |
| 3644 | |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3645 | void LocationsBuilderARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 3646 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3647 | if (intrinsic.TryDispatch(invoke)) { |
| 3648 | return; |
| 3649 | } |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3650 | HandleInvoke(invoke); |
| 3651 | } |
| 3652 | |
| 3653 | void InstructionCodeGeneratorARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 3654 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3655 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 9); |
| 3656 | return; |
| 3657 | } |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3658 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 3659 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 10); |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3660 | } |
| 3661 | |
| Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 3662 | void LocationsBuilderARMVIXL::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 3663 | HandleInvoke(invoke); |
| 3664 | } |
| 3665 | |
| 3666 | void InstructionCodeGeneratorARMVIXL::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 3667 | codegen_->GenerateInvokeCustomCall(invoke); |
| Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 3668 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 11); |
| Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 3669 | } |
| 3670 | |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3671 | void LocationsBuilderARMVIXL::VisitNeg(HNeg* neg) { |
| 3672 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3673 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3674 | switch (neg->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3675 | case DataType::Type::kInt32: { |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3676 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3677 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3678 | break; |
| 3679 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3680 | case DataType::Type::kInt64: { |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3681 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3682 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3683 | break; |
| 3684 | } |
| 3685 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3686 | case DataType::Type::kFloat32: |
| 3687 | case DataType::Type::kFloat64: |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3688 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3689 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3690 | break; |
| 3691 | |
| 3692 | default: |
| 3693 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3694 | } |
| 3695 | } |
| 3696 | |
| 3697 | void InstructionCodeGeneratorARMVIXL::VisitNeg(HNeg* neg) { |
| 3698 | LocationSummary* locations = neg->GetLocations(); |
| 3699 | Location out = locations->Out(); |
| 3700 | Location in = locations->InAt(0); |
| 3701 | switch (neg->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3702 | case DataType::Type::kInt32: |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3703 | __ Rsb(OutputRegister(neg), InputRegisterAt(neg, 0), 0); |
| 3704 | break; |
| 3705 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3706 | case DataType::Type::kInt64: |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3707 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 3708 | __ Rsbs(LowRegisterFrom(out), LowRegisterFrom(in), 0); |
| 3709 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 3710 | // instruction here, as it does not exist in the Thumb-2 |
| 3711 | // instruction set. We use the following approach |
| 3712 | // using SBC and SUB instead. |
| 3713 | // |
| 3714 | // out.hi = -C |
| 3715 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(out)); |
| 3716 | // out.hi = out.hi - in.hi |
| 3717 | __ Sub(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(in)); |
| 3718 | break; |
| 3719 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3720 | case DataType::Type::kFloat32: |
| 3721 | case DataType::Type::kFloat64: |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 3722 | __ Vneg(OutputVRegister(neg), InputVRegister(neg)); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3723 | break; |
| 3724 | |
| 3725 | default: |
| 3726 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3727 | } |
| 3728 | } |
| 3729 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3730 | void LocationsBuilderARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3731 | DataType::Type result_type = conversion->GetResultType(); |
| 3732 | DataType::Type input_type = conversion->GetInputType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3733 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 3734 | << input_type << " -> " << result_type; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3735 | |
| 3736 | // The float-to-long, double-to-long and long-to-float type conversions |
| 3737 | // rely on a call to the runtime. |
| 3738 | LocationSummary::CallKind call_kind = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3739 | (((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) |
| 3740 | && result_type == DataType::Type::kInt64) |
| 3741 | || (input_type == DataType::Type::kInt64 && result_type == DataType::Type::kFloat32)) |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3742 | ? LocationSummary::kCallOnMainOnly |
| 3743 | : LocationSummary::kNoCall; |
| 3744 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3745 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3746 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3747 | switch (result_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3748 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3749 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3750 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3751 | case DataType::Type::kInt16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3752 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 3753 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3754 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3755 | break; |
| 3756 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3757 | case DataType::Type::kInt32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3758 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3759 | case DataType::Type::kInt64: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3760 | locations->SetInAt(0, Location::Any()); |
| 3761 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3762 | break; |
| 3763 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3764 | case DataType::Type::kFloat32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3765 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3766 | locations->SetOut(Location::RequiresRegister()); |
| 3767 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3768 | break; |
| 3769 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3770 | case DataType::Type::kFloat64: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3771 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3772 | locations->SetOut(Location::RequiresRegister()); |
| 3773 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3774 | break; |
| 3775 | |
| 3776 | default: |
| 3777 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3778 | << " to " << result_type; |
| 3779 | } |
| 3780 | break; |
| 3781 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3782 | case DataType::Type::kInt64: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3783 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3784 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3785 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3786 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3787 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3788 | case DataType::Type::kInt16: |
| 3789 | case DataType::Type::kInt32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3790 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3791 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3792 | break; |
| 3793 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3794 | case DataType::Type::kFloat32: { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3795 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3796 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 3797 | locations->SetOut(LocationFrom(r0, r1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3798 | break; |
| 3799 | } |
| 3800 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3801 | case DataType::Type::kFloat64: { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3802 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3803 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0), |
| 3804 | calling_convention.GetFpuRegisterAt(1))); |
| 3805 | locations->SetOut(LocationFrom(r0, r1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3806 | break; |
| 3807 | } |
| 3808 | |
| 3809 | default: |
| 3810 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3811 | << " to " << result_type; |
| 3812 | } |
| 3813 | break; |
| 3814 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3815 | case DataType::Type::kFloat32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3816 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3817 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3818 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3819 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3820 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3821 | case DataType::Type::kInt16: |
| 3822 | case DataType::Type::kInt32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3823 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3824 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3825 | break; |
| 3826 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3827 | case DataType::Type::kInt64: { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3828 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3829 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0), |
| 3830 | calling_convention.GetRegisterAt(1))); |
| 3831 | locations->SetOut(LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3832 | break; |
| 3833 | } |
| 3834 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3835 | case DataType::Type::kFloat64: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3836 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3837 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3838 | break; |
| 3839 | |
| 3840 | default: |
| 3841 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3842 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3843 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3844 | break; |
| 3845 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3846 | case DataType::Type::kFloat64: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3847 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3848 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3849 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3850 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3851 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3852 | case DataType::Type::kInt16: |
| 3853 | case DataType::Type::kInt32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3854 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3855 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3856 | break; |
| 3857 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3858 | case DataType::Type::kInt64: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3859 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3860 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3861 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3862 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3863 | break; |
| 3864 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3865 | case DataType::Type::kFloat32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3866 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3867 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3868 | break; |
| 3869 | |
| 3870 | default: |
| 3871 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3872 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3873 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3874 | break; |
| 3875 | |
| 3876 | default: |
| 3877 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3878 | << " to " << result_type; |
| 3879 | } |
| 3880 | } |
| 3881 | |
| 3882 | void InstructionCodeGeneratorARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
| 3883 | LocationSummary* locations = conversion->GetLocations(); |
| 3884 | Location out = locations->Out(); |
| 3885 | Location in = locations->InAt(0); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3886 | DataType::Type result_type = conversion->GetResultType(); |
| 3887 | DataType::Type input_type = conversion->GetInputType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3888 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 3889 | << input_type << " -> " << result_type; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3890 | switch (result_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3891 | case DataType::Type::kUint8: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3892 | switch (input_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3893 | case DataType::Type::kInt8: |
| 3894 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3895 | case DataType::Type::kInt16: |
| 3896 | case DataType::Type::kInt32: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3897 | __ Ubfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 8); |
| 3898 | break; |
| 3899 | case DataType::Type::kInt64: |
| 3900 | __ Ubfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 8); |
| 3901 | break; |
| 3902 | |
| 3903 | default: |
| 3904 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3905 | << " to " << result_type; |
| 3906 | } |
| 3907 | break; |
| 3908 | |
| 3909 | case DataType::Type::kInt8: |
| 3910 | switch (input_type) { |
| 3911 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3912 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3913 | case DataType::Type::kInt16: |
| 3914 | case DataType::Type::kInt32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3915 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 8); |
| 3916 | break; |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3917 | case DataType::Type::kInt64: |
| 3918 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 8); |
| 3919 | break; |
| 3920 | |
| 3921 | default: |
| 3922 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3923 | << " to " << result_type; |
| 3924 | } |
| 3925 | break; |
| 3926 | |
| 3927 | case DataType::Type::kUint16: |
| 3928 | switch (input_type) { |
| 3929 | case DataType::Type::kInt8: |
| 3930 | case DataType::Type::kInt16: |
| 3931 | case DataType::Type::kInt32: |
| 3932 | __ Ubfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 3933 | break; |
| 3934 | case DataType::Type::kInt64: |
| 3935 | __ Ubfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
| 3936 | break; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3937 | |
| 3938 | default: |
| 3939 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3940 | << " to " << result_type; |
| 3941 | } |
| 3942 | break; |
| 3943 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3944 | case DataType::Type::kInt16: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3945 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3946 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3947 | case DataType::Type::kInt32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3948 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 3949 | break; |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3950 | case DataType::Type::kInt64: |
| 3951 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
| 3952 | break; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3953 | |
| 3954 | default: |
| 3955 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3956 | << " to " << result_type; |
| 3957 | } |
| 3958 | break; |
| 3959 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3960 | case DataType::Type::kInt32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3961 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3962 | case DataType::Type::kInt64: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3963 | DCHECK(out.IsRegister()); |
| 3964 | if (in.IsRegisterPair()) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3965 | __ Mov(OutputRegister(conversion), LowRegisterFrom(in)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3966 | } else if (in.IsDoubleStackSlot()) { |
| 3967 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3968 | OutputRegister(conversion), |
| 3969 | sp, |
| 3970 | in.GetStackIndex()); |
| 3971 | } else { |
| 3972 | DCHECK(in.IsConstant()); |
| 3973 | DCHECK(in.GetConstant()->IsLongConstant()); |
| Vladimir Marko | ba1a48e | 2017-04-13 11:50:14 +0100 | [diff] [blame] | 3974 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3975 | __ Mov(OutputRegister(conversion), static_cast<int32_t>(value)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3976 | } |
| 3977 | break; |
| 3978 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3979 | case DataType::Type::kFloat32: { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3980 | vixl32::SRegister temp = LowSRegisterFrom(locations->GetTemp(0)); |
| Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3981 | __ Vcvt(S32, F32, temp, InputSRegisterAt(conversion, 0)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3982 | __ Vmov(OutputRegister(conversion), temp); |
| 3983 | break; |
| 3984 | } |
| 3985 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3986 | case DataType::Type::kFloat64: { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3987 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
| Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3988 | __ Vcvt(S32, F64, temp_s, DRegisterFrom(in)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3989 | __ Vmov(OutputRegister(conversion), temp_s); |
| 3990 | break; |
| 3991 | } |
| 3992 | |
| 3993 | default: |
| 3994 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3995 | << " to " << result_type; |
| 3996 | } |
| 3997 | break; |
| 3998 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3999 | case DataType::Type::kInt64: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4000 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4001 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4002 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4003 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4004 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4005 | case DataType::Type::kInt16: |
| 4006 | case DataType::Type::kInt32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4007 | DCHECK(out.IsRegisterPair()); |
| 4008 | DCHECK(in.IsRegister()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4009 | __ Mov(LowRegisterFrom(out), InputRegisterAt(conversion, 0)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4010 | // Sign extension. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4011 | __ Asr(HighRegisterFrom(out), LowRegisterFrom(out), 31); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4012 | break; |
| 4013 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4014 | case DataType::Type::kFloat32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4015 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
| 4016 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 4017 | break; |
| 4018 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4019 | case DataType::Type::kFloat64: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4020 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
| 4021 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 4022 | break; |
| 4023 | |
| 4024 | default: |
| 4025 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4026 | << " to " << result_type; |
| 4027 | } |
| 4028 | break; |
| 4029 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4030 | case DataType::Type::kFloat32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4031 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4032 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4033 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4034 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4035 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4036 | case DataType::Type::kInt16: |
| 4037 | case DataType::Type::kInt32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4038 | __ Vmov(OutputSRegister(conversion), InputRegisterAt(conversion, 0)); |
| Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4039 | __ Vcvt(F32, S32, OutputSRegister(conversion), OutputSRegister(conversion)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4040 | break; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4041 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4042 | case DataType::Type::kInt64: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4043 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
| 4044 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 4045 | break; |
| 4046 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4047 | case DataType::Type::kFloat64: |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4048 | __ Vcvt(F32, F64, OutputSRegister(conversion), DRegisterFrom(in)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4049 | break; |
| 4050 | |
| 4051 | default: |
| 4052 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4053 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 4054 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4055 | break; |
| 4056 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4057 | case DataType::Type::kFloat64: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4058 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4059 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4060 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4061 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4062 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4063 | case DataType::Type::kInt16: |
| 4064 | case DataType::Type::kInt32: |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4065 | __ Vmov(LowSRegisterFrom(out), InputRegisterAt(conversion, 0)); |
| Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4066 | __ Vcvt(F64, S32, DRegisterFrom(out), LowSRegisterFrom(out)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4067 | break; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4068 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4069 | case DataType::Type::kInt64: { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4070 | vixl32::Register low = LowRegisterFrom(in); |
| 4071 | vixl32::Register high = HighRegisterFrom(in); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4072 | vixl32::SRegister out_s = LowSRegisterFrom(out); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4073 | vixl32::DRegister out_d = DRegisterFrom(out); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4074 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4075 | vixl32::DRegister temp_d = DRegisterFrom(locations->GetTemp(0)); |
| Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4076 | vixl32::DRegister constant_d = DRegisterFrom(locations->GetTemp(1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4077 | |
| 4078 | // temp_d = int-to-double(high) |
| 4079 | __ Vmov(temp_s, high); |
| Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4080 | __ Vcvt(F64, S32, temp_d, temp_s); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4081 | // constant_d = k2Pow32EncodingForDouble |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4082 | __ Vmov(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4083 | // out_d = unsigned-to-double(low) |
| 4084 | __ Vmov(out_s, low); |
| 4085 | __ Vcvt(F64, U32, out_d, out_s); |
| 4086 | // out_d += temp_d * constant_d |
| 4087 | __ Vmla(F64, out_d, temp_d, constant_d); |
| 4088 | break; |
| 4089 | } |
| 4090 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4091 | case DataType::Type::kFloat32: |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4092 | __ Vcvt(F64, F32, DRegisterFrom(out), InputSRegisterAt(conversion, 0)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4093 | break; |
| 4094 | |
| 4095 | default: |
| 4096 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4097 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 4098 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4099 | break; |
| 4100 | |
| 4101 | default: |
| 4102 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4103 | << " to " << result_type; |
| 4104 | } |
| 4105 | } |
| 4106 | |
| 4107 | void LocationsBuilderARMVIXL::VisitAdd(HAdd* add) { |
| 4108 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4109 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4110 | switch (add->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4111 | case DataType::Type::kInt32: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4112 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4113 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 4114 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4115 | break; |
| 4116 | } |
| 4117 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4118 | case DataType::Type::kInt64: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4119 | locations->SetInAt(0, Location::RequiresRegister()); |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4120 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4121 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4122 | break; |
| 4123 | } |
| 4124 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4125 | case DataType::Type::kFloat32: |
| 4126 | case DataType::Type::kFloat64: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4127 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4128 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4129 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4130 | break; |
| 4131 | } |
| 4132 | |
| 4133 | default: |
| 4134 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 4135 | } |
| 4136 | } |
| 4137 | |
| 4138 | void InstructionCodeGeneratorARMVIXL::VisitAdd(HAdd* add) { |
| 4139 | LocationSummary* locations = add->GetLocations(); |
| 4140 | Location out = locations->Out(); |
| 4141 | Location first = locations->InAt(0); |
| 4142 | Location second = locations->InAt(1); |
| 4143 | |
| 4144 | switch (add->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4145 | case DataType::Type::kInt32: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4146 | __ Add(OutputRegister(add), InputRegisterAt(add, 0), InputOperandAt(add, 1)); |
| 4147 | } |
| 4148 | break; |
| 4149 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4150 | case DataType::Type::kInt64: { |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4151 | if (second.IsConstant()) { |
| 4152 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 4153 | GenerateAddLongConst(out, first, value); |
| 4154 | } else { |
| 4155 | DCHECK(second.IsRegisterPair()); |
| 4156 | __ Adds(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 4157 | __ Adc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 4158 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4159 | break; |
| 4160 | } |
| 4161 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4162 | case DataType::Type::kFloat32: |
| 4163 | case DataType::Type::kFloat64: |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4164 | __ Vadd(OutputVRegister(add), InputVRegisterAt(add, 0), InputVRegisterAt(add, 1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4165 | break; |
| 4166 | |
| 4167 | default: |
| 4168 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 4169 | } |
| 4170 | } |
| 4171 | |
| 4172 | void LocationsBuilderARMVIXL::VisitSub(HSub* sub) { |
| 4173 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4174 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4175 | switch (sub->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4176 | case DataType::Type::kInt32: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4177 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4178 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
| 4179 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4180 | break; |
| 4181 | } |
| 4182 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4183 | case DataType::Type::kInt64: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4184 | locations->SetInAt(0, Location::RequiresRegister()); |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4185 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4186 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4187 | break; |
| 4188 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4189 | case DataType::Type::kFloat32: |
| 4190 | case DataType::Type::kFloat64: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4191 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4192 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4193 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4194 | break; |
| 4195 | } |
| 4196 | default: |
| 4197 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 4198 | } |
| 4199 | } |
| 4200 | |
| 4201 | void InstructionCodeGeneratorARMVIXL::VisitSub(HSub* sub) { |
| 4202 | LocationSummary* locations = sub->GetLocations(); |
| 4203 | Location out = locations->Out(); |
| 4204 | Location first = locations->InAt(0); |
| 4205 | Location second = locations->InAt(1); |
| 4206 | switch (sub->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4207 | case DataType::Type::kInt32: { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4208 | __ Sub(OutputRegister(sub), InputRegisterAt(sub, 0), InputOperandAt(sub, 1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4209 | break; |
| 4210 | } |
| 4211 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4212 | case DataType::Type::kInt64: { |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4213 | if (second.IsConstant()) { |
| 4214 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 4215 | GenerateAddLongConst(out, first, -value); |
| 4216 | } else { |
| 4217 | DCHECK(second.IsRegisterPair()); |
| 4218 | __ Subs(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 4219 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 4220 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4221 | break; |
| 4222 | } |
| 4223 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4224 | case DataType::Type::kFloat32: |
| 4225 | case DataType::Type::kFloat64: |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4226 | __ Vsub(OutputVRegister(sub), InputVRegisterAt(sub, 0), InputVRegisterAt(sub, 1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4227 | break; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4228 | |
| 4229 | default: |
| 4230 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 4231 | } |
| 4232 | } |
| 4233 | |
| 4234 | void LocationsBuilderARMVIXL::VisitMul(HMul* mul) { |
| 4235 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4236 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4237 | switch (mul->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4238 | case DataType::Type::kInt32: |
| 4239 | case DataType::Type::kInt64: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4240 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4241 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4242 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4243 | break; |
| 4244 | } |
| 4245 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4246 | case DataType::Type::kFloat32: |
| 4247 | case DataType::Type::kFloat64: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4248 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4249 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4250 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4251 | break; |
| 4252 | } |
| 4253 | |
| 4254 | default: |
| 4255 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4256 | } |
| 4257 | } |
| 4258 | |
| 4259 | void InstructionCodeGeneratorARMVIXL::VisitMul(HMul* mul) { |
| 4260 | LocationSummary* locations = mul->GetLocations(); |
| 4261 | Location out = locations->Out(); |
| 4262 | Location first = locations->InAt(0); |
| 4263 | Location second = locations->InAt(1); |
| 4264 | switch (mul->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4265 | case DataType::Type::kInt32: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4266 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 4267 | break; |
| 4268 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4269 | case DataType::Type::kInt64: { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4270 | vixl32::Register out_hi = HighRegisterFrom(out); |
| 4271 | vixl32::Register out_lo = LowRegisterFrom(out); |
| 4272 | vixl32::Register in1_hi = HighRegisterFrom(first); |
| 4273 | vixl32::Register in1_lo = LowRegisterFrom(first); |
| 4274 | vixl32::Register in2_hi = HighRegisterFrom(second); |
| 4275 | vixl32::Register in2_lo = LowRegisterFrom(second); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4276 | |
| 4277 | // Extra checks to protect caused by the existence of R1_R2. |
| 4278 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 4279 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4280 | DCHECK(!out_hi.Is(in1_lo)); |
| 4281 | DCHECK(!out_hi.Is(in2_lo)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4282 | |
| 4283 | // input: in1 - 64 bits, in2 - 64 bits |
| 4284 | // output: out |
| 4285 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 4286 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 4287 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 4288 | |
| 4289 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4290 | vixl32::Register temp = temps.Acquire(); |
| 4291 | // temp <- in1.lo * in2.hi |
| 4292 | __ Mul(temp, in1_lo, in2_hi); |
| 4293 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 4294 | __ Mla(out_hi, in1_hi, in2_lo, temp); |
| 4295 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 4296 | __ Umull(out_lo, temp, in1_lo, in2_lo); |
| 4297 | // 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] | 4298 | __ Add(out_hi, out_hi, temp); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4299 | break; |
| 4300 | } |
| 4301 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4302 | case DataType::Type::kFloat32: |
| 4303 | case DataType::Type::kFloat64: |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4304 | __ Vmul(OutputVRegister(mul), InputVRegisterAt(mul, 0), InputVRegisterAt(mul, 1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4305 | break; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4306 | |
| 4307 | default: |
| 4308 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4309 | } |
| 4310 | } |
| 4311 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4312 | void InstructionCodeGeneratorARMVIXL::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 4313 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4314 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4315 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4316 | Location second = instruction->GetLocations()->InAt(1); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4317 | DCHECK(second.IsConstant()); |
| 4318 | |
| 4319 | vixl32::Register out = OutputRegister(instruction); |
| 4320 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4321 | int32_t imm = Int32ConstantFrom(second); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4322 | DCHECK(imm == 1 || imm == -1); |
| 4323 | |
| 4324 | if (instruction->IsRem()) { |
| 4325 | __ Mov(out, 0); |
| 4326 | } else { |
| 4327 | if (imm == 1) { |
| 4328 | __ Mov(out, dividend); |
| 4329 | } else { |
| 4330 | __ Rsb(out, dividend, 0); |
| 4331 | } |
| 4332 | } |
| 4333 | } |
| 4334 | |
| 4335 | void InstructionCodeGeneratorARMVIXL::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 4336 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4337 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4338 | |
| 4339 | LocationSummary* locations = instruction->GetLocations(); |
| 4340 | Location second = locations->InAt(1); |
| 4341 | DCHECK(second.IsConstant()); |
| 4342 | |
| 4343 | vixl32::Register out = OutputRegister(instruction); |
| 4344 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4345 | int32_t imm = Int32ConstantFrom(second); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4346 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 4347 | int ctz_imm = CTZ(abs_imm); |
| 4348 | |
| Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 4349 | auto generate_div_code = [this, imm, ctz_imm](vixl32::Register out, vixl32::Register in) { |
| 4350 | __ Asr(out, in, ctz_imm); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4351 | if (imm < 0) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4352 | __ Rsb(out, out, 0); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4353 | } |
| Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 4354 | }; |
| 4355 | |
| Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 4356 | if (HasNonNegativeOrMinIntInputAt(instruction, 0)) { |
| Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 4357 | // No need to adjust the result for non-negative dividends or the INT32_MIN dividend. |
| 4358 | // NOTE: The generated code for HDiv/HRem correctly works for the INT32_MIN dividend: |
| 4359 | // imm == 2 |
| 4360 | // HDiv |
| 4361 | // add out, dividend(0x80000000), dividend(0x80000000), lsr #31 => out = 0x80000001 |
| 4362 | // asr out, out(0x80000001), #1 => out = 0xc0000000 |
| 4363 | // This is the same as 'asr out, dividend(0x80000000), #1' |
| 4364 | // |
| 4365 | // imm > 2 |
| 4366 | // HDiv |
| 4367 | // asr out, dividend(0x80000000), #31 => out = -1 |
| 4368 | // add out, dividend(0x80000000), out(-1), lsr #(32 - ctz_imm) => out = 0b10..01..1, |
| 4369 | // where the number of the rightmost 1s is ctz_imm. |
| 4370 | // asr out, out(0b10..01..1), #ctz_imm => out = 0b1..10..0, where the number of the |
| 4371 | // leftmost 1s is ctz_imm + 1. |
| 4372 | // This is the same as 'asr out, dividend(0x80000000), #ctz_imm'. |
| 4373 | // |
| 4374 | // imm == INT32_MIN |
| 4375 | // HDiv |
| 4376 | // asr out, dividend(0x80000000), #31 => out = -1 |
| 4377 | // add out, dividend(0x80000000), out(-1), lsr #1 => out = 0xc0000000 |
| 4378 | // asr out, out(0xc0000000), #31 => out = -1 |
| 4379 | // rsb out, out(-1), #0 => out = 1 |
| 4380 | // This is the same as |
| 4381 | // asr out, dividend(0x80000000), #31 |
| 4382 | // rsb out, out, #0 |
| 4383 | // |
| 4384 | // |
| 4385 | // INT_MIN % imm must be 0 for any imm of power 2. 'and' and 'ubfx' work only with bits |
| 4386 | // 0..30 of a dividend. For INT32_MIN those bits are zeros. So 'and' and 'ubfx' always |
| 4387 | // produce zero. |
| 4388 | if (instruction->IsDiv()) { |
| 4389 | generate_div_code(out, dividend); |
| 4390 | } else { |
| 4391 | if (GetVIXLAssembler()->IsModifiedImmediate(abs_imm - 1)) { |
| 4392 | __ And(out, dividend, abs_imm - 1); |
| 4393 | } else { |
| 4394 | __ Ubfx(out, dividend, 0, ctz_imm); |
| 4395 | } |
| 4396 | return; |
| 4397 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4398 | } else { |
| Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 4399 | vixl32::Register add_right_input = dividend; |
| 4400 | if (ctz_imm > 1) { |
| 4401 | __ Asr(out, dividend, 31); |
| 4402 | add_right_input = out; |
| 4403 | } |
| 4404 | __ Add(out, dividend, Operand(add_right_input, vixl32::LSR, 32 - ctz_imm)); |
| 4405 | |
| 4406 | if (instruction->IsDiv()) { |
| 4407 | generate_div_code(out, out); |
| 4408 | } else { |
| 4409 | __ Bfc(out, 0, ctz_imm); |
| 4410 | __ Sub(out, dividend, out); |
| 4411 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4412 | } |
| 4413 | } |
| 4414 | |
| 4415 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 4416 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4417 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4418 | |
| 4419 | LocationSummary* locations = instruction->GetLocations(); |
| 4420 | Location second = locations->InAt(1); |
| 4421 | DCHECK(second.IsConstant()); |
| 4422 | |
| 4423 | vixl32::Register out = OutputRegister(instruction); |
| 4424 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4425 | vixl32::Register temp1 = RegisterFrom(locations->GetTemp(0)); |
| 4426 | vixl32::Register temp2 = RegisterFrom(locations->GetTemp(1)); |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4427 | int32_t imm = Int32ConstantFrom(second); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4428 | |
| 4429 | int64_t magic; |
| 4430 | int shift; |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4431 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ false, &magic, &shift); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4432 | |
| Evgeny Astigeevich | f938841 | 2020-07-02 15:25:13 +0100 | [diff] [blame] | 4433 | auto generate_unsigned_div_code =[this, magic, shift](vixl32::Register out, |
| 4434 | vixl32::Register dividend, |
| 4435 | vixl32::Register temp1, |
| 4436 | vixl32::Register temp2) { |
| 4437 | // TODO(VIXL): Change the static cast to Operand::From() after VIXL is fixed. |
| 4438 | __ Mov(temp1, static_cast<int32_t>(magic)); |
| 4439 | if (magic > 0 && shift == 0) { |
| 4440 | __ Smull(temp2, out, dividend, temp1); |
| 4441 | } else { |
| 4442 | __ Smull(temp2, temp1, dividend, temp1); |
| 4443 | if (magic < 0) { |
| 4444 | // The negative magic M = static_cast<int>(m) means that the multiplier m is greater |
| 4445 | // than INT32_MAX. In such a case shift is never 0. |
| 4446 | // Proof: |
| 4447 | // m = (2^p + d - 2^p % d) / d, where p = 32 + shift, d > 2 |
| 4448 | // |
| 4449 | // If shift == 0, m = (2^32 + d - 2^32 % d) / d = |
| 4450 | // = (2^32 + d - (2^32 - (2^32 / d) * d)) / d = |
| 4451 | // = (d + (2^32 / d) * d) / d = 1 + (2^32 / d), here '/' is the integer division. |
| 4452 | // |
| 4453 | // 1 + (2^32 / d) is decreasing when d is increasing. |
| 4454 | // The maximum is 1 431 655 766, when d == 3. This value is less than INT32_MAX. |
| 4455 | // the minimum is 3, when d = 2^31 -1. |
| 4456 | // So for all values of d in [3, INT32_MAX] m with p == 32 is in [3, INT32_MAX) and |
| 4457 | // is never less than 0. |
| 4458 | __ Add(temp1, temp1, dividend); |
| 4459 | } |
| 4460 | DCHECK_NE(shift, 0); |
| 4461 | __ Lsr(out, temp1, shift); |
| 4462 | } |
| 4463 | }; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4464 | |
| Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 4465 | if (imm > 0 && HasNonNegativeInputAt(instruction, 0)) { |
| Evgeny Astigeevich | f938841 | 2020-07-02 15:25:13 +0100 | [diff] [blame] | 4466 | // No need to adjust the result for a non-negative dividend and a positive divisor. |
| 4467 | if (instruction->IsDiv()) { |
| 4468 | generate_unsigned_div_code(out, dividend, temp1, temp2); |
| 4469 | } else { |
| 4470 | generate_unsigned_div_code(temp1, dividend, temp1, temp2); |
| 4471 | __ Mov(temp2, imm); |
| 4472 | __ Mls(out, temp1, temp2, dividend); |
| 4473 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4474 | } else { |
| Evgeny Astigeevich | f938841 | 2020-07-02 15:25:13 +0100 | [diff] [blame] | 4475 | // TODO(VIXL): Change the static cast to Operand::From() after VIXL is fixed. |
| 4476 | __ Mov(temp1, static_cast<int32_t>(magic)); |
| 4477 | __ Smull(temp2, temp1, dividend, temp1); |
| 4478 | |
| 4479 | if (imm > 0 && magic < 0) { |
| 4480 | __ Add(temp1, temp1, dividend); |
| 4481 | } else if (imm < 0 && magic > 0) { |
| 4482 | __ Sub(temp1, temp1, dividend); |
| 4483 | } |
| 4484 | |
| 4485 | if (shift != 0) { |
| 4486 | __ Asr(temp1, temp1, shift); |
| 4487 | } |
| 4488 | |
| 4489 | if (instruction->IsDiv()) { |
| 4490 | __ Sub(out, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 4491 | } else { |
| 4492 | __ Sub(temp1, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 4493 | // TODO: Strength reduction for mls. |
| 4494 | __ Mov(temp2, imm); |
| 4495 | __ Mls(out, temp1, temp2, dividend); |
| 4496 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4497 | } |
| 4498 | } |
| 4499 | |
| 4500 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemConstantIntegral( |
| 4501 | HBinaryOperation* instruction) { |
| 4502 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4503 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4504 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4505 | Location second = instruction->GetLocations()->InAt(1); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4506 | DCHECK(second.IsConstant()); |
| 4507 | |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4508 | int32_t imm = Int32ConstantFrom(second); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4509 | if (imm == 0) { |
| 4510 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4511 | } else if (imm == 1 || imm == -1) { |
| 4512 | DivRemOneOrMinusOne(instruction); |
| 4513 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 4514 | DivRemByPowerOfTwo(instruction); |
| 4515 | } else { |
| 4516 | DCHECK(imm <= -2 || imm >= 2); |
| 4517 | GenerateDivRemWithAnyConstant(instruction); |
| 4518 | } |
| 4519 | } |
| 4520 | |
| 4521 | void LocationsBuilderARMVIXL::VisitDiv(HDiv* div) { |
| 4522 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4523 | if (div->GetResultType() == DataType::Type::kInt64) { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4524 | // pLdiv runtime call. |
| 4525 | call_kind = LocationSummary::kCallOnMainOnly; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4526 | } else if (div->GetResultType() == DataType::Type::kInt32 && div->InputAt(1)->IsConstant()) { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4527 | // sdiv will be replaced by other instruction sequence. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4528 | } else if (div->GetResultType() == DataType::Type::kInt32 && |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4529 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4530 | // pIdivmod runtime call. |
| 4531 | call_kind = LocationSummary::kCallOnMainOnly; |
| 4532 | } |
| 4533 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4534 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4535 | |
| 4536 | switch (div->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4537 | case DataType::Type::kInt32: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4538 | if (div->InputAt(1)->IsConstant()) { |
| 4539 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4540 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4541 | int32_t value = Int32ConstantFrom(div->InputAt(1)); |
| Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4542 | Location::OutputOverlap out_overlaps = Location::kNoOutputOverlap; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4543 | if (value == 1 || value == 0 || value == -1) { |
| 4544 | // No temp register required. |
| Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 4545 | } else if (IsPowerOfTwo(AbsOrMin(value)) && |
| 4546 | value != 2 && |
| 4547 | value != -2 && |
| Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 4548 | !HasNonNegativeOrMinIntInputAt(div, 0)) { |
| Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4549 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 4550 | out_overlaps = Location::kOutputOverlap; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4551 | } else { |
| Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4552 | locations->AddRegisterTemps(2); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4553 | } |
| Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4554 | locations->SetOut(Location::RequiresRegister(), out_overlaps); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4555 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4556 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4557 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4558 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4559 | } else { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4560 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4561 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4562 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4563 | // 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] | 4564 | // we only need the former. |
| 4565 | locations->SetOut(LocationFrom(r0)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4566 | } |
| 4567 | break; |
| 4568 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4569 | case DataType::Type::kInt64: { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4570 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4571 | locations->SetInAt(0, LocationFrom( |
| 4572 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4573 | locations->SetInAt(1, LocationFrom( |
| 4574 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4575 | locations->SetOut(LocationFrom(r0, r1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4576 | break; |
| 4577 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4578 | case DataType::Type::kFloat32: |
| 4579 | case DataType::Type::kFloat64: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4580 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4581 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4582 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4583 | break; |
| 4584 | } |
| 4585 | |
| 4586 | default: |
| 4587 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4588 | } |
| 4589 | } |
| 4590 | |
| 4591 | void InstructionCodeGeneratorARMVIXL::VisitDiv(HDiv* div) { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4592 | Location lhs = div->GetLocations()->InAt(0); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4593 | Location rhs = div->GetLocations()->InAt(1); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4594 | |
| 4595 | switch (div->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4596 | case DataType::Type::kInt32: { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4597 | if (rhs.IsConstant()) { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4598 | GenerateDivRemConstantIntegral(div); |
| 4599 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4600 | __ Sdiv(OutputRegister(div), InputRegisterAt(div, 0), InputRegisterAt(div, 1)); |
| 4601 | } else { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4602 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4603 | DCHECK(calling_convention.GetRegisterAt(0).Is(RegisterFrom(lhs))); |
| 4604 | DCHECK(calling_convention.GetRegisterAt(1).Is(RegisterFrom(rhs))); |
| 4605 | DCHECK(r0.Is(OutputRegister(div))); |
| 4606 | |
| 4607 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
| 4608 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4609 | } |
| 4610 | break; |
| 4611 | } |
| 4612 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4613 | case DataType::Type::kInt64: { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4614 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4615 | DCHECK(calling_convention.GetRegisterAt(0).Is(LowRegisterFrom(lhs))); |
| 4616 | DCHECK(calling_convention.GetRegisterAt(1).Is(HighRegisterFrom(lhs))); |
| 4617 | DCHECK(calling_convention.GetRegisterAt(2).Is(LowRegisterFrom(rhs))); |
| 4618 | DCHECK(calling_convention.GetRegisterAt(3).Is(HighRegisterFrom(rhs))); |
| 4619 | DCHECK(LowRegisterFrom(div->GetLocations()->Out()).Is(r0)); |
| 4620 | DCHECK(HighRegisterFrom(div->GetLocations()->Out()).Is(r1)); |
| 4621 | |
| 4622 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
| 4623 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4624 | break; |
| 4625 | } |
| 4626 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4627 | case DataType::Type::kFloat32: |
| 4628 | case DataType::Type::kFloat64: |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4629 | __ Vdiv(OutputVRegister(div), InputVRegisterAt(div, 0), InputVRegisterAt(div, 1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4630 | break; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4631 | |
| 4632 | default: |
| 4633 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4634 | } |
| 4635 | } |
| 4636 | |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4637 | void LocationsBuilderARMVIXL::VisitRem(HRem* rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4638 | DataType::Type type = rem->GetResultType(); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4639 | |
| 4640 | // Most remainders are implemented in the runtime. |
| 4641 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4642 | if (rem->GetResultType() == DataType::Type::kInt32 && rem->InputAt(1)->IsConstant()) { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4643 | // sdiv will be replaced by other instruction sequence. |
| 4644 | call_kind = LocationSummary::kNoCall; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4645 | } else if ((rem->GetResultType() == DataType::Type::kInt32) |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4646 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4647 | // Have hardware divide instruction for int, do it with three instructions. |
| 4648 | call_kind = LocationSummary::kNoCall; |
| 4649 | } |
| 4650 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4651 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4652 | |
| 4653 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4654 | case DataType::Type::kInt32: { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4655 | if (rem->InputAt(1)->IsConstant()) { |
| 4656 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4657 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4658 | int32_t value = Int32ConstantFrom(rem->InputAt(1)); |
| Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4659 | Location::OutputOverlap out_overlaps = Location::kNoOutputOverlap; |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4660 | if (value == 1 || value == 0 || value == -1) { |
| 4661 | // No temp register required. |
| Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 4662 | } else if (IsPowerOfTwo(AbsOrMin(value)) && !HasNonNegativeOrMinIntInputAt(rem, 0)) { |
| Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4663 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 4664 | out_overlaps = Location::kOutputOverlap; |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4665 | } else { |
| Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4666 | locations->AddRegisterTemps(2); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4667 | } |
| Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4668 | locations->SetOut(Location::RequiresRegister(), out_overlaps); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4669 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4670 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4671 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4672 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4673 | locations->AddTemp(Location::RequiresRegister()); |
| 4674 | } else { |
| 4675 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4676 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4677 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4678 | // 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] | 4679 | // we only need the latter. |
| 4680 | locations->SetOut(LocationFrom(r1)); |
| 4681 | } |
| 4682 | break; |
| 4683 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4684 | case DataType::Type::kInt64: { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4685 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4686 | locations->SetInAt(0, LocationFrom( |
| 4687 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4688 | locations->SetInAt(1, LocationFrom( |
| 4689 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4690 | // The runtime helper puts the output in R2,R3. |
| 4691 | locations->SetOut(LocationFrom(r2, r3)); |
| 4692 | break; |
| 4693 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4694 | case DataType::Type::kFloat32: { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4695 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4696 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 4697 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 4698 | locations->SetOut(LocationFrom(s0)); |
| 4699 | break; |
| 4700 | } |
| 4701 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4702 | case DataType::Type::kFloat64: { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4703 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4704 | locations->SetInAt(0, LocationFrom( |
| 4705 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 4706 | locations->SetInAt(1, LocationFrom( |
| 4707 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 4708 | locations->SetOut(LocationFrom(s0, s1)); |
| 4709 | break; |
| 4710 | } |
| 4711 | |
| 4712 | default: |
| 4713 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4714 | } |
| 4715 | } |
| 4716 | |
| 4717 | void InstructionCodeGeneratorARMVIXL::VisitRem(HRem* rem) { |
| 4718 | LocationSummary* locations = rem->GetLocations(); |
| 4719 | Location second = locations->InAt(1); |
| 4720 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4721 | DataType::Type type = rem->GetResultType(); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4722 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4723 | case DataType::Type::kInt32: { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4724 | vixl32::Register reg1 = InputRegisterAt(rem, 0); |
| 4725 | vixl32::Register out_reg = OutputRegister(rem); |
| 4726 | if (second.IsConstant()) { |
| 4727 | GenerateDivRemConstantIntegral(rem); |
| 4728 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4729 | vixl32::Register reg2 = RegisterFrom(second); |
| 4730 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 4731 | |
| 4732 | // temp = reg1 / reg2 (integer division) |
| 4733 | // dest = reg1 - temp * reg2 |
| 4734 | __ Sdiv(temp, reg1, reg2); |
| 4735 | __ Mls(out_reg, temp, reg2, reg1); |
| 4736 | } else { |
| 4737 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4738 | DCHECK(reg1.Is(calling_convention.GetRegisterAt(0))); |
| 4739 | DCHECK(RegisterFrom(second).Is(calling_convention.GetRegisterAt(1))); |
| 4740 | DCHECK(out_reg.Is(r1)); |
| 4741 | |
| 4742 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
| 4743 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
| 4744 | } |
| 4745 | break; |
| 4746 | } |
| 4747 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4748 | case DataType::Type::kInt64: { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4749 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
| 4750 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 4751 | break; |
| 4752 | } |
| 4753 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4754 | case DataType::Type::kFloat32: { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4755 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
| 4756 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 4757 | break; |
| 4758 | } |
| 4759 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4760 | case DataType::Type::kFloat64: { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4761 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
| 4762 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 4763 | break; |
| 4764 | } |
| 4765 | |
| 4766 | default: |
| 4767 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4768 | } |
| 4769 | } |
| 4770 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4771 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 4772 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 4773 | switch (minmax->GetResultType()) { |
| 4774 | case DataType::Type::kInt32: |
| 4775 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4776 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4777 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4778 | break; |
| 4779 | case DataType::Type::kInt64: |
| 4780 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4781 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4782 | locations->SetOut(Location::SameAsFirstInput()); |
| 4783 | break; |
| 4784 | case DataType::Type::kFloat32: |
| 4785 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4786 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4787 | locations->SetOut(Location::SameAsFirstInput()); |
| 4788 | locations->AddTemp(Location::RequiresRegister()); |
| 4789 | break; |
| 4790 | case DataType::Type::kFloat64: |
| 4791 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4792 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4793 | locations->SetOut(Location::SameAsFirstInput()); |
| 4794 | break; |
| 4795 | default: |
| 4796 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 4797 | } |
| 4798 | } |
| 4799 | |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4800 | void InstructionCodeGeneratorARMVIXL::GenerateMinMaxInt(LocationSummary* locations, bool is_min) { |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4801 | Location op1_loc = locations->InAt(0); |
| 4802 | Location op2_loc = locations->InAt(1); |
| 4803 | Location out_loc = locations->Out(); |
| 4804 | |
| 4805 | vixl32::Register op1 = RegisterFrom(op1_loc); |
| 4806 | vixl32::Register op2 = RegisterFrom(op2_loc); |
| 4807 | vixl32::Register out = RegisterFrom(out_loc); |
| 4808 | |
| 4809 | __ Cmp(op1, op2); |
| 4810 | |
| 4811 | { |
| 4812 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 4813 | 3 * kMaxInstructionSizeInBytes, |
| 4814 | CodeBufferCheckScope::kMaximumSize); |
| 4815 | |
| 4816 | __ ite(is_min ? lt : gt); |
| 4817 | __ mov(is_min ? lt : gt, out, op1); |
| 4818 | __ mov(is_min ? ge : le, out, op2); |
| 4819 | } |
| 4820 | } |
| 4821 | |
| 4822 | void InstructionCodeGeneratorARMVIXL::GenerateMinMaxLong(LocationSummary* locations, bool is_min) { |
| 4823 | Location op1_loc = locations->InAt(0); |
| 4824 | Location op2_loc = locations->InAt(1); |
| 4825 | Location out_loc = locations->Out(); |
| 4826 | |
| 4827 | // Optimization: don't generate any code if inputs are the same. |
| 4828 | if (op1_loc.Equals(op2_loc)) { |
| 4829 | DCHECK(out_loc.Equals(op1_loc)); // out_loc is set as SameAsFirstInput() in location builder. |
| 4830 | return; |
| 4831 | } |
| 4832 | |
| 4833 | vixl32::Register op1_lo = LowRegisterFrom(op1_loc); |
| 4834 | vixl32::Register op1_hi = HighRegisterFrom(op1_loc); |
| 4835 | vixl32::Register op2_lo = LowRegisterFrom(op2_loc); |
| 4836 | vixl32::Register op2_hi = HighRegisterFrom(op2_loc); |
| 4837 | vixl32::Register out_lo = LowRegisterFrom(out_loc); |
| 4838 | vixl32::Register out_hi = HighRegisterFrom(out_loc); |
| 4839 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4840 | const vixl32::Register temp = temps.Acquire(); |
| 4841 | |
| 4842 | DCHECK(op1_lo.Is(out_lo)); |
| 4843 | DCHECK(op1_hi.Is(out_hi)); |
| 4844 | |
| 4845 | // Compare op1 >= op2, or op1 < op2. |
| 4846 | __ Cmp(out_lo, op2_lo); |
| 4847 | __ Sbcs(temp, out_hi, op2_hi); |
| 4848 | |
| 4849 | // Now GE/LT condition code is correct for the long comparison. |
| 4850 | { |
| 4851 | vixl32::ConditionType cond = is_min ? ge : lt; |
| 4852 | ExactAssemblyScope it_scope(GetVIXLAssembler(), |
| 4853 | 3 * kMaxInstructionSizeInBytes, |
| 4854 | CodeBufferCheckScope::kMaximumSize); |
| 4855 | __ itt(cond); |
| 4856 | __ mov(cond, out_lo, op2_lo); |
| 4857 | __ mov(cond, out_hi, op2_hi); |
| 4858 | } |
| 4859 | } |
| 4860 | |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4861 | void InstructionCodeGeneratorARMVIXL::GenerateMinMaxFloat(HInstruction* minmax, bool is_min) { |
| 4862 | LocationSummary* locations = minmax->GetLocations(); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4863 | Location op1_loc = locations->InAt(0); |
| 4864 | Location op2_loc = locations->InAt(1); |
| 4865 | Location out_loc = locations->Out(); |
| 4866 | |
| 4867 | // Optimization: don't generate any code if inputs are the same. |
| 4868 | if (op1_loc.Equals(op2_loc)) { |
| 4869 | DCHECK(out_loc.Equals(op1_loc)); // out_loc is set as SameAsFirstInput() in location builder. |
| 4870 | return; |
| 4871 | } |
| 4872 | |
| 4873 | vixl32::SRegister op1 = SRegisterFrom(op1_loc); |
| 4874 | vixl32::SRegister op2 = SRegisterFrom(op2_loc); |
| 4875 | vixl32::SRegister out = SRegisterFrom(out_loc); |
| 4876 | |
| 4877 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4878 | const vixl32::Register temp1 = temps.Acquire(); |
| 4879 | vixl32::Register temp2 = RegisterFrom(locations->GetTemp(0)); |
| 4880 | vixl32::Label nan, done; |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4881 | vixl32::Label* final_label = codegen_->GetFinalLabel(minmax, &done); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4882 | |
| 4883 | DCHECK(op1.Is(out)); |
| 4884 | |
| 4885 | __ Vcmp(op1, op2); |
| 4886 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4887 | __ 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] | 4888 | |
| 4889 | // op1 <> op2 |
| 4890 | vixl32::ConditionType cond = is_min ? gt : lt; |
| 4891 | { |
| 4892 | ExactAssemblyScope it_scope(GetVIXLAssembler(), |
| 4893 | 2 * kMaxInstructionSizeInBytes, |
| 4894 | CodeBufferCheckScope::kMaximumSize); |
| 4895 | __ it(cond); |
| 4896 | __ vmov(cond, F32, out, op2); |
| 4897 | } |
| 4898 | // for <>(not equal), we've done min/max calculation. |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4899 | __ B(ne, final_label, /* is_far_target= */ false); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4900 | |
| 4901 | // handle op1 == op2, max(+0.0,-0.0), min(+0.0,-0.0). |
| 4902 | __ Vmov(temp1, op1); |
| 4903 | __ Vmov(temp2, op2); |
| 4904 | if (is_min) { |
| 4905 | __ Orr(temp1, temp1, temp2); |
| 4906 | } else { |
| 4907 | __ And(temp1, temp1, temp2); |
| 4908 | } |
| 4909 | __ Vmov(out, temp1); |
| 4910 | __ B(final_label); |
| 4911 | |
| 4912 | // handle NaN input. |
| 4913 | __ Bind(&nan); |
| 4914 | __ Movt(temp1, High16Bits(kNanFloat)); // 0x7FC0xxxx is a NaN. |
| 4915 | __ Vmov(out, temp1); |
| 4916 | |
| 4917 | if (done.IsReferenced()) { |
| 4918 | __ Bind(&done); |
| 4919 | } |
| 4920 | } |
| 4921 | |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4922 | void InstructionCodeGeneratorARMVIXL::GenerateMinMaxDouble(HInstruction* minmax, bool is_min) { |
| 4923 | LocationSummary* locations = minmax->GetLocations(); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4924 | Location op1_loc = locations->InAt(0); |
| 4925 | Location op2_loc = locations->InAt(1); |
| 4926 | Location out_loc = locations->Out(); |
| 4927 | |
| 4928 | // Optimization: don't generate any code if inputs are the same. |
| 4929 | if (op1_loc.Equals(op2_loc)) { |
| 4930 | DCHECK(out_loc.Equals(op1_loc)); // out_loc is set as SameAsFirstInput() in. |
| 4931 | return; |
| 4932 | } |
| 4933 | |
| 4934 | vixl32::DRegister op1 = DRegisterFrom(op1_loc); |
| 4935 | vixl32::DRegister op2 = DRegisterFrom(op2_loc); |
| 4936 | vixl32::DRegister out = DRegisterFrom(out_loc); |
| 4937 | vixl32::Label handle_nan_eq, done; |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4938 | vixl32::Label* final_label = codegen_->GetFinalLabel(minmax, &done); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4939 | |
| 4940 | DCHECK(op1.Is(out)); |
| 4941 | |
| 4942 | __ Vcmp(op1, op2); |
| 4943 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4944 | __ 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] | 4945 | |
| 4946 | // op1 <> op2 |
| 4947 | vixl32::ConditionType cond = is_min ? gt : lt; |
| 4948 | { |
| 4949 | ExactAssemblyScope it_scope(GetVIXLAssembler(), |
| 4950 | 2 * kMaxInstructionSizeInBytes, |
| 4951 | CodeBufferCheckScope::kMaximumSize); |
| 4952 | __ it(cond); |
| 4953 | __ vmov(cond, F64, out, op2); |
| 4954 | } |
| 4955 | // for <>(not equal), we've done min/max calculation. |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4956 | __ B(ne, final_label, /* is_far_target= */ false); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4957 | |
| 4958 | // handle op1 == op2, max(+0.0,-0.0). |
| 4959 | if (!is_min) { |
| 4960 | __ Vand(F64, out, op1, op2); |
| 4961 | __ B(final_label); |
| 4962 | } |
| 4963 | |
| 4964 | // handle op1 == op2, min(+0.0,-0.0), NaN input. |
| 4965 | __ Bind(&handle_nan_eq); |
| 4966 | __ Vorr(F64, out, op1, op2); // assemble op1/-0.0/NaN. |
| 4967 | |
| 4968 | if (done.IsReferenced()) { |
| 4969 | __ Bind(&done); |
| 4970 | } |
| 4971 | } |
| 4972 | |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4973 | void InstructionCodeGeneratorARMVIXL::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 4974 | DataType::Type type = minmax->GetResultType(); |
| 4975 | switch (type) { |
| 4976 | case DataType::Type::kInt32: |
| 4977 | GenerateMinMaxInt(minmax->GetLocations(), is_min); |
| 4978 | break; |
| 4979 | case DataType::Type::kInt64: |
| 4980 | GenerateMinMaxLong(minmax->GetLocations(), is_min); |
| 4981 | break; |
| 4982 | case DataType::Type::kFloat32: |
| 4983 | GenerateMinMaxFloat(minmax, is_min); |
| 4984 | break; |
| 4985 | case DataType::Type::kFloat64: |
| 4986 | GenerateMinMaxDouble(minmax, is_min); |
| 4987 | break; |
| 4988 | default: |
| 4989 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 4990 | } |
| 4991 | } |
| 4992 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4993 | void LocationsBuilderARMVIXL::VisitMin(HMin* min) { |
| 4994 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 4995 | } |
| 4996 | |
| 4997 | void InstructionCodeGeneratorARMVIXL::VisitMin(HMin* min) { |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4998 | GenerateMinMax(min, /*is_min*/ true); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4999 | } |
| 5000 | |
| 5001 | void LocationsBuilderARMVIXL::VisitMax(HMax* max) { |
| 5002 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 5003 | } |
| 5004 | |
| 5005 | void InstructionCodeGeneratorARMVIXL::VisitMax(HMax* max) { |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 5006 | GenerateMinMax(max, /*is_min*/ false); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5007 | } |
| 5008 | |
| Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5009 | void LocationsBuilderARMVIXL::VisitAbs(HAbs* abs) { |
| 5010 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 5011 | switch (abs->GetResultType()) { |
| 5012 | case DataType::Type::kInt32: |
| 5013 | case DataType::Type::kInt64: |
| 5014 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5015 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5016 | locations->AddTemp(Location::RequiresRegister()); |
| 5017 | break; |
| 5018 | case DataType::Type::kFloat32: |
| 5019 | case DataType::Type::kFloat64: |
| 5020 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5021 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5022 | break; |
| 5023 | default: |
| 5024 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 5025 | } |
| 5026 | } |
| 5027 | |
| 5028 | void InstructionCodeGeneratorARMVIXL::VisitAbs(HAbs* abs) { |
| 5029 | LocationSummary* locations = abs->GetLocations(); |
| 5030 | switch (abs->GetResultType()) { |
| 5031 | case DataType::Type::kInt32: { |
| 5032 | vixl32::Register in_reg = RegisterFrom(locations->InAt(0)); |
| 5033 | vixl32::Register out_reg = RegisterFrom(locations->Out()); |
| 5034 | vixl32::Register mask = RegisterFrom(locations->GetTemp(0)); |
| 5035 | __ Asr(mask, in_reg, 31); |
| 5036 | __ Add(out_reg, in_reg, mask); |
| 5037 | __ Eor(out_reg, out_reg, mask); |
| 5038 | break; |
| 5039 | } |
| 5040 | case DataType::Type::kInt64: { |
| 5041 | Location in = locations->InAt(0); |
| 5042 | vixl32::Register in_reg_lo = LowRegisterFrom(in); |
| 5043 | vixl32::Register in_reg_hi = HighRegisterFrom(in); |
| 5044 | Location output = locations->Out(); |
| 5045 | vixl32::Register out_reg_lo = LowRegisterFrom(output); |
| 5046 | vixl32::Register out_reg_hi = HighRegisterFrom(output); |
| 5047 | DCHECK(!out_reg_lo.Is(in_reg_hi)) << "Diagonal overlap unexpected."; |
| 5048 | vixl32::Register mask = RegisterFrom(locations->GetTemp(0)); |
| 5049 | __ Asr(mask, in_reg_hi, 31); |
| 5050 | __ Adds(out_reg_lo, in_reg_lo, mask); |
| 5051 | __ Adc(out_reg_hi, in_reg_hi, mask); |
| 5052 | __ Eor(out_reg_lo, out_reg_lo, mask); |
| 5053 | __ Eor(out_reg_hi, out_reg_hi, mask); |
| 5054 | break; |
| 5055 | } |
| 5056 | case DataType::Type::kFloat32: |
| 5057 | case DataType::Type::kFloat64: |
| 5058 | __ Vabs(OutputVRegister(abs), InputVRegisterAt(abs, 0)); |
| 5059 | break; |
| 5060 | default: |
| 5061 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 5062 | } |
| 5063 | } |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 5064 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5065 | void LocationsBuilderARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 5066 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5067 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5068 | } |
| 5069 | |
| 5070 | void InstructionCodeGeneratorARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 5071 | DivZeroCheckSlowPathARMVIXL* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5072 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathARMVIXL(instruction); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5073 | codegen_->AddSlowPath(slow_path); |
| 5074 | |
| 5075 | LocationSummary* locations = instruction->GetLocations(); |
| 5076 | Location value = locations->InAt(0); |
| 5077 | |
| 5078 | switch (instruction->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5079 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5080 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5081 | case DataType::Type::kInt8: |
| 5082 | case DataType::Type::kUint16: |
| 5083 | case DataType::Type::kInt16: |
| 5084 | case DataType::Type::kInt32: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5085 | if (value.IsRegister()) { |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5086 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5087 | } else { |
| 5088 | DCHECK(value.IsConstant()) << value; |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5089 | if (Int32ConstantFrom(value) == 0) { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5090 | __ B(slow_path->GetEntryLabel()); |
| 5091 | } |
| 5092 | } |
| 5093 | break; |
| 5094 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5095 | case DataType::Type::kInt64: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5096 | if (value.IsRegisterPair()) { |
| 5097 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5098 | vixl32::Register temp = temps.Acquire(); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5099 | __ Orrs(temp, LowRegisterFrom(value), HighRegisterFrom(value)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5100 | __ B(eq, slow_path->GetEntryLabel()); |
| 5101 | } else { |
| 5102 | DCHECK(value.IsConstant()) << value; |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5103 | if (Int64ConstantFrom(value) == 0) { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5104 | __ B(slow_path->GetEntryLabel()); |
| 5105 | } |
| 5106 | } |
| 5107 | break; |
| 5108 | } |
| 5109 | default: |
| 5110 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 5111 | } |
| 5112 | } |
| 5113 | |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5114 | void InstructionCodeGeneratorARMVIXL::HandleIntegerRotate(HRor* ror) { |
| 5115 | LocationSummary* locations = ror->GetLocations(); |
| 5116 | vixl32::Register in = InputRegisterAt(ror, 0); |
| 5117 | Location rhs = locations->InAt(1); |
| 5118 | vixl32::Register out = OutputRegister(ror); |
| 5119 | |
| 5120 | if (rhs.IsConstant()) { |
| 5121 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 5122 | // so map all rotations to a +ve. equivalent in that range. |
| 5123 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 5124 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 5125 | if (rot) { |
| 5126 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 5127 | // (e.g. left by 2 bits == right by 30.) |
| 5128 | __ Ror(out, in, rot); |
| 5129 | } else if (!out.Is(in)) { |
| 5130 | __ Mov(out, in); |
| 5131 | } |
| 5132 | } else { |
| 5133 | __ Ror(out, in, RegisterFrom(rhs)); |
| 5134 | } |
| 5135 | } |
| 5136 | |
| 5137 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 5138 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 5139 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 5140 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 5141 | void InstructionCodeGeneratorARMVIXL::HandleLongRotate(HRor* ror) { |
| 5142 | LocationSummary* locations = ror->GetLocations(); |
| 5143 | vixl32::Register in_reg_lo = LowRegisterFrom(locations->InAt(0)); |
| 5144 | vixl32::Register in_reg_hi = HighRegisterFrom(locations->InAt(0)); |
| 5145 | Location rhs = locations->InAt(1); |
| 5146 | vixl32::Register out_reg_lo = LowRegisterFrom(locations->Out()); |
| 5147 | vixl32::Register out_reg_hi = HighRegisterFrom(locations->Out()); |
| 5148 | |
| 5149 | if (rhs.IsConstant()) { |
| 5150 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 5151 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
| 5152 | rot &= kMaxLongShiftDistance; |
| 5153 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 5154 | // logic below to a simple pair of binary orr. |
| 5155 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 5156 | if (rot >= kArmBitsPerWord) { |
| 5157 | rot -= kArmBitsPerWord; |
| 5158 | std::swap(in_reg_hi, in_reg_lo); |
| 5159 | } |
| 5160 | // Rotate, or mov to out for zero or word size rotations. |
| 5161 | if (rot != 0u) { |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5162 | __ Lsr(out_reg_hi, in_reg_hi, Operand::From(rot)); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5163 | __ 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] | 5164 | __ Lsr(out_reg_lo, in_reg_lo, Operand::From(rot)); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5165 | __ Orr(out_reg_lo, out_reg_lo, Operand(in_reg_hi, ShiftType::LSL, kArmBitsPerWord - rot)); |
| 5166 | } else { |
| 5167 | __ Mov(out_reg_lo, in_reg_lo); |
| 5168 | __ Mov(out_reg_hi, in_reg_hi); |
| 5169 | } |
| 5170 | } else { |
| 5171 | vixl32::Register shift_right = RegisterFrom(locations->GetTemp(0)); |
| 5172 | vixl32::Register shift_left = RegisterFrom(locations->GetTemp(1)); |
| 5173 | vixl32::Label end; |
| 5174 | vixl32::Label shift_by_32_plus_shift_right; |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5175 | vixl32::Label* final_label = codegen_->GetFinalLabel(ror, &end); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5176 | |
| 5177 | __ And(shift_right, RegisterFrom(rhs), 0x1F); |
| 5178 | __ Lsrs(shift_left, RegisterFrom(rhs), 6); |
| Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 5179 | __ Rsb(LeaveFlags, shift_left, shift_right, Operand::From(kArmBitsPerWord)); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5180 | __ B(cc, &shift_by_32_plus_shift_right, /* is_far_target= */ false); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5181 | |
| 5182 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 5183 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 5184 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 5185 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 5186 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 5187 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 5188 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 5189 | __ Add(out_reg_lo, out_reg_lo, shift_left); |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5190 | __ B(final_label); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5191 | |
| 5192 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 5193 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 5194 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 5195 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 5196 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 5197 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 5198 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 5199 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 5200 | __ Add(out_reg_lo, out_reg_lo, shift_right); |
| 5201 | |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5202 | if (end.IsReferenced()) { |
| 5203 | __ Bind(&end); |
| 5204 | } |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5205 | } |
| 5206 | } |
| 5207 | |
| 5208 | void LocationsBuilderARMVIXL::VisitRor(HRor* ror) { |
| 5209 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5210 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5211 | switch (ror->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5212 | case DataType::Type::kInt32: { |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5213 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5214 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 5215 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5216 | break; |
| 5217 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5218 | case DataType::Type::kInt64: { |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5219 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5220 | if (ror->InputAt(1)->IsConstant()) { |
| 5221 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 5222 | } else { |
| 5223 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5224 | locations->AddTemp(Location::RequiresRegister()); |
| 5225 | locations->AddTemp(Location::RequiresRegister()); |
| 5226 | } |
| 5227 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5228 | break; |
| 5229 | } |
| 5230 | default: |
| 5231 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 5232 | } |
| 5233 | } |
| 5234 | |
| 5235 | void InstructionCodeGeneratorARMVIXL::VisitRor(HRor* ror) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5236 | DataType::Type type = ror->GetResultType(); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5237 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5238 | case DataType::Type::kInt32: { |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5239 | HandleIntegerRotate(ror); |
| 5240 | break; |
| 5241 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5242 | case DataType::Type::kInt64: { |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5243 | HandleLongRotate(ror); |
| 5244 | break; |
| 5245 | } |
| 5246 | default: |
| 5247 | LOG(FATAL) << "Unexpected operation type " << type; |
| 5248 | UNREACHABLE(); |
| 5249 | } |
| 5250 | } |
| 5251 | |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5252 | void LocationsBuilderARMVIXL::HandleShift(HBinaryOperation* op) { |
| 5253 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 5254 | |
| 5255 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5256 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5257 | |
| 5258 | switch (op->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5259 | case DataType::Type::kInt32: { |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5260 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5261 | if (op->InputAt(1)->IsConstant()) { |
| 5262 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 5263 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5264 | } else { |
| 5265 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5266 | // Make the output overlap, as it will be used to hold the masked |
| 5267 | // second input. |
| 5268 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5269 | } |
| 5270 | break; |
| 5271 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5272 | case DataType::Type::kInt64: { |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5273 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5274 | if (op->InputAt(1)->IsConstant()) { |
| 5275 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 5276 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 5277 | // don't clash with high registers which the register allocator currently guarantees. |
| 5278 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5279 | } else { |
| 5280 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5281 | locations->AddTemp(Location::RequiresRegister()); |
| 5282 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5283 | } |
| 5284 | break; |
| 5285 | } |
| 5286 | default: |
| 5287 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 5288 | } |
| 5289 | } |
| 5290 | |
| 5291 | void InstructionCodeGeneratorARMVIXL::HandleShift(HBinaryOperation* op) { |
| 5292 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 5293 | |
| 5294 | LocationSummary* locations = op->GetLocations(); |
| 5295 | Location out = locations->Out(); |
| 5296 | Location first = locations->InAt(0); |
| 5297 | Location second = locations->InAt(1); |
| 5298 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5299 | DataType::Type type = op->GetResultType(); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5300 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5301 | case DataType::Type::kInt32: { |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5302 | vixl32::Register out_reg = OutputRegister(op); |
| 5303 | vixl32::Register first_reg = InputRegisterAt(op, 0); |
| 5304 | if (second.IsRegister()) { |
| 5305 | vixl32::Register second_reg = RegisterFrom(second); |
| 5306 | // ARM doesn't mask the shift count so we need to do it ourselves. |
| 5307 | __ And(out_reg, second_reg, kMaxIntShiftDistance); |
| 5308 | if (op->IsShl()) { |
| 5309 | __ Lsl(out_reg, first_reg, out_reg); |
| 5310 | } else if (op->IsShr()) { |
| 5311 | __ Asr(out_reg, first_reg, out_reg); |
| 5312 | } else { |
| 5313 | __ Lsr(out_reg, first_reg, out_reg); |
| 5314 | } |
| 5315 | } else { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5316 | int32_t cst = Int32ConstantFrom(second); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5317 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
| 5318 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
| 5319 | __ Mov(out_reg, first_reg); |
| 5320 | } else if (op->IsShl()) { |
| 5321 | __ Lsl(out_reg, first_reg, shift_value); |
| 5322 | } else if (op->IsShr()) { |
| 5323 | __ Asr(out_reg, first_reg, shift_value); |
| 5324 | } else { |
| 5325 | __ Lsr(out_reg, first_reg, shift_value); |
| 5326 | } |
| 5327 | } |
| 5328 | break; |
| 5329 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5330 | case DataType::Type::kInt64: { |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5331 | vixl32::Register o_h = HighRegisterFrom(out); |
| 5332 | vixl32::Register o_l = LowRegisterFrom(out); |
| 5333 | |
| 5334 | vixl32::Register high = HighRegisterFrom(first); |
| 5335 | vixl32::Register low = LowRegisterFrom(first); |
| 5336 | |
| 5337 | if (second.IsRegister()) { |
| 5338 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5339 | |
| 5340 | vixl32::Register second_reg = RegisterFrom(second); |
| 5341 | |
| 5342 | if (op->IsShl()) { |
| 5343 | __ And(o_l, second_reg, kMaxLongShiftDistance); |
| 5344 | // Shift the high part |
| 5345 | __ Lsl(o_h, high, o_l); |
| 5346 | // Shift the low part and `or` what overflew on the high part |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5347 | __ Rsb(temp, o_l, Operand::From(kArmBitsPerWord)); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5348 | __ Lsr(temp, low, temp); |
| 5349 | __ Orr(o_h, o_h, temp); |
| 5350 | // If the shift is > 32 bits, override the high part |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5351 | __ Subs(temp, o_l, Operand::From(kArmBitsPerWord)); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5352 | { |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5353 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5354 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5355 | CodeBufferCheckScope::kMaximumSize); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5356 | __ it(pl); |
| 5357 | __ lsl(pl, o_h, low, temp); |
| 5358 | } |
| 5359 | // Shift the low part |
| 5360 | __ Lsl(o_l, low, o_l); |
| 5361 | } else if (op->IsShr()) { |
| 5362 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 5363 | // Shift the low part |
| 5364 | __ Lsr(o_l, low, o_h); |
| 5365 | // Shift the high part and `or` what underflew on the low part |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5366 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5367 | __ Lsl(temp, high, temp); |
| 5368 | __ Orr(o_l, o_l, temp); |
| 5369 | // If the shift is > 32 bits, override the low part |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5370 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5371 | { |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5372 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5373 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5374 | CodeBufferCheckScope::kMaximumSize); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5375 | __ it(pl); |
| 5376 | __ asr(pl, o_l, high, temp); |
| 5377 | } |
| 5378 | // Shift the high part |
| 5379 | __ Asr(o_h, high, o_h); |
| 5380 | } else { |
| 5381 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 5382 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 5383 | __ Lsr(o_l, low, o_h); |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5384 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5385 | __ Lsl(temp, high, temp); |
| 5386 | __ Orr(o_l, o_l, temp); |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5387 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5388 | { |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5389 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5390 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5391 | CodeBufferCheckScope::kMaximumSize); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5392 | __ it(pl); |
| 5393 | __ lsr(pl, o_l, high, temp); |
| 5394 | } |
| 5395 | __ Lsr(o_h, high, o_h); |
| 5396 | } |
| 5397 | } else { |
| 5398 | // Register allocator doesn't create partial overlap. |
| 5399 | DCHECK(!o_l.Is(high)); |
| 5400 | DCHECK(!o_h.Is(low)); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5401 | int32_t cst = Int32ConstantFrom(second); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5402 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
| 5403 | if (shift_value > 32) { |
| 5404 | if (op->IsShl()) { |
| 5405 | __ Lsl(o_h, low, shift_value - 32); |
| 5406 | __ Mov(o_l, 0); |
| 5407 | } else if (op->IsShr()) { |
| 5408 | __ Asr(o_l, high, shift_value - 32); |
| 5409 | __ Asr(o_h, high, 31); |
| 5410 | } else { |
| 5411 | __ Lsr(o_l, high, shift_value - 32); |
| 5412 | __ Mov(o_h, 0); |
| 5413 | } |
| 5414 | } else if (shift_value == 32) { |
| 5415 | if (op->IsShl()) { |
| 5416 | __ Mov(o_h, low); |
| 5417 | __ Mov(o_l, 0); |
| 5418 | } else if (op->IsShr()) { |
| 5419 | __ Mov(o_l, high); |
| 5420 | __ Asr(o_h, high, 31); |
| 5421 | } else { |
| 5422 | __ Mov(o_l, high); |
| 5423 | __ Mov(o_h, 0); |
| 5424 | } |
| 5425 | } else if (shift_value == 1) { |
| 5426 | if (op->IsShl()) { |
| 5427 | __ Lsls(o_l, low, 1); |
| 5428 | __ Adc(o_h, high, high); |
| 5429 | } else if (op->IsShr()) { |
| 5430 | __ Asrs(o_h, high, 1); |
| 5431 | __ Rrx(o_l, low); |
| 5432 | } else { |
| 5433 | __ Lsrs(o_h, high, 1); |
| 5434 | __ Rrx(o_l, low); |
| 5435 | } |
| Nicolas Geoffray | 9b195cc | 2019-04-02 08:29:00 +0100 | [diff] [blame] | 5436 | } else if (shift_value == 0) { |
| 5437 | __ Mov(o_l, low); |
| 5438 | __ Mov(o_h, high); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5439 | } else { |
| Nicolas Geoffray | 9b195cc | 2019-04-02 08:29:00 +0100 | [diff] [blame] | 5440 | DCHECK(0 < shift_value && shift_value < 32) << shift_value; |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5441 | if (op->IsShl()) { |
| 5442 | __ Lsl(o_h, high, shift_value); |
| 5443 | __ Orr(o_h, o_h, Operand(low, ShiftType::LSR, 32 - shift_value)); |
| 5444 | __ Lsl(o_l, low, shift_value); |
| 5445 | } else if (op->IsShr()) { |
| 5446 | __ Lsr(o_l, low, shift_value); |
| 5447 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 5448 | __ Asr(o_h, high, shift_value); |
| 5449 | } else { |
| 5450 | __ Lsr(o_l, low, shift_value); |
| 5451 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 5452 | __ Lsr(o_h, high, shift_value); |
| 5453 | } |
| 5454 | } |
| 5455 | } |
| 5456 | break; |
| 5457 | } |
| 5458 | default: |
| 5459 | LOG(FATAL) << "Unexpected operation type " << type; |
| 5460 | UNREACHABLE(); |
| 5461 | } |
| 5462 | } |
| 5463 | |
| 5464 | void LocationsBuilderARMVIXL::VisitShl(HShl* shl) { |
| 5465 | HandleShift(shl); |
| 5466 | } |
| 5467 | |
| 5468 | void InstructionCodeGeneratorARMVIXL::VisitShl(HShl* shl) { |
| 5469 | HandleShift(shl); |
| 5470 | } |
| 5471 | |
| 5472 | void LocationsBuilderARMVIXL::VisitShr(HShr* shr) { |
| 5473 | HandleShift(shr); |
| 5474 | } |
| 5475 | |
| 5476 | void InstructionCodeGeneratorARMVIXL::VisitShr(HShr* shr) { |
| 5477 | HandleShift(shr); |
| 5478 | } |
| 5479 | |
| 5480 | void LocationsBuilderARMVIXL::VisitUShr(HUShr* ushr) { |
| 5481 | HandleShift(ushr); |
| 5482 | } |
| 5483 | |
| 5484 | void InstructionCodeGeneratorARMVIXL::VisitUShr(HUShr* ushr) { |
| 5485 | HandleShift(ushr); |
| 5486 | } |
| 5487 | |
| 5488 | void LocationsBuilderARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5489 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5490 | instruction, LocationSummary::kCallOnMainOnly); |
| Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5491 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 5492 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5493 | locations->SetOut(LocationFrom(r0)); |
| 5494 | } |
| 5495 | |
| 5496 | void InstructionCodeGeneratorARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
| Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5497 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 5498 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 5499 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 12); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5500 | } |
| 5501 | |
| 5502 | void LocationsBuilderARMVIXL::VisitNewArray(HNewArray* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5503 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5504 | instruction, LocationSummary::kCallOnMainOnly); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5505 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5506 | locations->SetOut(LocationFrom(r0)); |
| Nicolas Geoffray | 8c7c4f1 | 2017-01-26 10:13:11 +0000 | [diff] [blame] | 5507 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5508 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5509 | } |
| 5510 | |
| 5511 | void InstructionCodeGeneratorARMVIXL::VisitNewArray(HNewArray* instruction) { |
| Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5512 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 5513 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
| Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 5514 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5515 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
| Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 5516 | DCHECK(!codegen_->IsLeafMethod()); |
| Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 5517 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 13); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5518 | } |
| 5519 | |
| 5520 | void LocationsBuilderARMVIXL::VisitParameterValue(HParameterValue* instruction) { |
| 5521 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5522 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5523 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5524 | if (location.IsStackSlot()) { |
| 5525 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5526 | } else if (location.IsDoubleStackSlot()) { |
| 5527 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5528 | } |
| 5529 | locations->SetOut(location); |
| 5530 | } |
| 5531 | |
| 5532 | void InstructionCodeGeneratorARMVIXL::VisitParameterValue( |
| 5533 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 5534 | // Nothing to do, the parameter is already at its location. |
| 5535 | } |
| 5536 | |
| 5537 | void LocationsBuilderARMVIXL::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5538 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5539 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5540 | locations->SetOut(LocationFrom(kMethodRegister)); |
| 5541 | } |
| 5542 | |
| 5543 | void InstructionCodeGeneratorARMVIXL::VisitCurrentMethod( |
| 5544 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5545 | // Nothing to do, the method is already at its location. |
| 5546 | } |
| 5547 | |
| 5548 | void LocationsBuilderARMVIXL::VisitNot(HNot* not_) { |
| 5549 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5550 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5551 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5552 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5553 | } |
| 5554 | |
| 5555 | void InstructionCodeGeneratorARMVIXL::VisitNot(HNot* not_) { |
| 5556 | LocationSummary* locations = not_->GetLocations(); |
| 5557 | Location out = locations->Out(); |
| 5558 | Location in = locations->InAt(0); |
| 5559 | switch (not_->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5560 | case DataType::Type::kInt32: |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5561 | __ Mvn(OutputRegister(not_), InputRegisterAt(not_, 0)); |
| 5562 | break; |
| 5563 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5564 | case DataType::Type::kInt64: |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5565 | __ Mvn(LowRegisterFrom(out), LowRegisterFrom(in)); |
| 5566 | __ Mvn(HighRegisterFrom(out), HighRegisterFrom(in)); |
| 5567 | break; |
| 5568 | |
| 5569 | default: |
| 5570 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 5571 | } |
| 5572 | } |
| 5573 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5574 | void LocationsBuilderARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5575 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5576 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5577 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5578 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5579 | } |
| 5580 | |
| 5581 | void InstructionCodeGeneratorARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5582 | __ Eor(OutputRegister(bool_not), InputRegister(bool_not), 1); |
| 5583 | } |
| 5584 | |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5585 | void LocationsBuilderARMVIXL::VisitCompare(HCompare* compare) { |
| 5586 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5587 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5588 | switch (compare->InputAt(0)->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5589 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5590 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5591 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5592 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5593 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5594 | case DataType::Type::kInt32: |
| 5595 | case DataType::Type::kInt64: { |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5596 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5597 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5598 | // Output overlaps because it is written before doing the low comparison. |
| 5599 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5600 | break; |
| 5601 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5602 | case DataType::Type::kFloat32: |
| 5603 | case DataType::Type::kFloat64: { |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5604 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5605 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
| 5606 | locations->SetOut(Location::RequiresRegister()); |
| 5607 | break; |
| 5608 | } |
| 5609 | default: |
| 5610 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 5611 | } |
| 5612 | } |
| 5613 | |
| 5614 | void InstructionCodeGeneratorARMVIXL::VisitCompare(HCompare* compare) { |
| 5615 | LocationSummary* locations = compare->GetLocations(); |
| 5616 | vixl32::Register out = OutputRegister(compare); |
| 5617 | Location left = locations->InAt(0); |
| 5618 | Location right = locations->InAt(1); |
| 5619 | |
| 5620 | vixl32::Label less, greater, done; |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5621 | vixl32::Label* final_label = codegen_->GetFinalLabel(compare, &done); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5622 | DataType::Type type = compare->InputAt(0)->GetType(); |
| Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 5623 | vixl32::Condition less_cond = vixl32::Condition::None(); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5624 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5625 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5626 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5627 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5628 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5629 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5630 | case DataType::Type::kInt32: { |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5631 | // Emit move to `out` before the `Cmp`, as `Mov` might affect the status flags. |
| 5632 | __ Mov(out, 0); |
| 5633 | __ Cmp(RegisterFrom(left), RegisterFrom(right)); // Signed compare. |
| 5634 | less_cond = lt; |
| 5635 | break; |
| 5636 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5637 | case DataType::Type::kInt64: { |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5638 | __ Cmp(HighRegisterFrom(left), HighRegisterFrom(right)); // Signed compare. |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5639 | __ B(lt, &less, /* is_far_target= */ false); |
| 5640 | __ B(gt, &greater, /* is_far_target= */ false); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5641 | // Emit move to `out` before the last `Cmp`, as `Mov` might affect the status flags. |
| 5642 | __ Mov(out, 0); |
| 5643 | __ Cmp(LowRegisterFrom(left), LowRegisterFrom(right)); // Unsigned compare. |
| 5644 | less_cond = lo; |
| 5645 | break; |
| 5646 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5647 | case DataType::Type::kFloat32: |
| 5648 | case DataType::Type::kFloat64: { |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5649 | __ Mov(out, 0); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 5650 | GenerateVcmp(compare, codegen_); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5651 | // To branch on the FP compare result we transfer FPSCR to APSR (encoded as PC in VMRS). |
| 5652 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 5653 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
| 5654 | break; |
| 5655 | } |
| 5656 | default: |
| 5657 | LOG(FATAL) << "Unexpected compare type " << type; |
| 5658 | UNREACHABLE(); |
| 5659 | } |
| 5660 | |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5661 | __ B(eq, final_label, /* is_far_target= */ false); |
| 5662 | __ B(less_cond, &less, /* is_far_target= */ false); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5663 | |
| 5664 | __ Bind(&greater); |
| 5665 | __ Mov(out, 1); |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5666 | __ B(final_label); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5667 | |
| 5668 | __ Bind(&less); |
| 5669 | __ Mov(out, -1); |
| 5670 | |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5671 | if (done.IsReferenced()) { |
| 5672 | __ Bind(&done); |
| 5673 | } |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5674 | } |
| 5675 | |
| 5676 | void LocationsBuilderARMVIXL::VisitPhi(HPhi* instruction) { |
| 5677 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5678 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5679 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| 5680 | locations->SetInAt(i, Location::Any()); |
| 5681 | } |
| 5682 | locations->SetOut(Location::Any()); |
| 5683 | } |
| 5684 | |
| 5685 | void InstructionCodeGeneratorARMVIXL::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 5686 | LOG(FATAL) << "Unreachable"; |
| 5687 | } |
| 5688 | |
| 5689 | void CodeGeneratorARMVIXL::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 5690 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 5691 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
| 5692 | switch (kind) { |
| 5693 | case MemBarrierKind::kAnyStore: |
| 5694 | case MemBarrierKind::kLoadAny: |
| 5695 | case MemBarrierKind::kAnyAny: { |
| 5696 | flavor = DmbOptions::ISH; |
| 5697 | break; |
| 5698 | } |
| 5699 | case MemBarrierKind::kStoreStore: { |
| 5700 | flavor = DmbOptions::ISHST; |
| 5701 | break; |
| 5702 | } |
| 5703 | default: |
| 5704 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 5705 | } |
| 5706 | __ Dmb(flavor); |
| 5707 | } |
| 5708 | |
| 5709 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicLoad(vixl32::Register addr, |
| 5710 | uint32_t offset, |
| 5711 | vixl32::Register out_lo, |
| 5712 | vixl32::Register out_hi) { |
| 5713 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5714 | if (offset != 0) { |
| 5715 | vixl32::Register temp = temps.Acquire(); |
| 5716 | __ Add(temp, addr, offset); |
| 5717 | addr = temp; |
| 5718 | } |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5719 | __ Ldrexd(out_lo, out_hi, MemOperand(addr)); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5720 | } |
| 5721 | |
| 5722 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicStore(vixl32::Register addr, |
| 5723 | uint32_t offset, |
| 5724 | vixl32::Register value_lo, |
| 5725 | vixl32::Register value_hi, |
| 5726 | vixl32::Register temp1, |
| 5727 | vixl32::Register temp2, |
| 5728 | HInstruction* instruction) { |
| 5729 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5730 | vixl32::Label fail; |
| 5731 | if (offset != 0) { |
| 5732 | vixl32::Register temp = temps.Acquire(); |
| 5733 | __ Add(temp, addr, offset); |
| 5734 | addr = temp; |
| 5735 | } |
| 5736 | __ Bind(&fail); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5737 | { |
| 5738 | // Ensure the pc position is recorded immediately after the `ldrexd` instruction. |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5739 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5740 | vixl32::kMaxInstructionSizeInBytes, |
| 5741 | CodeBufferCheckScope::kMaximumSize); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5742 | // We need a load followed by store. (The address used in a STREX instruction must |
| 5743 | // be the same as the address in the most recently executed LDREX instruction.) |
| 5744 | __ ldrexd(temp1, temp2, MemOperand(addr)); |
| 5745 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5746 | } |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5747 | __ Strexd(temp1, value_lo, value_hi, MemOperand(addr)); |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5748 | __ CompareAndBranchIfNonZero(temp1, &fail); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5749 | } |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5750 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5751 | void LocationsBuilderARMVIXL::HandleFieldSet( |
| 5752 | HInstruction* instruction, const FieldInfo& field_info) { |
| 5753 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5754 | |
| 5755 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5756 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5757 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5758 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5759 | DataType::Type field_type = field_info.GetFieldType(); |
| 5760 | if (DataType::IsFloatingPointType(field_type)) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5761 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5762 | } else { |
| 5763 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5764 | } |
| 5765 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5766 | 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] | 5767 | bool generate_volatile = field_info.IsVolatile() |
| 5768 | && is_wide |
| 5769 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5770 | bool needs_write_barrier = |
| 5771 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 5772 | // Temporary registers for the write barrier. |
| 5773 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
| 5774 | if (needs_write_barrier) { |
| 5775 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
| 5776 | locations->AddTemp(Location::RequiresRegister()); |
| 5777 | } else if (generate_volatile) { |
| 5778 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 5779 | // - registers need to be consecutive |
| 5780 | // - the first register should be even but not R14. |
| 5781 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5782 | // revisit this if we ever enable ARM encoding. |
| 5783 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5784 | |
| 5785 | locations->AddTemp(Location::RequiresRegister()); |
| 5786 | locations->AddTemp(Location::RequiresRegister()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5787 | if (field_type == DataType::Type::kFloat64) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5788 | // For doubles we need two more registers to copy the value. |
| 5789 | locations->AddTemp(LocationFrom(r2)); |
| 5790 | locations->AddTemp(LocationFrom(r3)); |
| 5791 | } |
| 5792 | } |
| 5793 | } |
| 5794 | |
| 5795 | void InstructionCodeGeneratorARMVIXL::HandleFieldSet(HInstruction* instruction, |
| 5796 | const FieldInfo& field_info, |
| 5797 | bool value_can_be_null) { |
| 5798 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5799 | |
| 5800 | LocationSummary* locations = instruction->GetLocations(); |
| 5801 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 5802 | Location value = locations->InAt(1); |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5803 | std::optional<vixl::aarch32::Label> pred_is_null; |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5804 | |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5805 | bool is_predicated = |
| 5806 | instruction->IsInstanceFieldSet() && instruction->AsInstanceFieldSet()->GetIsPredicatedSet(); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5807 | bool is_volatile = field_info.IsVolatile(); |
| 5808 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5809 | DataType::Type field_type = field_info.GetFieldType(); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5810 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5811 | bool needs_write_barrier = |
| 5812 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 5813 | |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5814 | if (is_predicated) { |
| 5815 | pred_is_null.emplace(); |
| 5816 | __ CompareAndBranchIfZero(base, &*pred_is_null, /* is_far_target= */ false); |
| 5817 | } |
| 5818 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5819 | if (is_volatile) { |
| 5820 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 5821 | } |
| 5822 | |
| 5823 | switch (field_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5824 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5825 | case DataType::Type::kUint8: |
| 5826 | case DataType::Type::kInt8: |
| 5827 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5828 | case DataType::Type::kInt16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5829 | case DataType::Type::kInt32: { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5830 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5831 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5832 | StoreOperandType operand_type = GetStoreOperandType(field_type); |
| 5833 | GetAssembler()->StoreToOffset(operand_type, RegisterFrom(value), base, offset); |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5834 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5835 | break; |
| 5836 | } |
| 5837 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5838 | case DataType::Type::kReference: { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5839 | vixl32::Register value_reg = RegisterFrom(value); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5840 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5841 | // Note that in the case where `value` is a null reference, |
| 5842 | // we do not enter this block, as a null reference does not |
| 5843 | // need poisoning. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5844 | DCHECK_EQ(field_type, DataType::Type::kReference); |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5845 | value_reg = RegisterFrom(locations->GetTemp(0)); |
| 5846 | __ Mov(value_reg, RegisterFrom(value)); |
| 5847 | GetAssembler()->PoisonHeapReference(value_reg); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5848 | } |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5849 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5850 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5851 | GetAssembler()->StoreToOffset(kStoreWord, value_reg, base, offset); |
| 5852 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5853 | break; |
| 5854 | } |
| 5855 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5856 | case DataType::Type::kInt64: { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5857 | if (is_volatile && !atomic_ldrd_strd) { |
| 5858 | GenerateWideAtomicStore(base, |
| 5859 | offset, |
| 5860 | LowRegisterFrom(value), |
| 5861 | HighRegisterFrom(value), |
| 5862 | RegisterFrom(locations->GetTemp(0)), |
| 5863 | RegisterFrom(locations->GetTemp(1)), |
| 5864 | instruction); |
| 5865 | } else { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5866 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5867 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5868 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), base, offset); |
| 5869 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5870 | } |
| 5871 | break; |
| 5872 | } |
| 5873 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5874 | case DataType::Type::kFloat32: { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5875 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5876 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5877 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), base, offset); |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5878 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5879 | break; |
| 5880 | } |
| 5881 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5882 | case DataType::Type::kFloat64: { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5883 | vixl32::DRegister value_reg = DRegisterFrom(value); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5884 | if (is_volatile && !atomic_ldrd_strd) { |
| 5885 | vixl32::Register value_reg_lo = RegisterFrom(locations->GetTemp(0)); |
| 5886 | vixl32::Register value_reg_hi = RegisterFrom(locations->GetTemp(1)); |
| 5887 | |
| 5888 | __ Vmov(value_reg_lo, value_reg_hi, value_reg); |
| 5889 | |
| 5890 | GenerateWideAtomicStore(base, |
| 5891 | offset, |
| 5892 | value_reg_lo, |
| 5893 | value_reg_hi, |
| 5894 | RegisterFrom(locations->GetTemp(2)), |
| 5895 | RegisterFrom(locations->GetTemp(3)), |
| 5896 | instruction); |
| 5897 | } else { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5898 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5899 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5900 | GetAssembler()->StoreDToOffset(value_reg, base, offset); |
| 5901 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5902 | } |
| 5903 | break; |
| 5904 | } |
| 5905 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5906 | case DataType::Type::kUint32: |
| 5907 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5908 | case DataType::Type::kVoid: |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5909 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5910 | UNREACHABLE(); |
| 5911 | } |
| 5912 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5913 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5914 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5915 | vixl32::Register card = RegisterFrom(locations->GetTemp(1)); |
| 5916 | codegen_->MarkGCCard(temp, card, base, RegisterFrom(value), value_can_be_null); |
| 5917 | } |
| 5918 | |
| 5919 | if (is_volatile) { |
| 5920 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 5921 | } |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5922 | |
| 5923 | if (is_predicated) { |
| 5924 | __ Bind(&*pred_is_null); |
| 5925 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5926 | } |
| 5927 | |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5928 | void LocationsBuilderARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 5929 | const FieldInfo& field_info) { |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5930 | DCHECK(instruction->IsInstanceFieldGet() || |
| 5931 | instruction->IsStaticFieldGet() || |
| 5932 | instruction->IsPredicatedInstanceFieldGet()); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5933 | |
| 5934 | bool object_field_get_with_read_barrier = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5935 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == DataType::Type::kReference); |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5936 | bool is_predicated = instruction->IsPredicatedInstanceFieldGet(); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5937 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5938 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5939 | object_field_get_with_read_barrier |
| 5940 | ? LocationSummary::kCallOnSlowPath |
| 5941 | : LocationSummary::kNoCall); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5942 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5943 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 5944 | } |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5945 | // Input for object receiver. |
| 5946 | locations->SetInAt(is_predicated ? 1 : 0, Location::RequiresRegister()); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5947 | |
| 5948 | bool volatile_for_double = field_info.IsVolatile() |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5949 | && (field_info.GetFieldType() == DataType::Type::kFloat64) |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5950 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5951 | // The output overlaps in case of volatile long: we don't want the |
| 5952 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 5953 | // object's location. Likewise, in the case of an object field get |
| 5954 | // with read barriers enabled, we do not want the load to overwrite |
| 5955 | // 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] | 5956 | bool overlap = |
| 5957 | (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) || |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5958 | object_field_get_with_read_barrier; |
| 5959 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5960 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5961 | if (is_predicated) { |
| 5962 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5963 | locations->SetOut(Location::SameAsFirstInput()); |
| 5964 | } else { |
| 5965 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5966 | } |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5967 | } else { |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5968 | if (is_predicated) { |
| 5969 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5970 | locations->SetOut(Location::SameAsFirstInput()); |
| 5971 | } else { |
| 5972 | locations->SetOut(Location::RequiresRegister(), |
| 5973 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 5974 | } |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5975 | } |
| 5976 | if (volatile_for_double) { |
| 5977 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 5978 | // - registers need to be consecutive |
| 5979 | // - the first register should be even but not R14. |
| 5980 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5981 | // revisit this if we ever enable ARM encoding. |
| 5982 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5983 | locations->AddTemp(Location::RequiresRegister()); |
| 5984 | locations->AddTemp(Location::RequiresRegister()); |
| 5985 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 5986 | // We need a temporary register for the read barrier load in |
| 5987 | // CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier() |
| 5988 | // only if the offset is too big. |
| 5989 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 5990 | locations->AddTemp(Location::RequiresRegister()); |
| 5991 | } |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5992 | } |
| 5993 | } |
| 5994 | |
| 5995 | Location LocationsBuilderARMVIXL::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5996 | DCHECK(DataType::IsFloatingPointType(input->GetType())) << input->GetType(); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5997 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 5998 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 5999 | return Location::ConstantLocation(input->AsConstant()); |
| 6000 | } else { |
| 6001 | return Location::RequiresFpuRegister(); |
| 6002 | } |
| 6003 | } |
| 6004 | |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 6005 | Location LocationsBuilderARMVIXL::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 6006 | Opcode opcode) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6007 | DCHECK(!DataType::IsFloatingPointType(constant->GetType())); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 6008 | if (constant->IsConstant() && |
| 6009 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 6010 | return Location::ConstantLocation(constant->AsConstant()); |
| 6011 | } |
| 6012 | return Location::RequiresRegister(); |
| 6013 | } |
| 6014 | |
| Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 6015 | static bool CanEncode32BitConstantAsImmediate( |
| 6016 | CodeGeneratorARMVIXL* codegen, |
| 6017 | uint32_t value, |
| 6018 | Opcode opcode, |
| 6019 | vixl32::FlagsUpdate flags_update = vixl32::FlagsUpdate::DontCare) { |
| 6020 | ArmVIXLAssembler* assembler = codegen->GetAssembler(); |
| 6021 | if (assembler->ShifterOperandCanHold(opcode, value, flags_update)) { |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 6022 | return true; |
| 6023 | } |
| 6024 | Opcode neg_opcode = kNoOperand; |
| Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 6025 | uint32_t neg_value = 0; |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 6026 | switch (opcode) { |
| Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 6027 | case AND: neg_opcode = BIC; neg_value = ~value; break; |
| 6028 | case ORR: neg_opcode = ORN; neg_value = ~value; break; |
| 6029 | case ADD: neg_opcode = SUB; neg_value = -value; break; |
| 6030 | case ADC: neg_opcode = SBC; neg_value = ~value; break; |
| 6031 | case SUB: neg_opcode = ADD; neg_value = -value; break; |
| 6032 | case SBC: neg_opcode = ADC; neg_value = ~value; break; |
| 6033 | case MOV: neg_opcode = MVN; neg_value = ~value; break; |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 6034 | default: |
| 6035 | return false; |
| 6036 | } |
| Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 6037 | |
| Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 6038 | if (assembler->ShifterOperandCanHold(neg_opcode, neg_value, flags_update)) { |
| Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 6039 | return true; |
| 6040 | } |
| 6041 | |
| 6042 | return opcode == AND && IsPowerOfTwo(value + 1); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 6043 | } |
| 6044 | |
| Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 6045 | bool LocationsBuilderARMVIXL::CanEncodeConstantAsImmediate(HConstant* input_cst, Opcode opcode) { |
| 6046 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 6047 | if (DataType::Is64BitType(input_cst->GetType())) { |
| 6048 | Opcode high_opcode = opcode; |
| 6049 | vixl32::FlagsUpdate low_flags_update = vixl32::FlagsUpdate::DontCare; |
| 6050 | switch (opcode) { |
| 6051 | case SUB: |
| 6052 | // Flip the operation to an ADD. |
| 6053 | value = -value; |
| 6054 | opcode = ADD; |
| 6055 | FALLTHROUGH_INTENDED; |
| 6056 | case ADD: |
| 6057 | if (Low32Bits(value) == 0u) { |
| 6058 | return CanEncode32BitConstantAsImmediate(codegen_, High32Bits(value), opcode); |
| 6059 | } |
| 6060 | high_opcode = ADC; |
| 6061 | low_flags_update = vixl32::FlagsUpdate::SetFlags; |
| 6062 | break; |
| 6063 | default: |
| 6064 | break; |
| 6065 | } |
| 6066 | return CanEncode32BitConstantAsImmediate(codegen_, High32Bits(value), high_opcode) && |
| 6067 | CanEncode32BitConstantAsImmediate(codegen_, Low32Bits(value), opcode, low_flags_update); |
| 6068 | } else { |
| 6069 | return CanEncode32BitConstantAsImmediate(codegen_, Low32Bits(value), opcode); |
| 6070 | } |
| 6071 | } |
| 6072 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6073 | void InstructionCodeGeneratorARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 6074 | const FieldInfo& field_info) { |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6075 | DCHECK(instruction->IsInstanceFieldGet() || |
| 6076 | instruction->IsStaticFieldGet() || |
| 6077 | instruction->IsPredicatedInstanceFieldGet()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6078 | |
| 6079 | LocationSummary* locations = instruction->GetLocations(); |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6080 | uint32_t receiver_input = instruction->IsPredicatedInstanceFieldGet() ? 1 : 0; |
| 6081 | vixl32::Register base = InputRegisterAt(instruction, receiver_input); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6082 | Location out = locations->Out(); |
| 6083 | bool is_volatile = field_info.IsVolatile(); |
| 6084 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6085 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 6086 | DataType::Type load_type = instruction->GetType(); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6087 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 6088 | |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6089 | switch (load_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6090 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6091 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6092 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6093 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6094 | case DataType::Type::kInt16: |
| 6095 | case DataType::Type::kInt32: { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6096 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6097 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6098 | LoadOperandType operand_type = GetLoadOperandType(load_type); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6099 | GetAssembler()->LoadFromOffset(operand_type, RegisterFrom(out), base, offset); |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6100 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6101 | break; |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6102 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6103 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6104 | case DataType::Type::kReference: { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6105 | // /* HeapReference<Object> */ out = *(base + offset) |
| 6106 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 6107 | Location maybe_temp = (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location(); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6108 | // Note that a potential implicit null check is handled in this |
| 6109 | // CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier call. |
| 6110 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6111 | instruction, out, base, offset, maybe_temp, /* needs_null_check= */ true); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6112 | if (is_volatile) { |
| 6113 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6114 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6115 | } else { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6116 | { |
| 6117 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6118 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6119 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(out), base, offset); |
| 6120 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6121 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6122 | if (is_volatile) { |
| 6123 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6124 | } |
| 6125 | // If read barriers are enabled, emit read barriers other than |
| 6126 | // Baker's using a slow path (and also unpoison the loaded |
| 6127 | // reference, if heap poisoning is enabled). |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6128 | codegen_->MaybeGenerateReadBarrierSlow( |
| 6129 | instruction, out, out, locations->InAt(receiver_input), offset); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6130 | } |
| 6131 | break; |
| 6132 | } |
| 6133 | |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6134 | case DataType::Type::kInt64: { |
| 6135 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6136 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6137 | if (is_volatile && !atomic_ldrd_strd) { |
| 6138 | GenerateWideAtomicLoad(base, offset, LowRegisterFrom(out), HighRegisterFrom(out)); |
| 6139 | } else { |
| 6140 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out), base, offset); |
| 6141 | } |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6142 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6143 | break; |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6144 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6145 | |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6146 | case DataType::Type::kFloat32: { |
| 6147 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6148 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6149 | GetAssembler()->LoadSFromOffset(SRegisterFrom(out), base, offset); |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6150 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6151 | break; |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6152 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6153 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6154 | case DataType::Type::kFloat64: { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6155 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6156 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6157 | vixl32::DRegister out_dreg = DRegisterFrom(out); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6158 | if (is_volatile && !atomic_ldrd_strd) { |
| 6159 | vixl32::Register lo = RegisterFrom(locations->GetTemp(0)); |
| 6160 | vixl32::Register hi = RegisterFrom(locations->GetTemp(1)); |
| 6161 | GenerateWideAtomicLoad(base, offset, lo, hi); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6162 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6163 | __ Vmov(out_dreg, lo, hi); |
| 6164 | } else { |
| 6165 | GetAssembler()->LoadDFromOffset(out_dreg, base, offset); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6166 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6167 | } |
| 6168 | break; |
| 6169 | } |
| 6170 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6171 | case DataType::Type::kUint32: |
| 6172 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6173 | case DataType::Type::kVoid: |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6174 | LOG(FATAL) << "Unreachable type " << load_type; |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6175 | UNREACHABLE(); |
| 6176 | } |
| 6177 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6178 | if (is_volatile) { |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6179 | if (load_type == DataType::Type::kReference) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6180 | // Memory barriers, in the case of references, are also handled |
| 6181 | // in the previous switch statement. |
| 6182 | } else { |
| 6183 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6184 | } |
| 6185 | } |
| 6186 | } |
| 6187 | |
| 6188 | void LocationsBuilderARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 6189 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6190 | } |
| 6191 | |
| 6192 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 6193 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 6194 | } |
| 6195 | |
| 6196 | void LocationsBuilderARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6197 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6198 | } |
| 6199 | |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6200 | void LocationsBuilderARMVIXL::VisitPredicatedInstanceFieldGet( |
| 6201 | HPredicatedInstanceFieldGet* instruction) { |
| 6202 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6203 | } |
| 6204 | |
| 6205 | void InstructionCodeGeneratorARMVIXL::VisitPredicatedInstanceFieldGet( |
| 6206 | HPredicatedInstanceFieldGet* instruction) { |
| 6207 | vixl::aarch32::Label finish; |
| 6208 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 1), &finish, false); |
| 6209 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6210 | __ Bind(&finish); |
| 6211 | } |
| 6212 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6213 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6214 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6215 | } |
| 6216 | |
| 6217 | void LocationsBuilderARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6218 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6219 | } |
| 6220 | |
| 6221 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6222 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6223 | } |
| 6224 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6225 | void LocationsBuilderARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 6226 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6227 | } |
| 6228 | |
| 6229 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 6230 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 6231 | } |
| 6232 | |
| Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 6233 | void LocationsBuilderARMVIXL::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 6234 | codegen_->CreateStringBuilderAppendLocations(instruction, LocationFrom(r0)); |
| 6235 | } |
| 6236 | |
| 6237 | void InstructionCodeGeneratorARMVIXL::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 6238 | __ Mov(r0, instruction->GetFormat()->GetValue()); |
| 6239 | codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc()); |
| 6240 | } |
| 6241 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6242 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 6243 | HUnresolvedInstanceFieldGet* instruction) { |
| 6244 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6245 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6246 | instruction, instruction->GetFieldType(), calling_convention); |
| 6247 | } |
| 6248 | |
| 6249 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 6250 | HUnresolvedInstanceFieldGet* instruction) { |
| 6251 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6252 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6253 | instruction->GetFieldType(), |
| 6254 | instruction->GetFieldIndex(), |
| 6255 | instruction->GetDexPc(), |
| 6256 | calling_convention); |
| 6257 | } |
| 6258 | |
| 6259 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 6260 | HUnresolvedInstanceFieldSet* instruction) { |
| 6261 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6262 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6263 | instruction, instruction->GetFieldType(), calling_convention); |
| 6264 | } |
| 6265 | |
| 6266 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 6267 | HUnresolvedInstanceFieldSet* instruction) { |
| 6268 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6269 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6270 | instruction->GetFieldType(), |
| 6271 | instruction->GetFieldIndex(), |
| 6272 | instruction->GetDexPc(), |
| 6273 | calling_convention); |
| 6274 | } |
| 6275 | |
| 6276 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldGet( |
| 6277 | HUnresolvedStaticFieldGet* instruction) { |
| 6278 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6279 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6280 | instruction, instruction->GetFieldType(), calling_convention); |
| 6281 | } |
| 6282 | |
| 6283 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldGet( |
| 6284 | HUnresolvedStaticFieldGet* instruction) { |
| 6285 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6286 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6287 | instruction->GetFieldType(), |
| 6288 | instruction->GetFieldIndex(), |
| 6289 | instruction->GetDexPc(), |
| 6290 | calling_convention); |
| 6291 | } |
| 6292 | |
| 6293 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldSet( |
| 6294 | HUnresolvedStaticFieldSet* instruction) { |
| 6295 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6296 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6297 | instruction, instruction->GetFieldType(), calling_convention); |
| 6298 | } |
| 6299 | |
| 6300 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldSet( |
| 6301 | HUnresolvedStaticFieldSet* instruction) { |
| 6302 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6303 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6304 | instruction->GetFieldType(), |
| 6305 | instruction->GetFieldIndex(), |
| 6306 | instruction->GetDexPc(), |
| 6307 | calling_convention); |
| 6308 | } |
| 6309 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6310 | void LocationsBuilderARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6311 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6312 | locations->SetInAt(0, Location::RequiresRegister()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6313 | } |
| 6314 | |
| 6315 | void CodeGeneratorARMVIXL::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 6316 | if (CanMoveNullCheckToUser(instruction)) { |
| 6317 | return; |
| 6318 | } |
| 6319 | |
| 6320 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6321 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6322 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6323 | vixl32::kMaxInstructionSizeInBytes, |
| 6324 | CodeBufferCheckScope::kMaximumSize); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6325 | __ ldr(temps.Acquire(), MemOperand(InputRegisterAt(instruction, 0))); |
| 6326 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 6327 | } |
| 6328 | |
| 6329 | void CodeGeneratorARMVIXL::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| 6330 | NullCheckSlowPathARMVIXL* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6331 | new (GetScopedAllocator()) NullCheckSlowPathARMVIXL(instruction); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6332 | AddSlowPath(slow_path); |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6333 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6334 | } |
| 6335 | |
| 6336 | void InstructionCodeGeneratorARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
| 6337 | codegen_->GenerateNullCheck(instruction); |
| 6338 | } |
| 6339 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6340 | void CodeGeneratorARMVIXL::LoadFromShiftedRegOffset(DataType::Type type, |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6341 | Location out_loc, |
| 6342 | vixl32::Register base, |
| 6343 | vixl32::Register reg_index, |
| 6344 | vixl32::Condition cond) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6345 | uint32_t shift_count = DataType::SizeShift(type); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6346 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 6347 | |
| 6348 | switch (type) { |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6349 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6350 | case DataType::Type::kUint8: |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6351 | __ Ldrb(cond, RegisterFrom(out_loc), mem_address); |
| 6352 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6353 | case DataType::Type::kInt8: |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6354 | __ Ldrsb(cond, RegisterFrom(out_loc), mem_address); |
| 6355 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6356 | case DataType::Type::kUint16: |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6357 | __ Ldrh(cond, RegisterFrom(out_loc), mem_address); |
| 6358 | break; |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6359 | case DataType::Type::kInt16: |
| 6360 | __ Ldrsh(cond, RegisterFrom(out_loc), mem_address); |
| 6361 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6362 | case DataType::Type::kReference: |
| 6363 | case DataType::Type::kInt32: |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6364 | __ Ldr(cond, RegisterFrom(out_loc), mem_address); |
| 6365 | break; |
| 6366 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6367 | case DataType::Type::kInt64: |
| 6368 | case DataType::Type::kFloat32: |
| 6369 | case DataType::Type::kFloat64: |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6370 | default: |
| 6371 | LOG(FATAL) << "Unreachable type " << type; |
| 6372 | UNREACHABLE(); |
| 6373 | } |
| 6374 | } |
| 6375 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6376 | void CodeGeneratorARMVIXL::StoreToShiftedRegOffset(DataType::Type type, |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6377 | Location loc, |
| 6378 | vixl32::Register base, |
| 6379 | vixl32::Register reg_index, |
| 6380 | vixl32::Condition cond) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6381 | uint32_t shift_count = DataType::SizeShift(type); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6382 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 6383 | |
| 6384 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6385 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6386 | case DataType::Type::kUint8: |
| 6387 | case DataType::Type::kInt8: |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6388 | __ Strb(cond, RegisterFrom(loc), mem_address); |
| 6389 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6390 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6391 | case DataType::Type::kInt16: |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6392 | __ Strh(cond, RegisterFrom(loc), mem_address); |
| 6393 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6394 | case DataType::Type::kReference: |
| 6395 | case DataType::Type::kInt32: |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6396 | __ Str(cond, RegisterFrom(loc), mem_address); |
| 6397 | break; |
| 6398 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6399 | case DataType::Type::kInt64: |
| 6400 | case DataType::Type::kFloat32: |
| 6401 | case DataType::Type::kFloat64: |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6402 | default: |
| 6403 | LOG(FATAL) << "Unreachable type " << type; |
| 6404 | UNREACHABLE(); |
| 6405 | } |
| 6406 | } |
| 6407 | |
| 6408 | void LocationsBuilderARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
| 6409 | bool object_array_get_with_read_barrier = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6410 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6411 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6412 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 6413 | object_array_get_with_read_barrier |
| 6414 | ? LocationSummary::kCallOnSlowPath |
| 6415 | : LocationSummary::kNoCall); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6416 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6417 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6418 | } |
| 6419 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6420 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6421 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6422 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6423 | } else { |
| 6424 | // The output overlaps in the case of an object array get with |
| 6425 | // read barriers enabled: we do not want the move to overwrite the |
| 6426 | // array's location, as we need it to emit the read barrier. |
| 6427 | locations->SetOut( |
| 6428 | Location::RequiresRegister(), |
| 6429 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 6430 | } |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6431 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6432 | if (instruction->GetIndex()->IsConstant()) { |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6433 | // Array loads with constant index are treated as field loads. |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6434 | // We need a temporary register for the read barrier load in |
| 6435 | // CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier() |
| 6436 | // only if the offset is too big. |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6437 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 6438 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6439 | offset += index << DataType::SizeShift(DataType::Type::kReference); |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6440 | if (offset >= kReferenceLoadMinFarOffset) { |
| 6441 | locations->AddTemp(Location::RequiresRegister()); |
| 6442 | } |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6443 | } else { |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6444 | // We need a non-scratch temporary for the array data pointer in |
| 6445 | // CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier(). |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6446 | locations->AddTemp(Location::RequiresRegister()); |
| 6447 | } |
| 6448 | } else if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 6449 | // Also need a temporary for String compression feature. |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6450 | locations->AddTemp(Location::RequiresRegister()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6451 | } |
| 6452 | } |
| 6453 | |
| 6454 | void InstructionCodeGeneratorARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6455 | LocationSummary* locations = instruction->GetLocations(); |
| 6456 | Location obj_loc = locations->InAt(0); |
| 6457 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 6458 | Location index = locations->InAt(1); |
| 6459 | Location out_loc = locations->Out(); |
| 6460 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6461 | DataType::Type type = instruction->GetType(); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6462 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 6463 | instruction->IsStringCharAt(); |
| 6464 | HInstruction* array_instr = instruction->GetArray(); |
| 6465 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6466 | |
| 6467 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6468 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6469 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6470 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6471 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6472 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6473 | case DataType::Type::kInt32: { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6474 | vixl32::Register length; |
| 6475 | if (maybe_compressed_char_at) { |
| 6476 | length = RegisterFrom(locations->GetTemp(0)); |
| 6477 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6478 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6479 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6480 | GetAssembler()->LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 6481 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6482 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6483 | if (index.IsConstant()) { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6484 | int32_t const_index = Int32ConstantFrom(index); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6485 | if (maybe_compressed_char_at) { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6486 | vixl32::Label uncompressed_load, done; |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6487 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6488 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 6489 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6490 | "Expecting 0=compressed, 1=uncompressed"); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6491 | __ B(cs, &uncompressed_load, /* is_far_target= */ false); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6492 | GetAssembler()->LoadFromOffset(kLoadUnsignedByte, |
| 6493 | RegisterFrom(out_loc), |
| 6494 | obj, |
| 6495 | data_offset + const_index); |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6496 | __ B(final_label); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6497 | __ Bind(&uncompressed_load); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6498 | GetAssembler()->LoadFromOffset(GetLoadOperandType(DataType::Type::kUint16), |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6499 | RegisterFrom(out_loc), |
| 6500 | obj, |
| 6501 | data_offset + (const_index << 1)); |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6502 | if (done.IsReferenced()) { |
| 6503 | __ Bind(&done); |
| 6504 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6505 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6506 | uint32_t full_offset = data_offset + (const_index << DataType::SizeShift(type)); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6507 | |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6508 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6509 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6510 | LoadOperandType load_type = GetLoadOperandType(type); |
| 6511 | GetAssembler()->LoadFromOffset(load_type, RegisterFrom(out_loc), obj, full_offset); |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6512 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6513 | } |
| 6514 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6515 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6516 | vixl32::Register temp = temps.Acquire(); |
| 6517 | |
| 6518 | if (has_intermediate_address) { |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6519 | // We do not need to compute the intermediate address from the array: the |
| 6520 | // input instruction has done it already. See the comment in |
| 6521 | // `TryExtractArrayAccessAddress()`. |
| 6522 | if (kIsDebugBuild) { |
| 6523 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6524 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6525 | } |
| 6526 | temp = obj; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6527 | } else { |
| 6528 | __ Add(temp, obj, data_offset); |
| 6529 | } |
| 6530 | if (maybe_compressed_char_at) { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6531 | vixl32::Label uncompressed_load, done; |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6532 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6533 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 6534 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6535 | "Expecting 0=compressed, 1=uncompressed"); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6536 | __ B(cs, &uncompressed_load, /* is_far_target= */ false); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6537 | __ Ldrb(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 0)); |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6538 | __ B(final_label); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6539 | __ Bind(&uncompressed_load); |
| 6540 | __ Ldrh(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 1)); |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6541 | if (done.IsReferenced()) { |
| 6542 | __ Bind(&done); |
| 6543 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6544 | } else { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6545 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6546 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6547 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6548 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6549 | } |
| 6550 | } |
| 6551 | break; |
| 6552 | } |
| 6553 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6554 | case DataType::Type::kReference: { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6555 | // The read barrier instrumentation of object ArrayGet |
| 6556 | // instructions does not support the HIntermediateAddress |
| 6557 | // instruction. |
| 6558 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 6559 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6560 | static_assert( |
| 6561 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6562 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 6563 | // /* HeapReference<Object> */ out = |
| 6564 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6565 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6566 | // Note that a potential implicit null check is handled in this |
| 6567 | // CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier call. |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6568 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 6569 | if (index.IsConstant()) { |
| 6570 | // 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] | 6571 | Location maybe_temp = |
| 6572 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6573 | data_offset += Int32ConstantFrom(index) << DataType::SizeShift(type); |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6574 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6575 | out_loc, |
| 6576 | obj, |
| 6577 | data_offset, |
| Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 6578 | maybe_temp, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6579 | /* needs_null_check= */ false); |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6580 | } else { |
| Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 6581 | Location temp = locations->GetTemp(0); |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6582 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6583 | out_loc, obj, data_offset, index, temp, /* needs_null_check= */ false); |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6584 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6585 | } else { |
| 6586 | vixl32::Register out = OutputRegister(instruction); |
| 6587 | if (index.IsConstant()) { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6588 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
| 6589 | { |
| 6590 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6591 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6592 | GetAssembler()->LoadFromOffset(kLoadWord, out, obj, offset); |
| 6593 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6594 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6595 | // If read barriers are enabled, emit read barriers other than |
| 6596 | // Baker's using a slow path (and also unpoison the loaded |
| 6597 | // reference, if heap poisoning is enabled). |
| 6598 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 6599 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6600 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6601 | vixl32::Register temp = temps.Acquire(); |
| 6602 | |
| 6603 | if (has_intermediate_address) { |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6604 | // We do not need to compute the intermediate address from the array: the |
| 6605 | // input instruction has done it already. See the comment in |
| 6606 | // `TryExtractArrayAccessAddress()`. |
| 6607 | if (kIsDebugBuild) { |
| 6608 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6609 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6610 | } |
| 6611 | temp = obj; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6612 | } else { |
| 6613 | __ Add(temp, obj, data_offset); |
| 6614 | } |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6615 | { |
| 6616 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6617 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6618 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
| 6619 | temps.Close(); |
| 6620 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6621 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6622 | // If read barriers are enabled, emit read barriers other than |
| 6623 | // Baker's using a slow path (and also unpoison the loaded |
| 6624 | // reference, if heap poisoning is enabled). |
| 6625 | codegen_->MaybeGenerateReadBarrierSlow( |
| 6626 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 6627 | } |
| 6628 | } |
| 6629 | break; |
| 6630 | } |
| 6631 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6632 | case DataType::Type::kInt64: { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6633 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6634 | // As two macro instructions can be emitted the max size is doubled. |
| 6635 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6636 | if (index.IsConstant()) { |
| 6637 | size_t offset = |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6638 | (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6639 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), obj, offset); |
| 6640 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6641 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6642 | vixl32::Register temp = temps.Acquire(); |
| 6643 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6644 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), temp, data_offset); |
| 6645 | } |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6646 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6647 | break; |
| 6648 | } |
| 6649 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6650 | case DataType::Type::kFloat32: { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6651 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6652 | // As two macro instructions can be emitted the max size is doubled. |
| 6653 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6654 | vixl32::SRegister out = SRegisterFrom(out_loc); |
| 6655 | if (index.IsConstant()) { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6656 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6657 | GetAssembler()->LoadSFromOffset(out, obj, offset); |
| 6658 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6659 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6660 | vixl32::Register temp = temps.Acquire(); |
| 6661 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 6662 | GetAssembler()->LoadSFromOffset(out, temp, data_offset); |
| 6663 | } |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6664 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6665 | break; |
| 6666 | } |
| 6667 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6668 | case DataType::Type::kFloat64: { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6669 | // Ensure that between load 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 | if (index.IsConstant()) { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6673 | size_t offset = (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6674 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), obj, offset); |
| 6675 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6676 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6677 | vixl32::Register temp = temps.Acquire(); |
| 6678 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6679 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), temp, data_offset); |
| 6680 | } |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6681 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6682 | break; |
| 6683 | } |
| 6684 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6685 | case DataType::Type::kUint32: |
| 6686 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6687 | case DataType::Type::kVoid: |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6688 | LOG(FATAL) << "Unreachable type " << type; |
| 6689 | UNREACHABLE(); |
| 6690 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6691 | } |
| 6692 | |
| 6693 | void LocationsBuilderARMVIXL::VisitArraySet(HArraySet* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6694 | DataType::Type value_type = instruction->GetComponentType(); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6695 | |
| 6696 | bool needs_write_barrier = |
| 6697 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6698 | bool needs_type_check = instruction->NeedsTypeCheck(); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6699 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6700 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6701 | instruction, |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6702 | needs_type_check ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6703 | |
| 6704 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6705 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6706 | if (DataType::IsFloatingPointType(value_type)) { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6707 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 6708 | } else { |
| 6709 | locations->SetInAt(2, Location::RequiresRegister()); |
| 6710 | } |
| 6711 | if (needs_write_barrier) { |
| 6712 | // Temporary registers for the write barrier. |
| 6713 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 6714 | locations->AddTemp(Location::RequiresRegister()); |
| 6715 | } |
| 6716 | } |
| 6717 | |
| 6718 | void InstructionCodeGeneratorARMVIXL::VisitArraySet(HArraySet* instruction) { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6719 | LocationSummary* locations = instruction->GetLocations(); |
| 6720 | vixl32::Register array = InputRegisterAt(instruction, 0); |
| 6721 | Location index = locations->InAt(1); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6722 | DataType::Type value_type = instruction->GetComponentType(); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6723 | bool needs_type_check = instruction->NeedsTypeCheck(); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6724 | bool needs_write_barrier = |
| 6725 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 6726 | uint32_t data_offset = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6727 | mirror::Array::DataOffset(DataType::Size(value_type)).Uint32Value(); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6728 | Location value_loc = locations->InAt(2); |
| 6729 | HInstruction* array_instr = instruction->GetArray(); |
| 6730 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6731 | |
| 6732 | switch (value_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6733 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6734 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6735 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6736 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6737 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6738 | case DataType::Type::kInt32: { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6739 | if (index.IsConstant()) { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6740 | int32_t const_index = Int32ConstantFrom(index); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6741 | uint32_t full_offset = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6742 | data_offset + (const_index << DataType::SizeShift(value_type)); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6743 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6744 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6745 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6746 | GetAssembler()->StoreToOffset(store_type, RegisterFrom(value_loc), array, full_offset); |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6747 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6748 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6749 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6750 | vixl32::Register temp = temps.Acquire(); |
| 6751 | |
| 6752 | if (has_intermediate_address) { |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6753 | // We do not need to compute the intermediate address from the array: the |
| 6754 | // input instruction has done it already. See the comment in |
| 6755 | // `TryExtractArrayAccessAddress()`. |
| 6756 | if (kIsDebugBuild) { |
| 6757 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6758 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6759 | } |
| 6760 | temp = array; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6761 | } else { |
| 6762 | __ Add(temp, array, data_offset); |
| 6763 | } |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6764 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6765 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6766 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6767 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6768 | } |
| 6769 | break; |
| 6770 | } |
| 6771 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6772 | case DataType::Type::kReference: { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6773 | vixl32::Register value = RegisterFrom(value_loc); |
| 6774 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 6775 | // See the comment in instruction_simplifier_shared.cc. |
| 6776 | DCHECK(!has_intermediate_address); |
| 6777 | |
| 6778 | if (instruction->InputAt(2)->IsNullConstant()) { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6779 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6780 | // As two macro instructions can be emitted the max size is doubled. |
| 6781 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6782 | // Just setting null. |
| 6783 | if (index.IsConstant()) { |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6784 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6785 | GetAssembler()->StoreToOffset(kStoreWord, value, array, offset); |
| 6786 | } else { |
| 6787 | DCHECK(index.IsRegister()) << index; |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6788 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6789 | vixl32::Register temp = temps.Acquire(); |
| 6790 | __ Add(temp, array, data_offset); |
| 6791 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 6792 | } |
| 6793 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6794 | DCHECK(!needs_write_barrier); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6795 | DCHECK(!needs_type_check); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6796 | break; |
| 6797 | } |
| 6798 | |
| 6799 | DCHECK(needs_write_barrier); |
| 6800 | Location temp1_loc = locations->GetTemp(0); |
| 6801 | vixl32::Register temp1 = RegisterFrom(temp1_loc); |
| 6802 | Location temp2_loc = locations->GetTemp(1); |
| 6803 | vixl32::Register temp2 = RegisterFrom(temp2_loc); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6804 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6805 | bool can_value_be_null = instruction->GetValueCanBeNull(); |
| 6806 | vixl32::Label do_store; |
| 6807 | if (can_value_be_null) { |
| 6808 | __ CompareAndBranchIfZero(value, &do_store, /* is_far_target= */ false); |
| 6809 | } |
| 6810 | |
| 6811 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 6812 | if (needs_type_check) { |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6813 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathARMVIXL(instruction); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6814 | codegen_->AddSlowPath(slow_path); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6815 | |
| 6816 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6817 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6818 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6819 | |
| 6820 | // Note that when read barriers are enabled, the type checks |
| 6821 | // are performed without read barriers. This is fine, even in |
| 6822 | // the case where a class object is in the from-space after |
| 6823 | // the flip, as a comparison involving such a type would not |
| 6824 | // produce a false positive; it may of course produce a false |
| 6825 | // negative, in which case we would take the ArraySet slow |
| 6826 | // path. |
| 6827 | |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6828 | { |
| 6829 | // Ensure we record the pc position immediately after the `ldr` instruction. |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6830 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6831 | vixl32::kMaxInstructionSizeInBytes, |
| 6832 | CodeBufferCheckScope::kMaximumSize); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6833 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 6834 | __ ldr(temp1, MemOperand(array, class_offset)); |
| 6835 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6836 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6837 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 6838 | |
| 6839 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 6840 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 6841 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 6842 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 6843 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 6844 | // nor `temp2`, as we are comparing two poisoned references. |
| 6845 | __ Cmp(temp1, temp2); |
| 6846 | |
| 6847 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6848 | vixl32::Label do_put; |
| 6849 | __ B(eq, &do_put, /* is_far_target= */ false); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6850 | // If heap poisoning is enabled, the `temp1` reference has |
| 6851 | // not been unpoisoned yet; unpoison it now. |
| 6852 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 6853 | |
| 6854 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 6855 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 6856 | // If heap poisoning is enabled, no need to unpoison |
| 6857 | // `temp1`, as we are comparing against null below. |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6858 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6859 | __ Bind(&do_put); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6860 | } else { |
| 6861 | __ B(ne, slow_path->GetEntryLabel()); |
| 6862 | } |
| 6863 | } |
| 6864 | |
| Vladimir Marko | ac3fcff | 2020-11-17 12:17:58 +0000 | [diff] [blame] | 6865 | codegen_->MarkGCCard(temp1, temp2, array, value, /* value_can_be_null= */ false); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6866 | |
| 6867 | if (can_value_be_null) { |
| 6868 | DCHECK(do_store.IsReferenced()); |
| 6869 | __ Bind(&do_store); |
| 6870 | } |
| 6871 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6872 | vixl32::Register source = value; |
| 6873 | if (kPoisonHeapReferences) { |
| 6874 | // Note that in the case where `value` is a null reference, |
| 6875 | // we do not enter this block, as a null reference does not |
| 6876 | // need poisoning. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6877 | DCHECK_EQ(value_type, DataType::Type::kReference); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6878 | __ Mov(temp1, value); |
| 6879 | GetAssembler()->PoisonHeapReference(temp1); |
| 6880 | source = temp1; |
| 6881 | } |
| 6882 | |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6883 | { |
| 6884 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6885 | // As two macro instructions can be emitted the max size is doubled. |
| 6886 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
| 6887 | if (index.IsConstant()) { |
| 6888 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
| 6889 | GetAssembler()->StoreToOffset(kStoreWord, source, array, offset); |
| 6890 | } else { |
| 6891 | DCHECK(index.IsRegister()) << index; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6892 | |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6893 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6894 | vixl32::Register temp = temps.Acquire(); |
| 6895 | __ Add(temp, array, data_offset); |
| 6896 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6897 | LocationFrom(source), |
| 6898 | temp, |
| 6899 | RegisterFrom(index)); |
| 6900 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6901 | |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6902 | if (can_value_be_null || !needs_type_check) { |
| 6903 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6904 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6905 | } |
| 6906 | |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6907 | if (slow_path != nullptr) { |
| 6908 | __ Bind(slow_path->GetExitLabel()); |
| 6909 | } |
| 6910 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6911 | break; |
| 6912 | } |
| 6913 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6914 | case DataType::Type::kInt64: { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6915 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6916 | // As two macro instructions can be emitted the max size is doubled. |
| 6917 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6918 | Location value = locations->InAt(2); |
| 6919 | if (index.IsConstant()) { |
| 6920 | size_t offset = |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6921 | (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6922 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), array, offset); |
| 6923 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6924 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6925 | vixl32::Register temp = temps.Acquire(); |
| 6926 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6927 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), temp, data_offset); |
| 6928 | } |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6929 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6930 | break; |
| 6931 | } |
| 6932 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6933 | case DataType::Type::kFloat32: { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6934 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6935 | // As two macro instructions can be emitted the max size is doubled. |
| 6936 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6937 | Location value = locations->InAt(2); |
| 6938 | DCHECK(value.IsFpuRegister()); |
| 6939 | if (index.IsConstant()) { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6940 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6941 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), array, offset); |
| 6942 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6943 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6944 | vixl32::Register temp = temps.Acquire(); |
| 6945 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 6946 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), temp, data_offset); |
| 6947 | } |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6948 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6949 | break; |
| 6950 | } |
| 6951 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6952 | case DataType::Type::kFloat64: { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6953 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6954 | // As two macro instructions can be emitted the max size is doubled. |
| 6955 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6956 | Location value = locations->InAt(2); |
| 6957 | DCHECK(value.IsFpuRegisterPair()); |
| 6958 | if (index.IsConstant()) { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6959 | size_t offset = (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6960 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), array, offset); |
| 6961 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6962 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6963 | vixl32::Register temp = temps.Acquire(); |
| 6964 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6965 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), temp, data_offset); |
| 6966 | } |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6967 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6968 | break; |
| 6969 | } |
| 6970 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6971 | case DataType::Type::kUint32: |
| 6972 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6973 | case DataType::Type::kVoid: |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6974 | LOG(FATAL) << "Unreachable type " << value_type; |
| 6975 | UNREACHABLE(); |
| 6976 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6977 | } |
| 6978 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6979 | void LocationsBuilderARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 6980 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6981 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6982 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6983 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6984 | } |
| 6985 | |
| 6986 | void InstructionCodeGeneratorARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 6987 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| 6988 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 6989 | vixl32::Register out = OutputRegister(instruction); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6990 | { |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6991 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6992 | vixl32::kMaxInstructionSizeInBytes, |
| 6993 | CodeBufferCheckScope::kMaximumSize); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6994 | __ ldr(out, MemOperand(obj, offset)); |
| 6995 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6996 | } |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6997 | // Mask out compression flag from String's array length. |
| 6998 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6999 | __ Lsr(out, out, 1u); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7000 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7001 | } |
| 7002 | |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 7003 | void LocationsBuilderARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 7004 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7005 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 7006 | |
| 7007 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7008 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 7009 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7010 | } |
| 7011 | |
| 7012 | void InstructionCodeGeneratorARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 7013 | vixl32::Register out = OutputRegister(instruction); |
| 7014 | vixl32::Register first = InputRegisterAt(instruction, 0); |
| 7015 | Location second = instruction->GetLocations()->InAt(1); |
| 7016 | |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 7017 | if (second.IsRegister()) { |
| 7018 | __ Add(out, first, RegisterFrom(second)); |
| 7019 | } else { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 7020 | __ Add(out, first, Int32ConstantFrom(second)); |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 7021 | } |
| 7022 | } |
| 7023 | |
| Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 7024 | void LocationsBuilderARMVIXL::VisitIntermediateAddressIndex( |
| 7025 | HIntermediateAddressIndex* instruction) { |
| 7026 | LOG(FATAL) << "Unreachable " << instruction->GetId(); |
| 7027 | } |
| 7028 | |
| 7029 | void InstructionCodeGeneratorARMVIXL::VisitIntermediateAddressIndex( |
| 7030 | HIntermediateAddressIndex* instruction) { |
| 7031 | LOG(FATAL) << "Unreachable " << instruction->GetId(); |
| 7032 | } |
| 7033 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7034 | void LocationsBuilderARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 7035 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 7036 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7037 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7038 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(1))); |
| 7039 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
| Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 7040 | |
| 7041 | HInstruction* index = instruction->InputAt(0); |
| 7042 | HInstruction* length = instruction->InputAt(1); |
| 7043 | // If both index and length are constants we can statically check the bounds. But if at least one |
| 7044 | // of them is not encodable ArmEncodableConstantOrRegister will create |
| 7045 | // Location::RequiresRegister() which is not desired to happen. Instead we create constant |
| 7046 | // locations. |
| 7047 | bool both_const = index->IsConstant() && length->IsConstant(); |
| 7048 | locations->SetInAt(0, both_const |
| 7049 | ? Location::ConstantLocation(index->AsConstant()) |
| 7050 | : ArmEncodableConstantOrRegister(index, CMP)); |
| 7051 | locations->SetInAt(1, both_const |
| 7052 | ? Location::ConstantLocation(length->AsConstant()) |
| 7053 | : ArmEncodableConstantOrRegister(length, CMP)); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7054 | } |
| 7055 | |
| 7056 | void InstructionCodeGeneratorARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
| Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 7057 | LocationSummary* locations = instruction->GetLocations(); |
| 7058 | Location index_loc = locations->InAt(0); |
| 7059 | Location length_loc = locations->InAt(1); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7060 | |
| Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 7061 | if (length_loc.IsConstant()) { |
| 7062 | int32_t length = Int32ConstantFrom(length_loc); |
| 7063 | if (index_loc.IsConstant()) { |
| 7064 | // BCE will remove the bounds check if we are guaranteed to pass. |
| 7065 | int32_t index = Int32ConstantFrom(index_loc); |
| 7066 | if (index < 0 || index >= length) { |
| 7067 | SlowPathCodeARMVIXL* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7068 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARMVIXL(instruction); |
| Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 7069 | codegen_->AddSlowPath(slow_path); |
| 7070 | __ B(slow_path->GetEntryLabel()); |
| 7071 | } else { |
| 7072 | // Some optimization after BCE may have generated this, and we should not |
| 7073 | // generate a bounds check if it is a valid range. |
| 7074 | } |
| 7075 | return; |
| 7076 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7077 | |
| Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 7078 | SlowPathCodeARMVIXL* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7079 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARMVIXL(instruction); |
| Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 7080 | __ Cmp(RegisterFrom(index_loc), length); |
| 7081 | codegen_->AddSlowPath(slow_path); |
| 7082 | __ B(hs, slow_path->GetEntryLabel()); |
| 7083 | } else { |
| 7084 | SlowPathCodeARMVIXL* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7085 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARMVIXL(instruction); |
| Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 7086 | __ Cmp(RegisterFrom(length_loc), InputOperandAt(instruction, 0)); |
| 7087 | codegen_->AddSlowPath(slow_path); |
| 7088 | __ B(ls, slow_path->GetEntryLabel()); |
| 7089 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7090 | } |
| 7091 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7092 | void CodeGeneratorARMVIXL::MarkGCCard(vixl32::Register temp, |
| 7093 | vixl32::Register card, |
| 7094 | vixl32::Register object, |
| 7095 | vixl32::Register value, |
| Vladimir Marko | ac3fcff | 2020-11-17 12:17:58 +0000 | [diff] [blame] | 7096 | bool value_can_be_null) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7097 | vixl32::Label is_null; |
| Vladimir Marko | ac3fcff | 2020-11-17 12:17:58 +0000 | [diff] [blame] | 7098 | if (value_can_be_null) { |
| 7099 | __ CompareAndBranchIfZero(value, &is_null, /* is_far_target=*/ false); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7100 | } |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 7101 | // Load the address of the card table into `card`. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7102 | GetAssembler()->LoadFromOffset( |
| 7103 | kLoadWord, card, tr, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 7104 | // Calculate the offset (in the card table) of the card corresponding to |
| 7105 | // `object`. |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 7106 | __ Lsr(temp, object, Operand::From(gc::accounting::CardTable::kCardShift)); |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 7107 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 7108 | // `object`'s card. |
| 7109 | // |
| 7110 | // Register `card` contains the address of the card table. Note that the card |
| 7111 | // table's base is biased during its creation so that it always starts at an |
| 7112 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 7113 | // art::gc::accounting::CardTable::Create). Therefore the STRB instruction |
| 7114 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 7115 | // (located at `card + object >> kCardShift`). |
| 7116 | // |
| 7117 | // This dual use of the value in register `card` (1. to calculate the location |
| 7118 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 7119 | // (no need to explicitly load `kCardDirty` as an immediate value). |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7120 | __ Strb(card, MemOperand(card, temp)); |
| Vladimir Marko | ac3fcff | 2020-11-17 12:17:58 +0000 | [diff] [blame] | 7121 | if (value_can_be_null) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7122 | __ Bind(&is_null); |
| 7123 | } |
| 7124 | } |
| 7125 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7126 | void LocationsBuilderARMVIXL::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 7127 | LOG(FATAL) << "Unreachable"; |
| 7128 | } |
| 7129 | |
| 7130 | void InstructionCodeGeneratorARMVIXL::VisitParallelMove(HParallelMove* instruction) { |
| Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 7131 | if (instruction->GetNext()->IsSuspendCheck() && |
| 7132 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 7133 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 7134 | // The back edge will generate the suspend check. |
| 7135 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 7136 | } |
| 7137 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7138 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 7139 | } |
| 7140 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7141 | void LocationsBuilderARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7142 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7143 | instruction, LocationSummary::kCallOnSlowPath); |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7144 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7145 | } |
| 7146 | |
| 7147 | void InstructionCodeGeneratorARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 7148 | HBasicBlock* block = instruction->GetBlock(); |
| 7149 | if (block->GetLoopInformation() != nullptr) { |
| 7150 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 7151 | // The back edge will generate the suspend check. |
| 7152 | return; |
| 7153 | } |
| 7154 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 7155 | // The goto will generate the suspend check. |
| 7156 | return; |
| 7157 | } |
| 7158 | GenerateSuspendCheck(instruction, nullptr); |
| Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 7159 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 14); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7160 | } |
| 7161 | |
| 7162 | void InstructionCodeGeneratorARMVIXL::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 7163 | HBasicBlock* successor) { |
| 7164 | SuspendCheckSlowPathARMVIXL* slow_path = |
| 7165 | down_cast<SuspendCheckSlowPathARMVIXL*>(instruction->GetSlowPath()); |
| 7166 | if (slow_path == nullptr) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7167 | slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7168 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathARMVIXL(instruction, successor); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7169 | instruction->SetSlowPath(slow_path); |
| 7170 | codegen_->AddSlowPath(slow_path); |
| 7171 | if (successor != nullptr) { |
| 7172 | DCHECK(successor->IsLoopHeader()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7173 | } |
| 7174 | } else { |
| 7175 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 7176 | } |
| 7177 | |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7178 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7179 | vixl32::Register temp = temps.Acquire(); |
| 7180 | GetAssembler()->LoadFromOffset( |
| 7181 | kLoadUnsignedHalfword, temp, tr, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
| 7182 | if (successor == nullptr) { |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7183 | __ CompareAndBranchIfNonZero(temp, slow_path->GetEntryLabel()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7184 | __ Bind(slow_path->GetReturnLabel()); |
| 7185 | } else { |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7186 | __ CompareAndBranchIfZero(temp, codegen_->GetLabelOf(successor)); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7187 | __ B(slow_path->GetEntryLabel()); |
| 7188 | } |
| 7189 | } |
| 7190 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7191 | ArmVIXLAssembler* ParallelMoveResolverARMVIXL::GetAssembler() const { |
| 7192 | return codegen_->GetAssembler(); |
| 7193 | } |
| 7194 | |
| 7195 | void ParallelMoveResolverARMVIXL::EmitMove(size_t index) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7196 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7197 | MoveOperands* move = moves_[index]; |
| 7198 | Location source = move->GetSource(); |
| 7199 | Location destination = move->GetDestination(); |
| 7200 | |
| 7201 | if (source.IsRegister()) { |
| 7202 | if (destination.IsRegister()) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7203 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7204 | } else if (destination.IsFpuRegister()) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7205 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7206 | } else { |
| 7207 | DCHECK(destination.IsStackSlot()); |
| 7208 | GetAssembler()->StoreToOffset(kStoreWord, |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7209 | RegisterFrom(source), |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7210 | sp, |
| 7211 | destination.GetStackIndex()); |
| 7212 | } |
| 7213 | } else if (source.IsStackSlot()) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7214 | if (destination.IsRegister()) { |
| 7215 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 7216 | RegisterFrom(destination), |
| 7217 | sp, |
| 7218 | source.GetStackIndex()); |
| 7219 | } else if (destination.IsFpuRegister()) { |
| 7220 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 7221 | } else { |
| 7222 | DCHECK(destination.IsStackSlot()); |
| 7223 | vixl32::Register temp = temps.Acquire(); |
| 7224 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 7225 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 7226 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7227 | } else if (source.IsFpuRegister()) { |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7228 | if (destination.IsRegister()) { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7229 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7230 | } else if (destination.IsFpuRegister()) { |
| 7231 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 7232 | } else { |
| 7233 | DCHECK(destination.IsStackSlot()); |
| 7234 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 7235 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7236 | } else if (source.IsDoubleStackSlot()) { |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7237 | if (destination.IsDoubleStackSlot()) { |
| 7238 | vixl32::DRegister temp = temps.AcquireD(); |
| 7239 | GetAssembler()->LoadDFromOffset(temp, sp, source.GetStackIndex()); |
| 7240 | GetAssembler()->StoreDToOffset(temp, sp, destination.GetStackIndex()); |
| 7241 | } else if (destination.IsRegisterPair()) { |
| 7242 | DCHECK(ExpectedPairLayout(destination)); |
| 7243 | GetAssembler()->LoadFromOffset( |
| 7244 | kLoadWordPair, LowRegisterFrom(destination), sp, source.GetStackIndex()); |
| 7245 | } else { |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7246 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 7247 | GetAssembler()->LoadDFromOffset(DRegisterFrom(destination), sp, source.GetStackIndex()); |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7248 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7249 | } else if (source.IsRegisterPair()) { |
| 7250 | if (destination.IsRegisterPair()) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7251 | __ Mov(LowRegisterFrom(destination), LowRegisterFrom(source)); |
| 7252 | __ Mov(HighRegisterFrom(destination), HighRegisterFrom(source)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7253 | } else if (destination.IsFpuRegisterPair()) { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7254 | __ Vmov(DRegisterFrom(destination), LowRegisterFrom(source), HighRegisterFrom(source)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7255 | } else { |
| 7256 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 7257 | DCHECK(ExpectedPairLayout(source)); |
| 7258 | GetAssembler()->StoreToOffset(kStoreWordPair, |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7259 | LowRegisterFrom(source), |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7260 | sp, |
| 7261 | destination.GetStackIndex()); |
| 7262 | } |
| 7263 | } else if (source.IsFpuRegisterPair()) { |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7264 | if (destination.IsRegisterPair()) { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7265 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), DRegisterFrom(source)); |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7266 | } else if (destination.IsFpuRegisterPair()) { |
| 7267 | __ Vmov(DRegisterFrom(destination), DRegisterFrom(source)); |
| 7268 | } else { |
| 7269 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 7270 | GetAssembler()->StoreDToOffset(DRegisterFrom(source), sp, destination.GetStackIndex()); |
| 7271 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7272 | } else { |
| 7273 | DCHECK(source.IsConstant()) << source; |
| 7274 | HConstant* constant = source.GetConstant(); |
| 7275 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 7276 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
| 7277 | if (destination.IsRegister()) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7278 | __ Mov(RegisterFrom(destination), value); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7279 | } else { |
| 7280 | DCHECK(destination.IsStackSlot()); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7281 | vixl32::Register temp = temps.Acquire(); |
| 7282 | __ Mov(temp, value); |
| 7283 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 7284 | } |
| 7285 | } else if (constant->IsLongConstant()) { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 7286 | int64_t value = Int64ConstantFrom(source); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7287 | if (destination.IsRegisterPair()) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7288 | __ Mov(LowRegisterFrom(destination), Low32Bits(value)); |
| 7289 | __ Mov(HighRegisterFrom(destination), High32Bits(value)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7290 | } else { |
| 7291 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7292 | vixl32::Register temp = temps.Acquire(); |
| 7293 | __ Mov(temp, Low32Bits(value)); |
| 7294 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 7295 | __ Mov(temp, High32Bits(value)); |
| 7296 | GetAssembler()->StoreToOffset(kStoreWord, |
| 7297 | temp, |
| 7298 | sp, |
| 7299 | destination.GetHighStackIndex(kArmWordSize)); |
| 7300 | } |
| 7301 | } else if (constant->IsDoubleConstant()) { |
| 7302 | double value = constant->AsDoubleConstant()->GetValue(); |
| 7303 | if (destination.IsFpuRegisterPair()) { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7304 | __ Vmov(DRegisterFrom(destination), value); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7305 | } else { |
| 7306 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 7307 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7308 | vixl32::Register temp = temps.Acquire(); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7309 | __ Mov(temp, Low32Bits(int_value)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7310 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7311 | __ Mov(temp, High32Bits(int_value)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7312 | GetAssembler()->StoreToOffset(kStoreWord, |
| 7313 | temp, |
| 7314 | sp, |
| 7315 | destination.GetHighStackIndex(kArmWordSize)); |
| 7316 | } |
| 7317 | } else { |
| 7318 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
| 7319 | float value = constant->AsFloatConstant()->GetValue(); |
| 7320 | if (destination.IsFpuRegister()) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7321 | __ Vmov(SRegisterFrom(destination), value); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7322 | } else { |
| 7323 | DCHECK(destination.IsStackSlot()); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7324 | vixl32::Register temp = temps.Acquire(); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7325 | __ Mov(temp, bit_cast<int32_t, float>(value)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7326 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 7327 | } |
| 7328 | } |
| 7329 | } |
| 7330 | } |
| 7331 | |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7332 | void ParallelMoveResolverARMVIXL::Exchange(vixl32::Register reg, int mem) { |
| 7333 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 7334 | vixl32::Register temp = temps.Acquire(); |
| 7335 | __ Mov(temp, reg); |
| 7336 | GetAssembler()->LoadFromOffset(kLoadWord, reg, sp, mem); |
| 7337 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7338 | } |
| 7339 | |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7340 | void ParallelMoveResolverARMVIXL::Exchange(int mem1, int mem2) { |
| 7341 | // TODO(VIXL32): Double check the performance of this implementation. |
| 7342 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7343 | vixl32::Register temp1 = temps.Acquire(); |
| 7344 | ScratchRegisterScope ensure_scratch( |
| 7345 | this, temp1.GetCode(), r0.GetCode(), codegen_->GetNumberOfCoreRegisters()); |
| 7346 | vixl32::Register temp2(ensure_scratch.GetRegister()); |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7347 | |
| Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7348 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 7349 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, sp, mem1 + stack_offset); |
| 7350 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, sp, mem2 + stack_offset); |
| 7351 | GetAssembler()->StoreToOffset(kStoreWord, temp1, sp, mem2 + stack_offset); |
| 7352 | GetAssembler()->StoreToOffset(kStoreWord, temp2, sp, mem1 + stack_offset); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7353 | } |
| 7354 | |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7355 | void ParallelMoveResolverARMVIXL::EmitSwap(size_t index) { |
| 7356 | MoveOperands* move = moves_[index]; |
| 7357 | Location source = move->GetSource(); |
| 7358 | Location destination = move->GetDestination(); |
| 7359 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 7360 | |
| 7361 | if (source.IsRegister() && destination.IsRegister()) { |
| 7362 | vixl32::Register temp = temps.Acquire(); |
| 7363 | DCHECK(!RegisterFrom(source).Is(temp)); |
| 7364 | DCHECK(!RegisterFrom(destination).Is(temp)); |
| 7365 | __ Mov(temp, RegisterFrom(destination)); |
| 7366 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 7367 | __ Mov(RegisterFrom(source), temp); |
| 7368 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| 7369 | Exchange(RegisterFrom(source), destination.GetStackIndex()); |
| 7370 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| 7371 | Exchange(RegisterFrom(destination), source.GetStackIndex()); |
| 7372 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7373 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7374 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7375 | vixl32::Register temp = temps.Acquire(); |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7376 | __ Vmov(temp, SRegisterFrom(source)); |
| 7377 | __ Vmov(SRegisterFrom(source), SRegisterFrom(destination)); |
| 7378 | __ Vmov(SRegisterFrom(destination), temp); |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7379 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
| 7380 | vixl32::DRegister temp = temps.AcquireD(); |
| 7381 | __ Vmov(temp, LowRegisterFrom(source), HighRegisterFrom(source)); |
| 7382 | __ Mov(LowRegisterFrom(source), LowRegisterFrom(destination)); |
| 7383 | __ Mov(HighRegisterFrom(source), HighRegisterFrom(destination)); |
| 7384 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), temp); |
| 7385 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
| 7386 | vixl32::Register low_reg = LowRegisterFrom(source.IsRegisterPair() ? source : destination); |
| 7387 | int mem = source.IsRegisterPair() ? destination.GetStackIndex() : source.GetStackIndex(); |
| 7388 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
| 7389 | vixl32::DRegister temp = temps.AcquireD(); |
| 7390 | __ Vmov(temp, low_reg, vixl32::Register(low_reg.GetCode() + 1)); |
| 7391 | GetAssembler()->LoadFromOffset(kLoadWordPair, low_reg, sp, mem); |
| 7392 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
| 7393 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7394 | vixl32::DRegister first = DRegisterFrom(source); |
| 7395 | vixl32::DRegister second = DRegisterFrom(destination); |
| 7396 | vixl32::DRegister temp = temps.AcquireD(); |
| 7397 | __ Vmov(temp, first); |
| 7398 | __ Vmov(first, second); |
| 7399 | __ Vmov(second, temp); |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7400 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7401 | vixl32::DRegister reg = source.IsFpuRegisterPair() |
| 7402 | ? DRegisterFrom(source) |
| 7403 | : DRegisterFrom(destination); |
| 7404 | int mem = source.IsFpuRegisterPair() |
| 7405 | ? destination.GetStackIndex() |
| 7406 | : source.GetStackIndex(); |
| 7407 | vixl32::DRegister temp = temps.AcquireD(); |
| 7408 | __ Vmov(temp, reg); |
| 7409 | GetAssembler()->LoadDFromOffset(reg, sp, mem); |
| 7410 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7411 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7412 | vixl32::SRegister reg = source.IsFpuRegister() |
| 7413 | ? SRegisterFrom(source) |
| 7414 | : SRegisterFrom(destination); |
| 7415 | int mem = source.IsFpuRegister() |
| 7416 | ? destination.GetStackIndex() |
| 7417 | : source.GetStackIndex(); |
| 7418 | vixl32::Register temp = temps.Acquire(); |
| 7419 | __ Vmov(temp, reg); |
| 7420 | GetAssembler()->LoadSFromOffset(reg, sp, mem); |
| 7421 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7422 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 7423 | vixl32::DRegister temp1 = temps.AcquireD(); |
| 7424 | vixl32::DRegister temp2 = temps.AcquireD(); |
| 7425 | __ Vldr(temp1, MemOperand(sp, source.GetStackIndex())); |
| 7426 | __ Vldr(temp2, MemOperand(sp, destination.GetStackIndex())); |
| 7427 | __ Vstr(temp1, MemOperand(sp, destination.GetStackIndex())); |
| 7428 | __ Vstr(temp2, MemOperand(sp, source.GetStackIndex())); |
| 7429 | } else { |
| 7430 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
| 7431 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7432 | } |
| 7433 | |
| Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7434 | void ParallelMoveResolverARMVIXL::SpillScratch(int reg) { |
| 7435 | __ Push(vixl32::Register(reg)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7436 | } |
| 7437 | |
| Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7438 | void ParallelMoveResolverARMVIXL::RestoreScratch(int reg) { |
| 7439 | __ Pop(vixl32::Register(reg)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7440 | } |
| 7441 | |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7442 | HLoadClass::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadClassKind( |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7443 | HLoadClass::LoadKind desired_class_load_kind) { |
| 7444 | switch (desired_class_load_kind) { |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7445 | case HLoadClass::LoadKind::kInvalid: |
| 7446 | LOG(FATAL) << "UNREACHABLE"; |
| 7447 | UNREACHABLE(); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7448 | case HLoadClass::LoadKind::kReferrersClass: |
| 7449 | break; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7450 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7451 | case HLoadClass::LoadKind::kBootImageRelRo: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7452 | case HLoadClass::LoadKind::kBssEntry: |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7453 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 7454 | case HLoadClass::LoadKind::kBssEntryPackage: |
| Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7455 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7456 | break; |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7457 | case HLoadClass::LoadKind::kJitBootImageAddress: |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7458 | case HLoadClass::LoadKind::kJitTableAddress: |
| Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7459 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7460 | break; |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7461 | case HLoadClass::LoadKind::kRuntimeCall: |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7462 | break; |
| 7463 | } |
| 7464 | return desired_class_load_kind; |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7465 | } |
| 7466 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7467 | void LocationsBuilderARMVIXL::VisitLoadClass(HLoadClass* cls) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7468 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7469 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7470 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7471 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7472 | cls, |
| 7473 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7474 | LocationFrom(r0)); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7475 | DCHECK(calling_convention.GetRegisterAt(0).Is(r0)); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7476 | return; |
| 7477 | } |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7478 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 7479 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 7480 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7481 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7482 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 7483 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7484 | ? LocationSummary::kCallOnSlowPath |
| 7485 | : LocationSummary::kNoCall; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7486 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7487 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7488 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7489 | } |
| 7490 | |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7491 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7492 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7493 | } |
| 7494 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7495 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 7496 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 7497 | // 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] | 7498 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7499 | } else { |
| 7500 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7501 | } |
| 7502 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7503 | } |
| 7504 | |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7505 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7506 | // move. |
| 7507 | void InstructionCodeGeneratorARMVIXL::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7508 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7509 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7510 | codegen_->GenerateLoadClassRuntimeCall(cls); |
| Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 7511 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 15); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7512 | return; |
| 7513 | } |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7514 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 7515 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 7516 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7517 | |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7518 | LocationSummary* locations = cls->GetLocations(); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7519 | Location out_loc = locations->Out(); |
| 7520 | vixl32::Register out = OutputRegister(cls); |
| 7521 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7522 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 7523 | ? kWithoutReadBarrier |
| 7524 | : kCompilerReadBarrierOption; |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7525 | bool generate_null_check = false; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7526 | switch (load_kind) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7527 | case HLoadClass::LoadKind::kReferrersClass: { |
| 7528 | DCHECK(!cls->CanCallRuntime()); |
| 7529 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 7530 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 7531 | vixl32::Register current_method = InputRegisterAt(cls, 0); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7532 | codegen_->GenerateGcRootFieldLoad(cls, |
| 7533 | out_loc, |
| 7534 | current_method, |
| 7535 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 7536 | read_barrier_option); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7537 | break; |
| 7538 | } |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7539 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 7540 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 7541 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7542 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 7543 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7544 | codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7545 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 7546 | break; |
| 7547 | } |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7548 | case HLoadClass::LoadKind::kBootImageRelRo: { |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7549 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7550 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 7551 | codegen_->NewBootImageRelRoPatch(CodeGenerator::GetBootImageOffset(cls)); |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7552 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7553 | __ Ldr(out, MemOperand(out, /* offset= */ 0)); |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7554 | break; |
| 7555 | } |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7556 | case HLoadClass::LoadKind::kBssEntry: |
| 7557 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 7558 | case HLoadClass::LoadKind::kBssEntryPackage: { |
| 7559 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = codegen_->NewTypeBssEntryPatch(cls); |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 7560 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 7561 | // All aligned loads are implicitly atomic consume operations on ARM. |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7562 | codegen_->GenerateGcRootFieldLoad(cls, out_loc, out, /* offset= */ 0, read_barrier_option); |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7563 | generate_null_check = true; |
| 7564 | break; |
| 7565 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7566 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 7567 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 7568 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 7569 | DCHECK_NE(address, 0u); |
| 7570 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 7571 | break; |
| 7572 | } |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7573 | case HLoadClass::LoadKind::kJitTableAddress: { |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7574 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 7575 | cls->GetTypeIndex(), |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7576 | cls->GetClass())); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7577 | // /* GcRoot<mirror::Class> */ out = *out |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7578 | codegen_->GenerateGcRootFieldLoad(cls, out_loc, out, /* offset= */ 0, read_barrier_option); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7579 | break; |
| 7580 | } |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7581 | case HLoadClass::LoadKind::kRuntimeCall: |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7582 | case HLoadClass::LoadKind::kInvalid: |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7583 | LOG(FATAL) << "UNREACHABLE"; |
| 7584 | UNREACHABLE(); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7585 | } |
| 7586 | |
| 7587 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 7588 | DCHECK(cls->CanCallRuntime()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7589 | LoadClassSlowPathARMVIXL* slow_path = |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 7590 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARMVIXL(cls, cls); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7591 | codegen_->AddSlowPath(slow_path); |
| 7592 | if (generate_null_check) { |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7593 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7594 | } |
| 7595 | if (cls->MustGenerateClinitCheck()) { |
| 7596 | GenerateClassInitializationCheck(slow_path, out); |
| 7597 | } else { |
| 7598 | __ Bind(slow_path->GetExitLabel()); |
| 7599 | } |
| Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 7600 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 16); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7601 | } |
| 7602 | } |
| 7603 | |
| Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 7604 | void LocationsBuilderARMVIXL::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 7605 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7606 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 7607 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 7608 | } |
| 7609 | |
| 7610 | void InstructionCodeGeneratorARMVIXL::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 7611 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 7612 | } |
| 7613 | |
| Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 7614 | void LocationsBuilderARMVIXL::VisitLoadMethodType(HLoadMethodType* load) { |
| 7615 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7616 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 7617 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 7618 | } |
| 7619 | |
| 7620 | void InstructionCodeGeneratorARMVIXL::VisitLoadMethodType(HLoadMethodType* load) { |
| 7621 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 7622 | } |
| 7623 | |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7624 | void LocationsBuilderARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 7625 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7626 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7627 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7628 | if (check->HasUses()) { |
| 7629 | locations->SetOut(Location::SameAsFirstInput()); |
| 7630 | } |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 7631 | // Rely on the type initialization to save everything we need. |
| 7632 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7633 | } |
| 7634 | |
| 7635 | void InstructionCodeGeneratorARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 7636 | // We assume the class is not null. |
| 7637 | LoadClassSlowPathARMVIXL* slow_path = |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 7638 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARMVIXL(check->GetLoadClass(), check); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7639 | codegen_->AddSlowPath(slow_path); |
| 7640 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 7641 | } |
| 7642 | |
| 7643 | void InstructionCodeGeneratorARMVIXL::GenerateClassInitializationCheck( |
| 7644 | LoadClassSlowPathARMVIXL* slow_path, vixl32::Register class_reg) { |
| 7645 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 7646 | vixl32::Register temp = temps.Acquire(); |
| Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 7647 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 7648 | constexpr uint32_t shifted_visibly_initialized_value = |
| 7649 | enum_cast<uint32_t>(ClassStatus::kVisiblyInitialized) << status_lsb_position; |
| Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 7650 | |
| Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 7651 | const size_t status_offset = mirror::Class::StatusOffset().SizeValue(); |
| 7652 | GetAssembler()->LoadFromOffset(kLoadWord, temp, class_reg, status_offset); |
| 7653 | __ Cmp(temp, shifted_visibly_initialized_value); |
| Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 7654 | __ B(lo, slow_path->GetEntryLabel()); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7655 | __ Bind(slow_path->GetExitLabel()); |
| 7656 | } |
| 7657 | |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7658 | void InstructionCodeGeneratorARMVIXL::GenerateBitstringTypeCheckCompare( |
| 7659 | HTypeCheckInstruction* check, |
| 7660 | vixl32::Register temp, |
| 7661 | vixl32::FlagsUpdate flags_update) { |
| 7662 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 7663 | uint32_t mask = check->GetBitstringMask(); |
| 7664 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 7665 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 7666 | |
| 7667 | // Note that HInstanceOf shall check for zero value in `temp` but HCheckCast needs |
| 7668 | // the Z flag for BNE. This is indicated by the `flags_update` parameter. |
| 7669 | if (mask_bits == 16u) { |
| 7670 | // Load only the bitstring part of the status word. |
| 7671 | __ Ldrh(temp, MemOperand(temp, mirror::Class::StatusOffset().Int32Value())); |
| 7672 | // Check if the bitstring bits are equal to `path_to_root`. |
| 7673 | if (flags_update == SetFlags) { |
| 7674 | __ Cmp(temp, path_to_root); |
| 7675 | } else { |
| 7676 | __ Sub(temp, temp, path_to_root); |
| 7677 | } |
| 7678 | } else { |
| 7679 | // /* uint32_t */ temp = temp->status_ |
| 7680 | __ Ldr(temp, MemOperand(temp, mirror::Class::StatusOffset().Int32Value())); |
| 7681 | if (GetAssembler()->ShifterOperandCanHold(SUB, path_to_root)) { |
| 7682 | // Compare the bitstring bits using SUB. |
| 7683 | __ Sub(temp, temp, path_to_root); |
| 7684 | // Shift out bits that do not contribute to the comparison. |
| 7685 | __ Lsl(flags_update, temp, temp, dchecked_integral_cast<uint32_t>(32u - mask_bits)); |
| 7686 | } else if (IsUint<16>(path_to_root)) { |
| 7687 | if (temp.IsLow()) { |
| 7688 | // Note: Optimized for size but contains one more dependent instruction than necessary. |
| 7689 | // MOVW+SUB(register) would be 8 bytes unless we find a low-reg temporary but the |
| 7690 | // macro assembler would use the high reg IP for the constant by default. |
| 7691 | // Compare the bitstring bits using SUB. |
| 7692 | __ Sub(temp, temp, path_to_root & 0x00ffu); // 16-bit SUB (immediate) T2 |
| 7693 | __ Sub(temp, temp, path_to_root & 0xff00u); // 32-bit SUB (immediate) T3 |
| 7694 | // Shift out bits that do not contribute to the comparison. |
| 7695 | __ Lsl(flags_update, temp, temp, dchecked_integral_cast<uint32_t>(32u - mask_bits)); |
| 7696 | } else { |
| 7697 | // Extract the bitstring bits. |
| 7698 | __ Ubfx(temp, temp, 0, mask_bits); |
| 7699 | // Check if the bitstring bits are equal to `path_to_root`. |
| 7700 | if (flags_update == SetFlags) { |
| 7701 | __ Cmp(temp, path_to_root); |
| 7702 | } else { |
| 7703 | __ Sub(temp, temp, path_to_root); |
| 7704 | } |
| 7705 | } |
| 7706 | } else { |
| 7707 | // Shift out bits that do not contribute to the comparison. |
| 7708 | __ Lsl(temp, temp, dchecked_integral_cast<uint32_t>(32u - mask_bits)); |
| 7709 | // Check if the shifted bitstring bits are equal to `path_to_root << (32u - mask_bits)`. |
| 7710 | if (flags_update == SetFlags) { |
| 7711 | __ Cmp(temp, path_to_root << (32u - mask_bits)); |
| 7712 | } else { |
| 7713 | __ Sub(temp, temp, path_to_root << (32u - mask_bits)); |
| 7714 | } |
| 7715 | } |
| 7716 | } |
| 7717 | } |
| 7718 | |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7719 | HLoadString::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadStringKind( |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7720 | HLoadString::LoadKind desired_string_load_kind) { |
| 7721 | switch (desired_string_load_kind) { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7722 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7723 | case HLoadString::LoadKind::kBootImageRelRo: |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7724 | case HLoadString::LoadKind::kBssEntry: |
| Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7725 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7726 | break; |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7727 | case HLoadString::LoadKind::kJitBootImageAddress: |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7728 | case HLoadString::LoadKind::kJitTableAddress: |
| Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7729 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7730 | break; |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7731 | case HLoadString::LoadKind::kRuntimeCall: |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7732 | break; |
| 7733 | } |
| 7734 | return desired_string_load_kind; |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7735 | } |
| 7736 | |
| 7737 | void LocationsBuilderARMVIXL::VisitLoadString(HLoadString* load) { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7738 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7739 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7740 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7741 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7742 | locations->SetOut(LocationFrom(r0)); |
| 7743 | } else { |
| 7744 | locations->SetOut(Location::RequiresRegister()); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7745 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 7746 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7747 | // 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] | 7748 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7749 | } else { |
| 7750 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7751 | } |
| 7752 | } |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7753 | } |
| 7754 | } |
| 7755 | |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7756 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7757 | // move. |
| 7758 | void InstructionCodeGeneratorARMVIXL::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7759 | LocationSummary* locations = load->GetLocations(); |
| 7760 | Location out_loc = locations->Out(); |
| 7761 | vixl32::Register out = OutputRegister(load); |
| 7762 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 7763 | |
| 7764 | switch (load_kind) { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7765 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 7766 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 7767 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7768 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7769 | codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex()); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7770 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7771 | return; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7772 | } |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7773 | case HLoadString::LoadKind::kBootImageRelRo: { |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7774 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7775 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 7776 | codegen_->NewBootImageRelRoPatch(CodeGenerator::GetBootImageOffset(load)); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7777 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7778 | __ Ldr(out, MemOperand(out, /* offset= */ 0)); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7779 | return; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7780 | } |
| 7781 | case HLoadString::LoadKind::kBssEntry: { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7782 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7783 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex()); |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 7784 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 7785 | // All aligned loads are implicitly atomic consume operations on ARM. |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7786 | codegen_->GenerateGcRootFieldLoad( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7787 | load, out_loc, out, /* offset= */ 0, kCompilerReadBarrierOption); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7788 | LoadStringSlowPathARMVIXL* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7789 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathARMVIXL(load); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7790 | codegen_->AddSlowPath(slow_path); |
| 7791 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 7792 | __ Bind(slow_path->GetExitLabel()); |
| Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 7793 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 17); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7794 | return; |
| 7795 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7796 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 7797 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 7798 | DCHECK_NE(address, 0u); |
| 7799 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 7800 | return; |
| 7801 | } |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7802 | case HLoadString::LoadKind::kJitTableAddress: { |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7803 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7804 | load->GetStringIndex(), |
| 7805 | load->GetString())); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7806 | // /* GcRoot<mirror::String> */ out = *out |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7807 | codegen_->GenerateGcRootFieldLoad( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7808 | load, out_loc, out, /* offset= */ 0, kCompilerReadBarrierOption); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7809 | return; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7810 | } |
| 7811 | default: |
| 7812 | break; |
| 7813 | } |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7814 | |
| 7815 | // 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] | 7816 | DCHECK_EQ(load->GetLoadKind(), HLoadString::LoadKind::kRuntimeCall); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7817 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7818 | __ Mov(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7819 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 7820 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 7821 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 18); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7822 | } |
| 7823 | |
| 7824 | static int32_t GetExceptionTlsOffset() { |
| 7825 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
| 7826 | } |
| 7827 | |
| 7828 | void LocationsBuilderARMVIXL::VisitLoadException(HLoadException* load) { |
| 7829 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7830 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7831 | locations->SetOut(Location::RequiresRegister()); |
| 7832 | } |
| 7833 | |
| 7834 | void InstructionCodeGeneratorARMVIXL::VisitLoadException(HLoadException* load) { |
| 7835 | vixl32::Register out = OutputRegister(load); |
| 7836 | GetAssembler()->LoadFromOffset(kLoadWord, out, tr, GetExceptionTlsOffset()); |
| 7837 | } |
| 7838 | |
| 7839 | |
| 7840 | void LocationsBuilderARMVIXL::VisitClearException(HClearException* clear) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7841 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7842 | } |
| 7843 | |
| 7844 | void InstructionCodeGeneratorARMVIXL::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 7845 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 7846 | vixl32::Register temp = temps.Acquire(); |
| 7847 | __ Mov(temp, 0); |
| 7848 | GetAssembler()->StoreToOffset(kStoreWord, temp, tr, GetExceptionTlsOffset()); |
| 7849 | } |
| 7850 | |
| 7851 | void LocationsBuilderARMVIXL::VisitThrow(HThrow* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7852 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7853 | instruction, LocationSummary::kCallOnMainOnly); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7854 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7855 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7856 | } |
| 7857 | |
| 7858 | void InstructionCodeGeneratorARMVIXL::VisitThrow(HThrow* instruction) { |
| 7859 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| 7860 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 7861 | } |
| 7862 | |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7863 | // Temp is used for read barrier. |
| 7864 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 7865 | if (kEmitCompilerReadBarrier && |
| 7866 | (kUseBakerReadBarrier || |
| 7867 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7868 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7869 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 7870 | return 1; |
| 7871 | } |
| 7872 | return 0; |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7873 | } |
| 7874 | |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7875 | // Interface case has 3 temps, one for holding the number of interfaces, one for the current |
| 7876 | // interface pointer, one for loading the current interface. |
| 7877 | // The other checks have one temp for loading the object's class. |
| 7878 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 7879 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7880 | return 3; |
| 7881 | } |
| 7882 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 7883 | } |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7884 | |
| 7885 | void LocationsBuilderARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 7886 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7887 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7888 | bool baker_read_barrier_slow_path = false; |
| 7889 | switch (type_check_kind) { |
| 7890 | case TypeCheckKind::kExactCheck: |
| 7891 | case TypeCheckKind::kAbstractClassCheck: |
| 7892 | case TypeCheckKind::kClassHierarchyCheck: |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7893 | case TypeCheckKind::kArrayObjectCheck: { |
| 7894 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 7895 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 7896 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7897 | break; |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7898 | } |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7899 | case TypeCheckKind::kArrayCheck: |
| 7900 | case TypeCheckKind::kUnresolvedCheck: |
| 7901 | case TypeCheckKind::kInterfaceCheck: |
| 7902 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7903 | break; |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7904 | case TypeCheckKind::kBitstringCheck: |
| 7905 | break; |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7906 | } |
| 7907 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7908 | LocationSummary* locations = |
| 7909 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7910 | if (baker_read_barrier_slow_path) { |
| 7911 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 7912 | } |
| 7913 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7914 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7915 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7916 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7917 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 7918 | } else { |
| 7919 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7920 | } |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7921 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 7922 | // Note that TypeCheckSlowPathARM uses this register too. |
| 7923 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7924 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7925 | } |
| 7926 | |
| 7927 | void InstructionCodeGeneratorARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 7928 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7929 | LocationSummary* locations = instruction->GetLocations(); |
| 7930 | Location obj_loc = locations->InAt(0); |
| 7931 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7932 | vixl32::Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 7933 | ? vixl32::Register() |
| 7934 | : InputRegisterAt(instruction, 1); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7935 | Location out_loc = locations->Out(); |
| 7936 | vixl32::Register out = OutputRegister(instruction); |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7937 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7938 | DCHECK_LE(num_temps, 1u); |
| 7939 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7940 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7941 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7942 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7943 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7944 | vixl32::Label done; |
| 7945 | vixl32::Label* const final_label = codegen_->GetFinalLabel(instruction, &done); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7946 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 7947 | |
| 7948 | // Return 0 if `obj` is null. |
| 7949 | // avoid null check if we know obj is not null. |
| 7950 | if (instruction->MustDoNullCheck()) { |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7951 | DCHECK(!out.Is(obj)); |
| 7952 | __ Mov(out, 0); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7953 | __ CompareAndBranchIfZero(obj, final_label, /* is_far_target= */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7954 | } |
| 7955 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7956 | switch (type_check_kind) { |
| 7957 | case TypeCheckKind::kExactCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7958 | ReadBarrierOption read_barrier_option = |
| 7959 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7960 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7961 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7962 | out_loc, |
| 7963 | obj_loc, |
| 7964 | class_offset, |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7965 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7966 | read_barrier_option); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7967 | // Classes must be equal for the instanceof to succeed. |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7968 | __ Cmp(out, cls); |
| 7969 | // We speculatively set the result to false without changing the condition |
| 7970 | // flags, which allows us to avoid some branching later. |
| 7971 | __ Mov(LeaveFlags, out, 0); |
| 7972 | |
| 7973 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7974 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7975 | // encoding can be used. |
| 7976 | if (out.IsLow()) { |
| 7977 | // We use the scope because of the IT block that follows. |
| 7978 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7979 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7980 | CodeBufferCheckScope::kExactSize); |
| 7981 | |
| 7982 | __ it(eq); |
| 7983 | __ mov(eq, out, 1); |
| 7984 | } else { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7985 | __ B(ne, final_label, /* is_far_target= */ false); |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7986 | __ Mov(out, 1); |
| 7987 | } |
| 7988 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7989 | break; |
| 7990 | } |
| 7991 | |
| 7992 | case TypeCheckKind::kAbstractClassCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7993 | ReadBarrierOption read_barrier_option = |
| 7994 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7995 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7996 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7997 | out_loc, |
| 7998 | obj_loc, |
| 7999 | class_offset, |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8000 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 8001 | read_barrier_option); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8002 | // If the class is abstract, we eagerly fetch the super class of the |
| 8003 | // object to avoid doing a comparison we know will fail. |
| 8004 | vixl32::Label loop; |
| 8005 | __ Bind(&loop); |
| 8006 | // /* HeapReference<Class> */ out = out->super_class_ |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8007 | GenerateReferenceLoadOneRegister(instruction, |
| 8008 | out_loc, |
| 8009 | super_offset, |
| 8010 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 8011 | read_barrier_option); |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 8012 | // 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] | 8013 | __ CompareAndBranchIfZero(out, final_label, /* is_far_target= */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8014 | __ Cmp(out, cls); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8015 | __ B(ne, &loop, /* is_far_target= */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8016 | __ Mov(out, 1); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8017 | break; |
| 8018 | } |
| 8019 | |
| 8020 | case TypeCheckKind::kClassHierarchyCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 8021 | ReadBarrierOption read_barrier_option = |
| 8022 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 8023 | // /* HeapReference<Class> */ out = obj->klass_ |
| 8024 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8025 | out_loc, |
| 8026 | obj_loc, |
| 8027 | class_offset, |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8028 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 8029 | read_barrier_option); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8030 | // Walk over the class hierarchy to find a match. |
| 8031 | vixl32::Label loop, success; |
| 8032 | __ Bind(&loop); |
| 8033 | __ Cmp(out, cls); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8034 | __ B(eq, &success, /* is_far_target= */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8035 | // /* HeapReference<Class> */ out = out->super_class_ |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8036 | GenerateReferenceLoadOneRegister(instruction, |
| 8037 | out_loc, |
| 8038 | super_offset, |
| 8039 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 8040 | read_barrier_option); |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 8041 | // This is essentially a null check, but it sets the condition flags to the |
| 8042 | // proper value for the code that follows the loop, i.e. not `eq`. |
| 8043 | __ Cmp(out, 1); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8044 | __ B(hs, &loop, /* is_far_target= */ false); |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 8045 | |
| 8046 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 8047 | // we check that the output is in a low register, so that a 16-bit MOV |
| 8048 | // encoding can be used. |
| 8049 | if (out.IsLow()) { |
| 8050 | // If `out` is null, we use it for the result, and the condition flags |
| 8051 | // have already been set to `ne`, so the IT block that comes afterwards |
| 8052 | // (and which handles the successful case) turns into a NOP (instead of |
| 8053 | // overwriting `out`). |
| 8054 | __ Bind(&success); |
| 8055 | |
| 8056 | // We use the scope because of the IT block that follows. |
| 8057 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 8058 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 8059 | CodeBufferCheckScope::kExactSize); |
| 8060 | |
| 8061 | // There is only one branch to the `success` label (which is bound to this |
| 8062 | // IT block), and it has the same condition, `eq`, so in that case the MOV |
| 8063 | // is executed. |
| 8064 | __ it(eq); |
| 8065 | __ mov(eq, out, 1); |
| 8066 | } else { |
| 8067 | // 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] | 8068 | __ B(final_label); |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 8069 | __ Bind(&success); |
| 8070 | __ Mov(out, 1); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8071 | } |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 8072 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8073 | break; |
| 8074 | } |
| 8075 | |
| 8076 | case TypeCheckKind::kArrayObjectCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 8077 | ReadBarrierOption read_barrier_option = |
| 8078 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 8079 | // /* HeapReference<Class> */ out = obj->klass_ |
| 8080 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8081 | out_loc, |
| 8082 | obj_loc, |
| 8083 | class_offset, |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8084 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 8085 | read_barrier_option); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8086 | // Do an exact check. |
| 8087 | vixl32::Label exact_check; |
| 8088 | __ Cmp(out, cls); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8089 | __ B(eq, &exact_check, /* is_far_target= */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8090 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 8091 | // /* HeapReference<Class> */ out = out->component_type_ |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8092 | GenerateReferenceLoadOneRegister(instruction, |
| 8093 | out_loc, |
| 8094 | component_offset, |
| 8095 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 8096 | read_barrier_option); |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 8097 | // 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] | 8098 | __ CompareAndBranchIfZero(out, final_label, /* is_far_target= */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8099 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 8100 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 8101 | __ Cmp(out, 0); |
| 8102 | // We speculatively set the result to false without changing the condition |
| 8103 | // flags, which allows us to avoid some branching later. |
| 8104 | __ Mov(LeaveFlags, out, 0); |
| 8105 | |
| 8106 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 8107 | // we check that the output is in a low register, so that a 16-bit MOV |
| 8108 | // encoding can be used. |
| 8109 | if (out.IsLow()) { |
| 8110 | __ Bind(&exact_check); |
| 8111 | |
| 8112 | // We use the scope because of the IT block that follows. |
| 8113 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 8114 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 8115 | CodeBufferCheckScope::kExactSize); |
| 8116 | |
| 8117 | __ it(eq); |
| 8118 | __ mov(eq, out, 1); |
| 8119 | } else { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8120 | __ B(ne, final_label, /* is_far_target= */ false); |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 8121 | __ Bind(&exact_check); |
| 8122 | __ Mov(out, 1); |
| 8123 | } |
| 8124 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8125 | break; |
| 8126 | } |
| 8127 | |
| 8128 | case TypeCheckKind::kArrayCheck: { |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8129 | // No read barrier since the slow path will retry upon failure. |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 8130 | // /* HeapReference<Class> */ out = obj->klass_ |
| 8131 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8132 | out_loc, |
| 8133 | obj_loc, |
| 8134 | class_offset, |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8135 | maybe_temp_loc, |
| 8136 | kWithoutReadBarrier); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8137 | __ Cmp(out, cls); |
| 8138 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8139 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8140 | instruction, /* is_fatal= */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8141 | codegen_->AddSlowPath(slow_path); |
| 8142 | __ B(ne, slow_path->GetEntryLabel()); |
| 8143 | __ Mov(out, 1); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8144 | break; |
| 8145 | } |
| 8146 | |
| 8147 | case TypeCheckKind::kUnresolvedCheck: |
| 8148 | case TypeCheckKind::kInterfaceCheck: { |
| 8149 | // Note that we indeed only call on slow path, but we always go |
| 8150 | // into the slow path for the unresolved and interface check |
| 8151 | // cases. |
| 8152 | // |
| 8153 | // We cannot directly call the InstanceofNonTrivial runtime |
| 8154 | // entry point without resorting to a type checking slow path |
| 8155 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 8156 | // require to assign fixed registers for the inputs of this |
| 8157 | // HInstanceOf instruction (following the runtime calling |
| 8158 | // convention), which might be cluttered by the potential first |
| 8159 | // read barrier emission at the beginning of this method. |
| 8160 | // |
| 8161 | // TODO: Introduce a new runtime entry point taking the object |
| 8162 | // to test (instead of its class) as argument, and let it deal |
| 8163 | // with the read barrier issues. This will let us refactor this |
| 8164 | // case of the `switch` code as it was previously (with a direct |
| 8165 | // call to the runtime not using a type checking slow path). |
| 8166 | // This should also be beneficial for the other cases above. |
| 8167 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8168 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8169 | instruction, /* is_fatal= */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8170 | codegen_->AddSlowPath(slow_path); |
| 8171 | __ B(slow_path->GetEntryLabel()); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8172 | break; |
| 8173 | } |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 8174 | |
| 8175 | case TypeCheckKind::kBitstringCheck: { |
| 8176 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8177 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8178 | out_loc, |
| 8179 | obj_loc, |
| 8180 | class_offset, |
| 8181 | maybe_temp_loc, |
| 8182 | kWithoutReadBarrier); |
| 8183 | |
| 8184 | GenerateBitstringTypeCheckCompare(instruction, out, DontCare); |
| 8185 | // If `out` is a low reg and we would have another low reg temp, we could |
| 8186 | // optimize this as RSBS+ADC, see GenerateConditionWithZero(). |
| 8187 | // |
| 8188 | // Also, in some cases when `out` is a low reg and we're loading a constant to IP |
| 8189 | // it would make sense to use CMP+MOV+IT+MOV instead of SUB+CLZ+LSR as the code size |
| 8190 | // would be the same and we would have fewer direct data dependencies. |
| 8191 | codegen_->GenerateConditionWithZero(kCondEQ, out, out); // CLZ+LSR |
| 8192 | break; |
| 8193 | } |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8194 | } |
| 8195 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8196 | if (done.IsReferenced()) { |
| 8197 | __ Bind(&done); |
| 8198 | } |
| 8199 | |
| 8200 | if (slow_path != nullptr) { |
| 8201 | __ Bind(slow_path->GetExitLabel()); |
| 8202 | } |
| 8203 | } |
| 8204 | |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8205 | void LocationsBuilderARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8206 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 8207 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8208 | LocationSummary* locations = |
| 8209 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8210 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 8211 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 8212 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 8213 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 8214 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 8215 | } else { |
| 8216 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8217 | } |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8218 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8219 | } |
| 8220 | |
| 8221 | void InstructionCodeGeneratorARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
| 8222 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 8223 | LocationSummary* locations = instruction->GetLocations(); |
| 8224 | Location obj_loc = locations->InAt(0); |
| 8225 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 8226 | vixl32::Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 8227 | ? vixl32::Register() |
| 8228 | : InputRegisterAt(instruction, 1); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8229 | Location temp_loc = locations->GetTemp(0); |
| 8230 | vixl32::Register temp = RegisterFrom(temp_loc); |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8231 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 8232 | DCHECK_LE(num_temps, 3u); |
| 8233 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 8234 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 8235 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 8236 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 8237 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 8238 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 8239 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 8240 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 8241 | const uint32_t object_array_data_offset = |
| 8242 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8243 | |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 8244 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8245 | SlowPathCodeARMVIXL* type_check_slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8246 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
| 8247 | instruction, is_type_check_slow_path_fatal); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8248 | codegen_->AddSlowPath(type_check_slow_path); |
| 8249 | |
| 8250 | vixl32::Label done; |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 8251 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8252 | // Avoid null check if we know obj is not null. |
| 8253 | if (instruction->MustDoNullCheck()) { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8254 | __ CompareAndBranchIfZero(obj, final_label, /* is_far_target= */ false); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8255 | } |
| 8256 | |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8257 | switch (type_check_kind) { |
| 8258 | case TypeCheckKind::kExactCheck: |
| 8259 | case TypeCheckKind::kArrayCheck: { |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8260 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8261 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8262 | temp_loc, |
| 8263 | obj_loc, |
| 8264 | class_offset, |
| 8265 | maybe_temp2_loc, |
| 8266 | kWithoutReadBarrier); |
| 8267 | |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8268 | __ Cmp(temp, cls); |
| 8269 | // Jump to slow path for throwing the exception or doing a |
| 8270 | // more involved array check. |
| 8271 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 8272 | break; |
| 8273 | } |
| 8274 | |
| 8275 | case TypeCheckKind::kAbstractClassCheck: { |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8276 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8277 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8278 | temp_loc, |
| 8279 | obj_loc, |
| 8280 | class_offset, |
| 8281 | maybe_temp2_loc, |
| 8282 | kWithoutReadBarrier); |
| 8283 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8284 | // If the class is abstract, we eagerly fetch the super class of the |
| 8285 | // object to avoid doing a comparison we know will fail. |
| 8286 | vixl32::Label loop; |
| 8287 | __ Bind(&loop); |
| 8288 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8289 | GenerateReferenceLoadOneRegister(instruction, |
| 8290 | temp_loc, |
| 8291 | super_offset, |
| 8292 | maybe_temp2_loc, |
| 8293 | kWithoutReadBarrier); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8294 | |
| 8295 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 8296 | // exception. |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 8297 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8298 | |
| 8299 | // Otherwise, compare the classes. |
| 8300 | __ Cmp(temp, cls); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8301 | __ B(ne, &loop, /* is_far_target= */ false); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8302 | break; |
| 8303 | } |
| 8304 | |
| 8305 | case TypeCheckKind::kClassHierarchyCheck: { |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8306 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8307 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8308 | temp_loc, |
| 8309 | obj_loc, |
| 8310 | class_offset, |
| 8311 | maybe_temp2_loc, |
| 8312 | kWithoutReadBarrier); |
| 8313 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8314 | // Walk over the class hierarchy to find a match. |
| 8315 | vixl32::Label loop; |
| 8316 | __ Bind(&loop); |
| 8317 | __ Cmp(temp, cls); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8318 | __ B(eq, final_label, /* is_far_target= */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8319 | |
| 8320 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8321 | GenerateReferenceLoadOneRegister(instruction, |
| 8322 | temp_loc, |
| 8323 | super_offset, |
| 8324 | maybe_temp2_loc, |
| 8325 | kWithoutReadBarrier); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8326 | |
| 8327 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 8328 | // exception. |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 8329 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8330 | // Otherwise, jump to the beginning of the loop. |
| 8331 | __ B(&loop); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8332 | break; |
| 8333 | } |
| 8334 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8335 | case TypeCheckKind::kArrayObjectCheck: { |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8336 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8337 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8338 | temp_loc, |
| 8339 | obj_loc, |
| 8340 | class_offset, |
| 8341 | maybe_temp2_loc, |
| 8342 | kWithoutReadBarrier); |
| 8343 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8344 | // Do an exact check. |
| 8345 | __ Cmp(temp, cls); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8346 | __ B(eq, final_label, /* is_far_target= */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8347 | |
| 8348 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 8349 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8350 | GenerateReferenceLoadOneRegister(instruction, |
| 8351 | temp_loc, |
| 8352 | component_offset, |
| 8353 | maybe_temp2_loc, |
| 8354 | kWithoutReadBarrier); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8355 | // 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] | 8356 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8357 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 8358 | // to further check that this component type is not a primitive type. |
| 8359 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8360 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 8361 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8362 | break; |
| 8363 | } |
| 8364 | |
| 8365 | case TypeCheckKind::kUnresolvedCheck: |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8366 | // 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] | 8367 | // We cannot directly call the CheckCast runtime entry point |
| 8368 | // without resorting to a type checking slow path here (i.e. by |
| 8369 | // calling InvokeRuntime directly), as it would require to |
| 8370 | // assign fixed registers for the inputs of this HInstanceOf |
| 8371 | // instruction (following the runtime calling convention), which |
| 8372 | // might be cluttered by the potential first read barrier |
| 8373 | // emission at the beginning of this method. |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8374 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8375 | __ B(type_check_slow_path->GetEntryLabel()); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8376 | break; |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8377 | |
| 8378 | case TypeCheckKind::kInterfaceCheck: { |
| 8379 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 8380 | // positives by doing this. |
| 8381 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8382 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8383 | temp_loc, |
| 8384 | obj_loc, |
| 8385 | class_offset, |
| 8386 | maybe_temp2_loc, |
| 8387 | kWithoutReadBarrier); |
| 8388 | |
| 8389 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 8390 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8391 | temp_loc, |
| 8392 | temp_loc, |
| 8393 | iftable_offset, |
| 8394 | maybe_temp2_loc, |
| 8395 | kWithoutReadBarrier); |
| 8396 | // Iftable is never null. |
| 8397 | __ Ldr(RegisterFrom(maybe_temp2_loc), MemOperand(temp, array_length_offset)); |
| 8398 | // Loop through the iftable and check if any class matches. |
| 8399 | vixl32::Label start_loop; |
| 8400 | __ Bind(&start_loop); |
| 8401 | __ CompareAndBranchIfZero(RegisterFrom(maybe_temp2_loc), |
| 8402 | type_check_slow_path->GetEntryLabel()); |
| 8403 | __ Ldr(RegisterFrom(maybe_temp3_loc), MemOperand(temp, object_array_data_offset)); |
| 8404 | GetAssembler()->MaybeUnpoisonHeapReference(RegisterFrom(maybe_temp3_loc)); |
| 8405 | // Go to next interface. |
| 8406 | __ Add(temp, temp, Operand::From(2 * kHeapReferenceSize)); |
| 8407 | __ Sub(RegisterFrom(maybe_temp2_loc), RegisterFrom(maybe_temp2_loc), 2); |
| 8408 | // Compare the classes and continue the loop if they do not match. |
| 8409 | __ Cmp(cls, RegisterFrom(maybe_temp3_loc)); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8410 | __ B(ne, &start_loop, /* is_far_target= */ false); |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8411 | break; |
| 8412 | } |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 8413 | |
| 8414 | case TypeCheckKind::kBitstringCheck: { |
| 8415 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8416 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8417 | temp_loc, |
| 8418 | obj_loc, |
| 8419 | class_offset, |
| 8420 | maybe_temp2_loc, |
| 8421 | kWithoutReadBarrier); |
| 8422 | |
| 8423 | GenerateBitstringTypeCheckCompare(instruction, temp, SetFlags); |
| 8424 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 8425 | break; |
| 8426 | } |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8427 | } |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 8428 | if (done.IsReferenced()) { |
| 8429 | __ Bind(&done); |
| 8430 | } |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8431 | |
| 8432 | __ Bind(type_check_slow_path->GetExitLabel()); |
| 8433 | } |
| 8434 | |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8435 | void LocationsBuilderARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8436 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8437 | instruction, LocationSummary::kCallOnMainOnly); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8438 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 8439 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 8440 | } |
| 8441 | |
| 8442 | void InstructionCodeGeneratorARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 8443 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 8444 | instruction, |
| 8445 | instruction->GetDexPc()); |
| 8446 | if (instruction->IsEnter()) { |
| 8447 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 8448 | } else { |
| 8449 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 8450 | } |
| Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 8451 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 19); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8452 | } |
| 8453 | |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8454 | void LocationsBuilderARMVIXL::VisitAnd(HAnd* instruction) { |
| 8455 | HandleBitwiseOperation(instruction, AND); |
| 8456 | } |
| 8457 | |
| 8458 | void LocationsBuilderARMVIXL::VisitOr(HOr* instruction) { |
| 8459 | HandleBitwiseOperation(instruction, ORR); |
| 8460 | } |
| 8461 | |
| 8462 | void LocationsBuilderARMVIXL::VisitXor(HXor* instruction) { |
| 8463 | HandleBitwiseOperation(instruction, EOR); |
| 8464 | } |
| 8465 | |
| 8466 | void LocationsBuilderARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
| 8467 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8468 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8469 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 8470 | || instruction->GetResultType() == DataType::Type::kInt64); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8471 | // Note: GVN reorders commutative operations to have the constant on the right hand side. |
| 8472 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8473 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
| 8474 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8475 | } |
| 8476 | |
| 8477 | void InstructionCodeGeneratorARMVIXL::VisitAnd(HAnd* instruction) { |
| 8478 | HandleBitwiseOperation(instruction); |
| 8479 | } |
| 8480 | |
| 8481 | void InstructionCodeGeneratorARMVIXL::VisitOr(HOr* instruction) { |
| 8482 | HandleBitwiseOperation(instruction); |
| 8483 | } |
| 8484 | |
| 8485 | void InstructionCodeGeneratorARMVIXL::VisitXor(HXor* instruction) { |
| 8486 | HandleBitwiseOperation(instruction); |
| 8487 | } |
| 8488 | |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8489 | void LocationsBuilderARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 8490 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8491 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8492 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 8493 | || instruction->GetResultType() == DataType::Type::kInt64); |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8494 | |
| 8495 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8496 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8497 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8498 | } |
| 8499 | |
| 8500 | void InstructionCodeGeneratorARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 8501 | LocationSummary* locations = instruction->GetLocations(); |
| 8502 | Location first = locations->InAt(0); |
| 8503 | Location second = locations->InAt(1); |
| 8504 | Location out = locations->Out(); |
| 8505 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8506 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8507 | vixl32::Register first_reg = RegisterFrom(first); |
| 8508 | vixl32::Register second_reg = RegisterFrom(second); |
| 8509 | vixl32::Register out_reg = RegisterFrom(out); |
| 8510 | |
| 8511 | switch (instruction->GetOpKind()) { |
| 8512 | case HInstruction::kAnd: |
| 8513 | __ Bic(out_reg, first_reg, second_reg); |
| 8514 | break; |
| 8515 | case HInstruction::kOr: |
| 8516 | __ Orn(out_reg, first_reg, second_reg); |
| 8517 | break; |
| 8518 | // There is no EON on arm. |
| 8519 | case HInstruction::kXor: |
| 8520 | default: |
| 8521 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 8522 | UNREACHABLE(); |
| 8523 | } |
| 8524 | return; |
| 8525 | |
| 8526 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8527 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8528 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8529 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8530 | vixl32::Register second_low = LowRegisterFrom(second); |
| 8531 | vixl32::Register second_high = HighRegisterFrom(second); |
| 8532 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8533 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8534 | |
| 8535 | switch (instruction->GetOpKind()) { |
| 8536 | case HInstruction::kAnd: |
| 8537 | __ Bic(out_low, first_low, second_low); |
| 8538 | __ Bic(out_high, first_high, second_high); |
| 8539 | break; |
| 8540 | case HInstruction::kOr: |
| 8541 | __ Orn(out_low, first_low, second_low); |
| 8542 | __ Orn(out_high, first_high, second_high); |
| 8543 | break; |
| 8544 | // There is no EON on arm. |
| 8545 | case HInstruction::kXor: |
| 8546 | default: |
| 8547 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 8548 | UNREACHABLE(); |
| 8549 | } |
| 8550 | } |
| 8551 | } |
| 8552 | |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8553 | void LocationsBuilderARMVIXL::VisitDataProcWithShifterOp( |
| 8554 | HDataProcWithShifterOp* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8555 | DCHECK(instruction->GetType() == DataType::Type::kInt32 || |
| 8556 | instruction->GetType() == DataType::Type::kInt64); |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8557 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8558 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8559 | const bool overlap = instruction->GetType() == DataType::Type::kInt64 && |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8560 | HDataProcWithShifterOp::IsExtensionOp(instruction->GetOpKind()); |
| 8561 | |
| 8562 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8563 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8564 | locations->SetOut(Location::RequiresRegister(), |
| 8565 | overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 8566 | } |
| 8567 | |
| 8568 | void InstructionCodeGeneratorARMVIXL::VisitDataProcWithShifterOp( |
| 8569 | HDataProcWithShifterOp* instruction) { |
| 8570 | const LocationSummary* const locations = instruction->GetLocations(); |
| 8571 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 8572 | const HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 8573 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8574 | if (instruction->GetType() == DataType::Type::kInt32) { |
| Anton Kirilov | 420ee30 | 2017-02-21 18:10:26 +0000 | [diff] [blame] | 8575 | const vixl32::Register first = InputRegisterAt(instruction, 0); |
| 8576 | const vixl32::Register output = OutputRegister(instruction); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8577 | const vixl32::Register second = instruction->InputAt(1)->GetType() == DataType::Type::kInt64 |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8578 | ? LowRegisterFrom(locations->InAt(1)) |
| 8579 | : InputRegisterAt(instruction, 1); |
| 8580 | |
| Anton Kirilov | 420ee30 | 2017-02-21 18:10:26 +0000 | [diff] [blame] | 8581 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 8582 | DCHECK_EQ(kind, HInstruction::kAdd); |
| 8583 | |
| 8584 | switch (op_kind) { |
| 8585 | case HDataProcWithShifterOp::kUXTB: |
| 8586 | __ Uxtab(output, first, second); |
| 8587 | break; |
| 8588 | case HDataProcWithShifterOp::kUXTH: |
| 8589 | __ Uxtah(output, first, second); |
| 8590 | break; |
| 8591 | case HDataProcWithShifterOp::kSXTB: |
| 8592 | __ Sxtab(output, first, second); |
| 8593 | break; |
| 8594 | case HDataProcWithShifterOp::kSXTH: |
| 8595 | __ Sxtah(output, first, second); |
| 8596 | break; |
| 8597 | default: |
| 8598 | LOG(FATAL) << "Unexpected operation kind: " << op_kind; |
| 8599 | UNREACHABLE(); |
| 8600 | } |
| 8601 | } else { |
| 8602 | GenerateDataProcInstruction(kind, |
| 8603 | output, |
| 8604 | first, |
| 8605 | Operand(second, |
| 8606 | ShiftFromOpKind(op_kind), |
| 8607 | instruction->GetShiftAmount()), |
| 8608 | codegen_); |
| 8609 | } |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8610 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8611 | DCHECK_EQ(instruction->GetType(), DataType::Type::kInt64); |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8612 | |
| 8613 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 8614 | const vixl32::Register second = InputRegisterAt(instruction, 1); |
| 8615 | |
| 8616 | DCHECK(!LowRegisterFrom(locations->Out()).Is(second)); |
| 8617 | GenerateDataProc(kind, |
| 8618 | locations->Out(), |
| 8619 | locations->InAt(0), |
| 8620 | second, |
| 8621 | Operand(second, ShiftType::ASR, 31), |
| 8622 | codegen_); |
| 8623 | } else { |
| 8624 | GenerateLongDataProc(instruction, codegen_); |
| 8625 | } |
| 8626 | } |
| 8627 | } |
| 8628 | |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8629 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8630 | void InstructionCodeGeneratorARMVIXL::GenerateAndConst(vixl32::Register out, |
| 8631 | vixl32::Register first, |
| 8632 | uint32_t value) { |
| 8633 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 8634 | if (value == 0xffffffffu) { |
| 8635 | if (!out.Is(first)) { |
| 8636 | __ Mov(out, first); |
| 8637 | } |
| 8638 | return; |
| 8639 | } |
| 8640 | if (value == 0u) { |
| 8641 | __ Mov(out, 0); |
| 8642 | return; |
| 8643 | } |
| 8644 | if (GetAssembler()->ShifterOperandCanHold(AND, value)) { |
| Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 8645 | __ And(out, first, value); |
| 8646 | } else if (GetAssembler()->ShifterOperandCanHold(BIC, ~value)) { |
| 8647 | __ Bic(out, first, ~value); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8648 | } else { |
| Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 8649 | DCHECK(IsPowerOfTwo(value + 1)); |
| 8650 | __ Ubfx(out, first, 0, WhichPowerOf2(value + 1)); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8651 | } |
| 8652 | } |
| 8653 | |
| 8654 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8655 | void InstructionCodeGeneratorARMVIXL::GenerateOrrConst(vixl32::Register out, |
| 8656 | vixl32::Register first, |
| 8657 | uint32_t value) { |
| 8658 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 8659 | if (value == 0u) { |
| 8660 | if (!out.Is(first)) { |
| 8661 | __ Mov(out, first); |
| 8662 | } |
| 8663 | return; |
| 8664 | } |
| 8665 | if (value == 0xffffffffu) { |
| 8666 | __ Mvn(out, 0); |
| 8667 | return; |
| 8668 | } |
| 8669 | if (GetAssembler()->ShifterOperandCanHold(ORR, value)) { |
| 8670 | __ Orr(out, first, value); |
| 8671 | } else { |
| 8672 | DCHECK(GetAssembler()->ShifterOperandCanHold(ORN, ~value)); |
| 8673 | __ Orn(out, first, ~value); |
| 8674 | } |
| 8675 | } |
| 8676 | |
| 8677 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8678 | void InstructionCodeGeneratorARMVIXL::GenerateEorConst(vixl32::Register out, |
| 8679 | vixl32::Register first, |
| 8680 | uint32_t value) { |
| 8681 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 8682 | if (value == 0u) { |
| 8683 | if (!out.Is(first)) { |
| 8684 | __ Mov(out, first); |
| 8685 | } |
| 8686 | return; |
| 8687 | } |
| 8688 | __ Eor(out, first, value); |
| 8689 | } |
| 8690 | |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8691 | void InstructionCodeGeneratorARMVIXL::GenerateAddLongConst(Location out, |
| 8692 | Location first, |
| 8693 | uint64_t value) { |
| 8694 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8695 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8696 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8697 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8698 | uint32_t value_low = Low32Bits(value); |
| 8699 | uint32_t value_high = High32Bits(value); |
| 8700 | if (value_low == 0u) { |
| 8701 | if (!out_low.Is(first_low)) { |
| 8702 | __ Mov(out_low, first_low); |
| 8703 | } |
| 8704 | __ Add(out_high, first_high, value_high); |
| 8705 | return; |
| 8706 | } |
| 8707 | __ Adds(out_low, first_low, value_low); |
| Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 8708 | if (GetAssembler()->ShifterOperandCanHold(ADC, value_high)) { |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8709 | __ Adc(out_high, first_high, value_high); |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8710 | } else { |
| Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 8711 | DCHECK(GetAssembler()->ShifterOperandCanHold(SBC, ~value_high)); |
| 8712 | __ Sbc(out_high, first_high, ~value_high); |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8713 | } |
| 8714 | } |
| 8715 | |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8716 | void InstructionCodeGeneratorARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 8717 | LocationSummary* locations = instruction->GetLocations(); |
| 8718 | Location first = locations->InAt(0); |
| 8719 | Location second = locations->InAt(1); |
| 8720 | Location out = locations->Out(); |
| 8721 | |
| 8722 | if (second.IsConstant()) { |
| 8723 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 8724 | uint32_t value_low = Low32Bits(value); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8725 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8726 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 8727 | vixl32::Register out_reg = OutputRegister(instruction); |
| 8728 | if (instruction->IsAnd()) { |
| 8729 | GenerateAndConst(out_reg, first_reg, value_low); |
| 8730 | } else if (instruction->IsOr()) { |
| 8731 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 8732 | } else { |
| 8733 | DCHECK(instruction->IsXor()); |
| 8734 | GenerateEorConst(out_reg, first_reg, value_low); |
| 8735 | } |
| 8736 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8737 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8738 | uint32_t value_high = High32Bits(value); |
| 8739 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8740 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8741 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8742 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8743 | if (instruction->IsAnd()) { |
| 8744 | GenerateAndConst(out_low, first_low, value_low); |
| 8745 | GenerateAndConst(out_high, first_high, value_high); |
| 8746 | } else if (instruction->IsOr()) { |
| 8747 | GenerateOrrConst(out_low, first_low, value_low); |
| 8748 | GenerateOrrConst(out_high, first_high, value_high); |
| 8749 | } else { |
| 8750 | DCHECK(instruction->IsXor()); |
| 8751 | GenerateEorConst(out_low, first_low, value_low); |
| 8752 | GenerateEorConst(out_high, first_high, value_high); |
| 8753 | } |
| 8754 | } |
| 8755 | return; |
| 8756 | } |
| 8757 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8758 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8759 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 8760 | vixl32::Register second_reg = InputRegisterAt(instruction, 1); |
| 8761 | vixl32::Register out_reg = OutputRegister(instruction); |
| 8762 | if (instruction->IsAnd()) { |
| 8763 | __ And(out_reg, first_reg, second_reg); |
| 8764 | } else if (instruction->IsOr()) { |
| 8765 | __ Orr(out_reg, first_reg, second_reg); |
| 8766 | } else { |
| 8767 | DCHECK(instruction->IsXor()); |
| 8768 | __ Eor(out_reg, first_reg, second_reg); |
| 8769 | } |
| 8770 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8771 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8772 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8773 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8774 | vixl32::Register second_low = LowRegisterFrom(second); |
| 8775 | vixl32::Register second_high = HighRegisterFrom(second); |
| 8776 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8777 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8778 | if (instruction->IsAnd()) { |
| 8779 | __ And(out_low, first_low, second_low); |
| 8780 | __ And(out_high, first_high, second_high); |
| 8781 | } else if (instruction->IsOr()) { |
| 8782 | __ Orr(out_low, first_low, second_low); |
| 8783 | __ Orr(out_high, first_high, second_high); |
| 8784 | } else { |
| 8785 | DCHECK(instruction->IsXor()); |
| 8786 | __ Eor(out_low, first_low, second_low); |
| 8787 | __ Eor(out_high, first_high, second_high); |
| 8788 | } |
| 8789 | } |
| 8790 | } |
| 8791 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8792 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadOneRegister( |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8793 | HInstruction* instruction, |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8794 | Location out, |
| 8795 | uint32_t offset, |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8796 | Location maybe_temp, |
| 8797 | ReadBarrierOption read_barrier_option) { |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8798 | vixl32::Register out_reg = RegisterFrom(out); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8799 | if (read_barrier_option == kWithReadBarrier) { |
| 8800 | CHECK(kEmitCompilerReadBarrier); |
| 8801 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 8802 | if (kUseBakerReadBarrier) { |
| 8803 | // Load with fast path based Baker's read barrier. |
| 8804 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8805 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8806 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check= */ false); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8807 | } else { |
| 8808 | // Load with slow path based read barrier. |
| 8809 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 8810 | // in the following move operation, as we will need it for the |
| 8811 | // read barrier below. |
| 8812 | __ Mov(RegisterFrom(maybe_temp), out_reg); |
| 8813 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8814 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 8815 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 8816 | } |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8817 | } else { |
| 8818 | // Plain load with no read barrier. |
| 8819 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8820 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 8821 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 8822 | } |
| 8823 | } |
| 8824 | |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8825 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadTwoRegisters( |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8826 | HInstruction* instruction, |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8827 | Location out, |
| 8828 | Location obj, |
| 8829 | uint32_t offset, |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8830 | Location maybe_temp, |
| 8831 | ReadBarrierOption read_barrier_option) { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8832 | vixl32::Register out_reg = RegisterFrom(out); |
| 8833 | vixl32::Register obj_reg = RegisterFrom(obj); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8834 | if (read_barrier_option == kWithReadBarrier) { |
| 8835 | CHECK(kEmitCompilerReadBarrier); |
| 8836 | if (kUseBakerReadBarrier) { |
| 8837 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 8838 | // Load with fast path based Baker's read barrier. |
| 8839 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8840 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8841 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check= */ false); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8842 | } else { |
| 8843 | // Load with slow path based read barrier. |
| 8844 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8845 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8846 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 8847 | } |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8848 | } else { |
| 8849 | // Plain load with no read barrier. |
| 8850 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8851 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8852 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 8853 | } |
| 8854 | } |
| 8855 | |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 8856 | void CodeGeneratorARMVIXL::GenerateGcRootFieldLoad( |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8857 | HInstruction* instruction, |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8858 | Location root, |
| 8859 | vixl32::Register obj, |
| 8860 | uint32_t offset, |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8861 | ReadBarrierOption read_barrier_option) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8862 | vixl32::Register root_reg = RegisterFrom(root); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8863 | if (read_barrier_option == kWithReadBarrier) { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8864 | DCHECK(kEmitCompilerReadBarrier); |
| 8865 | if (kUseBakerReadBarrier) { |
| 8866 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8867 | // Baker's read barrier are used. |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8868 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8869 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 8870 | // the Marking Register) to decide whether we need to enter |
| 8871 | // the slow path to mark the GC root. |
| 8872 | // |
| 8873 | // We use shared thunks for the slow path; shared within the method |
| 8874 | // for JIT, across methods for AOT. That thunk checks the reference |
| 8875 | // and jumps to the entrypoint if needed. |
| 8876 | // |
| 8877 | // lr = &return_address; |
| 8878 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 8879 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8880 | // goto gc_root_thunk<root_reg>(lr) |
| 8881 | // } |
| 8882 | // return_address: |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8883 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8884 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8885 | temps.Exclude(ip); |
| 8886 | bool narrow = CanEmitNarrowLdr(root_reg, obj, offset); |
| 8887 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(root_reg.GetCode(), narrow); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8888 | |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8889 | size_t narrow_instructions = /* CMP */ (mr.IsLow() ? 1u : 0u) + /* LDR */ (narrow ? 1u : 0u); |
| 8890 | size_t wide_instructions = /* ADR+CMP+LDR+BNE */ 4u - narrow_instructions; |
| 8891 | size_t exact_size = wide_instructions * vixl32::k32BitT32InstructionSizeInBytes + |
| 8892 | narrow_instructions * vixl32::k16BitT32InstructionSizeInBytes; |
| 8893 | ExactAssemblyScope guard(GetVIXLAssembler(), exact_size); |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8894 | vixl32::Label return_address; |
| 8895 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8896 | __ cmp(mr, Operand(0)); |
| 8897 | // Currently the offset is always within range. If that changes, |
| 8898 | // we shall have to split the load the same way as for fields. |
| 8899 | DCHECK_LT(offset, kReferenceLoadMinFarOffset); |
| 8900 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8901 | __ ldr(EncodingSize(narrow ? Narrow : Wide), root_reg, MemOperand(obj, offset)); |
| 8902 | EmitBakerReadBarrierBne(custom_data); |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8903 | __ bind(&return_address); |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8904 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8905 | narrow ? BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_OFFSET |
| 8906 | : BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_OFFSET); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8907 | } else { |
| 8908 | // GC root loaded through a slow path for read barriers other |
| 8909 | // than Baker's. |
| 8910 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 8911 | __ Add(root_reg, obj, offset); |
| 8912 | // /* mirror::Object* */ root = root->Read() |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 8913 | GenerateReadBarrierForRootSlow(instruction, root, root); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8914 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8915 | } else { |
| 8916 | // Plain GC root load with no read barrier. |
| 8917 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8918 | GetAssembler()->LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8919 | // Note that GC roots are not affected by heap poisoning, thus we |
| 8920 | // do not have to unpoison `root_reg` here. |
| 8921 | } |
| Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 8922 | MaybeGenerateMarkingRegisterCheck(/* code= */ 20); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8923 | } |
| 8924 | |
| Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 8925 | void CodeGeneratorARMVIXL::GenerateIntrinsicCasMoveWithBakerReadBarrier( |
| 8926 | vixl::aarch32::Register marked_old_value, |
| 8927 | vixl::aarch32::Register old_value) { |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8928 | DCHECK(kEmitCompilerReadBarrier); |
| 8929 | DCHECK(kUseBakerReadBarrier); |
| 8930 | |
| Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 8931 | // Similar to the Baker RB path in GenerateGcRootFieldLoad(), with a MOV instead of LDR. |
| 8932 | // For low registers, we can reuse the GC root narrow entrypoint, for high registers |
| 8933 | // we use a specialized entrypoint because the register bits are 8-11 instead of 12-15. |
| 8934 | bool narrow_mov = marked_old_value.IsLow(); |
| 8935 | uint32_t custom_data = narrow_mov |
| 8936 | ? EncodeBakerReadBarrierGcRootData(marked_old_value.GetCode(), /*narrow=*/ true) |
| 8937 | : EncodeBakerReadBarrierIntrinsicCasData(marked_old_value.GetCode()); |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8938 | |
| Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 8939 | size_t narrow_instructions = /* CMP */ (mr.IsLow() ? 1u : 0u) + /* MOV */ (narrow_mov ? 1u : 0u); |
| 8940 | size_t wide_instructions = /* ADR+CMP+MOV+BNE */ 4u - narrow_instructions; |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8941 | size_t exact_size = wide_instructions * vixl32::k32BitT32InstructionSizeInBytes + |
| 8942 | narrow_instructions * vixl32::k16BitT32InstructionSizeInBytes; |
| 8943 | ExactAssemblyScope guard(GetVIXLAssembler(), exact_size); |
| 8944 | vixl32::Label return_address; |
| 8945 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8946 | __ cmp(mr, Operand(0)); |
| 8947 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 8948 | __ mov(EncodingSize(narrow_mov ? Narrow : Wide), marked_old_value, old_value); |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8949 | EmitBakerReadBarrierBne(custom_data); |
| 8950 | __ bind(&return_address); |
| 8951 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 8952 | narrow_mov |
| 8953 | ? BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_OFFSET |
| 8954 | : BAKER_MARK_INTROSPECTION_INTRINSIC_CAS_MOV_OFFSET); |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8955 | } |
| 8956 | |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8957 | void CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8958 | Location ref, |
| 8959 | vixl32::Register obj, |
| Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8960 | const vixl32::MemOperand& src, |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8961 | bool needs_null_check) { |
| 8962 | DCHECK(kEmitCompilerReadBarrier); |
| 8963 | DCHECK(kUseBakerReadBarrier); |
| 8964 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8965 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 8966 | // Marking Register) to decide whether we need to enter the slow |
| 8967 | // path to mark the reference. Then, in the slow path, check the |
| 8968 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 8969 | // decide whether to mark `ref` or not. |
| 8970 | // |
| 8971 | // We use shared thunks for the slow path; shared within the method |
| 8972 | // for JIT, across methods for AOT. That thunk checks the holder |
| 8973 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 8974 | // it creates a fake dependency and returns to the LDR instruction. |
| 8975 | // |
| 8976 | // lr = &gray_return_address; |
| 8977 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8978 | // goto field_thunk<holder_reg, base_reg>(lr) |
| 8979 | // } |
| 8980 | // not_gray_return_address: |
| 8981 | // // Original reference load. If the offset is too large to fit |
| 8982 | // // into LDR, we use an adjusted base register here. |
| 8983 | // HeapReference<mirror::Object> reference = *(obj+offset); |
| 8984 | // gray_return_address: |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8985 | |
| Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8986 | DCHECK(src.GetAddrMode() == vixl32::Offset); |
| 8987 | DCHECK_ALIGNED(src.GetOffsetImmediate(), sizeof(mirror::HeapReference<mirror::Object>)); |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8988 | vixl32::Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
| Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8989 | bool narrow = CanEmitNarrowLdr(ref_reg, src.GetBaseRegister(), src.GetOffsetImmediate()); |
| 8990 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8991 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8992 | temps.Exclude(ip); |
| Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8993 | uint32_t custom_data = |
| 8994 | EncodeBakerReadBarrierFieldData(src.GetBaseRegister().GetCode(), obj.GetCode(), narrow); |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8995 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8996 | { |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8997 | size_t narrow_instructions = |
| 8998 | /* CMP */ (mr.IsLow() ? 1u : 0u) + |
| 8999 | /* LDR+unpoison? */ (narrow ? (kPoisonHeapReferences ? 2u : 1u) : 0u); |
| 9000 | size_t wide_instructions = |
| 9001 | /* ADR+CMP+LDR+BNE+unpoison? */ (kPoisonHeapReferences ? 5u : 4u) - narrow_instructions; |
| 9002 | size_t exact_size = wide_instructions * vixl32::k32BitT32InstructionSizeInBytes + |
| 9003 | narrow_instructions * vixl32::k16BitT32InstructionSizeInBytes; |
| 9004 | ExactAssemblyScope guard(GetVIXLAssembler(), exact_size); |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 9005 | vixl32::Label return_address; |
| 9006 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 9007 | __ cmp(mr, Operand(0)); |
| 9008 | EmitBakerReadBarrierBne(custom_data); |
| 9009 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 9010 | __ ldr(EncodingSize(narrow ? Narrow : Wide), ref_reg, src); |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 9011 | if (needs_null_check) { |
| 9012 | MaybeRecordImplicitNullCheck(instruction); |
| 9013 | } |
| 9014 | // Note: We need a specific width for the unpoisoning NEG. |
| 9015 | if (kPoisonHeapReferences) { |
| 9016 | if (narrow) { |
| 9017 | // The only 16-bit encoding is T1 which sets flags outside IT block (i.e. RSBS, not RSB). |
| 9018 | __ rsbs(EncodingSize(Narrow), ref_reg, ref_reg, Operand(0)); |
| 9019 | } else { |
| 9020 | __ rsb(EncodingSize(Wide), ref_reg, ref_reg, Operand(0)); |
| 9021 | } |
| 9022 | } |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 9023 | __ bind(&return_address); |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 9024 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 9025 | narrow ? BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_OFFSET |
| 9026 | : BAKER_MARK_INTROSPECTION_FIELD_LDR_WIDE_OFFSET); |
| 9027 | } |
| Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 9028 | MaybeGenerateMarkingRegisterCheck(/* code= */ 21, /* temp_loc= */ LocationFrom(ip)); |
| Roland Levillain | 6070e88 | 2016-11-03 17:51:58 +0000 | [diff] [blame] | 9029 | } |
| 9030 | |
| Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 9031 | void CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 9032 | Location ref, |
| 9033 | vixl32::Register obj, |
| 9034 | uint32_t offset, |
| Vladimir Marko | 01b6552 | 2020-10-28 15:43:54 +0000 | [diff] [blame] | 9035 | Location maybe_temp, |
| Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 9036 | bool needs_null_check) { |
| 9037 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 9038 | vixl32::Register base = obj; |
| 9039 | if (offset >= kReferenceLoadMinFarOffset) { |
| Vladimir Marko | 01b6552 | 2020-10-28 15:43:54 +0000 | [diff] [blame] | 9040 | base = RegisterFrom(maybe_temp); |
| Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 9041 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 9042 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 9043 | offset &= (kReferenceLoadMinFarOffset - 1u); |
| 9044 | } |
| 9045 | GenerateFieldLoadWithBakerReadBarrier( |
| 9046 | instruction, ref, obj, MemOperand(base, offset), needs_null_check); |
| 9047 | } |
| 9048 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 9049 | void CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier(Location ref, |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9050 | vixl32::Register obj, |
| 9051 | uint32_t data_offset, |
| 9052 | Location index, |
| 9053 | Location temp, |
| 9054 | bool needs_null_check) { |
| 9055 | DCHECK(kEmitCompilerReadBarrier); |
| 9056 | DCHECK(kUseBakerReadBarrier); |
| 9057 | |
| 9058 | static_assert( |
| 9059 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 9060 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9061 | ScaleFactor scale_factor = TIMES_4; |
| 9062 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 9063 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 9064 | // Marking Register) to decide whether we need to enter the slow |
| 9065 | // path to mark the reference. Then, in the slow path, check the |
| 9066 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 9067 | // decide whether to mark `ref` or not. |
| 9068 | // |
| 9069 | // We use shared thunks for the slow path; shared within the method |
| 9070 | // for JIT, across methods for AOT. That thunk checks the holder |
| 9071 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 9072 | // it creates a fake dependency and returns to the LDR instruction. |
| 9073 | // |
| 9074 | // lr = &gray_return_address; |
| 9075 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 9076 | // goto array_thunk<base_reg>(lr) |
| 9077 | // } |
| 9078 | // not_gray_return_address: |
| 9079 | // // Original reference load. If the offset is too large to fit |
| 9080 | // // into LDR, we use an adjusted base register here. |
| 9081 | // HeapReference<mirror::Object> reference = data[index]; |
| 9082 | // gray_return_address: |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9083 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 9084 | DCHECK(index.IsValid()); |
| 9085 | vixl32::Register index_reg = RegisterFrom(index, DataType::Type::kInt32); |
| 9086 | vixl32::Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
| 9087 | vixl32::Register data_reg = RegisterFrom(temp, DataType::Type::kInt32); // Raw pointer. |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9088 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 9089 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 9090 | temps.Exclude(ip); |
| 9091 | uint32_t custom_data = EncodeBakerReadBarrierArrayData(data_reg.GetCode()); |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9092 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 9093 | __ Add(data_reg, obj, Operand(data_offset)); |
| 9094 | { |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 9095 | size_t narrow_instructions = /* CMP */ (mr.IsLow() ? 1u : 0u); |
| 9096 | size_t wide_instructions = |
| 9097 | /* ADR+CMP+BNE+LDR+unpoison? */ (kPoisonHeapReferences ? 5u : 4u) - narrow_instructions; |
| 9098 | size_t exact_size = wide_instructions * vixl32::k32BitT32InstructionSizeInBytes + |
| 9099 | narrow_instructions * vixl32::k16BitT32InstructionSizeInBytes; |
| 9100 | ExactAssemblyScope guard(GetVIXLAssembler(), exact_size); |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 9101 | vixl32::Label return_address; |
| 9102 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 9103 | __ cmp(mr, Operand(0)); |
| 9104 | EmitBakerReadBarrierBne(custom_data); |
| 9105 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 9106 | __ ldr(ref_reg, MemOperand(data_reg, index_reg, vixl32::LSL, scale_factor)); |
| 9107 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 9108 | // Note: We need a Wide NEG for the unpoisoning. |
| 9109 | if (kPoisonHeapReferences) { |
| 9110 | __ rsb(EncodingSize(Wide), ref_reg, ref_reg, Operand(0)); |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9111 | } |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 9112 | __ bind(&return_address); |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 9113 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 9114 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9115 | } |
| Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 9116 | MaybeGenerateMarkingRegisterCheck(/* code= */ 22, /* temp_loc= */ LocationFrom(ip)); |
| Roland Levillain | 6070e88 | 2016-11-03 17:51:58 +0000 | [diff] [blame] | 9117 | } |
| 9118 | |
| Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 9119 | void CodeGeneratorARMVIXL::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 9120 | // The following condition is a compile-time one, so it does not have a run-time cost. |
| 9121 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && kIsDebugBuild) { |
| 9122 | // The following condition is a run-time one; it is executed after the |
| 9123 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 9124 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 9125 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 9126 | vixl32::Register temp = temp_loc.IsValid() ? RegisterFrom(temp_loc) : temps.Acquire(); |
| 9127 | GetAssembler()->GenerateMarkingRegisterCheck(temp, |
| 9128 | kMarkingRegisterCheckBreakCodeBaseCode + code); |
| 9129 | } |
| 9130 | } |
| 9131 | } |
| 9132 | |
| Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 9133 | SlowPathCodeARMVIXL* CodeGeneratorARMVIXL::AddReadBarrierSlowPath(HInstruction* instruction, |
| 9134 | Location out, |
| 9135 | Location ref, |
| 9136 | Location obj, |
| 9137 | uint32_t offset, |
| 9138 | Location index) { |
| 9139 | SlowPathCodeARMVIXL* slow_path = new (GetScopedAllocator()) |
| 9140 | ReadBarrierForHeapReferenceSlowPathARMVIXL(instruction, out, ref, obj, offset, index); |
| 9141 | AddSlowPath(slow_path); |
| 9142 | return slow_path; |
| 9143 | } |
| 9144 | |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9145 | void CodeGeneratorARMVIXL::GenerateReadBarrierSlow(HInstruction* instruction, |
| 9146 | Location out, |
| 9147 | Location ref, |
| 9148 | Location obj, |
| 9149 | uint32_t offset, |
| 9150 | Location index) { |
| 9151 | DCHECK(kEmitCompilerReadBarrier); |
| 9152 | |
| 9153 | // Insert a slow path based read barrier *after* the reference load. |
| 9154 | // |
| 9155 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 9156 | // reference will be carried out by the runtime within the slow |
| 9157 | // path. |
| 9158 | // |
| 9159 | // Note that `ref` currently does not get unpoisoned (when heap |
| 9160 | // poisoning is enabled), which is alright as the `ref` argument is |
| 9161 | // not used by the artReadBarrierSlow entry point. |
| 9162 | // |
| 9163 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 9164 | SlowPathCodeARMVIXL* slow_path = |
| 9165 | AddReadBarrierSlowPath(instruction, out, ref, obj, offset, index); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9166 | |
| 9167 | __ B(slow_path->GetEntryLabel()); |
| 9168 | __ Bind(slow_path->GetExitLabel()); |
| 9169 | } |
| 9170 | |
| 9171 | void CodeGeneratorARMVIXL::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9172 | Location out, |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9173 | Location ref, |
| 9174 | Location obj, |
| 9175 | uint32_t offset, |
| 9176 | Location index) { |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9177 | if (kEmitCompilerReadBarrier) { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9178 | // Baker's read barriers shall be handled by the fast path |
| Roland Levillain | 9983e30 | 2017-07-14 14:34:22 +0100 | [diff] [blame] | 9179 | // (CodeGeneratorARMVIXL::GenerateReferenceLoadWithBakerReadBarrier). |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9180 | DCHECK(!kUseBakerReadBarrier); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9181 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 9182 | // by the runtime within the slow path. |
| 9183 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9184 | } else if (kPoisonHeapReferences) { |
| 9185 | GetAssembler()->UnpoisonHeapReference(RegisterFrom(out)); |
| 9186 | } |
| 9187 | } |
| 9188 | |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9189 | void CodeGeneratorARMVIXL::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 9190 | Location out, |
| 9191 | Location root) { |
| 9192 | DCHECK(kEmitCompilerReadBarrier); |
| 9193 | |
| 9194 | // Insert a slow path based read barrier *after* the GC root load. |
| 9195 | // |
| 9196 | // Note that GC roots are not affected by heap poisoning, so we do |
| 9197 | // not need to do anything special for this here. |
| 9198 | SlowPathCodeARMVIXL* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9199 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathARMVIXL(instruction, out, root); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9200 | AddSlowPath(slow_path); |
| 9201 | |
| 9202 | __ B(slow_path->GetEntryLabel()); |
| 9203 | __ Bind(slow_path->GetExitLabel()); |
| 9204 | } |
| 9205 | |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9206 | // Check if the desired_dispatch_info is supported. If it is, return it, |
| 9207 | // otherwise return a fall-back info that should be used instead. |
| 9208 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARMVIXL::GetSupportedInvokeStaticOrDirectDispatch( |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9209 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9210 | ArtMethod* method) { |
| Vladimir Marko | d3e9c62 | 2020-08-05 12:20:28 +0100 | [diff] [blame] | 9211 | if (method->IsIntrinsic() && |
| Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9212 | desired_dispatch_info.code_ptr_location == CodePtrLocation::kCallCriticalNative) { |
| Vladimir Marko | d3e9c62 | 2020-08-05 12:20:28 +0100 | [diff] [blame] | 9213 | // As a work-around for soft-float native ABI interfering with type checks, we are |
| 9214 | // inserting fake calls to Float.floatToRawIntBits() or Double.doubleToRawLongBits() |
| 9215 | // when a float or double argument is passed in core registers but we cannot do that |
| 9216 | // for actual intrinsic implementations that expect them in FP registers. Therefore |
| 9217 | // we do not use `kCallCriticalNative` for intrinsics with FP arguments; if they are |
| 9218 | // properly intrinsified, the dispatch type does not matter anyway. |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9219 | ScopedObjectAccess soa(Thread::Current()); |
| 9220 | uint32_t shorty_len; |
| 9221 | const char* shorty = method->GetShorty(&shorty_len); |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9222 | for (uint32_t i = 1; i != shorty_len; ++i) { |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9223 | if (shorty[i] == 'D' || shorty[i] == 'F') { |
| 9224 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9225 | dispatch_info.code_ptr_location = CodePtrLocation::kCallArtMethod; |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9226 | return dispatch_info; |
| 9227 | } |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9228 | } |
| 9229 | } |
| Nicolas Geoffray | e807ff7 | 2017-01-23 09:03:12 +0000 | [diff] [blame] | 9230 | return desired_dispatch_info; |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9231 | } |
| 9232 | |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 9233 | |
| 9234 | void CodeGeneratorARMVIXL::LoadMethod(MethodLoadKind load_kind, Location temp, HInvoke* invoke) { |
| 9235 | switch (load_kind) { |
| Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9236 | case MethodLoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 9237 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
| Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 9238 | PcRelativePatchInfo* labels = NewBootImageMethodPatch(invoke->GetResolvedMethodReference()); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9239 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 9240 | EmitMovwMovtPlaceholder(labels, temp_reg); |
| 9241 | break; |
| 9242 | } |
| Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9243 | case MethodLoadKind::kBootImageRelRo: { |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 9244 | uint32_t boot_image_offset = GetBootImageOffset(invoke); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 9245 | PcRelativePatchInfo* labels = NewBootImageRelRoPatch(boot_image_offset); |
| 9246 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 9247 | EmitMovwMovtPlaceholder(labels, temp_reg); |
| 9248 | GetAssembler()->LoadFromOffset(kLoadWord, temp_reg, temp_reg, /* offset*/ 0); |
| 9249 | break; |
| 9250 | } |
| Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9251 | case MethodLoadKind::kBssEntry: { |
| Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 9252 | PcRelativePatchInfo* labels = NewMethodBssEntryPatch(invoke->GetMethodReference()); |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9253 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 9254 | EmitMovwMovtPlaceholder(labels, temp_reg); |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 9255 | // All aligned loads are implicitly atomic consume operations on ARM. |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9256 | GetAssembler()->LoadFromOffset(kLoadWord, temp_reg, temp_reg, /* offset*/ 0); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9257 | break; |
| 9258 | } |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 9259 | case MethodLoadKind::kJitDirectAddress: { |
| 9260 | __ Mov(RegisterFrom(temp), Operand::From(invoke->GetResolvedMethod())); |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 9261 | break; |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 9262 | } |
| 9263 | case MethodLoadKind::kRuntimeCall: { |
| 9264 | // Test situation, don't do anything. |
| 9265 | break; |
| 9266 | } |
| 9267 | default: { |
| 9268 | LOG(FATAL) << "Load kind should have already been handled " << load_kind; |
| 9269 | UNREACHABLE(); |
| 9270 | } |
| 9271 | } |
| 9272 | } |
| 9273 | |
| 9274 | void CodeGeneratorARMVIXL::GenerateStaticOrDirectCall( |
| 9275 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
| 9276 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 9277 | switch (invoke->GetMethodLoadKind()) { |
| 9278 | case MethodLoadKind::kStringInit: { |
| 9279 | uint32_t offset = |
| 9280 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 9281 | // temp = thread->string_init_entrypoint |
| 9282 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp), tr, offset); |
| 9283 | break; |
| 9284 | } |
| 9285 | case MethodLoadKind::kRecursive: { |
| 9286 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodIndex()); |
| 9287 | break; |
| 9288 | } |
| Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9289 | case MethodLoadKind::kRuntimeCall: { |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9290 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 9291 | return; // No code pointer retrieval; the runtime performs the call directly. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9292 | } |
| Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 9293 | case MethodLoadKind::kBootImageLinkTimePcRelative: |
| 9294 | // Note: Unlike arm64, x86 and x86-64, we do not avoid the materialization of method |
| 9295 | // pointer for kCallCriticalNative because it would not save us an instruction from |
| 9296 | // the current sequence MOVW+MOVT+ADD(pc)+LDR+BL. The ADD(pc) separates the patched |
| 9297 | // offset instructions MOVW+MOVT from the entrypoint load, so they cannot be fused. |
| 9298 | FALLTHROUGH_INTENDED; |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 9299 | default: { |
| 9300 | LoadMethod(invoke->GetMethodLoadKind(), temp, invoke); |
| 9301 | break; |
| 9302 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9303 | } |
| 9304 | |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9305 | auto call_code_pointer_member = [&](MemberOffset offset) { |
| 9306 | // LR = callee_method->member; |
| 9307 | GetAssembler()->LoadFromOffset(kLoadWord, lr, RegisterFrom(callee_method), offset.Int32Value()); |
| 9308 | { |
| 9309 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 9310 | // blx in T32 has only 16bit encoding that's why a stricter check for the scope is used. |
| 9311 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9312 | vixl32::k16BitT32InstructionSizeInBytes, |
| 9313 | CodeBufferCheckScope::kExactSize); |
| 9314 | // LR() |
| 9315 | __ blx(lr); |
| 9316 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 9317 | } |
| 9318 | }; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9319 | switch (invoke->GetCodePtrLocation()) { |
| Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9320 | case CodePtrLocation::kCallSelf: |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9321 | { |
| Nicolas Geoffray | 282795c | 2021-09-24 18:16:41 +0100 | [diff] [blame] | 9322 | DCHECK(!GetGraph()->HasShouldDeoptimizeFlag()); |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9323 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 9324 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9325 | vixl32::k32BitT32InstructionSizeInBytes, |
| 9326 | CodeBufferCheckScope::kMaximumSize); |
| 9327 | __ bl(GetFrameEntryLabel()); |
| 9328 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 9329 | } |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9330 | break; |
| Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9331 | case CodePtrLocation::kCallCriticalNative: { |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9332 | size_t out_frame_size = |
| 9333 | PrepareCriticalNativeCall<CriticalNativeCallingConventionVisitorARMVIXL, |
| 9334 | kAapcsStackAlignment, |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 9335 | GetCriticalNativeDirectCallFrameSize>(invoke); |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9336 | call_code_pointer_member(ArtMethod::EntryPointFromJniOffset(kArmPointerSize)); |
| 9337 | // Move the result when needed due to native and managed ABI mismatch. |
| 9338 | switch (invoke->GetType()) { |
| 9339 | case DataType::Type::kFloat32: |
| 9340 | __ Vmov(s0, r0); |
| 9341 | break; |
| 9342 | case DataType::Type::kFloat64: |
| 9343 | __ Vmov(d0, r0, r1); |
| 9344 | break; |
| 9345 | case DataType::Type::kBool: |
| 9346 | case DataType::Type::kInt8: |
| 9347 | case DataType::Type::kUint16: |
| 9348 | case DataType::Type::kInt16: |
| 9349 | case DataType::Type::kInt32: |
| 9350 | case DataType::Type::kInt64: |
| 9351 | case DataType::Type::kVoid: |
| 9352 | break; |
| 9353 | default: |
| 9354 | DCHECK(false) << invoke->GetType(); |
| 9355 | break; |
| 9356 | } |
| 9357 | if (out_frame_size != 0u) { |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 9358 | DecreaseFrame(out_frame_size); |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9359 | } |
| 9360 | break; |
| 9361 | } |
| Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9362 | case CodePtrLocation::kCallArtMethod: |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9363 | call_code_pointer_member(ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize)); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9364 | break; |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9365 | } |
| 9366 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9367 | DCHECK(!IsLeafMethod()); |
| 9368 | } |
| 9369 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9370 | void CodeGeneratorARMVIXL::GenerateVirtualCall( |
| 9371 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9372 | vixl32::Register temp = RegisterFrom(temp_location); |
| 9373 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 9374 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
| 9375 | |
| 9376 | // Use the calling convention instead of the location of the receiver, as |
| 9377 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 9378 | // slow path, the arguments have been moved to the right place, so here we are |
| 9379 | // guaranteed that the receiver is the first register of the calling convention. |
| 9380 | InvokeDexCallingConventionARMVIXL calling_convention; |
| 9381 | vixl32::Register receiver = calling_convention.GetRegisterAt(0); |
| 9382 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9383 | { |
| 9384 | // Make sure the pc is recorded immediately after the `ldr` instruction. |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 9385 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9386 | vixl32::kMaxInstructionSizeInBytes, |
| 9387 | CodeBufferCheckScope::kMaximumSize); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9388 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 9389 | __ ldr(temp, MemOperand(receiver, class_offset)); |
| 9390 | MaybeRecordImplicitNullCheck(invoke); |
| 9391 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9392 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 9393 | // emit a read barrier for the previous class reference load. |
| 9394 | // However this is not required in practice, as this is an |
| 9395 | // intermediate/temporary reference and because the current |
| 9396 | // concurrent copying collector keeps the from-space memory |
| 9397 | // intact/accessible until the end of the marking phase (the |
| 9398 | // concurrent copying collector may not in the future). |
| 9399 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 9400 | |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 9401 | // If we're compiling baseline, update the inline cache. |
| 9402 | MaybeGenerateInlineCacheCheck(invoke, temp); |
| 9403 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9404 | // temp = temp->GetMethodAt(method_offset); |
| 9405 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 9406 | kArmPointerSize).Int32Value(); |
| 9407 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 9408 | // LR = temp->GetEntryPoint(); |
| 9409 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9410 | { |
| 9411 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 9412 | // blx in T32 has only 16bit encoding that's why a stricter check for the scope is used. |
| 9413 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9414 | vixl32::k16BitT32InstructionSizeInBytes, |
| 9415 | CodeBufferCheckScope::kExactSize); |
| 9416 | // LR(); |
| 9417 | __ blx(lr); |
| 9418 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 9419 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9420 | } |
| 9421 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9422 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageIntrinsicPatch( |
| 9423 | uint32_t intrinsic_data) { |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 9424 | return NewPcRelativePatch(/* dex_file= */ nullptr, intrinsic_data, &boot_image_other_patches_); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9425 | } |
| 9426 | |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 9427 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageRelRoPatch( |
| 9428 | uint32_t boot_image_offset) { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9429 | return NewPcRelativePatch(/* dex_file= */ nullptr, |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 9430 | boot_image_offset, |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 9431 | &boot_image_other_patches_); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 9432 | } |
| 9433 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9434 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageMethodPatch( |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9435 | MethodReference target_method) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9436 | return NewPcRelativePatch( |
| 9437 | target_method.dex_file, target_method.index, &boot_image_method_patches_); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9438 | } |
| 9439 | |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9440 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewMethodBssEntryPatch( |
| 9441 | MethodReference target_method) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9442 | return NewPcRelativePatch( |
| 9443 | target_method.dex_file, target_method.index, &method_bss_entry_patches_); |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9444 | } |
| 9445 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9446 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageTypePatch( |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9447 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9448 | return NewPcRelativePatch(&dex_file, type_index.index_, &boot_image_type_patches_); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9449 | } |
| 9450 | |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9451 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewTypeBssEntryPatch( |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 9452 | HLoadClass* load_class) { |
| 9453 | const DexFile& dex_file = load_class->GetDexFile(); |
| 9454 | dex::TypeIndex type_index = load_class->GetTypeIndex(); |
| 9455 | ArenaDeque<PcRelativePatchInfo>* patches = nullptr; |
| 9456 | switch (load_class->GetLoadKind()) { |
| 9457 | case HLoadClass::LoadKind::kBssEntry: |
| 9458 | patches = &type_bss_entry_patches_; |
| 9459 | break; |
| 9460 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 9461 | patches = &public_type_bss_entry_patches_; |
| 9462 | break; |
| 9463 | case HLoadClass::LoadKind::kBssEntryPackage: |
| 9464 | patches = &package_type_bss_entry_patches_; |
| 9465 | break; |
| 9466 | default: |
| 9467 | LOG(FATAL) << "Unexpected load kind: " << load_class->GetLoadKind(); |
| 9468 | UNREACHABLE(); |
| 9469 | } |
| Vladimir Marko | baade40 | 2020-09-30 14:45:39 +0000 | [diff] [blame] | 9470 | return NewPcRelativePatch(&dex_file, type_index.index_, patches); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9471 | } |
| 9472 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9473 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageStringPatch( |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9474 | const DexFile& dex_file, dex::StringIndex string_index) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9475 | return NewPcRelativePatch(&dex_file, string_index.index_, &boot_image_string_patches_); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9476 | } |
| 9477 | |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 9478 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewStringBssEntryPatch( |
| 9479 | const DexFile& dex_file, dex::StringIndex string_index) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9480 | return NewPcRelativePatch(&dex_file, string_index.index_, &string_bss_entry_patches_); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 9481 | } |
| 9482 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9483 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativePatch( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9484 | const DexFile* dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9485 | patches->emplace_back(dex_file, offset_or_index); |
| 9486 | return &patches->back(); |
| 9487 | } |
| 9488 | |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9489 | void CodeGeneratorARMVIXL::EmitEntrypointThunkCall(ThreadOffset32 entrypoint_offset) { |
| 9490 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
| Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 9491 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9492 | call_entrypoint_patches_.emplace_back(/*dex_file*/ nullptr, entrypoint_offset.Uint32Value()); |
| 9493 | vixl::aarch32::Label* bl_label = &call_entrypoint_patches_.back().label; |
| 9494 | __ bind(bl_label); |
| 9495 | vixl32::Label placeholder_label; |
| 9496 | __ bl(&placeholder_label); // Placeholder, patched at link-time. |
| 9497 | __ bind(&placeholder_label); |
| 9498 | } |
| 9499 | |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 9500 | void CodeGeneratorARMVIXL::EmitBakerReadBarrierBne(uint32_t custom_data) { |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 9501 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
| Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 9502 | if (GetCompilerOptions().IsJitCompiler()) { |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 9503 | auto it = jit_baker_read_barrier_slow_paths_.FindOrAdd(custom_data); |
| 9504 | vixl::aarch32::Label* slow_path_entry = &it->second.label; |
| 9505 | __ b(ne, EncodingSize(Wide), slow_path_entry); |
| 9506 | } else { |
| 9507 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 9508 | vixl::aarch32::Label* patch_label = &baker_read_barrier_patches_.back().label; |
| 9509 | __ bind(patch_label); |
| 9510 | vixl32::Label placeholder_label; |
| 9511 | __ b(ne, EncodingSize(Wide), &placeholder_label); // Placeholder, patched at link-time. |
| 9512 | __ bind(&placeholder_label); |
| 9513 | } |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9514 | } |
| 9515 | |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9516 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateBootImageAddressLiteral(uint32_t address) { |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 9517 | return DeduplicateUint32Literal(address, &uint32_literals_); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9518 | } |
| 9519 | |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 9520 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitStringLiteral( |
| 9521 | const DexFile& dex_file, |
| 9522 | dex::StringIndex string_index, |
| 9523 | Handle<mirror::String> handle) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9524 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9525 | return jit_string_patches_.GetOrCreate( |
| 9526 | StringReference(&dex_file, string_index), |
| 9527 | [this]() { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9528 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ 0u); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9529 | }); |
| 9530 | } |
| 9531 | |
| 9532 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 9533 | dex::TypeIndex type_index, |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 9534 | Handle<mirror::Class> handle) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9535 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9536 | return jit_class_patches_.GetOrCreate( |
| 9537 | TypeReference(&dex_file, type_index), |
| 9538 | [this]() { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9539 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ 0u); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9540 | }); |
| 9541 | } |
| 9542 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9543 | void CodeGeneratorARMVIXL::LoadBootImageAddress(vixl32::Register reg, |
| 9544 | uint32_t boot_image_reference) { |
| 9545 | if (GetCompilerOptions().IsBootImage()) { |
| 9546 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 9547 | NewBootImageIntrinsicPatch(boot_image_reference); |
| 9548 | EmitMovwMovtPlaceholder(labels, reg); |
| Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 9549 | } else if (GetCompilerOptions().GetCompilePic()) { |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9550 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 9551 | NewBootImageRelRoPatch(boot_image_reference); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 9552 | EmitMovwMovtPlaceholder(labels, reg); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9553 | __ Ldr(reg, MemOperand(reg, /* offset= */ 0)); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 9554 | } else { |
| Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 9555 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 9556 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 9557 | DCHECK(!heap->GetBootImageSpaces().empty()); |
| 9558 | uintptr_t address = |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9559 | reinterpret_cast<uintptr_t>(heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 9560 | __ Ldr(reg, DeduplicateBootImageAddressLiteral(dchecked_integral_cast<uint32_t>(address))); |
| 9561 | } |
| 9562 | } |
| 9563 | |
| Vladimir Marko | 7968cae | 2021-01-19 12:02:35 +0000 | [diff] [blame] | 9564 | void CodeGeneratorARMVIXL::LoadTypeForBootImageIntrinsic(vixl::aarch32::Register reg, |
| 9565 | TypeReference target_type) { |
| 9566 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
| 9567 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 9568 | PcRelativePatchInfo* labels = |
| 9569 | NewBootImageTypePatch(*target_type.dex_file, target_type.TypeIndex()); |
| 9570 | EmitMovwMovtPlaceholder(labels, reg); |
| 9571 | } |
| 9572 | |
| Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 9573 | void CodeGeneratorARMVIXL::LoadIntrinsicDeclaringClass(vixl32::Register reg, HInvoke* invoke) { |
| 9574 | DCHECK_NE(invoke->GetIntrinsic(), Intrinsics::kNone); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9575 | if (GetCompilerOptions().IsBootImage()) { |
| Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 9576 | MethodReference target_method = invoke->GetResolvedMethodReference(); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9577 | 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] | 9578 | LoadTypeForBootImageIntrinsic(reg, TypeReference(target_method.dex_file, type_idx)); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9579 | } else { |
| Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 9580 | uint32_t boot_image_offset = GetBootImageOffsetOfIntrinsicDeclaringClass(invoke); |
| 9581 | LoadBootImageAddress(reg, boot_image_offset); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9582 | } |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9583 | } |
| 9584 | |
| Vladimir Marko | 7968cae | 2021-01-19 12:02:35 +0000 | [diff] [blame] | 9585 | void CodeGeneratorARMVIXL::LoadClassRootForIntrinsic(vixl::aarch32::Register reg, |
| 9586 | ClassRoot class_root) { |
| 9587 | if (GetCompilerOptions().IsBootImage()) { |
| 9588 | ScopedObjectAccess soa(Thread::Current()); |
| 9589 | ObjPtr<mirror::Class> klass = GetClassRoot(class_root); |
| 9590 | TypeReference target_type(&klass->GetDexFile(), klass->GetDexTypeIndex()); |
| 9591 | LoadTypeForBootImageIntrinsic(reg, target_type); |
| 9592 | } else { |
| 9593 | uint32_t boot_image_offset = GetBootImageOffset(class_root); |
| 9594 | LoadBootImageAddress(reg, boot_image_offset); |
| 9595 | } |
| 9596 | } |
| 9597 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9598 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9599 | inline void CodeGeneratorARMVIXL::EmitPcRelativeLinkerPatches( |
| 9600 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9601 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9602 | for (const PcRelativePatchInfo& info : infos) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9603 | const DexFile* dex_file = info.target_dex_file; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9604 | size_t offset_or_index = info.offset_or_index; |
| 9605 | DCHECK(info.add_pc_label.IsBound()); |
| 9606 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.GetLocation()); |
| 9607 | // Add MOVW patch. |
| 9608 | DCHECK(info.movw_label.IsBound()); |
| 9609 | 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] | 9610 | 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] | 9611 | // Add MOVT patch. |
| 9612 | DCHECK(info.movt_label.IsBound()); |
| 9613 | 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] | 9614 | 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] | 9615 | } |
| 9616 | } |
| 9617 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9618 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 9619 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 9620 | const DexFile* target_dex_file, |
| 9621 | uint32_t pc_insn_offset, |
| 9622 | uint32_t boot_image_offset) { |
| 9623 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 9624 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 9625 | } |
| 9626 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9627 | void CodeGeneratorARMVIXL::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9628 | DCHECK(linker_patches->empty()); |
| 9629 | size_t size = |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9630 | /* MOVW+MOVT for each entry */ 2u * boot_image_method_patches_.size() + |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9631 | /* MOVW+MOVT for each entry */ 2u * method_bss_entry_patches_.size() + |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9632 | /* MOVW+MOVT for each entry */ 2u * boot_image_type_patches_.size() + |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9633 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size() + |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 9634 | /* MOVW+MOVT for each entry */ 2u * public_type_bss_entry_patches_.size() + |
| 9635 | /* MOVW+MOVT for each entry */ 2u * package_type_bss_entry_patches_.size() + |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9636 | /* MOVW+MOVT for each entry */ 2u * boot_image_string_patches_.size() + |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 9637 | /* MOVW+MOVT for each entry */ 2u * string_bss_entry_patches_.size() + |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 9638 | /* MOVW+MOVT for each entry */ 2u * boot_image_other_patches_.size() + |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9639 | call_entrypoint_patches_.size() + |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9640 | baker_read_barrier_patches_.size(); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9641 | linker_patches->reserve(size); |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 9642 | if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) { |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9643 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9644 | boot_image_method_patches_, linker_patches); |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9645 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9646 | boot_image_type_patches_, linker_patches); |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9647 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9648 | boot_image_string_patches_, linker_patches); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9649 | } else { |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 9650 | DCHECK(boot_image_method_patches_.empty()); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 9651 | DCHECK(boot_image_type_patches_.empty()); |
| 9652 | DCHECK(boot_image_string_patches_.empty()); |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 9653 | } |
| 9654 | if (GetCompilerOptions().IsBootImage()) { |
| 9655 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 9656 | boot_image_other_patches_, linker_patches); |
| 9657 | } else { |
| 9658 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| 9659 | boot_image_other_patches_, linker_patches); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9660 | } |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9661 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 9662 | method_bss_entry_patches_, linker_patches); |
| 9663 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 9664 | type_bss_entry_patches_, linker_patches); |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 9665 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PublicTypeBssEntryPatch>( |
| 9666 | public_type_bss_entry_patches_, linker_patches); |
| 9667 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PackageTypeBssEntryPatch>( |
| 9668 | package_type_bss_entry_patches_, linker_patches); |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9669 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 9670 | string_bss_entry_patches_, linker_patches); |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9671 | for (const PatchInfo<vixl32::Label>& info : call_entrypoint_patches_) { |
| 9672 | DCHECK(info.target_dex_file == nullptr); |
| 9673 | linker_patches->push_back(linker::LinkerPatch::CallEntrypointPatch( |
| 9674 | info.label.GetLocation(), info.offset_or_index)); |
| 9675 | } |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9676 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9677 | linker_patches->push_back(linker::LinkerPatch::BakerReadBarrierBranchPatch( |
| 9678 | info.label.GetLocation(), info.custom_data)); |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9679 | } |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9680 | DCHECK_EQ(size, linker_patches->size()); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9681 | } |
| 9682 | |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9683 | bool CodeGeneratorARMVIXL::NeedsThunkCode(const linker::LinkerPatch& patch) const { |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9684 | return patch.GetType() == linker::LinkerPatch::Type::kCallEntrypoint || |
| 9685 | patch.GetType() == linker::LinkerPatch::Type::kBakerReadBarrierBranch || |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9686 | patch.GetType() == linker::LinkerPatch::Type::kCallRelative; |
| 9687 | } |
| 9688 | |
| 9689 | void CodeGeneratorARMVIXL::EmitThunkCode(const linker::LinkerPatch& patch, |
| 9690 | /*out*/ ArenaVector<uint8_t>* code, |
| 9691 | /*out*/ std::string* debug_name) { |
| 9692 | arm::ArmVIXLAssembler assembler(GetGraph()->GetAllocator()); |
| 9693 | switch (patch.GetType()) { |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9694 | case linker::LinkerPatch::Type::kCallRelative: { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9695 | // The thunk just uses the entry point in the ArtMethod. This works even for calls |
| 9696 | // to the generic JNI and interpreter trampolines. |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9697 | MemberOffset offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
| 9698 | assembler.LoadFromOffset(arm::kLoadWord, vixl32::pc, vixl32::r0, offset.Int32Value()); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9699 | assembler.GetVIXLAssembler()->Bkpt(0); |
| David Srbecky | 889da94 | 2021-04-30 13:03:14 +0100 | [diff] [blame] | 9700 | if (debug_name != nullptr && GetCompilerOptions().GenerateAnyDebugInfo()) { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9701 | *debug_name = "MethodCallThunk"; |
| 9702 | } |
| 9703 | break; |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9704 | } |
| 9705 | case linker::LinkerPatch::Type::kCallEntrypoint: { |
| 9706 | assembler.LoadFromOffset(arm::kLoadWord, vixl32::pc, tr, patch.EntrypointOffset()); |
| 9707 | assembler.GetVIXLAssembler()->Bkpt(0); |
| David Srbecky | 889da94 | 2021-04-30 13:03:14 +0100 | [diff] [blame] | 9708 | if (debug_name != nullptr && GetCompilerOptions().GenerateAnyDebugInfo()) { |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9709 | *debug_name = "EntrypointCallThunk_" + std::to_string(patch.EntrypointOffset()); |
| 9710 | } |
| 9711 | break; |
| 9712 | } |
| 9713 | case linker::LinkerPatch::Type::kBakerReadBarrierBranch: { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9714 | DCHECK_EQ(patch.GetBakerCustomValue2(), 0u); |
| 9715 | CompileBakerReadBarrierThunk(assembler, patch.GetBakerCustomValue1(), debug_name); |
| 9716 | break; |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9717 | } |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9718 | default: |
| 9719 | LOG(FATAL) << "Unexpected patch type " << patch.GetType(); |
| 9720 | UNREACHABLE(); |
| 9721 | } |
| 9722 | |
| 9723 | // Ensure we emit the literal pool if any. |
| 9724 | assembler.FinalizeCode(); |
| 9725 | code->resize(assembler.CodeSize()); |
| 9726 | MemoryRegion code_region(code->data(), code->size()); |
| 9727 | assembler.FinalizeInstructions(code_region); |
| 9728 | } |
| 9729 | |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9730 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateUint32Literal( |
| 9731 | uint32_t value, |
| 9732 | Uint32ToLiteralMap* map) { |
| 9733 | return map->GetOrCreate( |
| 9734 | value, |
| 9735 | [this, value]() { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9736 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ value); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9737 | }); |
| 9738 | } |
| 9739 | |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 9740 | void LocationsBuilderARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 9741 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9742 | new (GetGraph()->GetAllocator()) LocationSummary(instr, LocationSummary::kNoCall); |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 9743 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 9744 | Location::RequiresRegister()); |
| 9745 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 9746 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 9747 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 9748 | } |
| 9749 | |
| 9750 | void InstructionCodeGeneratorARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 9751 | vixl32::Register res = OutputRegister(instr); |
| 9752 | vixl32::Register accumulator = |
| 9753 | InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 9754 | vixl32::Register mul_left = |
| 9755 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 9756 | vixl32::Register mul_right = |
| 9757 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
| 9758 | |
| 9759 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 9760 | __ Mla(res, mul_left, mul_right, accumulator); |
| 9761 | } else { |
| 9762 | __ Mls(res, mul_left, mul_right, accumulator); |
| 9763 | } |
| 9764 | } |
| 9765 | |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9766 | void LocationsBuilderARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9767 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9768 | LOG(FATAL) << "Unreachable"; |
| 9769 | } |
| 9770 | |
| 9771 | void InstructionCodeGeneratorARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9772 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9773 | LOG(FATAL) << "Unreachable"; |
| 9774 | } |
| 9775 | |
| 9776 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 9777 | void LocationsBuilderARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9778 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9779 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9780 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9781 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
| 9782 | codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 9783 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 9784 | if (switch_instr->GetStartValue() != 0) { |
| 9785 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 9786 | } |
| 9787 | } |
| 9788 | } |
| 9789 | |
| 9790 | // TODO(VIXL): Investigate and reach the parity with old arm codegen. |
| 9791 | void InstructionCodeGeneratorARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9792 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 9793 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9794 | LocationSummary* locations = switch_instr->GetLocations(); |
| 9795 | vixl32::Register value_reg = InputRegisterAt(switch_instr, 0); |
| 9796 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 9797 | |
| 9798 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
| 9799 | !codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 9800 | // Create a series of compare/jumps. |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9801 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9802 | vixl32::Register temp_reg = temps.Acquire(); |
| 9803 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 9804 | // the immediate, because IP is used as the destination register. For the other |
| 9805 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 9806 | // and they can be encoded in the instruction without making use of IP register. |
| 9807 | __ Adds(temp_reg, value_reg, -lower_bound); |
| 9808 | |
| 9809 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 9810 | // Jump to successors[0] if value == lower_bound. |
| 9811 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 9812 | int32_t last_index = 0; |
| 9813 | for (; num_entries - last_index > 2; last_index += 2) { |
| 9814 | __ Adds(temp_reg, temp_reg, -2); |
| 9815 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 9816 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9817 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 9818 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 9819 | } |
| 9820 | if (num_entries - last_index == 2) { |
| 9821 | // The last missing case_value. |
| 9822 | __ Cmp(temp_reg, 1); |
| 9823 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9824 | } |
| 9825 | |
| 9826 | // And the default for any other value. |
| 9827 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 9828 | __ B(codegen_->GetLabelOf(default_block)); |
| 9829 | } |
| 9830 | } else { |
| 9831 | // Create a table lookup. |
| 9832 | vixl32::Register table_base = RegisterFrom(locations->GetTemp(0)); |
| 9833 | |
| 9834 | JumpTableARMVIXL* jump_table = codegen_->CreateJumpTable(switch_instr); |
| 9835 | |
| 9836 | // Remove the bias. |
| 9837 | vixl32::Register key_reg; |
| 9838 | if (lower_bound != 0) { |
| 9839 | key_reg = RegisterFrom(locations->GetTemp(1)); |
| 9840 | __ Sub(key_reg, value_reg, lower_bound); |
| 9841 | } else { |
| 9842 | key_reg = value_reg; |
| 9843 | } |
| 9844 | |
| 9845 | // Check whether the value is in the table, jump to default block if not. |
| 9846 | __ Cmp(key_reg, num_entries - 1); |
| 9847 | __ B(hi, codegen_->GetLabelOf(default_block)); |
| 9848 | |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9849 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9850 | vixl32::Register jump_offset = temps.Acquire(); |
| 9851 | |
| 9852 | // Load jump offset from the table. |
| Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9853 | { |
| 9854 | const size_t jump_size = switch_instr->GetNumEntries() * sizeof(int32_t); |
| 9855 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9856 | (vixl32::kMaxInstructionSizeInBytes * 4) + jump_size, |
| 9857 | CodeBufferCheckScope::kMaximumSize); |
| 9858 | __ adr(table_base, jump_table->GetTableStartLabel()); |
| 9859 | __ ldr(jump_offset, MemOperand(table_base, key_reg, vixl32::LSL, 2)); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9860 | |
| Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9861 | // Jump to target block by branching to table_base(pc related) + offset. |
| 9862 | vixl32::Register target_address = table_base; |
| 9863 | __ add(target_address, table_base, jump_offset); |
| 9864 | __ bx(target_address); |
| Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 9865 | |
| Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9866 | jump_table->EmitTable(codegen_); |
| 9867 | } |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9868 | } |
| 9869 | } |
| 9870 | |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9871 | // Copy the result of a call into the given target. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9872 | void CodeGeneratorARMVIXL::MoveFromReturnRegister(Location trg, DataType::Type type) { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9873 | if (!trg.IsValid()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9874 | DCHECK_EQ(type, DataType::Type::kVoid); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9875 | return; |
| 9876 | } |
| 9877 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9878 | DCHECK_NE(type, DataType::Type::kVoid); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9879 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9880 | Location return_loc = InvokeDexCallingConventionVisitorARMVIXL().GetReturnLocation(type); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9881 | if (return_loc.Equals(trg)) { |
| 9882 | return; |
| 9883 | } |
| 9884 | |
| Vladimir Marko | ac3fcff | 2020-11-17 12:17:58 +0000 | [diff] [blame] | 9885 | // Let the parallel move resolver take care of all of this. |
| 9886 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
| 9887 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 9888 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9889 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9890 | |
| xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9891 | void LocationsBuilderARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 9892 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9893 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9894 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9895 | locations->SetOut(Location::RequiresRegister()); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9896 | } |
| 9897 | |
| xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9898 | void InstructionCodeGeneratorARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 9899 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| 9900 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 9901 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
| 9902 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9903 | OutputRegister(instruction), |
| 9904 | InputRegisterAt(instruction, 0), |
| 9905 | method_offset); |
| 9906 | } else { |
| 9907 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 9908 | instruction->GetIndex(), kArmPointerSize)); |
| 9909 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9910 | OutputRegister(instruction), |
| 9911 | InputRegisterAt(instruction, 0), |
| 9912 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 9913 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9914 | OutputRegister(instruction), |
| 9915 | OutputRegister(instruction), |
| 9916 | method_offset); |
| 9917 | } |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9918 | } |
| 9919 | |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9920 | static void PatchJitRootUse(uint8_t* code, |
| 9921 | const uint8_t* roots_data, |
| 9922 | VIXLUInt32Literal* literal, |
| 9923 | uint64_t index_in_table) { |
| 9924 | DCHECK(literal->IsBound()); |
| 9925 | uint32_t literal_offset = literal->GetLocation(); |
| 9926 | uintptr_t address = |
| 9927 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 9928 | uint8_t* data = code + literal_offset; |
| 9929 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 9930 | } |
| 9931 | |
| 9932 | void CodeGeneratorARMVIXL::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 9933 | for (const auto& entry : jit_string_patches_) { |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9934 | const StringReference& string_reference = entry.first; |
| 9935 | VIXLUInt32Literal* table_entry_literal = entry.second; |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9936 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9937 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9938 | } |
| 9939 | for (const auto& entry : jit_class_patches_) { |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9940 | const TypeReference& type_reference = entry.first; |
| 9941 | VIXLUInt32Literal* table_entry_literal = entry.second; |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9942 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9943 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9944 | } |
| 9945 | } |
| 9946 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9947 | void CodeGeneratorARMVIXL::EmitMovwMovtPlaceholder( |
| 9948 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels, |
| 9949 | vixl32::Register out) { |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 9950 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9951 | 3 * vixl32::kMaxInstructionSizeInBytes, |
| 9952 | CodeBufferCheckScope::kMaximumSize); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9953 | // TODO(VIXL): Think about using mov instead of movw. |
| 9954 | __ bind(&labels->movw_label); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9955 | __ movw(out, /* operand= */ 0u); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9956 | __ bind(&labels->movt_label); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9957 | __ movt(out, /* operand= */ 0u); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9958 | __ bind(&labels->add_pc_label); |
| 9959 | __ add(out, out, pc); |
| 9960 | } |
| 9961 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9962 | #undef __ |
| 9963 | #undef QUICK_ENTRY_POINT |
| 9964 | #undef TODO_VIXL32 |
| 9965 | |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9966 | #define __ assembler.GetVIXLAssembler()-> |
| 9967 | |
| 9968 | static void EmitGrayCheckAndFastPath(ArmVIXLAssembler& assembler, |
| 9969 | vixl32::Register base_reg, |
| 9970 | vixl32::MemOperand& lock_word, |
| 9971 | vixl32::Label* slow_path, |
| Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9972 | int32_t raw_ldr_offset, |
| 9973 | vixl32::Label* throw_npe = nullptr) { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9974 | // Load the lock word containing the rb_state. |
| 9975 | __ Ldr(ip, lock_word); |
| 9976 | // 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] | 9977 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9978 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 9979 | __ Tst(ip, Operand(LockWord::kReadBarrierStateMaskShifted)); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9980 | __ B(ne, slow_path, /* is_far_target= */ false); |
| Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9981 | // To throw NPE, we return to the fast path; the artificial dependence below does not matter. |
| 9982 | if (throw_npe != nullptr) { |
| 9983 | __ Bind(throw_npe); |
| 9984 | } |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9985 | __ Add(lr, lr, raw_ldr_offset); |
| 9986 | // Introduce a dependency on the lock_word including rb_state, |
| 9987 | // to prevent load-load reordering, and without using |
| 9988 | // a memory barrier (which would be more expensive). |
| 9989 | __ Add(base_reg, base_reg, Operand(ip, LSR, 32)); |
| 9990 | __ Bx(lr); // And return back to the function. |
| 9991 | // Note: The fake dependency is unnecessary for the slow path. |
| 9992 | } |
| 9993 | |
| 9994 | // Load the read barrier introspection entrypoint in register `entrypoint` |
| Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 9995 | static vixl32::Register LoadReadBarrierMarkIntrospectionEntrypoint(ArmVIXLAssembler& assembler) { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9996 | // The register where the read barrier introspection entrypoint is loaded |
| Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 9997 | // is the marking register. We clobber it here and the entrypoint restores it to 1. |
| 9998 | vixl32::Register entrypoint = mr; |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9999 | // entrypoint = Thread::Current()->pReadBarrierMarkReg12, i.e. pReadBarrierMarkIntrospection. |
| 10000 | DCHECK_EQ(ip.GetCode(), 12u); |
| 10001 | const int32_t entry_point_offset = |
| 10002 | Thread::ReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ip.GetCode()); |
| 10003 | __ Ldr(entrypoint, MemOperand(tr, entry_point_offset)); |
| Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 10004 | return entrypoint; |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 10005 | } |
| 10006 | |
| 10007 | void CodeGeneratorARMVIXL::CompileBakerReadBarrierThunk(ArmVIXLAssembler& assembler, |
| 10008 | uint32_t encoded_data, |
| 10009 | /*out*/ std::string* debug_name) { |
| 10010 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 10011 | switch (kind) { |
| 10012 | case BakerReadBarrierKind::kField: { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 10013 | vixl32::Register base_reg(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 10014 | CheckValidReg(base_reg.GetCode()); |
| 10015 | vixl32::Register holder_reg(BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 10016 | CheckValidReg(holder_reg.GetCode()); |
| 10017 | BakerReadBarrierWidth width = BakerReadBarrierWidthField::Decode(encoded_data); |
| 10018 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 10019 | temps.Exclude(ip); |
| Roland Levillain | 988c391 | 2019-09-25 19:33:35 +0100 | [diff] [blame] | 10020 | // In the case of a field load, if `base_reg` differs from |
| 10021 | // `holder_reg`, the offset was too large and we must have emitted (during the construction |
| 10022 | // of the HIR graph, see `art::HInstructionBuilder::BuildInstanceFieldAccess`) and preserved |
| 10023 | // (see `art::PrepareForRegisterAllocation::VisitNullCheck`) an explicit null check before |
| 10024 | // the load. Otherwise, for implicit null checks, we need to null-check the holder as we do |
| 10025 | // not necessarily do that check before going to the thunk. |
| Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 10026 | vixl32::Label throw_npe_label; |
| 10027 | vixl32::Label* throw_npe = nullptr; |
| 10028 | if (GetCompilerOptions().GetImplicitNullChecks() && holder_reg.Is(base_reg)) { |
| 10029 | throw_npe = &throw_npe_label; |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 10030 | __ CompareAndBranchIfZero(holder_reg, throw_npe, /* is_far_target= */ false); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 10031 | } |
| Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 10032 | // Check if the holder is gray and, if not, add fake dependency to the base register |
| 10033 | // and return to the LDR instruction to load the reference. Otherwise, use introspection |
| 10034 | // to load the reference and call the entrypoint that performs further checks on the |
| 10035 | // reference and marks it if needed. |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 10036 | vixl32::Label slow_path; |
| 10037 | MemOperand lock_word(holder_reg, mirror::Object::MonitorOffset().Int32Value()); |
| 10038 | const int32_t raw_ldr_offset = (width == BakerReadBarrierWidth::kWide) |
| 10039 | ? BAKER_MARK_INTROSPECTION_FIELD_LDR_WIDE_OFFSET |
| 10040 | : BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_OFFSET; |
| Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 10041 | EmitGrayCheckAndFastPath( |
| 10042 | assembler, base_reg, lock_word, &slow_path, raw_ldr_offset, throw_npe); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 10043 | __ Bind(&slow_path); |
| 10044 | const int32_t ldr_offset = /* Thumb state adjustment (LR contains Thumb state). */ -1 + |
| 10045 | raw_ldr_offset; |
| Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 10046 | vixl32::Register ep_reg = LoadReadBarrierMarkIntrospectionEntrypoint(assembler); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 10047 | if (width == BakerReadBarrierWidth::kWide) { |
| 10048 | MemOperand ldr_half_address(lr, ldr_offset + 2); |
| 10049 | __ Ldrh(ip, ldr_half_address); // Load the LDR immediate half-word with "Rt | imm12". |
| 10050 | __ Ubfx(ip, ip, 0, 12); // Extract the offset imm12. |
| 10051 | __ Ldr(ip, MemOperand(base_reg, ip)); // Load the reference. |
| 10052 | } else { |
| 10053 | MemOperand ldr_address(lr, ldr_offset); |
| 10054 | __ Ldrh(ip, ldr_address); // Load the LDR immediate, encoding T1. |
| 10055 | __ Add(ep_reg, // Adjust the entrypoint address to the entrypoint |
| 10056 | ep_reg, // for narrow LDR. |
| 10057 | Operand(BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_ENTRYPOINT_OFFSET)); |
| 10058 | __ Ubfx(ip, ip, 6, 5); // Extract the imm5, i.e. offset / 4. |
| 10059 | __ Ldr(ip, MemOperand(base_reg, ip, LSL, 2)); // Load the reference. |
| 10060 | } |
| 10061 | // Do not unpoison. With heap poisoning enabled, the entrypoint expects a poisoned reference. |
| 10062 | __ Bx(ep_reg); // Jump to the entrypoint. |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 10063 | break; |
| 10064 | } |
| 10065 | case BakerReadBarrierKind::kArray: { |
| 10066 | vixl32::Register base_reg(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 10067 | CheckValidReg(base_reg.GetCode()); |
| 10068 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 10069 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 10070 | DCHECK(BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide); |
| 10071 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 10072 | temps.Exclude(ip); |
| 10073 | vixl32::Label slow_path; |
| 10074 | int32_t data_offset = |
| 10075 | mirror::Array::DataOffset(Primitive::ComponentSize(Primitive::kPrimNot)).Int32Value(); |
| 10076 | MemOperand lock_word(base_reg, mirror::Object::MonitorOffset().Int32Value() - data_offset); |
| 10077 | DCHECK_LT(lock_word.GetOffsetImmediate(), 0); |
| 10078 | const int32_t raw_ldr_offset = BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET; |
| 10079 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path, raw_ldr_offset); |
| 10080 | __ Bind(&slow_path); |
| 10081 | const int32_t ldr_offset = /* Thumb state adjustment (LR contains Thumb state). */ -1 + |
| 10082 | raw_ldr_offset; |
| 10083 | MemOperand ldr_address(lr, ldr_offset + 2); |
| 10084 | __ Ldrb(ip, ldr_address); // Load the LDR (register) byte with "00 | imm2 | Rm", |
| 10085 | // i.e. Rm+32 because the scale in imm2 is 2. |
| Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 10086 | vixl32::Register ep_reg = LoadReadBarrierMarkIntrospectionEntrypoint(assembler); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 10087 | __ Bfi(ep_reg, ip, 3, 6); // Insert ip to the entrypoint address to create |
| 10088 | // a switch case target based on the index register. |
| 10089 | __ Mov(ip, base_reg); // Move the base register to ip0. |
| 10090 | __ Bx(ep_reg); // Jump to the entrypoint's array switch case. |
| 10091 | break; |
| 10092 | } |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 10093 | case BakerReadBarrierKind::kGcRoot: |
| Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 10094 | case BakerReadBarrierKind::kIntrinsicCas: { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 10095 | // Check if the reference needs to be marked and if so (i.e. not null, not marked yet |
| 10096 | // and it does not have a forwarding address), call the correct introspection entrypoint; |
| 10097 | // otherwise return the reference (or the extracted forwarding address). |
| 10098 | // There is no gray bit check for GC roots. |
| 10099 | vixl32::Register root_reg(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 10100 | CheckValidReg(root_reg.GetCode()); |
| 10101 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 10102 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 10103 | BakerReadBarrierWidth width = BakerReadBarrierWidthField::Decode(encoded_data); |
| 10104 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 10105 | temps.Exclude(ip); |
| 10106 | vixl32::Label return_label, not_marked, forwarding_address; |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 10107 | __ CompareAndBranchIfZero(root_reg, &return_label, /* is_far_target= */ false); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 10108 | MemOperand lock_word(root_reg, mirror::Object::MonitorOffset().Int32Value()); |
| 10109 | __ Ldr(ip, lock_word); |
| 10110 | __ Tst(ip, LockWord::kMarkBitStateMaskShifted); |
| 10111 | __ B(eq, ¬_marked); |
| 10112 | __ Bind(&return_label); |
| 10113 | __ Bx(lr); |
| 10114 | __ Bind(¬_marked); |
| 10115 | static_assert(LockWord::kStateShift == 30 && LockWord::kStateForwardingAddress == 3, |
| 10116 | "To use 'CMP ip, #modified-immediate; BHS', we need the lock word state in " |
| 10117 | " the highest bits and the 'forwarding address' state to have all bits set"); |
| 10118 | __ Cmp(ip, Operand(0xc0000000)); |
| 10119 | __ B(hs, &forwarding_address); |
| Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 10120 | vixl32::Register ep_reg = LoadReadBarrierMarkIntrospectionEntrypoint(assembler); |
| Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 10121 | // Adjust the art_quick_read_barrier_mark_introspection address |
| 10122 | // in kBakerCcEntrypointRegister to one of |
| 10123 | // art_quick_read_barrier_mark_introspection_{gc_roots_{wide,narrow},intrinsic_cas}. |
| 10124 | if (kind == BakerReadBarrierKind::kIntrinsicCas) { |
| 10125 | DCHECK(width == BakerReadBarrierWidth::kWide); |
| 10126 | DCHECK(!root_reg.IsLow()); |
| 10127 | } |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 10128 | int32_t entrypoint_offset = |
| 10129 | (kind == BakerReadBarrierKind::kGcRoot) |
| 10130 | ? (width == BakerReadBarrierWidth::kWide) |
| 10131 | ? BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_ENTRYPOINT_OFFSET |
| 10132 | : BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_ENTRYPOINT_OFFSET |
| Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 10133 | : BAKER_MARK_INTROSPECTION_INTRINSIC_CAS_ENTRYPOINT_OFFSET; |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 10134 | __ Add(ep_reg, ep_reg, Operand(entrypoint_offset)); |
| 10135 | __ Mov(ip, root_reg); |
| 10136 | __ Bx(ep_reg); |
| 10137 | __ Bind(&forwarding_address); |
| 10138 | __ Lsl(root_reg, ip, LockWord::kForwardingAddressShift); |
| 10139 | __ Bx(lr); |
| 10140 | break; |
| 10141 | } |
| 10142 | default: |
| 10143 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 10144 | UNREACHABLE(); |
| 10145 | } |
| 10146 | |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 10147 | // For JIT, the slow path is considered part of the compiled method, |
| Vladimir Marko | f91fc12 | 2020-05-13 09:21:00 +0100 | [diff] [blame] | 10148 | // so JIT should pass null as `debug_name`. |
| Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 10149 | DCHECK(!GetCompilerOptions().IsJitCompiler() || debug_name == nullptr); |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 10150 | if (debug_name != nullptr && GetCompilerOptions().GenerateAnyDebugInfo()) { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 10151 | std::ostringstream oss; |
| 10152 | oss << "BakerReadBarrierThunk"; |
| 10153 | switch (kind) { |
| 10154 | case BakerReadBarrierKind::kField: |
| 10155 | oss << "Field"; |
| 10156 | if (BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide) { |
| 10157 | oss << "Wide"; |
| 10158 | } |
| 10159 | oss << "_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 10160 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 10161 | break; |
| 10162 | case BakerReadBarrierKind::kArray: |
| 10163 | oss << "Array_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 10164 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 10165 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 10166 | DCHECK(BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide); |
| 10167 | break; |
| 10168 | case BakerReadBarrierKind::kGcRoot: |
| 10169 | oss << "GcRoot"; |
| 10170 | if (BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide) { |
| 10171 | oss << "Wide"; |
| 10172 | } |
| 10173 | oss << "_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 10174 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 10175 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 10176 | break; |
| Vladimir Marko | 3d350a8 | 2020-11-18 14:14:27 +0000 | [diff] [blame] | 10177 | case BakerReadBarrierKind::kIntrinsicCas: |
| 10178 | oss << "IntrinsicCas_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 10179 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 10180 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 10181 | DCHECK(BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide); |
| 10182 | break; |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 10183 | } |
| 10184 | *debug_name = oss.str(); |
| 10185 | } |
| 10186 | } |
| 10187 | |
| 10188 | #undef __ |
| 10189 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 10190 | } // namespace arm |
| 10191 | } // namespace art |