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" |
| 21 | #include "art_method.h" |
Andreas Gampe | 5678db5 | 2017-06-08 14:11:18 -0700 | [diff] [blame] | 22 | #include "base/bit_utils.h" |
| 23 | #include "base/bit_utils_iterator.h" |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 24 | #include "class_table.h" |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 25 | #include "code_generator_utils.h" |
| 26 | #include "common_arm.h" |
| 27 | #include "compiled_method.h" |
| 28 | #include "entrypoints/quick/quick_entrypoints.h" |
| 29 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 30 | #include "heap_poisoning.h" |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 31 | #include "intrinsics_arm_vixl.h" |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 32 | #include "linker/arm/relative_patcher_thumb2.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 33 | #include "linker/linker_patch.h" |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 34 | #include "mirror/array-inl.h" |
| 35 | #include "mirror/class-inl.h" |
| 36 | #include "thread.h" |
| 37 | #include "utils/arm/assembler_arm_vixl.h" |
| 38 | #include "utils/arm/managed_register_arm.h" |
| 39 | #include "utils/assembler.h" |
| 40 | #include "utils/stack_checks.h" |
| 41 | |
| 42 | namespace art { |
| 43 | namespace arm { |
| 44 | |
| 45 | namespace vixl32 = vixl::aarch32; |
| 46 | using namespace vixl32; // NOLINT(build/namespaces) |
| 47 | |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 48 | using helpers::DRegisterFrom; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 49 | using helpers::DWARFReg; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 50 | using helpers::HighDRegisterFrom; |
| 51 | using helpers::HighRegisterFrom; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 52 | using helpers::InputDRegisterAt; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 53 | using helpers::InputOperandAt; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 54 | using helpers::InputRegister; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 55 | using helpers::InputRegisterAt; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 56 | using helpers::InputSRegisterAt; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 57 | using helpers::InputVRegister; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 58 | using helpers::InputVRegisterAt; |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 59 | using helpers::Int32ConstantFrom; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 60 | using helpers::Int64ConstantFrom; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 61 | using helpers::LocationFrom; |
| 62 | using helpers::LowRegisterFrom; |
| 63 | using helpers::LowSRegisterFrom; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 64 | using helpers::OperandFrom; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 65 | using helpers::OutputRegister; |
| 66 | using helpers::OutputSRegister; |
| 67 | using helpers::OutputVRegister; |
| 68 | using helpers::RegisterFrom; |
| 69 | using helpers::SRegisterFrom; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 70 | using helpers::Uint64ConstantFrom; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 71 | |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 72 | using vixl::ExactAssemblyScope; |
| 73 | using vixl::CodeBufferCheckScope; |
| 74 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 75 | using RegisterList = vixl32::RegisterList; |
| 76 | |
| 77 | static bool ExpectedPairLayout(Location location) { |
| 78 | // We expected this for both core and fpu register pairs. |
| 79 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 80 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 81 | // Use a local definition to prevent copying mistakes. |
| 82 | static constexpr size_t kArmWordSize = static_cast<size_t>(kArmPointerSize); |
| 83 | static constexpr size_t kArmBitsPerWord = kArmWordSize * kBitsPerByte; |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 84 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 85 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 86 | // Reference load (except object array loads) is using LDR Rt, [Rn, #offset] which can handle |
| 87 | // offset < 4KiB. For offsets >= 4KiB, the load shall be emitted as two or more instructions. |
| 88 | // For the Baker read barrier implementation using link-generated thunks we need to split |
| 89 | // the offset explicitly. |
| 90 | constexpr uint32_t kReferenceLoadMinFarOffset = 4 * KB; |
| 91 | |
| 92 | // Flags controlling the use of link-time generated thunks for Baker read barriers. |
| 93 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForFields = true; |
| 94 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForArrays = true; |
| 95 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForGcRoots = true; |
| 96 | |
| 97 | // The reserved entrypoint register for link-time generated thunks. |
| 98 | const vixl32::Register kBakerCcEntrypointRegister = r4; |
| 99 | |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 100 | // Using a base helps identify when we hit Marking Register check breakpoints. |
| 101 | constexpr int kMarkingRegisterCheckBreakCodeBaseCode = 0x10; |
| 102 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 103 | #ifdef __ |
| 104 | #error "ARM Codegen VIXL macro-assembler macro already defined." |
| 105 | #endif |
| 106 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 107 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 108 | #define __ down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()-> // NOLINT |
| 109 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, x).Int32Value() |
| 110 | |
| 111 | // Marker that code is yet to be, and must, be implemented. |
| 112 | #define TODO_VIXL32(level) LOG(level) << __PRETTY_FUNCTION__ << " unimplemented " |
| 113 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 114 | static inline void ExcludeIPAndBakerCcEntrypointRegister(UseScratchRegisterScope* temps, |
| 115 | HInstruction* instruction) { |
| 116 | DCHECK(temps->IsAvailable(ip)); |
| 117 | temps->Exclude(ip); |
| 118 | DCHECK(!temps->IsAvailable(kBakerCcEntrypointRegister)); |
| 119 | DCHECK_EQ(kBakerCcEntrypointRegister.GetCode(), |
| 120 | linker::Thumb2RelativePatcher::kBakerCcEntrypointRegister); |
| 121 | DCHECK_NE(instruction->GetLocations()->GetTempCount(), 0u); |
| 122 | DCHECK(RegisterFrom(instruction->GetLocations()->GetTemp( |
| 123 | instruction->GetLocations()->GetTempCount() - 1u)).Is(kBakerCcEntrypointRegister)); |
| 124 | } |
| 125 | |
| 126 | static inline void EmitPlaceholderBne(CodeGeneratorARMVIXL* codegen, vixl32::Label* patch_label) { |
| 127 | ExactAssemblyScope eas(codegen->GetVIXLAssembler(), kMaxInstructionSizeInBytes); |
| 128 | __ bind(patch_label); |
| 129 | vixl32::Label placeholder_label; |
| 130 | __ b(ne, EncodingSize(Wide), &placeholder_label); // Placeholder, patched at link-time. |
| 131 | __ bind(&placeholder_label); |
| 132 | } |
| 133 | |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 134 | static inline bool CanEmitNarrowLdr(vixl32::Register rt, vixl32::Register rn, uint32_t offset) { |
| 135 | return rt.IsLow() && rn.IsLow() && offset < 32u; |
| 136 | } |
| 137 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 138 | class EmitAdrCode { |
| 139 | public: |
| 140 | EmitAdrCode(ArmVIXLMacroAssembler* assembler, vixl32::Register rd, vixl32::Label* label) |
| 141 | : assembler_(assembler), rd_(rd), label_(label) { |
| 142 | ExactAssemblyScope aas(assembler, kMaxInstructionSizeInBytes); |
| 143 | adr_location_ = assembler->GetCursorOffset(); |
| 144 | assembler->adr(EncodingSize(Wide), rd, label); |
| 145 | } |
| 146 | |
| 147 | ~EmitAdrCode() { |
| 148 | DCHECK(label_->IsBound()); |
| 149 | // The ADR emitted by the assembler does not set the Thumb mode bit we need. |
| 150 | // TODO: Maybe extend VIXL to allow ADR for return address? |
| 151 | uint8_t* raw_adr = assembler_->GetBuffer()->GetOffsetAddress<uint8_t*>(adr_location_); |
| 152 | // Expecting ADR encoding T3 with `(offset & 1) == 0`. |
| 153 | DCHECK_EQ(raw_adr[1] & 0xfbu, 0xf2u); // Check bits 24-31, except 26. |
| 154 | DCHECK_EQ(raw_adr[0] & 0xffu, 0x0fu); // Check bits 16-23. |
| 155 | DCHECK_EQ(raw_adr[3] & 0x8fu, rd_.GetCode()); // Check bits 8-11 and 15. |
| 156 | DCHECK_EQ(raw_adr[2] & 0x01u, 0x00u); // Check bit 0, i.e. the `offset & 1`. |
| 157 | // Add the Thumb mode bit. |
| 158 | raw_adr[2] |= 0x01u; |
| 159 | } |
| 160 | |
| 161 | private: |
| 162 | ArmVIXLMacroAssembler* const assembler_; |
| 163 | vixl32::Register rd_; |
| 164 | vixl32::Label* const label_; |
| 165 | int32_t adr_location_; |
| 166 | }; |
| 167 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 168 | // SaveLiveRegisters and RestoreLiveRegisters from SlowPathCodeARM operate on sets of S registers, |
| 169 | // for each live D registers they treat two corresponding S registers as live ones. |
| 170 | // |
| 171 | // Two following functions (SaveContiguousSRegisterList, RestoreContiguousSRegisterList) build |
| 172 | // from a list of contiguous S registers a list of contiguous D registers (processing first/last |
| 173 | // S registers corner cases) and save/restore this new list treating them as D registers. |
| 174 | // - decreasing code size |
| 175 | // - avoiding hazards on Cortex-A57, when a pair of S registers for an actual live D register is |
| 176 | // restored and then used in regular non SlowPath code as D register. |
| 177 | // |
| 178 | // For the following example (v means the S register is live): |
| 179 | // D names: | D0 | D1 | D2 | D4 | ... |
| 180 | // S names: | S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | ... |
| 181 | // Live? | | v | v | v | v | v | v | | ... |
| 182 | // |
| 183 | // S1 and S6 will be saved/restored independently; D registers list (D1, D2) will be processed |
| 184 | // as D registers. |
| 185 | // |
| 186 | // TODO(VIXL): All this code should be unnecessary once the VIXL AArch32 backend provides helpers |
| 187 | // for lists of floating-point registers. |
| 188 | static size_t SaveContiguousSRegisterList(size_t first, |
| 189 | size_t last, |
| 190 | CodeGenerator* codegen, |
| 191 | size_t stack_offset) { |
| 192 | static_assert(kSRegSizeInBytes == kArmWordSize, "Broken assumption on reg/word sizes."); |
| 193 | static_assert(kDRegSizeInBytes == 2 * kArmWordSize, "Broken assumption on reg/word sizes."); |
| 194 | DCHECK_LE(first, last); |
| 195 | if ((first == last) && (first == 0)) { |
| 196 | __ Vstr(vixl32::SRegister(first), MemOperand(sp, stack_offset)); |
| 197 | return stack_offset + kSRegSizeInBytes; |
| 198 | } |
| 199 | if (first % 2 == 1) { |
| 200 | __ Vstr(vixl32::SRegister(first++), MemOperand(sp, stack_offset)); |
| 201 | stack_offset += kSRegSizeInBytes; |
| 202 | } |
| 203 | |
| 204 | bool save_last = false; |
| 205 | if (last % 2 == 0) { |
| 206 | save_last = true; |
| 207 | --last; |
| 208 | } |
| 209 | |
| 210 | if (first < last) { |
| 211 | vixl32::DRegister d_reg = vixl32::DRegister(first / 2); |
| 212 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 213 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 214 | |
| 215 | if (number_of_d_regs == 1) { |
| 216 | __ Vstr(d_reg, MemOperand(sp, stack_offset)); |
| 217 | } else if (number_of_d_regs > 1) { |
| 218 | UseScratchRegisterScope temps(down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 219 | vixl32::Register base = sp; |
| 220 | if (stack_offset != 0) { |
| 221 | base = temps.Acquire(); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 222 | __ Add(base, sp, Operand::From(stack_offset)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 223 | } |
| 224 | __ Vstm(F64, base, NO_WRITE_BACK, DRegisterList(d_reg, number_of_d_regs)); |
| 225 | } |
| 226 | stack_offset += number_of_d_regs * kDRegSizeInBytes; |
| 227 | } |
| 228 | |
| 229 | if (save_last) { |
| 230 | __ Vstr(vixl32::SRegister(last + 1), MemOperand(sp, stack_offset)); |
| 231 | stack_offset += kSRegSizeInBytes; |
| 232 | } |
| 233 | |
| 234 | return stack_offset; |
| 235 | } |
| 236 | |
| 237 | static size_t RestoreContiguousSRegisterList(size_t first, |
| 238 | size_t last, |
| 239 | CodeGenerator* codegen, |
| 240 | size_t stack_offset) { |
| 241 | static_assert(kSRegSizeInBytes == kArmWordSize, "Broken assumption on reg/word sizes."); |
| 242 | static_assert(kDRegSizeInBytes == 2 * kArmWordSize, "Broken assumption on reg/word sizes."); |
| 243 | DCHECK_LE(first, last); |
| 244 | if ((first == last) && (first == 0)) { |
| 245 | __ Vldr(vixl32::SRegister(first), MemOperand(sp, stack_offset)); |
| 246 | return stack_offset + kSRegSizeInBytes; |
| 247 | } |
| 248 | if (first % 2 == 1) { |
| 249 | __ Vldr(vixl32::SRegister(first++), MemOperand(sp, stack_offset)); |
| 250 | stack_offset += kSRegSizeInBytes; |
| 251 | } |
| 252 | |
| 253 | bool restore_last = false; |
| 254 | if (last % 2 == 0) { |
| 255 | restore_last = true; |
| 256 | --last; |
| 257 | } |
| 258 | |
| 259 | if (first < last) { |
| 260 | vixl32::DRegister d_reg = vixl32::DRegister(first / 2); |
| 261 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 262 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 263 | if (number_of_d_regs == 1) { |
| 264 | __ Vldr(d_reg, MemOperand(sp, stack_offset)); |
| 265 | } else if (number_of_d_regs > 1) { |
| 266 | UseScratchRegisterScope temps(down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 267 | vixl32::Register base = sp; |
| 268 | if (stack_offset != 0) { |
| 269 | base = temps.Acquire(); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 270 | __ Add(base, sp, Operand::From(stack_offset)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 271 | } |
| 272 | __ Vldm(F64, base, NO_WRITE_BACK, DRegisterList(d_reg, number_of_d_regs)); |
| 273 | } |
| 274 | stack_offset += number_of_d_regs * kDRegSizeInBytes; |
| 275 | } |
| 276 | |
| 277 | if (restore_last) { |
| 278 | __ Vldr(vixl32::SRegister(last + 1), MemOperand(sp, stack_offset)); |
| 279 | stack_offset += kSRegSizeInBytes; |
| 280 | } |
| 281 | |
| 282 | return stack_offset; |
| 283 | } |
| 284 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 285 | static LoadOperandType GetLoadOperandType(DataType::Type type) { |
| 286 | switch (type) { |
| 287 | case DataType::Type::kReference: |
| 288 | return kLoadWord; |
| 289 | case DataType::Type::kBool: |
| 290 | case DataType::Type::kUint8: |
| 291 | return kLoadUnsignedByte; |
| 292 | case DataType::Type::kInt8: |
| 293 | return kLoadSignedByte; |
| 294 | case DataType::Type::kUint16: |
| 295 | return kLoadUnsignedHalfword; |
| 296 | case DataType::Type::kInt16: |
| 297 | return kLoadSignedHalfword; |
| 298 | case DataType::Type::kInt32: |
| 299 | return kLoadWord; |
| 300 | case DataType::Type::kInt64: |
| 301 | return kLoadWordPair; |
| 302 | case DataType::Type::kFloat32: |
| 303 | return kLoadSWord; |
| 304 | case DataType::Type::kFloat64: |
| 305 | return kLoadDWord; |
| 306 | default: |
| 307 | LOG(FATAL) << "Unreachable type " << type; |
| 308 | UNREACHABLE(); |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | static StoreOperandType GetStoreOperandType(DataType::Type type) { |
| 313 | switch (type) { |
| 314 | case DataType::Type::kReference: |
| 315 | return kStoreWord; |
| 316 | case DataType::Type::kBool: |
| 317 | case DataType::Type::kUint8: |
| 318 | case DataType::Type::kInt8: |
| 319 | return kStoreByte; |
| 320 | case DataType::Type::kUint16: |
| 321 | case DataType::Type::kInt16: |
| 322 | return kStoreHalfword; |
| 323 | case DataType::Type::kInt32: |
| 324 | return kStoreWord; |
| 325 | case DataType::Type::kInt64: |
| 326 | return kStoreWordPair; |
| 327 | case DataType::Type::kFloat32: |
| 328 | return kStoreSWord; |
| 329 | case DataType::Type::kFloat64: |
| 330 | return kStoreDWord; |
| 331 | default: |
| 332 | LOG(FATAL) << "Unreachable type " << type; |
| 333 | UNREACHABLE(); |
| 334 | } |
| 335 | } |
| 336 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 337 | void SlowPathCodeARMVIXL::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 338 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 339 | size_t orig_offset = stack_offset; |
| 340 | |
| 341 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 342 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 343 | // If the register holds an object, update the stack mask. |
| 344 | if (locations->RegisterContainsObject(i)) { |
| 345 | locations->SetStackBit(stack_offset / kVRegSize); |
| 346 | } |
| 347 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 348 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 349 | saved_core_stack_offsets_[i] = stack_offset; |
| 350 | stack_offset += kArmWordSize; |
| 351 | } |
| 352 | |
| 353 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 354 | arm_codegen->GetAssembler()->StoreRegisterList(core_spills, orig_offset); |
| 355 | |
| 356 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 357 | orig_offset = stack_offset; |
| 358 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 359 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 360 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 361 | stack_offset += kArmWordSize; |
| 362 | } |
| 363 | |
| 364 | stack_offset = orig_offset; |
| 365 | while (fp_spills != 0u) { |
| 366 | uint32_t begin = CTZ(fp_spills); |
| 367 | uint32_t tmp = fp_spills + (1u << begin); |
| 368 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 369 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 370 | stack_offset = SaveContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 371 | } |
| 372 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 373 | } |
| 374 | |
| 375 | void SlowPathCodeARMVIXL::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 376 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 377 | size_t orig_offset = stack_offset; |
| 378 | |
| 379 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 380 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 381 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 382 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 383 | stack_offset += kArmWordSize; |
| 384 | } |
| 385 | |
| 386 | // TODO(VIXL): Check the coherency of stack_offset after this with a test. |
| 387 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 388 | arm_codegen->GetAssembler()->LoadRegisterList(core_spills, orig_offset); |
| 389 | |
| 390 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 391 | while (fp_spills != 0u) { |
| 392 | uint32_t begin = CTZ(fp_spills); |
| 393 | uint32_t tmp = fp_spills + (1u << begin); |
| 394 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 395 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 396 | stack_offset = RestoreContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 397 | } |
| 398 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 399 | } |
| 400 | |
| 401 | class NullCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 402 | public: |
| 403 | explicit NullCheckSlowPathARMVIXL(HNullCheck* instruction) : SlowPathCodeARMVIXL(instruction) {} |
| 404 | |
| 405 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 406 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 407 | __ Bind(GetEntryLabel()); |
| 408 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 409 | // Live registers will be restored in the catch block if caught. |
| 410 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 411 | } |
| 412 | arm_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 413 | instruction_, |
| 414 | instruction_->GetDexPc(), |
| 415 | this); |
| 416 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| 417 | } |
| 418 | |
| 419 | bool IsFatal() const OVERRIDE { return true; } |
| 420 | |
| 421 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARMVIXL"; } |
| 422 | |
| 423 | private: |
| 424 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARMVIXL); |
| 425 | }; |
| 426 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 427 | class DivZeroCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 428 | public: |
| 429 | explicit DivZeroCheckSlowPathARMVIXL(HDivZeroCheck* instruction) |
| 430 | : SlowPathCodeARMVIXL(instruction) {} |
| 431 | |
| 432 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 433 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 434 | __ Bind(GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 435 | arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 436 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| 437 | } |
| 438 | |
| 439 | bool IsFatal() const OVERRIDE { return true; } |
| 440 | |
| 441 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARMVIXL"; } |
| 442 | |
| 443 | private: |
| 444 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARMVIXL); |
| 445 | }; |
| 446 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 447 | class SuspendCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 448 | public: |
| 449 | SuspendCheckSlowPathARMVIXL(HSuspendCheck* instruction, HBasicBlock* successor) |
| 450 | : SlowPathCodeARMVIXL(instruction), successor_(successor) {} |
| 451 | |
| 452 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 453 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 454 | __ Bind(GetEntryLabel()); |
| 455 | arm_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
| 456 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
| 457 | if (successor_ == nullptr) { |
| 458 | __ B(GetReturnLabel()); |
| 459 | } else { |
| 460 | __ B(arm_codegen->GetLabelOf(successor_)); |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | vixl32::Label* GetReturnLabel() { |
| 465 | DCHECK(successor_ == nullptr); |
| 466 | return &return_label_; |
| 467 | } |
| 468 | |
| 469 | HBasicBlock* GetSuccessor() const { |
| 470 | return successor_; |
| 471 | } |
| 472 | |
| 473 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARMVIXL"; } |
| 474 | |
| 475 | private: |
| 476 | // If not null, the block to branch to after the suspend check. |
| 477 | HBasicBlock* const successor_; |
| 478 | |
| 479 | // If `successor_` is null, the label to branch to after the suspend check. |
| 480 | vixl32::Label return_label_; |
| 481 | |
| 482 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARMVIXL); |
| 483 | }; |
| 484 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 485 | class BoundsCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 486 | public: |
| 487 | explicit BoundsCheckSlowPathARMVIXL(HBoundsCheck* instruction) |
| 488 | : SlowPathCodeARMVIXL(instruction) {} |
| 489 | |
| 490 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 491 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 492 | LocationSummary* locations = instruction_->GetLocations(); |
| 493 | |
| 494 | __ Bind(GetEntryLabel()); |
| 495 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 496 | // Live registers will be restored in the catch block if caught. |
| 497 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 498 | } |
| 499 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 500 | // move resolver. |
| 501 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 502 | codegen->EmitParallelMoves( |
| 503 | locations->InAt(0), |
| 504 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 505 | DataType::Type::kInt32, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 506 | locations->InAt(1), |
| 507 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 508 | DataType::Type::kInt32); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 509 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 510 | ? kQuickThrowStringBounds |
| 511 | : kQuickThrowArrayBounds; |
| 512 | arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
| 513 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
| 514 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| 515 | } |
| 516 | |
| 517 | bool IsFatal() const OVERRIDE { return true; } |
| 518 | |
| 519 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARMVIXL"; } |
| 520 | |
| 521 | private: |
| 522 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARMVIXL); |
| 523 | }; |
| 524 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 525 | class LoadClassSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 526 | public: |
| 527 | LoadClassSlowPathARMVIXL(HLoadClass* cls, HInstruction* at, uint32_t dex_pc, bool do_clinit) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 528 | : SlowPathCodeARMVIXL(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 529 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 530 | } |
| 531 | |
| 532 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 533 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 534 | Location out = locations->Out(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 535 | |
| 536 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 537 | __ Bind(GetEntryLabel()); |
| 538 | SaveLiveRegisters(codegen, locations); |
| 539 | |
| 540 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 541 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 542 | __ Mov(calling_convention.GetRegisterAt(0), type_index.index_); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 543 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 544 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 545 | arm_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 546 | if (do_clinit_) { |
| 547 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 548 | } else { |
| 549 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 550 | } |
| 551 | |
| 552 | // Move the class to the desired location. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 553 | if (out.IsValid()) { |
| 554 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 555 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
| 556 | } |
| 557 | RestoreLiveRegisters(codegen, locations); |
| 558 | __ B(GetExitLabel()); |
| 559 | } |
| 560 | |
| 561 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARMVIXL"; } |
| 562 | |
| 563 | private: |
| 564 | // The class this slow path will load. |
| 565 | HLoadClass* const cls_; |
| 566 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 567 | // The dex PC of `at_`. |
| 568 | const uint32_t dex_pc_; |
| 569 | |
| 570 | // Whether to initialize the class. |
| 571 | const bool do_clinit_; |
| 572 | |
| 573 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARMVIXL); |
| 574 | }; |
| 575 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 576 | class LoadStringSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 577 | public: |
| 578 | explicit LoadStringSlowPathARMVIXL(HLoadString* instruction) |
| 579 | : SlowPathCodeARMVIXL(instruction) {} |
| 580 | |
| 581 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 582 | DCHECK(instruction_->IsLoadString()); |
| 583 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 584 | LocationSummary* locations = instruction_->GetLocations(); |
| 585 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 586 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 587 | |
| 588 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 589 | __ Bind(GetEntryLabel()); |
| 590 | SaveLiveRegisters(codegen, locations); |
| 591 | |
| 592 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 593 | __ Mov(calling_convention.GetRegisterAt(0), string_index.index_); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 594 | arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 595 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 596 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 597 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
| 598 | RestoreLiveRegisters(codegen, locations); |
| 599 | |
| 600 | __ B(GetExitLabel()); |
| 601 | } |
| 602 | |
| 603 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARMVIXL"; } |
| 604 | |
| 605 | private: |
| 606 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARMVIXL); |
| 607 | }; |
| 608 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 609 | class TypeCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 610 | public: |
| 611 | TypeCheckSlowPathARMVIXL(HInstruction* instruction, bool is_fatal) |
| 612 | : SlowPathCodeARMVIXL(instruction), is_fatal_(is_fatal) {} |
| 613 | |
| 614 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 615 | LocationSummary* locations = instruction_->GetLocations(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 616 | DCHECK(instruction_->IsCheckCast() |
| 617 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 618 | |
| 619 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 620 | __ Bind(GetEntryLabel()); |
| 621 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 622 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 623 | SaveLiveRegisters(codegen, locations); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 627 | // move resolver. |
| 628 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 629 | |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 630 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 631 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 632 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 633 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 634 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 635 | DataType::Type::kReference); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 636 | if (instruction_->IsInstanceOf()) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 637 | arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
| 638 | instruction_, |
| 639 | instruction_->GetDexPc(), |
| 640 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 641 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 642 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 643 | } else { |
| 644 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 645 | arm_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 646 | instruction_, |
| 647 | instruction_->GetDexPc(), |
| 648 | this); |
| 649 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | if (!is_fatal_) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 653 | RestoreLiveRegisters(codegen, locations); |
| 654 | __ B(GetExitLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 655 | } |
| 656 | } |
| 657 | |
| 658 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARMVIXL"; } |
| 659 | |
| 660 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 661 | |
| 662 | private: |
| 663 | const bool is_fatal_; |
| 664 | |
| 665 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARMVIXL); |
| 666 | }; |
| 667 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 668 | class DeoptimizationSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 669 | public: |
| 670 | explicit DeoptimizationSlowPathARMVIXL(HDeoptimize* instruction) |
| 671 | : SlowPathCodeARMVIXL(instruction) {} |
| 672 | |
| 673 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 674 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 675 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 676 | LocationSummary* locations = instruction_->GetLocations(); |
| 677 | SaveLiveRegisters(codegen, locations); |
| 678 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 679 | __ Mov(calling_convention.GetRegisterAt(0), |
| 680 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
| 681 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 682 | arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 683 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARMVIXL"; } |
| 687 | |
| 688 | private: |
| 689 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARMVIXL); |
| 690 | }; |
| 691 | |
| 692 | class ArraySetSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 693 | public: |
| 694 | explicit ArraySetSlowPathARMVIXL(HInstruction* instruction) : SlowPathCodeARMVIXL(instruction) {} |
| 695 | |
| 696 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 697 | LocationSummary* locations = instruction_->GetLocations(); |
| 698 | __ Bind(GetEntryLabel()); |
| 699 | SaveLiveRegisters(codegen, locations); |
| 700 | |
| 701 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 702 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 703 | parallel_move.AddMove( |
| 704 | locations->InAt(0), |
| 705 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 706 | DataType::Type::kReference, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 707 | nullptr); |
| 708 | parallel_move.AddMove( |
| 709 | locations->InAt(1), |
| 710 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 711 | DataType::Type::kInt32, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 712 | nullptr); |
| 713 | parallel_move.AddMove( |
| 714 | locations->InAt(2), |
| 715 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 716 | DataType::Type::kReference, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 717 | nullptr); |
| 718 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 719 | |
| 720 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 721 | arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| 722 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 723 | RestoreLiveRegisters(codegen, locations); |
| 724 | __ B(GetExitLabel()); |
| 725 | } |
| 726 | |
| 727 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARMVIXL"; } |
| 728 | |
| 729 | private: |
| 730 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARMVIXL); |
| 731 | }; |
| 732 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 733 | // Abstract base class for read barrier slow paths marking a reference |
| 734 | // `ref`. |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 735 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 736 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 737 | // barrier marking runtime entry point to be invoked or an empty |
| 738 | // location; in the latter case, the read barrier marking runtime |
| 739 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 740 | class ReadBarrierMarkSlowPathBaseARMVIXL : public SlowPathCodeARMVIXL { |
| 741 | protected: |
| 742 | ReadBarrierMarkSlowPathBaseARMVIXL(HInstruction* instruction, Location ref, Location entrypoint) |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 743 | : SlowPathCodeARMVIXL(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 744 | DCHECK(kEmitCompilerReadBarrier); |
| 745 | } |
| 746 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 747 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathBaseARMVIXL"; } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 748 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 749 | // Generate assembly code calling the read barrier marking runtime |
| 750 | // entry point (ReadBarrierMarkRegX). |
| 751 | void GenerateReadBarrierMarkRuntimeCall(CodeGenerator* codegen) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 752 | vixl32::Register ref_reg = RegisterFrom(ref_); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 753 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 754 | // No need to save live registers; it's taken care of by the |
| 755 | // entrypoint. Also, there is no need to update the stack mask, |
| 756 | // as this runtime call will not trigger a garbage collection. |
| 757 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 758 | DCHECK(!ref_reg.Is(sp)); |
| 759 | DCHECK(!ref_reg.Is(lr)); |
| 760 | DCHECK(!ref_reg.Is(pc)); |
| 761 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 762 | // as a temporary, it cannot be the entry point's input/output. |
| 763 | DCHECK(!ref_reg.Is(ip)); |
| 764 | DCHECK(ref_reg.IsRegister()) << ref_reg; |
| 765 | // "Compact" slow path, saving two moves. |
| 766 | // |
| 767 | // Instead of using the standard runtime calling convention (input |
| 768 | // and output in R0): |
| 769 | // |
| 770 | // R0 <- ref |
| 771 | // R0 <- ReadBarrierMark(R0) |
| 772 | // ref <- R0 |
| 773 | // |
| 774 | // we just use rX (the register containing `ref`) as input and output |
| 775 | // of a dedicated entrypoint: |
| 776 | // |
| 777 | // rX <- ReadBarrierMarkRegX(rX) |
| 778 | // |
| 779 | if (entrypoint_.IsValid()) { |
| 780 | arm_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 781 | __ Blx(RegisterFrom(entrypoint_)); |
| 782 | } else { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 783 | // Entrypoint is not already loaded, load from the thread. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 784 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 785 | Thread::ReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg.GetCode()); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 786 | // This runtime call does not require a stack map. |
| 787 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 788 | } |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 789 | } |
| 790 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 791 | // The location (register) of the marked object reference. |
| 792 | const Location ref_; |
| 793 | |
| 794 | // The location of the entrypoint if already loaded. |
| 795 | const Location entrypoint_; |
| 796 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 797 | private: |
| 798 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathBaseARMVIXL); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 799 | }; |
| 800 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 801 | // Slow path marking an object reference `ref` during a read |
| 802 | // barrier. The field `obj.field` in the object `obj` holding this |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 803 | // reference does not get updated by this slow path after marking. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 804 | // |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 805 | // This means that after the execution of this slow path, `ref` will |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 806 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 807 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 808 | // probably still be a from-space reference (unless it gets updated by |
| 809 | // another thread, or if another thread installed another object |
| 810 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 811 | // |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 812 | // Argument `entrypoint` must be a register location holding the read |
| 813 | // barrier marking runtime entry point to be invoked or an empty |
| 814 | // location; in the latter case, the read barrier marking runtime |
| 815 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 816 | class ReadBarrierMarkSlowPathARMVIXL : public ReadBarrierMarkSlowPathBaseARMVIXL { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 817 | public: |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 818 | ReadBarrierMarkSlowPathARMVIXL(HInstruction* instruction, |
| 819 | Location ref, |
| 820 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 821 | : ReadBarrierMarkSlowPathBaseARMVIXL(instruction, ref, entrypoint) { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 822 | DCHECK(kEmitCompilerReadBarrier); |
| 823 | } |
| 824 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 825 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARMVIXL"; } |
| 826 | |
| 827 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 828 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 829 | DCHECK(locations->CanCall()); |
| 830 | DCHECK(ref_.IsRegister()) << ref_; |
| 831 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
| 832 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 833 | << "Unexpected instruction in read barrier marking slow path: " |
| 834 | << instruction_->DebugName(); |
| 835 | |
| 836 | __ Bind(GetEntryLabel()); |
| 837 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 838 | __ B(GetExitLabel()); |
| 839 | } |
| 840 | |
| 841 | private: |
| 842 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARMVIXL); |
| 843 | }; |
| 844 | |
| 845 | // Slow path loading `obj`'s lock word, loading a reference from |
| 846 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 847 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 848 | // read barrier). The field `obj.field` in the object `obj` holding |
| 849 | // this reference does not get updated by this slow path after marking |
| 850 | // (see LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL |
| 851 | // below for that). |
| 852 | // |
| 853 | // This means that after the execution of this slow path, `ref` will |
| 854 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 855 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 856 | // probably still be a from-space reference (unless it gets updated by |
| 857 | // another thread, or if another thread installed another object |
| 858 | // reference (different from `ref`) in `obj.field`). |
| 859 | // |
| 860 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 861 | // barrier marking runtime entry point to be invoked or an empty |
| 862 | // location; in the latter case, the read barrier marking runtime |
| 863 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 864 | class LoadReferenceWithBakerReadBarrierSlowPathARMVIXL : public ReadBarrierMarkSlowPathBaseARMVIXL { |
| 865 | public: |
| 866 | LoadReferenceWithBakerReadBarrierSlowPathARMVIXL(HInstruction* instruction, |
| 867 | Location ref, |
| 868 | vixl32::Register obj, |
| 869 | uint32_t offset, |
| 870 | Location index, |
| 871 | ScaleFactor scale_factor, |
| 872 | bool needs_null_check, |
| 873 | vixl32::Register temp, |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 874 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 875 | : ReadBarrierMarkSlowPathBaseARMVIXL(instruction, ref, entrypoint), |
| 876 | obj_(obj), |
| 877 | offset_(offset), |
| 878 | index_(index), |
| 879 | scale_factor_(scale_factor), |
| 880 | needs_null_check_(needs_null_check), |
| 881 | temp_(temp) { |
| 882 | DCHECK(kEmitCompilerReadBarrier); |
| 883 | DCHECK(kUseBakerReadBarrier); |
| 884 | } |
| 885 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 886 | const char* GetDescription() const OVERRIDE { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 887 | return "LoadReferenceWithBakerReadBarrierSlowPathARMVIXL"; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 891 | LocationSummary* locations = instruction_->GetLocations(); |
| 892 | vixl32::Register ref_reg = RegisterFrom(ref_); |
| 893 | DCHECK(locations->CanCall()); |
| 894 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg.GetCode())) << ref_reg; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 895 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 896 | instruction_->IsStaticFieldGet() || |
| 897 | instruction_->IsArrayGet() || |
| 898 | instruction_->IsArraySet() || |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 899 | instruction_->IsInstanceOf() || |
| 900 | instruction_->IsCheckCast() || |
| 901 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 902 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 903 | << "Unexpected instruction in read barrier marking slow path: " |
| 904 | << instruction_->DebugName(); |
| 905 | // The read barrier instrumentation of object ArrayGet |
| 906 | // instructions does not support the HIntermediateAddress |
| 907 | // instruction. |
| 908 | DCHECK(!(instruction_->IsArrayGet() && |
| 909 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 910 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 911 | // Temporary register `temp_`, used to store the lock word, must |
| 912 | // not be IP, as we may use it to emit the reference load (in the |
| 913 | // call to GenerateRawReferenceLoad below), and we need the lock |
| 914 | // word to still be in `temp_` after the reference load. |
| 915 | DCHECK(!temp_.Is(ip)); |
| 916 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 917 | __ Bind(GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 918 | |
| 919 | // When using MaybeGenerateReadBarrierSlow, the read barrier call is |
| 920 | // inserted after the original load. However, in fast path based |
| 921 | // Baker's read barriers, we need to perform the load of |
| 922 | // mirror::Object::monitor_ *before* the original reference load. |
| 923 | // This load-load ordering is required by the read barrier. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 924 | // The slow path (for Baker's algorithm) should look like: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 925 | // |
| 926 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 927 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 928 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 929 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 930 | // if (is_gray) { |
| 931 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 932 | // } |
| 933 | // |
| 934 | // Note: the original implementation in ReadBarrier::Barrier is |
| 935 | // slightly more complex as it performs additional checks that we do |
| 936 | // not do here for performance reasons. |
| 937 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 938 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 939 | |
| 940 | // /* int32_t */ monitor = obj->monitor_ |
| 941 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 942 | arm_codegen->GetAssembler()->LoadFromOffset(kLoadWord, temp_, obj_, monitor_offset); |
| 943 | if (needs_null_check_) { |
| 944 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 945 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 946 | // /* LockWord */ lock_word = LockWord(monitor) |
| 947 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 948 | "art::LockWord and int32_t have different sizes."); |
| 949 | |
| 950 | // Introduce a dependency on the lock_word including the rb_state, |
| 951 | // which shall prevent load-load reordering without using |
| 952 | // a memory barrier (which would be more expensive). |
| 953 | // `obj` is unchanged by this operation, but its value now depends |
| 954 | // on `temp`. |
| 955 | __ Add(obj_, obj_, Operand(temp_, ShiftType::LSR, 32)); |
| 956 | |
| 957 | // The actual reference load. |
| 958 | // A possible implicit null check has already been handled above. |
| 959 | arm_codegen->GenerateRawReferenceLoad( |
| 960 | instruction_, ref_, obj_, offset_, index_, scale_factor_, /* needs_null_check */ false); |
| 961 | |
| 962 | // Mark the object `ref` when `obj` is gray. |
| 963 | // |
| 964 | // if (rb_state == ReadBarrier::GrayState()) |
| 965 | // ref = ReadBarrier::Mark(ref); |
| 966 | // |
| 967 | // Given the numeric representation, it's enough to check the low bit of the |
| 968 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 969 | // which can be a 16-bit instruction unlike the TST immediate. |
| 970 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 971 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 972 | __ Lsrs(temp_, temp_, LockWord::kReadBarrierStateShift + 1); |
| 973 | __ B(cc, GetExitLabel()); // Carry flag is the last bit shifted out by LSRS. |
| 974 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 975 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 976 | __ B(GetExitLabel()); |
| 977 | } |
| 978 | |
| 979 | private: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 980 | // The register containing the object holding the marked object reference field. |
| 981 | vixl32::Register obj_; |
| 982 | // The offset, index and scale factor to access the reference in `obj_`. |
| 983 | uint32_t offset_; |
| 984 | Location index_; |
| 985 | ScaleFactor scale_factor_; |
| 986 | // Is a null check required? |
| 987 | bool needs_null_check_; |
| 988 | // A temporary register used to hold the lock word of `obj_`. |
| 989 | vixl32::Register temp_; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 990 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 991 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierSlowPathARMVIXL); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 992 | }; |
| 993 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 994 | // Slow path loading `obj`'s lock word, loading a reference from |
| 995 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 996 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 997 | // read barrier). If needed, this slow path also atomically updates |
| 998 | // the field `obj.field` in the object `obj` holding this reference |
| 999 | // after marking (contrary to |
| 1000 | // LoadReferenceWithBakerReadBarrierSlowPathARMVIXL above, which never |
| 1001 | // tries to update `obj.field`). |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1002 | // |
| 1003 | // This means that after the execution of this slow path, both `ref` |
| 1004 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 1005 | // hold the same to-space reference (unless another thread installed |
| 1006 | // another object reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 1007 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1008 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 1009 | // barrier marking runtime entry point to be invoked or an empty |
| 1010 | // location; in the latter case, the read barrier marking runtime |
| 1011 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1012 | class LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL |
| 1013 | : public ReadBarrierMarkSlowPathBaseARMVIXL { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1014 | public: |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 1015 | LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL( |
| 1016 | HInstruction* instruction, |
| 1017 | Location ref, |
| 1018 | vixl32::Register obj, |
| 1019 | uint32_t offset, |
| 1020 | Location index, |
| 1021 | ScaleFactor scale_factor, |
| 1022 | bool needs_null_check, |
| 1023 | vixl32::Register temp1, |
| 1024 | vixl32::Register temp2, |
| 1025 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1026 | : ReadBarrierMarkSlowPathBaseARMVIXL(instruction, ref, entrypoint), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1027 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1028 | offset_(offset), |
| 1029 | index_(index), |
| 1030 | scale_factor_(scale_factor), |
| 1031 | needs_null_check_(needs_null_check), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1032 | temp1_(temp1), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1033 | temp2_(temp2) { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1034 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1035 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | const char* GetDescription() const OVERRIDE { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1039 | return "LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL"; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1043 | LocationSummary* locations = instruction_->GetLocations(); |
| 1044 | vixl32::Register ref_reg = RegisterFrom(ref_); |
| 1045 | DCHECK(locations->CanCall()); |
| 1046 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg.GetCode())) << ref_reg; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1047 | DCHECK_NE(ref_.reg(), LocationFrom(temp1_).reg()); |
| 1048 | |
| 1049 | // This slow path is only used by the UnsafeCASObject intrinsic at the moment. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1050 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 1051 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 1052 | << instruction_->DebugName(); |
| 1053 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1054 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1055 | DCHECK_EQ(offset_, 0u); |
| 1056 | DCHECK_EQ(scale_factor_, ScaleFactor::TIMES_1); |
| 1057 | Location field_offset = index_; |
| 1058 | DCHECK(field_offset.IsRegisterPair()) << field_offset; |
| 1059 | |
| 1060 | // Temporary register `temp1_`, used to store the lock word, must |
| 1061 | // not be IP, as we may use it to emit the reference load (in the |
| 1062 | // call to GenerateRawReferenceLoad below), and we need the lock |
| 1063 | // word to still be in `temp1_` after the reference load. |
| 1064 | DCHECK(!temp1_.Is(ip)); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1065 | |
| 1066 | __ Bind(GetEntryLabel()); |
| 1067 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 1068 | // The implementation is similar to LoadReferenceWithBakerReadBarrierSlowPathARMVIXL's: |
| 1069 | // |
| 1070 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 1071 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 1072 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 1073 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 1074 | // if (is_gray) { |
| 1075 | // old_ref = ref; |
| 1076 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 1077 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 1078 | // } |
| 1079 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1080 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 1081 | |
| 1082 | // /* int32_t */ monitor = obj->monitor_ |
| 1083 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 1084 | arm_codegen->GetAssembler()->LoadFromOffset(kLoadWord, temp1_, obj_, monitor_offset); |
| 1085 | if (needs_null_check_) { |
| 1086 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| 1087 | } |
| 1088 | // /* LockWord */ lock_word = LockWord(monitor) |
| 1089 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 1090 | "art::LockWord and int32_t have different sizes."); |
| 1091 | |
| 1092 | // Introduce a dependency on the lock_word including the rb_state, |
| 1093 | // which shall prevent load-load reordering without using |
| 1094 | // a memory barrier (which would be more expensive). |
| 1095 | // `obj` is unchanged by this operation, but its value now depends |
| 1096 | // on `temp`. |
| 1097 | __ Add(obj_, obj_, Operand(temp1_, ShiftType::LSR, 32)); |
| 1098 | |
| 1099 | // The actual reference load. |
| 1100 | // A possible implicit null check has already been handled above. |
| 1101 | arm_codegen->GenerateRawReferenceLoad( |
| 1102 | instruction_, ref_, obj_, offset_, index_, scale_factor_, /* needs_null_check */ false); |
| 1103 | |
| 1104 | // Mark the object `ref` when `obj` is gray. |
| 1105 | // |
| 1106 | // if (rb_state == ReadBarrier::GrayState()) |
| 1107 | // ref = ReadBarrier::Mark(ref); |
| 1108 | // |
| 1109 | // Given the numeric representation, it's enough to check the low bit of the |
| 1110 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 1111 | // which can be a 16-bit instruction unlike the TST immediate. |
| 1112 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 1113 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 1114 | __ Lsrs(temp1_, temp1_, LockWord::kReadBarrierStateShift + 1); |
| 1115 | __ B(cc, GetExitLabel()); // Carry flag is the last bit shifted out by LSRS. |
| 1116 | |
| 1117 | // Save the old value of the reference before marking it. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1118 | // Note that we cannot use IP to save the old reference, as IP is |
| 1119 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 1120 | // need the old reference after the call to that entry point. |
| 1121 | DCHECK(!temp1_.Is(ip)); |
| 1122 | __ Mov(temp1_, ref_reg); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 1123 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1124 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1125 | |
| 1126 | // If the new reference is different from the old reference, |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1127 | // update the field in the holder (`*(obj_ + field_offset)`). |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1128 | // |
| 1129 | // Note that this field could also hold a different object, if |
| 1130 | // another thread had concurrently changed it. In that case, the |
Anton Kirilov | 349e61f | 2017-12-15 17:11:33 +0000 | [diff] [blame] | 1131 | // LDREX/CMP/BNE sequence of instructions in the compare-and-set |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1132 | // (CAS) operation below would abort the CAS, leaving the field |
| 1133 | // as-is. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1134 | __ Cmp(temp1_, ref_reg); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1135 | __ B(eq, GetExitLabel()); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1136 | |
| 1137 | // Update the the holder's field atomically. This may fail if |
| 1138 | // mutator updates before us, but it's OK. This is achieved |
| 1139 | // using a strong compare-and-set (CAS) operation with relaxed |
| 1140 | // memory synchronization ordering, where the expected value is |
| 1141 | // the old reference and the desired value is the new reference. |
| 1142 | |
| 1143 | UseScratchRegisterScope temps(arm_codegen->GetVIXLAssembler()); |
| 1144 | // Convenience aliases. |
| 1145 | vixl32::Register base = obj_; |
| 1146 | // The UnsafeCASObject intrinsic uses a register pair as field |
| 1147 | // offset ("long offset"), of which only the low part contains |
| 1148 | // data. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1149 | vixl32::Register offset = LowRegisterFrom(field_offset); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1150 | vixl32::Register expected = temp1_; |
| 1151 | vixl32::Register value = ref_reg; |
| 1152 | vixl32::Register tmp_ptr = temps.Acquire(); // Pointer to actual memory. |
| 1153 | vixl32::Register tmp = temp2_; // Value in memory. |
| 1154 | |
| 1155 | __ Add(tmp_ptr, base, offset); |
| 1156 | |
| 1157 | if (kPoisonHeapReferences) { |
| 1158 | arm_codegen->GetAssembler()->PoisonHeapReference(expected); |
| 1159 | if (value.Is(expected)) { |
| 1160 | // Do not poison `value`, as it is the same register as |
| 1161 | // `expected`, which has just been poisoned. |
| 1162 | } else { |
| 1163 | arm_codegen->GetAssembler()->PoisonHeapReference(value); |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | // do { |
| 1168 | // tmp = [r_ptr] - expected; |
| 1169 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 1170 | |
Anton Kirilov | 349e61f | 2017-12-15 17:11:33 +0000 | [diff] [blame] | 1171 | vixl32::Label loop_head, comparison_failed, exit_loop; |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1172 | __ Bind(&loop_head); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1173 | __ Ldrex(tmp, MemOperand(tmp_ptr)); |
Anton Kirilov | 349e61f | 2017-12-15 17:11:33 +0000 | [diff] [blame] | 1174 | __ Cmp(tmp, expected); |
| 1175 | __ B(ne, &comparison_failed, /* far_target */ false); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1176 | __ Strex(tmp, value, MemOperand(tmp_ptr)); |
Anton Kirilov | 349e61f | 2017-12-15 17:11:33 +0000 | [diff] [blame] | 1177 | __ CompareAndBranchIfZero(tmp, &exit_loop, /* far_target */ false); |
| 1178 | __ B(&loop_head); |
| 1179 | __ Bind(&comparison_failed); |
| 1180 | __ Clrex(); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1181 | __ Bind(&exit_loop); |
| 1182 | |
| 1183 | if (kPoisonHeapReferences) { |
| 1184 | arm_codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 1185 | if (value.Is(expected)) { |
| 1186 | // Do not unpoison `value`, as it is the same register as |
| 1187 | // `expected`, which has just been unpoisoned. |
| 1188 | } else { |
| 1189 | arm_codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 1190 | } |
| 1191 | } |
| 1192 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1193 | __ B(GetExitLabel()); |
| 1194 | } |
| 1195 | |
| 1196 | private: |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1197 | // The register containing the object holding the marked object reference field. |
| 1198 | const vixl32::Register obj_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1199 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1200 | uint32_t offset_; |
| 1201 | Location index_; |
| 1202 | ScaleFactor scale_factor_; |
| 1203 | // Is a null check required? |
| 1204 | bool needs_null_check_; |
| 1205 | // A temporary register used to hold the lock word of `obj_`; and |
| 1206 | // also to hold the original reference value, when the reference is |
| 1207 | // marked. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1208 | const vixl32::Register temp1_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1209 | // A temporary register used in the implementation of the CAS, to |
| 1210 | // update the object's reference field. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1211 | const vixl32::Register temp2_; |
| 1212 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1213 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1214 | }; |
| 1215 | |
| 1216 | // Slow path generating a read barrier for a heap reference. |
| 1217 | class ReadBarrierForHeapReferenceSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 1218 | public: |
| 1219 | ReadBarrierForHeapReferenceSlowPathARMVIXL(HInstruction* instruction, |
| 1220 | Location out, |
| 1221 | Location ref, |
| 1222 | Location obj, |
| 1223 | uint32_t offset, |
| 1224 | Location index) |
| 1225 | : SlowPathCodeARMVIXL(instruction), |
| 1226 | out_(out), |
| 1227 | ref_(ref), |
| 1228 | obj_(obj), |
| 1229 | offset_(offset), |
| 1230 | index_(index) { |
| 1231 | DCHECK(kEmitCompilerReadBarrier); |
| 1232 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 1233 | // has been overwritten by (or after) the heap object reference load |
| 1234 | // to be instrumented, e.g.: |
| 1235 | // |
| 1236 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
| 1237 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| 1238 | // |
| 1239 | // In that case, we have lost the information about the original |
| 1240 | // object, and the emitted read barrier cannot work properly. |
| 1241 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 1242 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 1243 | } |
| 1244 | |
| 1245 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1246 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 1247 | LocationSummary* locations = instruction_->GetLocations(); |
| 1248 | vixl32::Register reg_out = RegisterFrom(out_); |
| 1249 | DCHECK(locations->CanCall()); |
| 1250 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.GetCode())); |
| 1251 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 1252 | instruction_->IsStaticFieldGet() || |
| 1253 | instruction_->IsArrayGet() || |
| 1254 | instruction_->IsInstanceOf() || |
| 1255 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 1256 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1257 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 1258 | << instruction_->DebugName(); |
| 1259 | // The read barrier instrumentation of object ArrayGet |
| 1260 | // instructions does not support the HIntermediateAddress |
| 1261 | // instruction. |
| 1262 | DCHECK(!(instruction_->IsArrayGet() && |
| 1263 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 1264 | |
| 1265 | __ Bind(GetEntryLabel()); |
| 1266 | SaveLiveRegisters(codegen, locations); |
| 1267 | |
| 1268 | // We may have to change the index's value, but as `index_` is a |
| 1269 | // constant member (like other "inputs" of this slow path), |
| 1270 | // introduce a copy of it, `index`. |
| 1271 | Location index = index_; |
| 1272 | if (index_.IsValid()) { |
| 1273 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 1274 | if (instruction_->IsArrayGet()) { |
| 1275 | // Compute the actual memory offset and store it in `index`. |
| 1276 | vixl32::Register index_reg = RegisterFrom(index_); |
| 1277 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg.GetCode())); |
| 1278 | if (codegen->IsCoreCalleeSaveRegister(index_reg.GetCode())) { |
| 1279 | // We are about to change the value of `index_reg` (see the |
Roland Levillain | 9983e30 | 2017-07-14 14:34:22 +0100 | [diff] [blame] | 1280 | // calls to art::arm::ArmVIXLMacroAssembler::Lsl and |
| 1281 | // art::arm::ArmVIXLMacroAssembler::Add below), but it has |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1282 | // not been saved by the previous call to |
| 1283 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1284 | // callee-save register -- |
| 1285 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1286 | // callee-save registers, as it has been designed with the |
| 1287 | // assumption that callee-save registers are supposed to be |
| 1288 | // handled by the called function. So, as a callee-save |
| 1289 | // register, `index_reg` _would_ eventually be saved onto |
| 1290 | // the stack, but it would be too late: we would have |
| 1291 | // changed its value earlier. Therefore, we manually save |
| 1292 | // it here into another freely available register, |
| 1293 | // `free_reg`, chosen of course among the caller-save |
| 1294 | // registers (as a callee-save `free_reg` register would |
| 1295 | // exhibit the same problem). |
| 1296 | // |
| 1297 | // Note we could have requested a temporary register from |
| 1298 | // the register allocator instead; but we prefer not to, as |
| 1299 | // this is a slow path, and we know we can find a |
| 1300 | // caller-save register that is available. |
| 1301 | vixl32::Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1302 | __ Mov(free_reg, index_reg); |
| 1303 | index_reg = free_reg; |
| 1304 | index = LocationFrom(index_reg); |
| 1305 | } else { |
| 1306 | // The initial register stored in `index_` has already been |
| 1307 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1308 | // (as it is not a callee-save register), so we can freely |
| 1309 | // use it. |
| 1310 | } |
| 1311 | // Shifting the index value contained in `index_reg` by the scale |
| 1312 | // factor (2) cannot overflow in practice, as the runtime is |
| 1313 | // unable to allocate object arrays with a size larger than |
| 1314 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 1315 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 1316 | static_assert( |
| 1317 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1318 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1319 | __ Add(index_reg, index_reg, offset_); |
| 1320 | } else { |
| 1321 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1322 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1323 | // (as in the case of ArrayGet), as it is actually an offset |
| 1324 | // to an object field within an object. |
| 1325 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| 1326 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1327 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1328 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1329 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 1330 | DCHECK_EQ(offset_, 0U); |
| 1331 | DCHECK(index_.IsRegisterPair()); |
| 1332 | // UnsafeGet's offset location is a register pair, the low |
| 1333 | // part contains the correct offset. |
| 1334 | index = index_.ToLow(); |
| 1335 | } |
| 1336 | } |
| 1337 | |
| 1338 | // We're moving two or three locations to locations that could |
| 1339 | // overlap, so we need a parallel move resolver. |
| 1340 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1341 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1342 | parallel_move.AddMove(ref_, |
| 1343 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1344 | DataType::Type::kReference, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1345 | nullptr); |
| 1346 | parallel_move.AddMove(obj_, |
| 1347 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1348 | DataType::Type::kReference, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1349 | nullptr); |
| 1350 | if (index.IsValid()) { |
| 1351 | parallel_move.AddMove(index, |
| 1352 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1353 | DataType::Type::kInt32, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1354 | nullptr); |
| 1355 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1356 | } else { |
| 1357 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1358 | __ Mov(calling_convention.GetRegisterAt(2), offset_); |
| 1359 | } |
| 1360 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
| 1361 | CheckEntrypointTypes< |
| 1362 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1363 | arm_codegen->Move32(out_, LocationFrom(r0)); |
| 1364 | |
| 1365 | RestoreLiveRegisters(codegen, locations); |
| 1366 | __ B(GetExitLabel()); |
| 1367 | } |
| 1368 | |
| 1369 | const char* GetDescription() const OVERRIDE { |
| 1370 | return "ReadBarrierForHeapReferenceSlowPathARMVIXL"; |
| 1371 | } |
| 1372 | |
| 1373 | private: |
| 1374 | vixl32::Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 1375 | uint32_t ref = RegisterFrom(ref_).GetCode(); |
| 1376 | uint32_t obj = RegisterFrom(obj_).GetCode(); |
| 1377 | for (uint32_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1378 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1379 | return vixl32::Register(i); |
| 1380 | } |
| 1381 | } |
| 1382 | // We shall never fail to find a free caller-save register, as |
| 1383 | // there are more than two core caller-save registers on ARM |
| 1384 | // (meaning it is possible to find one which is different from |
| 1385 | // `ref` and `obj`). |
| 1386 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1387 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 1388 | UNREACHABLE(); |
| 1389 | } |
| 1390 | |
| 1391 | const Location out_; |
| 1392 | const Location ref_; |
| 1393 | const Location obj_; |
| 1394 | const uint32_t offset_; |
| 1395 | // An additional location containing an index to an array. |
| 1396 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1397 | // UnsafeGetObjectVolatile intrinsics. |
| 1398 | const Location index_; |
| 1399 | |
| 1400 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARMVIXL); |
| 1401 | }; |
| 1402 | |
| 1403 | // Slow path generating a read barrier for a GC root. |
| 1404 | class ReadBarrierForRootSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 1405 | public: |
| 1406 | ReadBarrierForRootSlowPathARMVIXL(HInstruction* instruction, Location out, Location root) |
| 1407 | : SlowPathCodeARMVIXL(instruction), out_(out), root_(root) { |
| 1408 | DCHECK(kEmitCompilerReadBarrier); |
| 1409 | } |
| 1410 | |
| 1411 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1412 | LocationSummary* locations = instruction_->GetLocations(); |
| 1413 | vixl32::Register reg_out = RegisterFrom(out_); |
| 1414 | DCHECK(locations->CanCall()); |
| 1415 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.GetCode())); |
| 1416 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1417 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1418 | << instruction_->DebugName(); |
| 1419 | |
| 1420 | __ Bind(GetEntryLabel()); |
| 1421 | SaveLiveRegisters(codegen, locations); |
| 1422 | |
| 1423 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 1424 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 1425 | arm_codegen->Move32(LocationFrom(calling_convention.GetRegisterAt(0)), root_); |
| 1426 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| 1427 | instruction_, |
| 1428 | instruction_->GetDexPc(), |
| 1429 | this); |
| 1430 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1431 | arm_codegen->Move32(out_, LocationFrom(r0)); |
| 1432 | |
| 1433 | RestoreLiveRegisters(codegen, locations); |
| 1434 | __ B(GetExitLabel()); |
| 1435 | } |
| 1436 | |
| 1437 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARMVIXL"; } |
| 1438 | |
| 1439 | private: |
| 1440 | const Location out_; |
| 1441 | const Location root_; |
| 1442 | |
| 1443 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARMVIXL); |
| 1444 | }; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 1445 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1446 | inline vixl32::Condition ARMCondition(IfCondition cond) { |
| 1447 | switch (cond) { |
| 1448 | case kCondEQ: return eq; |
| 1449 | case kCondNE: return ne; |
| 1450 | case kCondLT: return lt; |
| 1451 | case kCondLE: return le; |
| 1452 | case kCondGT: return gt; |
| 1453 | case kCondGE: return ge; |
| 1454 | case kCondB: return lo; |
| 1455 | case kCondBE: return ls; |
| 1456 | case kCondA: return hi; |
| 1457 | case kCondAE: return hs; |
| 1458 | } |
| 1459 | LOG(FATAL) << "Unreachable"; |
| 1460 | UNREACHABLE(); |
| 1461 | } |
| 1462 | |
| 1463 | // Maps signed condition to unsigned condition. |
| 1464 | inline vixl32::Condition ARMUnsignedCondition(IfCondition cond) { |
| 1465 | switch (cond) { |
| 1466 | case kCondEQ: return eq; |
| 1467 | case kCondNE: return ne; |
| 1468 | // Signed to unsigned. |
| 1469 | case kCondLT: return lo; |
| 1470 | case kCondLE: return ls; |
| 1471 | case kCondGT: return hi; |
| 1472 | case kCondGE: return hs; |
| 1473 | // Unsigned remain unchanged. |
| 1474 | case kCondB: return lo; |
| 1475 | case kCondBE: return ls; |
| 1476 | case kCondA: return hi; |
| 1477 | case kCondAE: return hs; |
| 1478 | } |
| 1479 | LOG(FATAL) << "Unreachable"; |
| 1480 | UNREACHABLE(); |
| 1481 | } |
| 1482 | |
| 1483 | inline vixl32::Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 1484 | // The ARM condition codes can express all the necessary branches, see the |
| 1485 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 1486 | // There is no dex instruction or HIR that would need the missing conditions |
| 1487 | // "equal or unordered" or "not equal". |
| 1488 | switch (cond) { |
| 1489 | case kCondEQ: return eq; |
| 1490 | case kCondNE: return ne /* unordered */; |
| 1491 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 1492 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 1493 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 1494 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 1495 | default: |
| 1496 | LOG(FATAL) << "UNREACHABLE"; |
| 1497 | UNREACHABLE(); |
| 1498 | } |
| 1499 | } |
| 1500 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1501 | inline ShiftType ShiftFromOpKind(HDataProcWithShifterOp::OpKind op_kind) { |
| 1502 | switch (op_kind) { |
| 1503 | case HDataProcWithShifterOp::kASR: return ShiftType::ASR; |
| 1504 | case HDataProcWithShifterOp::kLSL: return ShiftType::LSL; |
| 1505 | case HDataProcWithShifterOp::kLSR: return ShiftType::LSR; |
| 1506 | default: |
| 1507 | LOG(FATAL) << "Unexpected op kind " << op_kind; |
| 1508 | UNREACHABLE(); |
| 1509 | } |
| 1510 | } |
| 1511 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1512 | void CodeGeneratorARMVIXL::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 1513 | stream << vixl32::Register(reg); |
| 1514 | } |
| 1515 | |
| 1516 | void CodeGeneratorARMVIXL::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| 1517 | stream << vixl32::SRegister(reg); |
| 1518 | } |
| 1519 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1520 | static uint32_t ComputeSRegisterListMask(const SRegisterList& regs) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1521 | uint32_t mask = 0; |
| 1522 | for (uint32_t i = regs.GetFirstSRegister().GetCode(); |
| 1523 | i <= regs.GetLastSRegister().GetCode(); |
| 1524 | ++i) { |
| 1525 | mask |= (1 << i); |
| 1526 | } |
| 1527 | return mask; |
| 1528 | } |
| 1529 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1530 | // Saves the register in the stack. Returns the size taken on stack. |
| 1531 | size_t CodeGeneratorARMVIXL::SaveCoreRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1532 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1533 | TODO_VIXL32(FATAL); |
| 1534 | return 0; |
| 1535 | } |
| 1536 | |
| 1537 | // Restores the register from the stack. Returns the size taken on stack. |
| 1538 | size_t CodeGeneratorARMVIXL::RestoreCoreRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1539 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1540 | TODO_VIXL32(FATAL); |
| 1541 | return 0; |
| 1542 | } |
| 1543 | |
| 1544 | size_t CodeGeneratorARMVIXL::SaveFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1545 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1546 | TODO_VIXL32(FATAL); |
| 1547 | return 0; |
| 1548 | } |
| 1549 | |
| 1550 | size_t CodeGeneratorARMVIXL::RestoreFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1551 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1552 | TODO_VIXL32(FATAL); |
| 1553 | return 0; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 1554 | } |
| 1555 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1556 | static void GenerateDataProcInstruction(HInstruction::InstructionKind kind, |
| 1557 | vixl32::Register out, |
| 1558 | vixl32::Register first, |
| 1559 | const Operand& second, |
| 1560 | CodeGeneratorARMVIXL* codegen) { |
| 1561 | if (second.IsImmediate() && second.GetImmediate() == 0) { |
| 1562 | const Operand in = kind == HInstruction::kAnd |
| 1563 | ? Operand(0) |
| 1564 | : Operand(first); |
| 1565 | |
| 1566 | __ Mov(out, in); |
| 1567 | } else { |
| 1568 | switch (kind) { |
| 1569 | case HInstruction::kAdd: |
| 1570 | __ Add(out, first, second); |
| 1571 | break; |
| 1572 | case HInstruction::kAnd: |
| 1573 | __ And(out, first, second); |
| 1574 | break; |
| 1575 | case HInstruction::kOr: |
| 1576 | __ Orr(out, first, second); |
| 1577 | break; |
| 1578 | case HInstruction::kSub: |
| 1579 | __ Sub(out, first, second); |
| 1580 | break; |
| 1581 | case HInstruction::kXor: |
| 1582 | __ Eor(out, first, second); |
| 1583 | break; |
| 1584 | default: |
| 1585 | LOG(FATAL) << "Unexpected instruction kind: " << kind; |
| 1586 | UNREACHABLE(); |
| 1587 | } |
| 1588 | } |
| 1589 | } |
| 1590 | |
| 1591 | static void GenerateDataProc(HInstruction::InstructionKind kind, |
| 1592 | const Location& out, |
| 1593 | const Location& first, |
| 1594 | const Operand& second_lo, |
| 1595 | const Operand& second_hi, |
| 1596 | CodeGeneratorARMVIXL* codegen) { |
| 1597 | const vixl32::Register first_hi = HighRegisterFrom(first); |
| 1598 | const vixl32::Register first_lo = LowRegisterFrom(first); |
| 1599 | const vixl32::Register out_hi = HighRegisterFrom(out); |
| 1600 | const vixl32::Register out_lo = LowRegisterFrom(out); |
| 1601 | |
| 1602 | if (kind == HInstruction::kAdd) { |
| 1603 | __ Adds(out_lo, first_lo, second_lo); |
| 1604 | __ Adc(out_hi, first_hi, second_hi); |
| 1605 | } else if (kind == HInstruction::kSub) { |
| 1606 | __ Subs(out_lo, first_lo, second_lo); |
| 1607 | __ Sbc(out_hi, first_hi, second_hi); |
| 1608 | } else { |
| 1609 | GenerateDataProcInstruction(kind, out_lo, first_lo, second_lo, codegen); |
| 1610 | GenerateDataProcInstruction(kind, out_hi, first_hi, second_hi, codegen); |
| 1611 | } |
| 1612 | } |
| 1613 | |
| 1614 | static Operand GetShifterOperand(vixl32::Register rm, ShiftType shift, uint32_t shift_imm) { |
| 1615 | return shift_imm == 0 ? Operand(rm) : Operand(rm, shift, shift_imm); |
| 1616 | } |
| 1617 | |
| 1618 | static void GenerateLongDataProc(HDataProcWithShifterOp* instruction, |
| 1619 | CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1620 | DCHECK_EQ(instruction->GetType(), DataType::Type::kInt64); |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1621 | DCHECK(HDataProcWithShifterOp::IsShiftOp(instruction->GetOpKind())); |
| 1622 | |
| 1623 | const LocationSummary* const locations = instruction->GetLocations(); |
| 1624 | const uint32_t shift_value = instruction->GetShiftAmount(); |
| 1625 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 1626 | const Location first = locations->InAt(0); |
| 1627 | const Location second = locations->InAt(1); |
| 1628 | const Location out = locations->Out(); |
| 1629 | const vixl32::Register first_hi = HighRegisterFrom(first); |
| 1630 | const vixl32::Register first_lo = LowRegisterFrom(first); |
| 1631 | const vixl32::Register out_hi = HighRegisterFrom(out); |
| 1632 | const vixl32::Register out_lo = LowRegisterFrom(out); |
| 1633 | const vixl32::Register second_hi = HighRegisterFrom(second); |
| 1634 | const vixl32::Register second_lo = LowRegisterFrom(second); |
| 1635 | const ShiftType shift = ShiftFromOpKind(instruction->GetOpKind()); |
| 1636 | |
| 1637 | if (shift_value >= 32) { |
| 1638 | if (shift == ShiftType::LSL) { |
| 1639 | GenerateDataProcInstruction(kind, |
| 1640 | out_hi, |
| 1641 | first_hi, |
| 1642 | Operand(second_lo, ShiftType::LSL, shift_value - 32), |
| 1643 | codegen); |
| 1644 | GenerateDataProcInstruction(kind, out_lo, first_lo, 0, codegen); |
| 1645 | } else if (shift == ShiftType::ASR) { |
| 1646 | GenerateDataProc(kind, |
| 1647 | out, |
| 1648 | first, |
| 1649 | GetShifterOperand(second_hi, ShiftType::ASR, shift_value - 32), |
| 1650 | Operand(second_hi, ShiftType::ASR, 31), |
| 1651 | codegen); |
| 1652 | } else { |
| 1653 | DCHECK_EQ(shift, ShiftType::LSR); |
| 1654 | GenerateDataProc(kind, |
| 1655 | out, |
| 1656 | first, |
| 1657 | GetShifterOperand(second_hi, ShiftType::LSR, shift_value - 32), |
| 1658 | 0, |
| 1659 | codegen); |
| 1660 | } |
| 1661 | } else { |
| 1662 | DCHECK_GT(shift_value, 1U); |
| 1663 | DCHECK_LT(shift_value, 32U); |
| 1664 | |
| 1665 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1666 | |
| 1667 | if (shift == ShiftType::LSL) { |
| 1668 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1669 | // Location::kOutputOverlap; not applicable to other cases. |
| 1670 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1671 | GenerateDataProcInstruction(kind, |
| 1672 | out_hi, |
| 1673 | first_hi, |
| 1674 | Operand(second_hi, ShiftType::LSL, shift_value), |
| 1675 | codegen); |
| 1676 | GenerateDataProcInstruction(kind, |
| 1677 | out_hi, |
| 1678 | out_hi, |
| 1679 | Operand(second_lo, ShiftType::LSR, 32 - shift_value), |
| 1680 | codegen); |
| 1681 | GenerateDataProcInstruction(kind, |
| 1682 | out_lo, |
| 1683 | first_lo, |
| 1684 | Operand(second_lo, ShiftType::LSL, shift_value), |
| 1685 | codegen); |
| 1686 | } else { |
| 1687 | const vixl32::Register temp = temps.Acquire(); |
| 1688 | |
| 1689 | __ Lsl(temp, second_hi, shift_value); |
| 1690 | __ Orr(temp, temp, Operand(second_lo, ShiftType::LSR, 32 - shift_value)); |
| 1691 | GenerateDataProc(kind, |
| 1692 | out, |
| 1693 | first, |
| 1694 | Operand(second_lo, ShiftType::LSL, shift_value), |
| 1695 | temp, |
| 1696 | codegen); |
| 1697 | } |
| 1698 | } else { |
| 1699 | DCHECK(shift == ShiftType::ASR || shift == ShiftType::LSR); |
| 1700 | |
| 1701 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1702 | // Location::kOutputOverlap; not applicable to other cases. |
| 1703 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1704 | GenerateDataProcInstruction(kind, |
| 1705 | out_lo, |
| 1706 | first_lo, |
| 1707 | Operand(second_lo, ShiftType::LSR, shift_value), |
| 1708 | codegen); |
| 1709 | GenerateDataProcInstruction(kind, |
| 1710 | out_lo, |
| 1711 | out_lo, |
| 1712 | Operand(second_hi, ShiftType::LSL, 32 - shift_value), |
| 1713 | codegen); |
| 1714 | GenerateDataProcInstruction(kind, |
| 1715 | out_hi, |
| 1716 | first_hi, |
| 1717 | Operand(second_hi, shift, shift_value), |
| 1718 | codegen); |
| 1719 | } else { |
| 1720 | const vixl32::Register temp = temps.Acquire(); |
| 1721 | |
| 1722 | __ Lsr(temp, second_lo, shift_value); |
| 1723 | __ Orr(temp, temp, Operand(second_hi, ShiftType::LSL, 32 - shift_value)); |
| 1724 | GenerateDataProc(kind, |
| 1725 | out, |
| 1726 | first, |
| 1727 | temp, |
| 1728 | Operand(second_hi, shift, shift_value), |
| 1729 | codegen); |
| 1730 | } |
| 1731 | } |
| 1732 | } |
| 1733 | } |
| 1734 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1735 | static void GenerateVcmp(HInstruction* instruction, CodeGeneratorARMVIXL* codegen) { |
| 1736 | const Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1737 | if (rhs_loc.IsConstant()) { |
| 1738 | // 0.0 is the only immediate that can be encoded directly in |
| 1739 | // a VCMP instruction. |
| 1740 | // |
| 1741 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1742 | // specify that in a floating-point comparison, positive zero |
| 1743 | // and negative zero are considered equal, so we can use the |
| 1744 | // literal 0.0 for both cases here. |
| 1745 | // |
| 1746 | // Note however that some methods (Float.equal, Float.compare, |
| 1747 | // Float.compareTo, Double.equal, Double.compare, |
| 1748 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1749 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1750 | // -0.0. So if we ever translate calls to these methods into a |
| 1751 | // HCompare instruction, we must handle the -0.0 case with |
| 1752 | // care here. |
| 1753 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1754 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1755 | const DataType::Type type = instruction->InputAt(0)->GetType(); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1756 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1757 | if (type == DataType::Type::kFloat32) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1758 | __ Vcmp(F32, InputSRegisterAt(instruction, 0), 0.0); |
| 1759 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1760 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1761 | __ Vcmp(F64, InputDRegisterAt(instruction, 0), 0.0); |
| 1762 | } |
| 1763 | } else { |
| 1764 | __ Vcmp(InputVRegisterAt(instruction, 0), InputVRegisterAt(instruction, 1)); |
| 1765 | } |
| 1766 | } |
| 1767 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1768 | static int64_t AdjustConstantForCondition(int64_t value, |
| 1769 | IfCondition* condition, |
| 1770 | IfCondition* opposite) { |
| 1771 | if (value == 1) { |
| 1772 | if (*condition == kCondB) { |
| 1773 | value = 0; |
| 1774 | *condition = kCondEQ; |
| 1775 | *opposite = kCondNE; |
| 1776 | } else if (*condition == kCondAE) { |
| 1777 | value = 0; |
| 1778 | *condition = kCondNE; |
| 1779 | *opposite = kCondEQ; |
| 1780 | } |
| 1781 | } else if (value == -1) { |
| 1782 | if (*condition == kCondGT) { |
| 1783 | value = 0; |
| 1784 | *condition = kCondGE; |
| 1785 | *opposite = kCondLT; |
| 1786 | } else if (*condition == kCondLE) { |
| 1787 | value = 0; |
| 1788 | *condition = kCondLT; |
| 1789 | *opposite = kCondGE; |
| 1790 | } |
| 1791 | } |
| 1792 | |
| 1793 | return value; |
| 1794 | } |
| 1795 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1796 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateLongTestConstant( |
| 1797 | HCondition* condition, |
| 1798 | bool invert, |
| 1799 | CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1800 | DCHECK_EQ(condition->GetLeft()->GetType(), DataType::Type::kInt64); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1801 | |
| 1802 | const LocationSummary* const locations = condition->GetLocations(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1803 | IfCondition cond = condition->GetCondition(); |
| 1804 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1805 | |
| 1806 | if (invert) { |
| 1807 | std::swap(cond, opposite); |
| 1808 | } |
| 1809 | |
| 1810 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1811 | const Location left = locations->InAt(0); |
| 1812 | const Location right = locations->InAt(1); |
| 1813 | |
| 1814 | DCHECK(right.IsConstant()); |
| 1815 | |
| 1816 | const vixl32::Register left_high = HighRegisterFrom(left); |
| 1817 | const vixl32::Register left_low = LowRegisterFrom(left); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1818 | int64_t value = AdjustConstantForCondition(Int64ConstantFrom(right), &cond, &opposite); |
| 1819 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1820 | |
| 1821 | // Comparisons against 0 are common enough to deserve special attention. |
| 1822 | if (value == 0) { |
| 1823 | switch (cond) { |
| 1824 | case kCondNE: |
| 1825 | // x > 0 iff x != 0 when the comparison is unsigned. |
| 1826 | case kCondA: |
| 1827 | ret = std::make_pair(ne, eq); |
| 1828 | FALLTHROUGH_INTENDED; |
| 1829 | case kCondEQ: |
| 1830 | // x <= 0 iff x == 0 when the comparison is unsigned. |
| 1831 | case kCondBE: |
| 1832 | __ Orrs(temps.Acquire(), left_low, left_high); |
| 1833 | return ret; |
| 1834 | case kCondLT: |
| 1835 | case kCondGE: |
| 1836 | __ Cmp(left_high, 0); |
| 1837 | return std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
| 1838 | // Trivially true or false. |
| 1839 | case kCondB: |
| 1840 | ret = std::make_pair(ne, eq); |
| 1841 | FALLTHROUGH_INTENDED; |
| 1842 | case kCondAE: |
| 1843 | __ Cmp(left_low, left_low); |
| 1844 | return ret; |
| 1845 | default: |
| 1846 | break; |
| 1847 | } |
| 1848 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1849 | |
| 1850 | switch (cond) { |
| 1851 | case kCondEQ: |
| 1852 | case kCondNE: |
| 1853 | case kCondB: |
| 1854 | case kCondBE: |
| 1855 | case kCondA: |
| 1856 | case kCondAE: { |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1857 | const uint32_t value_low = Low32Bits(value); |
| 1858 | Operand operand_low(value_low); |
| 1859 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1860 | __ Cmp(left_high, High32Bits(value)); |
| 1861 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1862 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1863 | // we must ensure that the operands corresponding to the least significant |
| 1864 | // halves of the inputs fit into a 16-bit CMP encoding. |
| 1865 | if (!left_low.IsLow() || !IsUint<8>(value_low)) { |
| 1866 | operand_low = Operand(temps.Acquire()); |
| 1867 | __ Mov(LeaveFlags, operand_low.GetBaseRegister(), value_low); |
| 1868 | } |
| 1869 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1870 | // We use the scope because of the IT block that follows. |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1871 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1872 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1873 | CodeBufferCheckScope::kExactSize); |
| 1874 | |
| 1875 | __ it(eq); |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1876 | __ cmp(eq, left_low, operand_low); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1877 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1878 | break; |
| 1879 | } |
| 1880 | case kCondLE: |
| 1881 | case kCondGT: |
| 1882 | // Trivially true or false. |
| 1883 | if (value == std::numeric_limits<int64_t>::max()) { |
| 1884 | __ Cmp(left_low, left_low); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1885 | 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] | 1886 | break; |
| 1887 | } |
| 1888 | |
| 1889 | if (cond == kCondLE) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1890 | DCHECK_EQ(opposite, kCondGT); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1891 | cond = kCondLT; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1892 | opposite = kCondGE; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1893 | } else { |
| 1894 | DCHECK_EQ(cond, kCondGT); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1895 | DCHECK_EQ(opposite, kCondLE); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1896 | cond = kCondGE; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1897 | opposite = kCondLT; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | value++; |
| 1901 | FALLTHROUGH_INTENDED; |
| 1902 | case kCondGE: |
| 1903 | case kCondLT: { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1904 | __ Cmp(left_low, Low32Bits(value)); |
| 1905 | __ Sbcs(temps.Acquire(), left_high, High32Bits(value)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1906 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1907 | break; |
| 1908 | } |
| 1909 | default: |
| 1910 | LOG(FATAL) << "Unreachable"; |
| 1911 | UNREACHABLE(); |
| 1912 | } |
| 1913 | |
| 1914 | return ret; |
| 1915 | } |
| 1916 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1917 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateLongTest( |
| 1918 | HCondition* condition, |
| 1919 | bool invert, |
| 1920 | CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1921 | DCHECK_EQ(condition->GetLeft()->GetType(), DataType::Type::kInt64); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1922 | |
| 1923 | const LocationSummary* const locations = condition->GetLocations(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1924 | IfCondition cond = condition->GetCondition(); |
| 1925 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1926 | |
| 1927 | if (invert) { |
| 1928 | std::swap(cond, opposite); |
| 1929 | } |
| 1930 | |
| 1931 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1932 | Location left = locations->InAt(0); |
| 1933 | Location right = locations->InAt(1); |
| 1934 | |
| 1935 | DCHECK(right.IsRegisterPair()); |
| 1936 | |
| 1937 | switch (cond) { |
| 1938 | case kCondEQ: |
| 1939 | case kCondNE: |
| 1940 | case kCondB: |
| 1941 | case kCondBE: |
| 1942 | case kCondA: |
| 1943 | case kCondAE: { |
| 1944 | __ Cmp(HighRegisterFrom(left), HighRegisterFrom(right)); |
| 1945 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1946 | // We use the scope because of the IT block that follows. |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1947 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1948 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1949 | CodeBufferCheckScope::kExactSize); |
| 1950 | |
| 1951 | __ it(eq); |
| 1952 | __ cmp(eq, LowRegisterFrom(left), LowRegisterFrom(right)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1953 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1954 | break; |
| 1955 | } |
| 1956 | case kCondLE: |
| 1957 | case kCondGT: |
| 1958 | if (cond == kCondLE) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1959 | DCHECK_EQ(opposite, kCondGT); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1960 | cond = kCondGE; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1961 | opposite = kCondLT; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1962 | } else { |
| 1963 | DCHECK_EQ(cond, kCondGT); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1964 | DCHECK_EQ(opposite, kCondLE); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1965 | cond = kCondLT; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1966 | opposite = kCondGE; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | std::swap(left, right); |
| 1970 | FALLTHROUGH_INTENDED; |
| 1971 | case kCondGE: |
| 1972 | case kCondLT: { |
| 1973 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1974 | |
| 1975 | __ Cmp(LowRegisterFrom(left), LowRegisterFrom(right)); |
| 1976 | __ Sbcs(temps.Acquire(), HighRegisterFrom(left), HighRegisterFrom(right)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1977 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1978 | break; |
| 1979 | } |
| 1980 | default: |
| 1981 | LOG(FATAL) << "Unreachable"; |
| 1982 | UNREACHABLE(); |
| 1983 | } |
| 1984 | |
| 1985 | return ret; |
| 1986 | } |
| 1987 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1988 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateTest(HCondition* condition, |
| 1989 | bool invert, |
| 1990 | CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1991 | const DataType::Type type = condition->GetLeft()->GetType(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1992 | IfCondition cond = condition->GetCondition(); |
| 1993 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1994 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1995 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1996 | if (invert) { |
| 1997 | std::swap(cond, opposite); |
| 1998 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1999 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2000 | if (type == DataType::Type::kInt64) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2001 | ret = condition->GetLocations()->InAt(1).IsConstant() |
| 2002 | ? GenerateLongTestConstant(condition, invert, codegen) |
| 2003 | : GenerateLongTest(condition, invert, codegen); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2004 | } else if (DataType::IsFloatingPointType(type)) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2005 | GenerateVcmp(condition, codegen); |
| 2006 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 2007 | ret = std::make_pair(ARMFPCondition(cond, condition->IsGtBias()), |
| 2008 | ARMFPCondition(opposite, condition->IsGtBias())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2009 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2010 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2011 | __ Cmp(InputRegisterAt(condition, 0), InputOperandAt(condition, 1)); |
| 2012 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | return ret; |
| 2016 | } |
| 2017 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2018 | static void GenerateConditionGeneric(HCondition* cond, CodeGeneratorARMVIXL* codegen) { |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2019 | const vixl32::Register out = OutputRegister(cond); |
| 2020 | const auto condition = GenerateTest(cond, false, codegen); |
| 2021 | |
| 2022 | __ Mov(LeaveFlags, out, 0); |
| 2023 | |
| 2024 | if (out.IsLow()) { |
| 2025 | // We use the scope because of the IT block that follows. |
| 2026 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 2027 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 2028 | CodeBufferCheckScope::kExactSize); |
| 2029 | |
| 2030 | __ it(condition.first); |
| 2031 | __ mov(condition.first, out, 1); |
| 2032 | } else { |
| 2033 | vixl32::Label done_label; |
| 2034 | vixl32::Label* const final_label = codegen->GetFinalLabel(cond, &done_label); |
| 2035 | |
| 2036 | __ B(condition.second, final_label, /* far_target */ false); |
| 2037 | __ Mov(out, 1); |
| 2038 | |
| 2039 | if (done_label.IsReferenced()) { |
| 2040 | __ Bind(&done_label); |
| 2041 | } |
| 2042 | } |
| 2043 | } |
| 2044 | |
| 2045 | static void GenerateEqualLong(HCondition* cond, CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2046 | DCHECK_EQ(cond->GetLeft()->GetType(), DataType::Type::kInt64); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2047 | |
| 2048 | const LocationSummary* const locations = cond->GetLocations(); |
| 2049 | IfCondition condition = cond->GetCondition(); |
| 2050 | const vixl32::Register out = OutputRegister(cond); |
| 2051 | const Location left = locations->InAt(0); |
| 2052 | const Location right = locations->InAt(1); |
| 2053 | vixl32::Register left_high = HighRegisterFrom(left); |
| 2054 | vixl32::Register left_low = LowRegisterFrom(left); |
| 2055 | vixl32::Register temp; |
| 2056 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 2057 | |
| 2058 | if (right.IsConstant()) { |
| 2059 | IfCondition opposite = cond->GetOppositeCondition(); |
| 2060 | const int64_t value = AdjustConstantForCondition(Int64ConstantFrom(right), |
| 2061 | &condition, |
| 2062 | &opposite); |
| 2063 | Operand right_high = High32Bits(value); |
| 2064 | Operand right_low = Low32Bits(value); |
| 2065 | |
| 2066 | // The output uses Location::kNoOutputOverlap. |
| 2067 | if (out.Is(left_high)) { |
| 2068 | std::swap(left_low, left_high); |
| 2069 | std::swap(right_low, right_high); |
| 2070 | } |
| 2071 | |
| 2072 | __ Sub(out, left_low, right_low); |
| 2073 | temp = temps.Acquire(); |
| 2074 | __ Sub(temp, left_high, right_high); |
| 2075 | } else { |
| 2076 | DCHECK(right.IsRegisterPair()); |
| 2077 | temp = temps.Acquire(); |
| 2078 | __ Sub(temp, left_high, HighRegisterFrom(right)); |
| 2079 | __ Sub(out, left_low, LowRegisterFrom(right)); |
| 2080 | } |
| 2081 | |
| 2082 | // Need to check after calling AdjustConstantForCondition(). |
| 2083 | DCHECK(condition == kCondEQ || condition == kCondNE) << condition; |
| 2084 | |
| 2085 | if (condition == kCondNE && out.IsLow()) { |
| 2086 | __ Orrs(out, out, temp); |
| 2087 | |
| 2088 | // We use the scope because of the IT block that follows. |
| 2089 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 2090 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 2091 | CodeBufferCheckScope::kExactSize); |
| 2092 | |
| 2093 | __ it(ne); |
| 2094 | __ mov(ne, out, 1); |
| 2095 | } else { |
| 2096 | __ Orr(out, out, temp); |
| 2097 | codegen->GenerateConditionWithZero(condition, out, out, temp); |
| 2098 | } |
| 2099 | } |
| 2100 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2101 | static void GenerateConditionLong(HCondition* cond, CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2102 | DCHECK_EQ(cond->GetLeft()->GetType(), DataType::Type::kInt64); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2103 | |
| 2104 | const LocationSummary* const locations = cond->GetLocations(); |
| 2105 | IfCondition condition = cond->GetCondition(); |
| 2106 | const vixl32::Register out = OutputRegister(cond); |
| 2107 | const Location left = locations->InAt(0); |
| 2108 | const Location right = locations->InAt(1); |
| 2109 | |
| 2110 | if (right.IsConstant()) { |
| 2111 | IfCondition opposite = cond->GetOppositeCondition(); |
| 2112 | |
| 2113 | // Comparisons against 0 are common enough to deserve special attention. |
| 2114 | if (AdjustConstantForCondition(Int64ConstantFrom(right), &condition, &opposite) == 0) { |
| 2115 | switch (condition) { |
| 2116 | case kCondNE: |
| 2117 | case kCondA: |
| 2118 | if (out.IsLow()) { |
| 2119 | // We only care if both input registers are 0 or not. |
| 2120 | __ Orrs(out, LowRegisterFrom(left), HighRegisterFrom(left)); |
| 2121 | |
| 2122 | // We use the scope because of the IT block that follows. |
| 2123 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 2124 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 2125 | CodeBufferCheckScope::kExactSize); |
| 2126 | |
| 2127 | __ it(ne); |
| 2128 | __ mov(ne, out, 1); |
| 2129 | return; |
| 2130 | } |
| 2131 | |
| 2132 | FALLTHROUGH_INTENDED; |
| 2133 | case kCondEQ: |
| 2134 | case kCondBE: |
| 2135 | // We only care if both input registers are 0 or not. |
| 2136 | __ Orr(out, LowRegisterFrom(left), HighRegisterFrom(left)); |
| 2137 | codegen->GenerateConditionWithZero(condition, out, out); |
| 2138 | return; |
| 2139 | case kCondLT: |
| 2140 | case kCondGE: |
| 2141 | // We only care about the sign bit. |
| 2142 | FALLTHROUGH_INTENDED; |
| 2143 | case kCondAE: |
| 2144 | case kCondB: |
| 2145 | codegen->GenerateConditionWithZero(condition, out, HighRegisterFrom(left)); |
| 2146 | return; |
| 2147 | case kCondLE: |
| 2148 | case kCondGT: |
| 2149 | default: |
| 2150 | break; |
| 2151 | } |
| 2152 | } |
| 2153 | } |
| 2154 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2155 | // If `out` is a low register, then the GenerateConditionGeneric() |
| 2156 | // function generates a shorter code sequence that is still branchless. |
| 2157 | if ((condition == kCondEQ || condition == kCondNE) && !out.IsLow()) { |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2158 | GenerateEqualLong(cond, codegen); |
| 2159 | return; |
| 2160 | } |
| 2161 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2162 | GenerateConditionGeneric(cond, codegen); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2163 | } |
| 2164 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 2165 | static void GenerateConditionIntegralOrNonPrimitive(HCondition* cond, |
| 2166 | CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2167 | const DataType::Type type = cond->GetLeft()->GetType(); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2168 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2169 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2170 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2171 | if (type == DataType::Type::kInt64) { |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2172 | GenerateConditionLong(cond, codegen); |
| 2173 | return; |
| 2174 | } |
| 2175 | |
| 2176 | IfCondition condition = cond->GetCondition(); |
| 2177 | vixl32::Register in = InputRegisterAt(cond, 0); |
| 2178 | const vixl32::Register out = OutputRegister(cond); |
| 2179 | const Location right = cond->GetLocations()->InAt(1); |
| 2180 | int64_t value; |
| 2181 | |
| 2182 | if (right.IsConstant()) { |
| 2183 | IfCondition opposite = cond->GetOppositeCondition(); |
| 2184 | |
| 2185 | value = AdjustConstantForCondition(Int64ConstantFrom(right), &condition, &opposite); |
| 2186 | |
| 2187 | // Comparisons against 0 are common enough to deserve special attention. |
| 2188 | if (value == 0) { |
| 2189 | switch (condition) { |
| 2190 | case kCondNE: |
| 2191 | case kCondA: |
| 2192 | if (out.IsLow() && out.Is(in)) { |
| 2193 | __ Cmp(out, 0); |
| 2194 | |
| 2195 | // We use the scope because of the IT block that follows. |
| 2196 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 2197 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 2198 | CodeBufferCheckScope::kExactSize); |
| 2199 | |
| 2200 | __ it(ne); |
| 2201 | __ mov(ne, out, 1); |
| 2202 | return; |
| 2203 | } |
| 2204 | |
| 2205 | FALLTHROUGH_INTENDED; |
| 2206 | case kCondEQ: |
| 2207 | case kCondBE: |
| 2208 | case kCondLT: |
| 2209 | case kCondGE: |
| 2210 | case kCondAE: |
| 2211 | case kCondB: |
| 2212 | codegen->GenerateConditionWithZero(condition, out, in); |
| 2213 | return; |
| 2214 | case kCondLE: |
| 2215 | case kCondGT: |
| 2216 | default: |
| 2217 | break; |
| 2218 | } |
| 2219 | } |
| 2220 | } |
| 2221 | |
| 2222 | if (condition == kCondEQ || condition == kCondNE) { |
| 2223 | Operand operand(0); |
| 2224 | |
| 2225 | if (right.IsConstant()) { |
| 2226 | operand = Operand::From(value); |
| 2227 | } else if (out.Is(RegisterFrom(right))) { |
| 2228 | // Avoid 32-bit instructions if possible. |
| 2229 | operand = InputOperandAt(cond, 0); |
| 2230 | in = RegisterFrom(right); |
| 2231 | } else { |
| 2232 | operand = InputOperandAt(cond, 1); |
| 2233 | } |
| 2234 | |
| 2235 | if (condition == kCondNE && out.IsLow()) { |
| 2236 | __ Subs(out, in, operand); |
| 2237 | |
| 2238 | // We use the scope because of the IT block that follows. |
| 2239 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 2240 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 2241 | CodeBufferCheckScope::kExactSize); |
| 2242 | |
| 2243 | __ it(ne); |
| 2244 | __ mov(ne, out, 1); |
| 2245 | } else { |
| 2246 | __ Sub(out, in, operand); |
| 2247 | codegen->GenerateConditionWithZero(condition, out, out); |
| 2248 | } |
| 2249 | |
| 2250 | return; |
| 2251 | } |
| 2252 | |
| 2253 | GenerateConditionGeneric(cond, codegen); |
| 2254 | } |
| 2255 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2256 | static bool CanEncodeConstantAs8BitImmediate(HConstant* constant) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2257 | const DataType::Type type = constant->GetType(); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2258 | bool ret = false; |
| 2259 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2260 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2261 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2262 | if (type == DataType::Type::kInt64) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2263 | const uint64_t value = Uint64ConstantFrom(constant); |
| 2264 | |
| 2265 | ret = IsUint<8>(Low32Bits(value)) && IsUint<8>(High32Bits(value)); |
| 2266 | } else { |
| 2267 | ret = IsUint<8>(Int32ConstantFrom(constant)); |
| 2268 | } |
| 2269 | |
| 2270 | return ret; |
| 2271 | } |
| 2272 | |
| 2273 | static Location Arm8BitEncodableConstantOrRegister(HInstruction* constant) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2274 | DCHECK(!DataType::IsFloatingPointType(constant->GetType())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2275 | |
| 2276 | if (constant->IsConstant() && CanEncodeConstantAs8BitImmediate(constant->AsConstant())) { |
| 2277 | return Location::ConstantLocation(constant->AsConstant()); |
| 2278 | } |
| 2279 | |
| 2280 | return Location::RequiresRegister(); |
| 2281 | } |
| 2282 | |
| 2283 | static bool CanGenerateConditionalMove(const Location& out, const Location& src) { |
| 2284 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 2285 | // we check that we are not dealing with floating-point output (there is no |
| 2286 | // 16-bit VMOV encoding). |
| 2287 | if (!out.IsRegister() && !out.IsRegisterPair()) { |
| 2288 | return false; |
| 2289 | } |
| 2290 | |
| 2291 | // For constants, we also check that the output is in one or two low registers, |
| 2292 | // and that the constants fit in an 8-bit unsigned integer, so that a 16-bit |
| 2293 | // MOV encoding can be used. |
| 2294 | if (src.IsConstant()) { |
| 2295 | if (!CanEncodeConstantAs8BitImmediate(src.GetConstant())) { |
| 2296 | return false; |
| 2297 | } |
| 2298 | |
| 2299 | if (out.IsRegister()) { |
| 2300 | if (!RegisterFrom(out).IsLow()) { |
| 2301 | return false; |
| 2302 | } |
| 2303 | } else { |
| 2304 | DCHECK(out.IsRegisterPair()); |
| 2305 | |
| 2306 | if (!HighRegisterFrom(out).IsLow()) { |
| 2307 | return false; |
| 2308 | } |
| 2309 | } |
| 2310 | } |
| 2311 | |
| 2312 | return true; |
| 2313 | } |
| 2314 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2315 | #undef __ |
| 2316 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2317 | vixl32::Label* CodeGeneratorARMVIXL::GetFinalLabel(HInstruction* instruction, |
| 2318 | vixl32::Label* final_label) { |
| 2319 | DCHECK(!instruction->IsControlFlow() && !instruction->IsSuspendCheck()); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 2320 | DCHECK(!instruction->IsInvoke() || !instruction->GetLocations()->CanCall()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2321 | |
| 2322 | const HBasicBlock* const block = instruction->GetBlock(); |
| 2323 | const HLoopInformation* const info = block->GetLoopInformation(); |
| 2324 | HInstruction* const next = instruction->GetNext(); |
| 2325 | |
| 2326 | // Avoid a branch to a branch. |
| 2327 | if (next->IsGoto() && (info == nullptr || |
| 2328 | !info->IsBackEdge(*block) || |
| 2329 | !info->HasSuspendCheck())) { |
| 2330 | final_label = GetLabelOf(next->AsGoto()->GetSuccessor()); |
| 2331 | } |
| 2332 | |
| 2333 | return final_label; |
| 2334 | } |
| 2335 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2336 | CodeGeneratorARMVIXL::CodeGeneratorARMVIXL(HGraph* graph, |
| 2337 | const ArmInstructionSetFeatures& isa_features, |
| 2338 | const CompilerOptions& compiler_options, |
| 2339 | OptimizingCompilerStats* stats) |
| 2340 | : CodeGenerator(graph, |
| 2341 | kNumberOfCoreRegisters, |
| 2342 | kNumberOfSRegisters, |
| 2343 | kNumberOfRegisterPairs, |
| 2344 | kCoreCalleeSaves.GetList(), |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2345 | ComputeSRegisterListMask(kFpuCalleeSaves), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2346 | compiler_options, |
| 2347 | stats), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2348 | block_labels_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 2349 | jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2350 | location_builder_(graph, this), |
| 2351 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2352 | move_resolver_(graph->GetAllocator(), this), |
| 2353 | assembler_(graph->GetAllocator()), |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2354 | isa_features_(isa_features), |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 2355 | uint32_literals_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2356 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 2357 | pc_relative_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 2358 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 2359 | pc_relative_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 2360 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 2361 | pc_relative_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 2362 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 2363 | baker_read_barrier_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 2364 | jit_string_patches_(StringReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2365 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 2366 | jit_class_patches_(TypeReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2367 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2368 | // Always save the LR register to mimic Quick. |
| 2369 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 2370 | // Give D30 and D31 as scratch register to VIXL. The register allocator only works on |
| 2371 | // S0-S31, which alias to D0-D15. |
| 2372 | GetVIXLAssembler()->GetScratchVRegisterList()->Combine(d31); |
| 2373 | GetVIXLAssembler()->GetScratchVRegisterList()->Combine(d30); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2374 | } |
| 2375 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2376 | void JumpTableARMVIXL::EmitTable(CodeGeneratorARMVIXL* codegen) { |
| 2377 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| 2378 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| 2379 | |
| 2380 | // 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] | 2381 | // underlying code buffer and we have generated a jump table of the right size, using |
| 2382 | // codegen->GetVIXLAssembler()->GetBuffer().Align(); |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 2383 | ExactAssemblyScope aas(codegen->GetVIXLAssembler(), |
| 2384 | num_entries * sizeof(int32_t), |
| 2385 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2386 | // TODO(VIXL): Check that using lower case bind is fine here. |
| 2387 | codegen->GetVIXLAssembler()->bind(&table_start_); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2388 | for (uint32_t i = 0; i < num_entries; i++) { |
| 2389 | codegen->GetVIXLAssembler()->place(bb_addresses_[i].get()); |
| 2390 | } |
| 2391 | } |
| 2392 | |
| 2393 | void JumpTableARMVIXL::FixTable(CodeGeneratorARMVIXL* codegen) { |
| 2394 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| 2395 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| 2396 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2397 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 2398 | for (uint32_t i = 0; i < num_entries; i++) { |
| 2399 | vixl32::Label* target_label = codegen->GetLabelOf(successors[i]); |
| 2400 | DCHECK(target_label->IsBound()); |
| 2401 | int32_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
| 2402 | // When doing BX to address we need to have lower bit set to 1 in T32. |
| 2403 | if (codegen->GetVIXLAssembler()->IsUsingT32()) { |
| 2404 | jump_offset++; |
| 2405 | } |
| 2406 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 2407 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2408 | |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 2409 | bb_addresses_[i].get()->UpdateValue(jump_offset, codegen->GetVIXLAssembler()->GetBuffer()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2410 | } |
| 2411 | } |
| 2412 | |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2413 | void CodeGeneratorARMVIXL::FixJumpTables() { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2414 | for (auto&& jump_table : jump_tables_) { |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2415 | jump_table->FixTable(this); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2416 | } |
| 2417 | } |
| 2418 | |
Andreas Gampe | ca620d7 | 2016-11-08 08:09:33 -0800 | [diff] [blame] | 2419 | #define __ reinterpret_cast<ArmVIXLAssembler*>(GetAssembler())->GetVIXLAssembler()-> // NOLINT |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2420 | |
| 2421 | void CodeGeneratorARMVIXL::Finalize(CodeAllocator* allocator) { |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2422 | FixJumpTables(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2423 | GetAssembler()->FinalizeCode(); |
| 2424 | CodeGenerator::Finalize(allocator); |
| 2425 | } |
| 2426 | |
| 2427 | void CodeGeneratorARMVIXL::SetupBlockedRegisters() const { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2428 | // Stack register, LR and PC are always reserved. |
| 2429 | blocked_core_registers_[SP] = true; |
| 2430 | blocked_core_registers_[LR] = true; |
| 2431 | blocked_core_registers_[PC] = true; |
| 2432 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 2433 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2434 | // Reserve marking register. |
| 2435 | blocked_core_registers_[MR] = true; |
| 2436 | } |
| 2437 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2438 | // Reserve thread register. |
| 2439 | blocked_core_registers_[TR] = true; |
| 2440 | |
| 2441 | // Reserve temp register. |
| 2442 | blocked_core_registers_[IP] = true; |
| 2443 | |
| 2444 | if (GetGraph()->IsDebuggable()) { |
| 2445 | // Stubs do not save callee-save floating point registers. If the graph |
| 2446 | // is debuggable, we need to deal with these registers differently. For |
| 2447 | // now, just block them. |
| 2448 | for (uint32_t i = kFpuCalleeSaves.GetFirstSRegister().GetCode(); |
| 2449 | i <= kFpuCalleeSaves.GetLastSRegister().GetCode(); |
| 2450 | ++i) { |
| 2451 | blocked_fpu_registers_[i] = true; |
| 2452 | } |
| 2453 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2454 | } |
| 2455 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2456 | InstructionCodeGeneratorARMVIXL::InstructionCodeGeneratorARMVIXL(HGraph* graph, |
| 2457 | CodeGeneratorARMVIXL* codegen) |
| 2458 | : InstructionCodeGenerator(graph, codegen), |
| 2459 | assembler_(codegen->GetAssembler()), |
| 2460 | codegen_(codegen) {} |
| 2461 | |
| 2462 | void CodeGeneratorARMVIXL::ComputeSpillMask() { |
| 2463 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 2464 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
| 2465 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 2466 | // restore another arbitrary register. |
| 2467 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister.GetCode()); |
| 2468 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 2469 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 2470 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 2471 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 2472 | // but in the range. |
| 2473 | if (fpu_spill_mask_ != 0) { |
| 2474 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 2475 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 2476 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 2477 | fpu_spill_mask_ |= (1 << i); |
| 2478 | } |
| 2479 | } |
| 2480 | } |
| 2481 | |
| 2482 | void CodeGeneratorARMVIXL::GenerateFrameEntry() { |
| 2483 | bool skip_overflow_check = |
| 2484 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
| 2485 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
| 2486 | __ Bind(&frame_entry_label_); |
| 2487 | |
| 2488 | if (HasEmptyFrame()) { |
| 2489 | return; |
| 2490 | } |
| 2491 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2492 | if (!skip_overflow_check) { |
Vladimir Marko | 4eb4563 | 2018-01-23 14:26:01 +0000 | [diff] [blame] | 2493 | // Using r4 instead of IP saves 2 bytes. Start by asserting that r4 is available here. |
| 2494 | for (vixl32::Register reg : kParameterCoreRegistersVIXL) { |
| 2495 | DCHECK(!reg.Is(r4)); |
| 2496 | } |
| 2497 | DCHECK(!kCoreCalleeSaves.Includes(r4)); |
| 2498 | vixl32::Register temp = r4; |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 2499 | __ Sub(temp, sp, Operand::From(GetStackOverflowReservedBytes(InstructionSet::kArm))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2500 | // The load must immediately precede RecordPcInfo. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 2501 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2502 | vixl32::kMaxInstructionSizeInBytes, |
| 2503 | CodeBufferCheckScope::kMaximumSize); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2504 | __ ldr(temp, MemOperand(temp)); |
| 2505 | RecordPcInfo(nullptr, 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2506 | } |
| 2507 | |
| 2508 | __ Push(RegisterList(core_spill_mask_)); |
| 2509 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 2510 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(kMethodRegister), |
| 2511 | 0, |
| 2512 | core_spill_mask_, |
| 2513 | kArmWordSize); |
| 2514 | if (fpu_spill_mask_ != 0) { |
| 2515 | uint32_t first = LeastSignificantBit(fpu_spill_mask_); |
| 2516 | |
| 2517 | // Check that list is contiguous. |
| 2518 | DCHECK_EQ(fpu_spill_mask_ >> CTZ(fpu_spill_mask_), ~0u >> (32 - POPCOUNT(fpu_spill_mask_))); |
| 2519 | |
| 2520 | __ Vpush(SRegisterList(vixl32::SRegister(first), POPCOUNT(fpu_spill_mask_))); |
| 2521 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2522 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(s0), 0, fpu_spill_mask_, kArmWordSize); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2523 | } |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 2524 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2525 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 2526 | __ Sub(sp, sp, adjust); |
| 2527 | GetAssembler()->cfi().AdjustCFAOffset(adjust); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 2528 | |
| 2529 | // Save the current method if we need it. Note that we do not |
| 2530 | // do this in HCurrentMethod, as the instruction might have been removed |
| 2531 | // in the SSA graph. |
| 2532 | if (RequiresCurrentMethod()) { |
| 2533 | GetAssembler()->StoreToOffset(kStoreWord, kMethodRegister, sp, 0); |
| 2534 | } |
Nicolas Geoffray | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 2535 | |
| 2536 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 2537 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2538 | vixl32::Register temp = temps.Acquire(); |
| 2539 | // Initialize should_deoptimize flag to 0. |
| 2540 | __ Mov(temp, 0); |
| 2541 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, GetStackOffsetOfShouldDeoptimizeFlag()); |
| 2542 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 2543 | |
| 2544 | MaybeGenerateMarkingRegisterCheck(/* code */ 1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2545 | } |
| 2546 | |
| 2547 | void CodeGeneratorARMVIXL::GenerateFrameExit() { |
| 2548 | if (HasEmptyFrame()) { |
| 2549 | __ Bx(lr); |
| 2550 | return; |
| 2551 | } |
| 2552 | GetAssembler()->cfi().RememberState(); |
| 2553 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 2554 | __ Add(sp, sp, adjust); |
| 2555 | GetAssembler()->cfi().AdjustCFAOffset(-adjust); |
| 2556 | if (fpu_spill_mask_ != 0) { |
| 2557 | uint32_t first = LeastSignificantBit(fpu_spill_mask_); |
| 2558 | |
| 2559 | // Check that list is contiguous. |
| 2560 | DCHECK_EQ(fpu_spill_mask_ >> CTZ(fpu_spill_mask_), ~0u >> (32 - POPCOUNT(fpu_spill_mask_))); |
| 2561 | |
| 2562 | __ Vpop(SRegisterList(vixl32::SRegister(first), POPCOUNT(fpu_spill_mask_))); |
| 2563 | GetAssembler()->cfi().AdjustCFAOffset( |
| 2564 | -static_cast<int>(kArmWordSize) * POPCOUNT(fpu_spill_mask_)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2565 | GetAssembler()->cfi().RestoreMany(DWARFReg(vixl32::SRegister(0)), fpu_spill_mask_); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2566 | } |
| 2567 | // Pop LR into PC to return. |
| 2568 | DCHECK_NE(core_spill_mask_ & (1 << kLrCode), 0U); |
| 2569 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << kLrCode))) | 1 << kPcCode; |
| 2570 | __ Pop(RegisterList(pop_mask)); |
| 2571 | GetAssembler()->cfi().RestoreState(); |
| 2572 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
| 2573 | } |
| 2574 | |
| 2575 | void CodeGeneratorARMVIXL::Bind(HBasicBlock* block) { |
| 2576 | __ Bind(GetLabelOf(block)); |
| 2577 | } |
| 2578 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2579 | Location InvokeDexCallingConventionVisitorARMVIXL::GetNextLocation(DataType::Type type) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2580 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2581 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2582 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2583 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2584 | case DataType::Type::kInt8: |
| 2585 | case DataType::Type::kUint16: |
| 2586 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2587 | case DataType::Type::kInt32: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2588 | uint32_t index = gp_index_++; |
| 2589 | uint32_t stack_index = stack_index_++; |
| 2590 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2591 | return LocationFrom(calling_convention.GetRegisterAt(index)); |
| 2592 | } else { |
| 2593 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2594 | } |
| 2595 | } |
| 2596 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2597 | case DataType::Type::kInt64: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2598 | uint32_t index = gp_index_; |
| 2599 | uint32_t stack_index = stack_index_; |
| 2600 | gp_index_ += 2; |
| 2601 | stack_index_ += 2; |
| 2602 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2603 | if (calling_convention.GetRegisterAt(index).Is(r1)) { |
| 2604 | // Skip R1, and use R2_R3 instead. |
| 2605 | gp_index_++; |
| 2606 | index++; |
| 2607 | } |
| 2608 | } |
| 2609 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2610 | DCHECK_EQ(calling_convention.GetRegisterAt(index).GetCode() + 1, |
| 2611 | calling_convention.GetRegisterAt(index + 1).GetCode()); |
| 2612 | |
| 2613 | return LocationFrom(calling_convention.GetRegisterAt(index), |
| 2614 | calling_convention.GetRegisterAt(index + 1)); |
| 2615 | } else { |
| 2616 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2617 | } |
| 2618 | } |
| 2619 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2620 | case DataType::Type::kFloat32: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2621 | uint32_t stack_index = stack_index_++; |
| 2622 | if (float_index_ % 2 == 0) { |
| 2623 | float_index_ = std::max(double_index_, float_index_); |
| 2624 | } |
| 2625 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 2626 | return LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 2627 | } else { |
| 2628 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2629 | } |
| 2630 | } |
| 2631 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2632 | case DataType::Type::kFloat64: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2633 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 2634 | uint32_t stack_index = stack_index_; |
| 2635 | stack_index_ += 2; |
| 2636 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 2637 | uint32_t index = double_index_; |
| 2638 | double_index_ += 2; |
| 2639 | Location result = LocationFrom( |
| 2640 | calling_convention.GetFpuRegisterAt(index), |
| 2641 | calling_convention.GetFpuRegisterAt(index + 1)); |
| 2642 | DCHECK(ExpectedPairLayout(result)); |
| 2643 | return result; |
| 2644 | } else { |
| 2645 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2646 | } |
| 2647 | } |
| 2648 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2649 | case DataType::Type::kVoid: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2650 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2651 | break; |
| 2652 | } |
| 2653 | return Location::NoLocation(); |
| 2654 | } |
| 2655 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2656 | Location InvokeDexCallingConventionVisitorARMVIXL::GetReturnLocation(DataType::Type type) const { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2657 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2658 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2659 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2660 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2661 | case DataType::Type::kInt8: |
| 2662 | case DataType::Type::kUint16: |
| 2663 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2664 | case DataType::Type::kInt32: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2665 | return LocationFrom(r0); |
| 2666 | } |
| 2667 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2668 | case DataType::Type::kFloat32: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2669 | return LocationFrom(s0); |
| 2670 | } |
| 2671 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2672 | case DataType::Type::kInt64: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2673 | return LocationFrom(r0, r1); |
| 2674 | } |
| 2675 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2676 | case DataType::Type::kFloat64: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2677 | return LocationFrom(s0, s1); |
| 2678 | } |
| 2679 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2680 | case DataType::Type::kVoid: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2681 | return Location::NoLocation(); |
| 2682 | } |
| 2683 | |
| 2684 | UNREACHABLE(); |
| 2685 | } |
| 2686 | |
| 2687 | Location InvokeDexCallingConventionVisitorARMVIXL::GetMethodLocation() const { |
| 2688 | return LocationFrom(kMethodRegister); |
| 2689 | } |
| 2690 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2691 | void CodeGeneratorARMVIXL::Move32(Location destination, Location source) { |
| 2692 | if (source.Equals(destination)) { |
| 2693 | return; |
| 2694 | } |
| 2695 | if (destination.IsRegister()) { |
| 2696 | if (source.IsRegister()) { |
| 2697 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 2698 | } else if (source.IsFpuRegister()) { |
| 2699 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
| 2700 | } else { |
| 2701 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 2702 | RegisterFrom(destination), |
| 2703 | sp, |
| 2704 | source.GetStackIndex()); |
| 2705 | } |
| 2706 | } else if (destination.IsFpuRegister()) { |
| 2707 | if (source.IsRegister()) { |
| 2708 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
| 2709 | } else if (source.IsFpuRegister()) { |
| 2710 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 2711 | } else { |
| 2712 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 2713 | } |
| 2714 | } else { |
| 2715 | DCHECK(destination.IsStackSlot()) << destination; |
| 2716 | if (source.IsRegister()) { |
| 2717 | GetAssembler()->StoreToOffset(kStoreWord, |
| 2718 | RegisterFrom(source), |
| 2719 | sp, |
| 2720 | destination.GetStackIndex()); |
| 2721 | } else if (source.IsFpuRegister()) { |
| 2722 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 2723 | } else { |
| 2724 | DCHECK(source.IsStackSlot()) << source; |
| 2725 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2726 | vixl32::Register temp = temps.Acquire(); |
| 2727 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 2728 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 2729 | } |
| 2730 | } |
| 2731 | } |
| 2732 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2733 | void CodeGeneratorARMVIXL::MoveConstant(Location location, int32_t value) { |
| 2734 | DCHECK(location.IsRegister()); |
| 2735 | __ Mov(RegisterFrom(location), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2736 | } |
| 2737 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2738 | void CodeGeneratorARMVIXL::MoveLocation(Location dst, Location src, DataType::Type dst_type) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2739 | // TODO(VIXL): Maybe refactor to have the 'move' implementation here and use it in |
| 2740 | // `ParallelMoveResolverARMVIXL::EmitMove`, as is done in the `arm64` backend. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2741 | HParallelMove move(GetGraph()->GetAllocator()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2742 | move.AddMove(src, dst, dst_type, nullptr); |
| 2743 | GetMoveResolver()->EmitNativeCode(&move); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2744 | } |
| 2745 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2746 | void CodeGeneratorARMVIXL::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 2747 | if (location.IsRegister()) { |
| 2748 | locations->AddTemp(location); |
| 2749 | } else if (location.IsRegisterPair()) { |
| 2750 | locations->AddTemp(LocationFrom(LowRegisterFrom(location))); |
| 2751 | locations->AddTemp(LocationFrom(HighRegisterFrom(location))); |
| 2752 | } else { |
| 2753 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 2754 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2755 | } |
| 2756 | |
| 2757 | void CodeGeneratorARMVIXL::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2758 | HInstruction* instruction, |
| 2759 | uint32_t dex_pc, |
| 2760 | SlowPathCode* slow_path) { |
| 2761 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2762 | __ Ldr(lr, MemOperand(tr, GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value())); |
| 2763 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 2764 | // 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] | 2765 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2766 | vixl32::k16BitT32InstructionSizeInBytes, |
| 2767 | CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2768 | __ blx(lr); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2769 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2770 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2771 | } |
| 2772 | } |
| 2773 | |
| 2774 | void CodeGeneratorARMVIXL::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2775 | HInstruction* instruction, |
| 2776 | SlowPathCode* slow_path) { |
| 2777 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2778 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2779 | __ Blx(lr); |
| 2780 | } |
| 2781 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2782 | void InstructionCodeGeneratorARMVIXL::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 2783 | if (successor->IsExitBlock()) { |
| 2784 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 2785 | return; // no code needed |
| 2786 | } |
| 2787 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2788 | HBasicBlock* block = got->GetBlock(); |
| 2789 | HInstruction* previous = got->GetPrevious(); |
| 2790 | HLoopInformation* info = block->GetLoopInformation(); |
| 2791 | |
| 2792 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2793 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2794 | return; |
| 2795 | } |
| 2796 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2797 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 2798 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 2); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2799 | } |
| 2800 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 2801 | __ B(codegen_->GetLabelOf(successor)); |
| 2802 | } |
| 2803 | } |
| 2804 | |
| 2805 | void LocationsBuilderARMVIXL::VisitGoto(HGoto* got) { |
| 2806 | got->SetLocations(nullptr); |
| 2807 | } |
| 2808 | |
| 2809 | void InstructionCodeGeneratorARMVIXL::VisitGoto(HGoto* got) { |
| 2810 | HandleGoto(got, got->GetSuccessor()); |
| 2811 | } |
| 2812 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2813 | void LocationsBuilderARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2814 | try_boundary->SetLocations(nullptr); |
| 2815 | } |
| 2816 | |
| 2817 | void InstructionCodeGeneratorARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2818 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2819 | if (!successor->IsExitBlock()) { |
| 2820 | HandleGoto(try_boundary, successor); |
| 2821 | } |
| 2822 | } |
| 2823 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2824 | void LocationsBuilderARMVIXL::VisitExit(HExit* exit) { |
| 2825 | exit->SetLocations(nullptr); |
| 2826 | } |
| 2827 | |
| 2828 | void InstructionCodeGeneratorARMVIXL::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 2829 | } |
| 2830 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2831 | void InstructionCodeGeneratorARMVIXL::GenerateCompareTestAndBranch(HCondition* condition, |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2832 | vixl32::Label* true_target, |
| 2833 | vixl32::Label* false_target, |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2834 | bool is_far_target) { |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2835 | if (true_target == false_target) { |
| 2836 | DCHECK(true_target != nullptr); |
| 2837 | __ B(true_target); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2838 | return; |
| 2839 | } |
| 2840 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2841 | vixl32::Label* non_fallthrough_target; |
| 2842 | bool invert; |
| 2843 | bool emit_both_branches; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2844 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2845 | if (true_target == nullptr) { |
| 2846 | // The true target is fallthrough. |
| 2847 | DCHECK(false_target != nullptr); |
| 2848 | non_fallthrough_target = false_target; |
| 2849 | invert = true; |
| 2850 | emit_both_branches = false; |
| 2851 | } else { |
| 2852 | non_fallthrough_target = true_target; |
| 2853 | invert = false; |
| 2854 | // Either the false target is fallthrough, or there is no fallthrough |
| 2855 | // and both branches must be emitted. |
| 2856 | emit_both_branches = (false_target != nullptr); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2857 | } |
| 2858 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2859 | const auto cond = GenerateTest(condition, invert, codegen_); |
| 2860 | |
| 2861 | __ B(cond.first, non_fallthrough_target, is_far_target); |
| 2862 | |
| 2863 | if (emit_both_branches) { |
| 2864 | // No target falls through, we need to branch. |
| 2865 | __ B(false_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2866 | } |
| 2867 | } |
| 2868 | |
| 2869 | void InstructionCodeGeneratorARMVIXL::GenerateTestAndBranch(HInstruction* instruction, |
| 2870 | size_t condition_input_index, |
| 2871 | vixl32::Label* true_target, |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2872 | vixl32::Label* false_target, |
| 2873 | bool far_target) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2874 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 2875 | |
| 2876 | if (true_target == nullptr && false_target == nullptr) { |
| 2877 | // Nothing to do. The code always falls through. |
| 2878 | return; |
| 2879 | } else if (cond->IsIntConstant()) { |
| 2880 | // Constant condition, statically compared against "true" (integer value 1). |
| 2881 | if (cond->AsIntConstant()->IsTrue()) { |
| 2882 | if (true_target != nullptr) { |
| 2883 | __ B(true_target); |
| 2884 | } |
| 2885 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 2886 | DCHECK(cond->AsIntConstant()->IsFalse()) << Int32ConstantFrom(cond); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2887 | if (false_target != nullptr) { |
| 2888 | __ B(false_target); |
| 2889 | } |
| 2890 | } |
| 2891 | return; |
| 2892 | } |
| 2893 | |
| 2894 | // The following code generates these patterns: |
| 2895 | // (1) true_target == nullptr && false_target != nullptr |
| 2896 | // - opposite condition true => branch to false_target |
| 2897 | // (2) true_target != nullptr && false_target == nullptr |
| 2898 | // - condition true => branch to true_target |
| 2899 | // (3) true_target != nullptr && false_target != nullptr |
| 2900 | // - condition true => branch to true_target |
| 2901 | // - branch to false_target |
| 2902 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 2903 | // Condition has been materialized, compare the output to 0. |
| 2904 | if (kIsDebugBuild) { |
| 2905 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 2906 | DCHECK(cond_val.IsRegister()); |
| 2907 | } |
| 2908 | if (true_target == nullptr) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2909 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, condition_input_index), |
| 2910 | false_target, |
| 2911 | far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2912 | } else { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2913 | __ CompareAndBranchIfNonZero(InputRegisterAt(instruction, condition_input_index), |
| 2914 | true_target, |
| 2915 | far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2916 | } |
| 2917 | } else { |
| 2918 | // Condition has not been materialized. Use its inputs as the comparison and |
| 2919 | // its condition as the branch condition. |
| 2920 | HCondition* condition = cond->AsCondition(); |
| 2921 | |
| 2922 | // If this is a long or FP comparison that has been folded into |
| 2923 | // the HCondition, generate the comparison directly. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2924 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 2925 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2926 | GenerateCompareTestAndBranch(condition, true_target, false_target, far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2927 | return; |
| 2928 | } |
| 2929 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2930 | vixl32::Label* non_fallthrough_target; |
| 2931 | vixl32::Condition arm_cond = vixl32::Condition::None(); |
| 2932 | const vixl32::Register left = InputRegisterAt(cond, 0); |
| 2933 | const Operand right = InputOperandAt(cond, 1); |
| 2934 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2935 | if (true_target == nullptr) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2936 | arm_cond = ARMCondition(condition->GetOppositeCondition()); |
| 2937 | non_fallthrough_target = false_target; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2938 | } else { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2939 | arm_cond = ARMCondition(condition->GetCondition()); |
| 2940 | non_fallthrough_target = true_target; |
| 2941 | } |
| 2942 | |
| 2943 | if (right.IsImmediate() && right.GetImmediate() == 0 && (arm_cond.Is(ne) || arm_cond.Is(eq))) { |
| 2944 | if (arm_cond.Is(eq)) { |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2945 | __ CompareAndBranchIfZero(left, non_fallthrough_target, far_target); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2946 | } else { |
| 2947 | DCHECK(arm_cond.Is(ne)); |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2948 | __ CompareAndBranchIfNonZero(left, non_fallthrough_target, far_target); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2949 | } |
| 2950 | } else { |
| 2951 | __ Cmp(left, right); |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2952 | __ B(arm_cond, non_fallthrough_target, far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2953 | } |
| 2954 | } |
| 2955 | |
| 2956 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 2957 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 2958 | if (true_target != nullptr && false_target != nullptr) { |
| 2959 | __ B(false_target); |
| 2960 | } |
| 2961 | } |
| 2962 | |
| 2963 | void LocationsBuilderARMVIXL::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2964 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2965 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| 2966 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2967 | } |
| 2968 | } |
| 2969 | |
| 2970 | void InstructionCodeGeneratorARMVIXL::VisitIf(HIf* if_instr) { |
| 2971 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 2972 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2973 | vixl32::Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 2974 | nullptr : codegen_->GetLabelOf(true_successor); |
| 2975 | vixl32::Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 2976 | nullptr : codegen_->GetLabelOf(false_successor); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2977 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
| 2978 | } |
| 2979 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2980 | void LocationsBuilderARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2981 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2982 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 2983 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 2984 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2985 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 2986 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2987 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| 2988 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2989 | } |
| 2990 | } |
| 2991 | |
| 2992 | void InstructionCodeGeneratorARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2993 | SlowPathCodeARMVIXL* slow_path = |
| 2994 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARMVIXL>(deoptimize); |
| 2995 | GenerateTestAndBranch(deoptimize, |
| 2996 | /* condition_input_index */ 0, |
| 2997 | slow_path->GetEntryLabel(), |
| 2998 | /* false_target */ nullptr); |
| 2999 | } |
| 3000 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3001 | void LocationsBuilderARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3002 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3003 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3004 | locations->SetOut(Location::RequiresRegister()); |
| 3005 | } |
| 3006 | |
| 3007 | void InstructionCodeGeneratorARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3008 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3009 | OutputRegister(flag), |
| 3010 | sp, |
| 3011 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 3012 | } |
| 3013 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3014 | void LocationsBuilderARMVIXL::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3015 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3016 | const bool is_floating_point = DataType::IsFloatingPointType(select->GetType()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3017 | |
| 3018 | if (is_floating_point) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3019 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3020 | locations->SetInAt(1, Location::FpuRegisterOrConstant(select->GetTrueValue())); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3021 | } else { |
| 3022 | locations->SetInAt(0, Location::RequiresRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3023 | locations->SetInAt(1, Arm8BitEncodableConstantOrRegister(select->GetTrueValue())); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3024 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3025 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3026 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3027 | locations->SetInAt(2, Location::RegisterOrConstant(select->GetCondition())); |
| 3028 | // The code generator handles overlap with the values, but not with the condition. |
| 3029 | locations->SetOut(Location::SameAsFirstInput()); |
| 3030 | } else if (is_floating_point) { |
| 3031 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3032 | } else { |
| 3033 | if (!locations->InAt(1).IsConstant()) { |
| 3034 | locations->SetInAt(0, Arm8BitEncodableConstantOrRegister(select->GetFalseValue())); |
| 3035 | } |
| 3036 | |
| 3037 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3038 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3039 | } |
| 3040 | |
| 3041 | void InstructionCodeGeneratorARMVIXL::VisitSelect(HSelect* select) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3042 | HInstruction* const condition = select->GetCondition(); |
| 3043 | const LocationSummary* const locations = select->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3044 | const DataType::Type type = select->GetType(); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3045 | const Location first = locations->InAt(0); |
| 3046 | const Location out = locations->Out(); |
| 3047 | const Location second = locations->InAt(1); |
| 3048 | Location src; |
| 3049 | |
| 3050 | if (condition->IsIntConstant()) { |
| 3051 | if (condition->AsIntConstant()->IsFalse()) { |
| 3052 | src = first; |
| 3053 | } else { |
| 3054 | src = second; |
| 3055 | } |
| 3056 | |
| 3057 | codegen_->MoveLocation(out, src, type); |
| 3058 | return; |
| 3059 | } |
| 3060 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3061 | if (!DataType::IsFloatingPointType(type)) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3062 | bool invert = false; |
| 3063 | |
| 3064 | if (out.Equals(second)) { |
| 3065 | src = first; |
| 3066 | invert = true; |
| 3067 | } else if (out.Equals(first)) { |
| 3068 | src = second; |
| 3069 | } else if (second.IsConstant()) { |
| 3070 | DCHECK(CanEncodeConstantAs8BitImmediate(second.GetConstant())); |
| 3071 | src = second; |
| 3072 | } else if (first.IsConstant()) { |
| 3073 | DCHECK(CanEncodeConstantAs8BitImmediate(first.GetConstant())); |
| 3074 | src = first; |
| 3075 | invert = true; |
| 3076 | } else { |
| 3077 | src = second; |
| 3078 | } |
| 3079 | |
| 3080 | if (CanGenerateConditionalMove(out, src)) { |
| 3081 | if (!out.Equals(first) && !out.Equals(second)) { |
| 3082 | codegen_->MoveLocation(out, src.Equals(first) ? second : first, type); |
| 3083 | } |
| 3084 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3085 | std::pair<vixl32::Condition, vixl32::Condition> cond(eq, ne); |
| 3086 | |
| 3087 | if (IsBooleanValueOrMaterializedCondition(condition)) { |
| 3088 | __ Cmp(InputRegisterAt(select, 2), 0); |
| 3089 | cond = invert ? std::make_pair(eq, ne) : std::make_pair(ne, eq); |
| 3090 | } else { |
| 3091 | cond = GenerateTest(condition->AsCondition(), invert, codegen_); |
| 3092 | } |
| 3093 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3094 | const size_t instr_count = out.IsRegisterPair() ? 4 : 2; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3095 | // We use the scope because of the IT block that follows. |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3096 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 3097 | instr_count * vixl32::k16BitT32InstructionSizeInBytes, |
| 3098 | CodeBufferCheckScope::kExactSize); |
| 3099 | |
| 3100 | if (out.IsRegister()) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3101 | __ it(cond.first); |
| 3102 | __ mov(cond.first, RegisterFrom(out), OperandFrom(src, type)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3103 | } else { |
| 3104 | DCHECK(out.IsRegisterPair()); |
| 3105 | |
| 3106 | Operand operand_high(0); |
| 3107 | Operand operand_low(0); |
| 3108 | |
| 3109 | if (src.IsConstant()) { |
| 3110 | const int64_t value = Int64ConstantFrom(src); |
| 3111 | |
| 3112 | operand_high = High32Bits(value); |
| 3113 | operand_low = Low32Bits(value); |
| 3114 | } else { |
| 3115 | DCHECK(src.IsRegisterPair()); |
| 3116 | operand_high = HighRegisterFrom(src); |
| 3117 | operand_low = LowRegisterFrom(src); |
| 3118 | } |
| 3119 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3120 | __ it(cond.first); |
| 3121 | __ mov(cond.first, LowRegisterFrom(out), operand_low); |
| 3122 | __ it(cond.first); |
| 3123 | __ mov(cond.first, HighRegisterFrom(out), operand_high); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3124 | } |
| 3125 | |
| 3126 | return; |
| 3127 | } |
| 3128 | } |
| 3129 | |
| 3130 | vixl32::Label* false_target = nullptr; |
| 3131 | vixl32::Label* true_target = nullptr; |
| 3132 | vixl32::Label select_end; |
| 3133 | vixl32::Label* const target = codegen_->GetFinalLabel(select, &select_end); |
| 3134 | |
| 3135 | if (out.Equals(second)) { |
| 3136 | true_target = target; |
| 3137 | src = first; |
| 3138 | } else { |
| 3139 | false_target = target; |
| 3140 | src = second; |
| 3141 | |
| 3142 | if (!out.Equals(first)) { |
| 3143 | codegen_->MoveLocation(out, first, type); |
| 3144 | } |
| 3145 | } |
| 3146 | |
| 3147 | GenerateTestAndBranch(select, 2, true_target, false_target, /* far_target */ false); |
| 3148 | codegen_->MoveLocation(out, src, type); |
| 3149 | |
| 3150 | if (select_end.IsReferenced()) { |
| 3151 | __ Bind(&select_end); |
| 3152 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3153 | } |
| 3154 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 3155 | void LocationsBuilderARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3156 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 3157 | } |
| 3158 | |
| 3159 | void InstructionCodeGeneratorARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3160 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| 3161 | } |
| 3162 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3163 | void CodeGeneratorARMVIXL::GenerateNop() { |
| 3164 | __ Nop(); |
| 3165 | } |
| 3166 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3167 | // `temp` is an extra temporary register that is used for some conditions; |
| 3168 | // callers may not specify it, in which case the method will use a scratch |
| 3169 | // register instead. |
| 3170 | void CodeGeneratorARMVIXL::GenerateConditionWithZero(IfCondition condition, |
| 3171 | vixl32::Register out, |
| 3172 | vixl32::Register in, |
| 3173 | vixl32::Register temp) { |
| 3174 | switch (condition) { |
| 3175 | case kCondEQ: |
| 3176 | // x <= 0 iff x == 0 when the comparison is unsigned. |
| 3177 | case kCondBE: |
| 3178 | if (!temp.IsValid() || (out.IsLow() && !out.Is(in))) { |
| 3179 | temp = out; |
| 3180 | } |
| 3181 | |
| 3182 | // Avoid 32-bit instructions if possible; note that `in` and `temp` must be |
| 3183 | // different as well. |
| 3184 | if (in.IsLow() && temp.IsLow() && !in.Is(temp)) { |
| 3185 | // temp = - in; only 0 sets the carry flag. |
| 3186 | __ Rsbs(temp, in, 0); |
| 3187 | |
| 3188 | if (out.Is(in)) { |
| 3189 | std::swap(in, temp); |
| 3190 | } |
| 3191 | |
| 3192 | // out = - in + in + carry = carry |
| 3193 | __ Adc(out, temp, in); |
| 3194 | } else { |
| 3195 | // If `in` is 0, then it has 32 leading zeros, and less than that otherwise. |
| 3196 | __ Clz(out, in); |
| 3197 | // Any number less than 32 logically shifted right by 5 bits results in 0; |
| 3198 | // the same operation on 32 yields 1. |
| 3199 | __ Lsr(out, out, 5); |
| 3200 | } |
| 3201 | |
| 3202 | break; |
| 3203 | case kCondNE: |
| 3204 | // x > 0 iff x != 0 when the comparison is unsigned. |
| 3205 | case kCondA: { |
| 3206 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3207 | |
| 3208 | if (out.Is(in)) { |
| 3209 | if (!temp.IsValid() || in.Is(temp)) { |
| 3210 | temp = temps.Acquire(); |
| 3211 | } |
| 3212 | } else if (!temp.IsValid() || !temp.IsLow()) { |
| 3213 | temp = out; |
| 3214 | } |
| 3215 | |
| 3216 | // temp = in - 1; only 0 does not set the carry flag. |
| 3217 | __ Subs(temp, in, 1); |
| 3218 | // out = in + ~temp + carry = in + (-(in - 1) - 1) + carry = in - in + 1 - 1 + carry = carry |
| 3219 | __ Sbc(out, in, temp); |
| 3220 | break; |
| 3221 | } |
| 3222 | case kCondGE: |
| 3223 | __ Mvn(out, in); |
| 3224 | in = out; |
| 3225 | FALLTHROUGH_INTENDED; |
| 3226 | case kCondLT: |
| 3227 | // We only care about the sign bit. |
| 3228 | __ Lsr(out, in, 31); |
| 3229 | break; |
| 3230 | case kCondAE: |
| 3231 | // Trivially true. |
| 3232 | __ Mov(out, 1); |
| 3233 | break; |
| 3234 | case kCondB: |
| 3235 | // Trivially false. |
| 3236 | __ Mov(out, 0); |
| 3237 | break; |
| 3238 | default: |
| 3239 | LOG(FATAL) << "Unexpected condition " << condition; |
| 3240 | UNREACHABLE(); |
| 3241 | } |
| 3242 | } |
| 3243 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3244 | void LocationsBuilderARMVIXL::HandleCondition(HCondition* cond) { |
| 3245 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3246 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3247 | // Handle the long/FP comparisons made in instruction simplification. |
| 3248 | switch (cond->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3249 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3250 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3251 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 3252 | if (!cond->IsEmittedAtUseSite()) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3253 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3254 | } |
| 3255 | break; |
| 3256 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3257 | case DataType::Type::kFloat32: |
| 3258 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3259 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 3260 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3261 | if (!cond->IsEmittedAtUseSite()) { |
| 3262 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3263 | } |
| 3264 | break; |
| 3265 | |
| 3266 | default: |
| 3267 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3268 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 3269 | if (!cond->IsEmittedAtUseSite()) { |
| 3270 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3271 | } |
| 3272 | } |
| 3273 | } |
| 3274 | |
| 3275 | void InstructionCodeGeneratorARMVIXL::HandleCondition(HCondition* cond) { |
| 3276 | if (cond->IsEmittedAtUseSite()) { |
| 3277 | return; |
| 3278 | } |
| 3279 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3280 | const DataType::Type type = cond->GetLeft()->GetType(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3281 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3282 | if (DataType::IsFloatingPointType(type)) { |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3283 | GenerateConditionGeneric(cond, codegen_); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3284 | return; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3285 | } |
| 3286 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3287 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3288 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3289 | const IfCondition condition = cond->GetCondition(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3290 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3291 | // A condition with only one boolean input, or two boolean inputs without being equality or |
| 3292 | // inequality results from transformations done by the instruction simplifier, and is handled |
| 3293 | // as a regular condition with integral inputs. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3294 | if (type == DataType::Type::kBool && |
| 3295 | cond->GetRight()->GetType() == DataType::Type::kBool && |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3296 | (condition == kCondEQ || condition == kCondNE)) { |
| 3297 | vixl32::Register left = InputRegisterAt(cond, 0); |
| 3298 | const vixl32::Register out = OutputRegister(cond); |
| 3299 | const Location right_loc = cond->GetLocations()->InAt(1); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3300 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3301 | // The constant case is handled by the instruction simplifier. |
| 3302 | DCHECK(!right_loc.IsConstant()); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3303 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3304 | vixl32::Register right = RegisterFrom(right_loc); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3305 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3306 | // Avoid 32-bit instructions if possible. |
| 3307 | if (out.Is(right)) { |
| 3308 | std::swap(left, right); |
| 3309 | } |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3310 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3311 | __ Eor(out, left, right); |
| 3312 | |
| 3313 | if (condition == kCondEQ) { |
| 3314 | __ Eor(out, out, 1); |
| 3315 | } |
| 3316 | |
| 3317 | return; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3318 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 3319 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3320 | GenerateConditionIntegralOrNonPrimitive(cond, codegen_); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3321 | } |
| 3322 | |
| 3323 | void LocationsBuilderARMVIXL::VisitEqual(HEqual* comp) { |
| 3324 | HandleCondition(comp); |
| 3325 | } |
| 3326 | |
| 3327 | void InstructionCodeGeneratorARMVIXL::VisitEqual(HEqual* comp) { |
| 3328 | HandleCondition(comp); |
| 3329 | } |
| 3330 | |
| 3331 | void LocationsBuilderARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 3332 | HandleCondition(comp); |
| 3333 | } |
| 3334 | |
| 3335 | void InstructionCodeGeneratorARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 3336 | HandleCondition(comp); |
| 3337 | } |
| 3338 | |
| 3339 | void LocationsBuilderARMVIXL::VisitLessThan(HLessThan* comp) { |
| 3340 | HandleCondition(comp); |
| 3341 | } |
| 3342 | |
| 3343 | void InstructionCodeGeneratorARMVIXL::VisitLessThan(HLessThan* comp) { |
| 3344 | HandleCondition(comp); |
| 3345 | } |
| 3346 | |
| 3347 | void LocationsBuilderARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 3348 | HandleCondition(comp); |
| 3349 | } |
| 3350 | |
| 3351 | void InstructionCodeGeneratorARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 3352 | HandleCondition(comp); |
| 3353 | } |
| 3354 | |
| 3355 | void LocationsBuilderARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 3356 | HandleCondition(comp); |
| 3357 | } |
| 3358 | |
| 3359 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 3360 | HandleCondition(comp); |
| 3361 | } |
| 3362 | |
| 3363 | void LocationsBuilderARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 3364 | HandleCondition(comp); |
| 3365 | } |
| 3366 | |
| 3367 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 3368 | HandleCondition(comp); |
| 3369 | } |
| 3370 | |
| 3371 | void LocationsBuilderARMVIXL::VisitBelow(HBelow* comp) { |
| 3372 | HandleCondition(comp); |
| 3373 | } |
| 3374 | |
| 3375 | void InstructionCodeGeneratorARMVIXL::VisitBelow(HBelow* comp) { |
| 3376 | HandleCondition(comp); |
| 3377 | } |
| 3378 | |
| 3379 | void LocationsBuilderARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 3380 | HandleCondition(comp); |
| 3381 | } |
| 3382 | |
| 3383 | void InstructionCodeGeneratorARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 3384 | HandleCondition(comp); |
| 3385 | } |
| 3386 | |
| 3387 | void LocationsBuilderARMVIXL::VisitAbove(HAbove* comp) { |
| 3388 | HandleCondition(comp); |
| 3389 | } |
| 3390 | |
| 3391 | void InstructionCodeGeneratorARMVIXL::VisitAbove(HAbove* comp) { |
| 3392 | HandleCondition(comp); |
| 3393 | } |
| 3394 | |
| 3395 | void LocationsBuilderARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 3396 | HandleCondition(comp); |
| 3397 | } |
| 3398 | |
| 3399 | void InstructionCodeGeneratorARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 3400 | HandleCondition(comp); |
| 3401 | } |
| 3402 | |
| 3403 | void LocationsBuilderARMVIXL::VisitIntConstant(HIntConstant* constant) { |
| 3404 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3405 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3406 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3407 | } |
| 3408 | |
| 3409 | void InstructionCodeGeneratorARMVIXL::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 3410 | // Will be generated at use site. |
| 3411 | } |
| 3412 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3413 | void LocationsBuilderARMVIXL::VisitNullConstant(HNullConstant* constant) { |
| 3414 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3415 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3416 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3417 | } |
| 3418 | |
| 3419 | void InstructionCodeGeneratorARMVIXL::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 3420 | // Will be generated at use site. |
| 3421 | } |
| 3422 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3423 | void LocationsBuilderARMVIXL::VisitLongConstant(HLongConstant* constant) { |
| 3424 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3425 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3426 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3427 | } |
| 3428 | |
| 3429 | void InstructionCodeGeneratorARMVIXL::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 3430 | // Will be generated at use site. |
| 3431 | } |
| 3432 | |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3433 | void LocationsBuilderARMVIXL::VisitFloatConstant(HFloatConstant* constant) { |
| 3434 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3435 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3436 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3437 | } |
| 3438 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3439 | void InstructionCodeGeneratorARMVIXL::VisitFloatConstant( |
| 3440 | HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3441 | // Will be generated at use site. |
| 3442 | } |
| 3443 | |
| 3444 | void LocationsBuilderARMVIXL::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3445 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3446 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3447 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3448 | } |
| 3449 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3450 | void InstructionCodeGeneratorARMVIXL::VisitDoubleConstant( |
| 3451 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3452 | // Will be generated at use site. |
| 3453 | } |
| 3454 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 3455 | void LocationsBuilderARMVIXL::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 3456 | constructor_fence->SetLocations(nullptr); |
| 3457 | } |
| 3458 | |
| 3459 | void InstructionCodeGeneratorARMVIXL::VisitConstructorFence( |
| 3460 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 3461 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 3462 | } |
| 3463 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3464 | void LocationsBuilderARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3465 | memory_barrier->SetLocations(nullptr); |
| 3466 | } |
| 3467 | |
| 3468 | void InstructionCodeGeneratorARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3469 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 3470 | } |
| 3471 | |
| 3472 | void LocationsBuilderARMVIXL::VisitReturnVoid(HReturnVoid* ret) { |
| 3473 | ret->SetLocations(nullptr); |
| 3474 | } |
| 3475 | |
| 3476 | void InstructionCodeGeneratorARMVIXL::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 3477 | codegen_->GenerateFrameExit(); |
| 3478 | } |
| 3479 | |
| 3480 | void LocationsBuilderARMVIXL::VisitReturn(HReturn* ret) { |
| 3481 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3482 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3483 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
| 3484 | } |
| 3485 | |
| 3486 | void InstructionCodeGeneratorARMVIXL::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 3487 | codegen_->GenerateFrameExit(); |
| 3488 | } |
| 3489 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3490 | void LocationsBuilderARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3491 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3492 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3493 | // the method_idx. |
| 3494 | HandleInvoke(invoke); |
| 3495 | } |
| 3496 | |
| 3497 | void InstructionCodeGeneratorARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3498 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3499 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 3); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3500 | } |
| 3501 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3502 | void LocationsBuilderARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3503 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3504 | // art::PrepareForRegisterAllocation. |
| 3505 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 3506 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3507 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3508 | if (intrinsic.TryDispatch(invoke)) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3509 | return; |
| 3510 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3511 | |
| 3512 | HandleInvoke(invoke); |
| 3513 | } |
| 3514 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3515 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARMVIXL* codegen) { |
| 3516 | if (invoke->GetLocations()->Intrinsified()) { |
| 3517 | IntrinsicCodeGeneratorARMVIXL intrinsic(codegen); |
| 3518 | intrinsic.Dispatch(invoke); |
| 3519 | return true; |
| 3520 | } |
| 3521 | return false; |
| 3522 | } |
| 3523 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3524 | void InstructionCodeGeneratorARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3525 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3526 | // art::PrepareForRegisterAllocation. |
| 3527 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 3528 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3529 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3530 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 4); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3531 | return; |
| 3532 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3533 | |
| 3534 | LocationSummary* locations = invoke->GetLocations(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3535 | codegen_->GenerateStaticOrDirectCall( |
| 3536 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3537 | |
| 3538 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 5); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3539 | } |
| 3540 | |
| 3541 | void LocationsBuilderARMVIXL::HandleInvoke(HInvoke* invoke) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3542 | InvokeDexCallingConventionVisitorARMVIXL calling_convention_visitor; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3543 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 3544 | } |
| 3545 | |
| 3546 | void LocationsBuilderARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3547 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3548 | if (intrinsic.TryDispatch(invoke)) { |
| 3549 | return; |
| 3550 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3551 | |
| 3552 | HandleInvoke(invoke); |
| 3553 | } |
| 3554 | |
| 3555 | void InstructionCodeGeneratorARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3556 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3557 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 6); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3558 | return; |
| 3559 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3560 | |
| 3561 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3562 | DCHECK(!codegen_->IsLeafMethod()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3563 | |
| 3564 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 7); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3565 | } |
| 3566 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3567 | void LocationsBuilderARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3568 | HandleInvoke(invoke); |
| 3569 | // Add the hidden argument. |
| 3570 | invoke->GetLocations()->AddTemp(LocationFrom(r12)); |
| 3571 | } |
| 3572 | |
| 3573 | void InstructionCodeGeneratorARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3574 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 3575 | LocationSummary* locations = invoke->GetLocations(); |
| 3576 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 3577 | vixl32::Register hidden_reg = RegisterFrom(locations->GetTemp(1)); |
| 3578 | Location receiver = locations->InAt(0); |
| 3579 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3580 | |
| 3581 | DCHECK(!receiver.IsStackSlot()); |
| 3582 | |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3583 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
| 3584 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 3585 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 3586 | vixl32::kMaxInstructionSizeInBytes, |
| 3587 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3588 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 3589 | __ ldr(temp, MemOperand(RegisterFrom(receiver), class_offset)); |
| 3590 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 3591 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3592 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3593 | // emit a read barrier for the previous class reference load. |
| 3594 | // However this is not required in practice, as this is an |
| 3595 | // intermediate/temporary reference and because the current |
| 3596 | // concurrent copying collector keeps the from-space memory |
| 3597 | // intact/accessible until the end of the marking phase (the |
| 3598 | // concurrent copying collector may not in the future). |
| 3599 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 3600 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3601 | temp, |
| 3602 | temp, |
| 3603 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 3604 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 3605 | invoke->GetImtIndex(), kArmPointerSize)); |
| 3606 | // temp = temp->GetImtEntryAt(method_offset); |
| 3607 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 3608 | uint32_t entry_point = |
| 3609 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
| 3610 | // LR = temp->GetEntryPoint(); |
| 3611 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
| 3612 | |
| 3613 | // Set the hidden (in r12) argument. It is done here, right before a BLX to prevent other |
| 3614 | // instruction from clobbering it as they might use r12 as a scratch register. |
| 3615 | DCHECK(hidden_reg.Is(r12)); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3616 | |
| 3617 | { |
| 3618 | // The VIXL macro assembler may clobber any of the scratch registers that are available to it, |
| 3619 | // so it checks if the application is using them (by passing them to the macro assembler |
| 3620 | // methods). The following application of UseScratchRegisterScope corrects VIXL's notion of |
| 3621 | // what is available, and is the opposite of the standard usage: Instead of requesting a |
| 3622 | // temporary location, it imposes an external constraint (i.e. a specific register is reserved |
| 3623 | // for the hidden argument). Note that this works even if VIXL needs a scratch register itself |
| 3624 | // (to materialize the constant), since the destination register becomes available for such use |
| 3625 | // internally for the duration of the macro instruction. |
| 3626 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3627 | temps.Exclude(hidden_reg); |
| 3628 | __ Mov(hidden_reg, invoke->GetDexMethodIndex()); |
| 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 | |
| 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) { |
| 3646 | HandleInvoke(invoke); |
| 3647 | } |
| 3648 | |
| 3649 | void InstructionCodeGeneratorARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3650 | codegen_->GenerateInvokePolymorphicCall(invoke); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3651 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 9); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3652 | } |
| 3653 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3654 | void LocationsBuilderARMVIXL::VisitNeg(HNeg* neg) { |
| 3655 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3656 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3657 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3658 | case DataType::Type::kInt32: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3659 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3660 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3661 | break; |
| 3662 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3663 | case DataType::Type::kInt64: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3664 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3665 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3666 | break; |
| 3667 | } |
| 3668 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3669 | case DataType::Type::kFloat32: |
| 3670 | case DataType::Type::kFloat64: |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3671 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3672 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3673 | break; |
| 3674 | |
| 3675 | default: |
| 3676 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3677 | } |
| 3678 | } |
| 3679 | |
| 3680 | void InstructionCodeGeneratorARMVIXL::VisitNeg(HNeg* neg) { |
| 3681 | LocationSummary* locations = neg->GetLocations(); |
| 3682 | Location out = locations->Out(); |
| 3683 | Location in = locations->InAt(0); |
| 3684 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3685 | case DataType::Type::kInt32: |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3686 | __ Rsb(OutputRegister(neg), InputRegisterAt(neg, 0), 0); |
| 3687 | break; |
| 3688 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3689 | case DataType::Type::kInt64: |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3690 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 3691 | __ Rsbs(LowRegisterFrom(out), LowRegisterFrom(in), 0); |
| 3692 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 3693 | // instruction here, as it does not exist in the Thumb-2 |
| 3694 | // instruction set. We use the following approach |
| 3695 | // using SBC and SUB instead. |
| 3696 | // |
| 3697 | // out.hi = -C |
| 3698 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(out)); |
| 3699 | // out.hi = out.hi - in.hi |
| 3700 | __ Sub(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(in)); |
| 3701 | break; |
| 3702 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3703 | case DataType::Type::kFloat32: |
| 3704 | case DataType::Type::kFloat64: |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 3705 | __ Vneg(OutputVRegister(neg), InputVRegister(neg)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3706 | break; |
| 3707 | |
| 3708 | default: |
| 3709 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3710 | } |
| 3711 | } |
| 3712 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3713 | void LocationsBuilderARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3714 | DataType::Type result_type = conversion->GetResultType(); |
| 3715 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3716 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 3717 | << input_type << " -> " << result_type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3718 | |
| 3719 | // The float-to-long, double-to-long and long-to-float type conversions |
| 3720 | // rely on a call to the runtime. |
| 3721 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3722 | (((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) |
| 3723 | && result_type == DataType::Type::kInt64) |
| 3724 | || (input_type == DataType::Type::kInt64 && result_type == DataType::Type::kFloat32)) |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3725 | ? LocationSummary::kCallOnMainOnly |
| 3726 | : LocationSummary::kNoCall; |
| 3727 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3728 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3729 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3730 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3731 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3732 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3733 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3734 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3735 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 3736 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3737 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3738 | break; |
| 3739 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3740 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3741 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3742 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3743 | locations->SetInAt(0, Location::Any()); |
| 3744 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3745 | break; |
| 3746 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3747 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3748 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3749 | locations->SetOut(Location::RequiresRegister()); |
| 3750 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3751 | break; |
| 3752 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3753 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3754 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3755 | locations->SetOut(Location::RequiresRegister()); |
| 3756 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3757 | break; |
| 3758 | |
| 3759 | default: |
| 3760 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3761 | << " to " << result_type; |
| 3762 | } |
| 3763 | break; |
| 3764 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3765 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3766 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3767 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3768 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3769 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3770 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3771 | case DataType::Type::kInt16: |
| 3772 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3773 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3774 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3775 | break; |
| 3776 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3777 | case DataType::Type::kFloat32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3778 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3779 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 3780 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3781 | break; |
| 3782 | } |
| 3783 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3784 | case DataType::Type::kFloat64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3785 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3786 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0), |
| 3787 | calling_convention.GetFpuRegisterAt(1))); |
| 3788 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3789 | break; |
| 3790 | } |
| 3791 | |
| 3792 | default: |
| 3793 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3794 | << " to " << result_type; |
| 3795 | } |
| 3796 | break; |
| 3797 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3798 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3799 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3800 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3801 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3802 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3803 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3804 | case DataType::Type::kInt16: |
| 3805 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3806 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3807 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3808 | break; |
| 3809 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3810 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3811 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3812 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0), |
| 3813 | calling_convention.GetRegisterAt(1))); |
| 3814 | locations->SetOut(LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3815 | break; |
| 3816 | } |
| 3817 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3818 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3819 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3820 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3821 | break; |
| 3822 | |
| 3823 | default: |
| 3824 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3825 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3826 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3827 | break; |
| 3828 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3829 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3830 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3831 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3832 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3833 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3834 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3835 | case DataType::Type::kInt16: |
| 3836 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3837 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3838 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3839 | break; |
| 3840 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3841 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3842 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3843 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3844 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3845 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3846 | break; |
| 3847 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3848 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3849 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3850 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3851 | break; |
| 3852 | |
| 3853 | default: |
| 3854 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3855 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3856 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3857 | break; |
| 3858 | |
| 3859 | default: |
| 3860 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3861 | << " to " << result_type; |
| 3862 | } |
| 3863 | } |
| 3864 | |
| 3865 | void InstructionCodeGeneratorARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
| 3866 | LocationSummary* locations = conversion->GetLocations(); |
| 3867 | Location out = locations->Out(); |
| 3868 | Location in = locations->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3869 | DataType::Type result_type = conversion->GetResultType(); |
| 3870 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3871 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 3872 | << input_type << " -> " << result_type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3873 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3874 | case DataType::Type::kUint8: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3875 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3876 | case DataType::Type::kInt8: |
| 3877 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3878 | case DataType::Type::kInt16: |
| 3879 | case DataType::Type::kInt32: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3880 | __ Ubfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 8); |
| 3881 | break; |
| 3882 | case DataType::Type::kInt64: |
| 3883 | __ Ubfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 8); |
| 3884 | break; |
| 3885 | |
| 3886 | default: |
| 3887 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3888 | << " to " << result_type; |
| 3889 | } |
| 3890 | break; |
| 3891 | |
| 3892 | case DataType::Type::kInt8: |
| 3893 | switch (input_type) { |
| 3894 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3895 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3896 | case DataType::Type::kInt16: |
| 3897 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3898 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 8); |
| 3899 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3900 | case DataType::Type::kInt64: |
| 3901 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 8); |
| 3902 | break; |
| 3903 | |
| 3904 | default: |
| 3905 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3906 | << " to " << result_type; |
| 3907 | } |
| 3908 | break; |
| 3909 | |
| 3910 | case DataType::Type::kUint16: |
| 3911 | switch (input_type) { |
| 3912 | case DataType::Type::kInt8: |
| 3913 | case DataType::Type::kInt16: |
| 3914 | case DataType::Type::kInt32: |
| 3915 | __ Ubfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 3916 | break; |
| 3917 | case DataType::Type::kInt64: |
| 3918 | __ Ubfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
| 3919 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3920 | |
| 3921 | default: |
| 3922 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3923 | << " to " << result_type; |
| 3924 | } |
| 3925 | break; |
| 3926 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3927 | case DataType::Type::kInt16: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3928 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3929 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3930 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3931 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 3932 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3933 | case DataType::Type::kInt64: |
| 3934 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
| 3935 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3936 | |
| 3937 | default: |
| 3938 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3939 | << " to " << result_type; |
| 3940 | } |
| 3941 | break; |
| 3942 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3943 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3944 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3945 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3946 | DCHECK(out.IsRegister()); |
| 3947 | if (in.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3948 | __ Mov(OutputRegister(conversion), LowRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3949 | } else if (in.IsDoubleStackSlot()) { |
| 3950 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3951 | OutputRegister(conversion), |
| 3952 | sp, |
| 3953 | in.GetStackIndex()); |
| 3954 | } else { |
| 3955 | DCHECK(in.IsConstant()); |
| 3956 | DCHECK(in.GetConstant()->IsLongConstant()); |
Vladimir Marko | ba1a48e | 2017-04-13 11:50:14 +0100 | [diff] [blame] | 3957 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3958 | __ Mov(OutputRegister(conversion), static_cast<int32_t>(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3959 | } |
| 3960 | break; |
| 3961 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3962 | case DataType::Type::kFloat32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3963 | vixl32::SRegister temp = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3964 | __ Vcvt(S32, F32, temp, InputSRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3965 | __ Vmov(OutputRegister(conversion), temp); |
| 3966 | break; |
| 3967 | } |
| 3968 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3969 | case DataType::Type::kFloat64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3970 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3971 | __ Vcvt(S32, F64, temp_s, DRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3972 | __ Vmov(OutputRegister(conversion), temp_s); |
| 3973 | break; |
| 3974 | } |
| 3975 | |
| 3976 | default: |
| 3977 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3978 | << " to " << result_type; |
| 3979 | } |
| 3980 | break; |
| 3981 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3982 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3983 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3984 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3985 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3986 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3987 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3988 | case DataType::Type::kInt16: |
| 3989 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3990 | DCHECK(out.IsRegisterPair()); |
| 3991 | DCHECK(in.IsRegister()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3992 | __ Mov(LowRegisterFrom(out), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3993 | // Sign extension. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3994 | __ Asr(HighRegisterFrom(out), LowRegisterFrom(out), 31); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3995 | break; |
| 3996 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3997 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3998 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
| 3999 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 4000 | break; |
| 4001 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4002 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4003 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
| 4004 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 4005 | break; |
| 4006 | |
| 4007 | default: |
| 4008 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4009 | << " to " << result_type; |
| 4010 | } |
| 4011 | break; |
| 4012 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4013 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4014 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4015 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4016 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4017 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4018 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4019 | case DataType::Type::kInt16: |
| 4020 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4021 | __ Vmov(OutputSRegister(conversion), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4022 | __ Vcvt(F32, S32, OutputSRegister(conversion), OutputSRegister(conversion)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4023 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4024 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4025 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4026 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
| 4027 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 4028 | break; |
| 4029 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4030 | case DataType::Type::kFloat64: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4031 | __ Vcvt(F32, F64, OutputSRegister(conversion), DRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4032 | break; |
| 4033 | |
| 4034 | default: |
| 4035 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4036 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 4037 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4038 | break; |
| 4039 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4040 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4041 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4042 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4043 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4044 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4045 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4046 | case DataType::Type::kInt16: |
| 4047 | case DataType::Type::kInt32: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4048 | __ Vmov(LowSRegisterFrom(out), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4049 | __ Vcvt(F64, S32, DRegisterFrom(out), LowSRegisterFrom(out)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4050 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4051 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4052 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4053 | vixl32::Register low = LowRegisterFrom(in); |
| 4054 | vixl32::Register high = HighRegisterFrom(in); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4055 | vixl32::SRegister out_s = LowSRegisterFrom(out); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4056 | vixl32::DRegister out_d = DRegisterFrom(out); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4057 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4058 | vixl32::DRegister temp_d = DRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4059 | vixl32::DRegister constant_d = DRegisterFrom(locations->GetTemp(1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4060 | |
| 4061 | // temp_d = int-to-double(high) |
| 4062 | __ Vmov(temp_s, high); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4063 | __ Vcvt(F64, S32, temp_d, temp_s); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4064 | // constant_d = k2Pow32EncodingForDouble |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4065 | __ Vmov(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4066 | // out_d = unsigned-to-double(low) |
| 4067 | __ Vmov(out_s, low); |
| 4068 | __ Vcvt(F64, U32, out_d, out_s); |
| 4069 | // out_d += temp_d * constant_d |
| 4070 | __ Vmla(F64, out_d, temp_d, constant_d); |
| 4071 | break; |
| 4072 | } |
| 4073 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4074 | case DataType::Type::kFloat32: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4075 | __ Vcvt(F64, F32, DRegisterFrom(out), InputSRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4076 | break; |
| 4077 | |
| 4078 | default: |
| 4079 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4080 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 4081 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4082 | break; |
| 4083 | |
| 4084 | default: |
| 4085 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4086 | << " to " << result_type; |
| 4087 | } |
| 4088 | } |
| 4089 | |
| 4090 | void LocationsBuilderARMVIXL::VisitAdd(HAdd* add) { |
| 4091 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4092 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4093 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4094 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4095 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4096 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 4097 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4098 | break; |
| 4099 | } |
| 4100 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4101 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4102 | locations->SetInAt(0, Location::RequiresRegister()); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4103 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4104 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4105 | break; |
| 4106 | } |
| 4107 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4108 | case DataType::Type::kFloat32: |
| 4109 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4110 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4111 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4112 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4113 | break; |
| 4114 | } |
| 4115 | |
| 4116 | default: |
| 4117 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 4118 | } |
| 4119 | } |
| 4120 | |
| 4121 | void InstructionCodeGeneratorARMVIXL::VisitAdd(HAdd* add) { |
| 4122 | LocationSummary* locations = add->GetLocations(); |
| 4123 | Location out = locations->Out(); |
| 4124 | Location first = locations->InAt(0); |
| 4125 | Location second = locations->InAt(1); |
| 4126 | |
| 4127 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4128 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4129 | __ Add(OutputRegister(add), InputRegisterAt(add, 0), InputOperandAt(add, 1)); |
| 4130 | } |
| 4131 | break; |
| 4132 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4133 | case DataType::Type::kInt64: { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4134 | if (second.IsConstant()) { |
| 4135 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 4136 | GenerateAddLongConst(out, first, value); |
| 4137 | } else { |
| 4138 | DCHECK(second.IsRegisterPair()); |
| 4139 | __ Adds(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 4140 | __ Adc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 4141 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4142 | break; |
| 4143 | } |
| 4144 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4145 | case DataType::Type::kFloat32: |
| 4146 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4147 | __ Vadd(OutputVRegister(add), InputVRegisterAt(add, 0), InputVRegisterAt(add, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4148 | break; |
| 4149 | |
| 4150 | default: |
| 4151 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 4152 | } |
| 4153 | } |
| 4154 | |
| 4155 | void LocationsBuilderARMVIXL::VisitSub(HSub* sub) { |
| 4156 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4157 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4158 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4159 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4160 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4161 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
| 4162 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4163 | break; |
| 4164 | } |
| 4165 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4166 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4167 | locations->SetInAt(0, Location::RequiresRegister()); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4168 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4169 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4170 | break; |
| 4171 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4172 | case DataType::Type::kFloat32: |
| 4173 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4174 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4175 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4176 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4177 | break; |
| 4178 | } |
| 4179 | default: |
| 4180 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 4181 | } |
| 4182 | } |
| 4183 | |
| 4184 | void InstructionCodeGeneratorARMVIXL::VisitSub(HSub* sub) { |
| 4185 | LocationSummary* locations = sub->GetLocations(); |
| 4186 | Location out = locations->Out(); |
| 4187 | Location first = locations->InAt(0); |
| 4188 | Location second = locations->InAt(1); |
| 4189 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4190 | case DataType::Type::kInt32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4191 | __ Sub(OutputRegister(sub), InputRegisterAt(sub, 0), InputOperandAt(sub, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4192 | break; |
| 4193 | } |
| 4194 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4195 | case DataType::Type::kInt64: { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4196 | if (second.IsConstant()) { |
| 4197 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 4198 | GenerateAddLongConst(out, first, -value); |
| 4199 | } else { |
| 4200 | DCHECK(second.IsRegisterPair()); |
| 4201 | __ Subs(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 4202 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 4203 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4204 | break; |
| 4205 | } |
| 4206 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4207 | case DataType::Type::kFloat32: |
| 4208 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4209 | __ Vsub(OutputVRegister(sub), InputVRegisterAt(sub, 0), InputVRegisterAt(sub, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4210 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4211 | |
| 4212 | default: |
| 4213 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 4214 | } |
| 4215 | } |
| 4216 | |
| 4217 | void LocationsBuilderARMVIXL::VisitMul(HMul* mul) { |
| 4218 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4219 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4220 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4221 | case DataType::Type::kInt32: |
| 4222 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4223 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4224 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4225 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4226 | break; |
| 4227 | } |
| 4228 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4229 | case DataType::Type::kFloat32: |
| 4230 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4231 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4232 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4233 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4234 | break; |
| 4235 | } |
| 4236 | |
| 4237 | default: |
| 4238 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4239 | } |
| 4240 | } |
| 4241 | |
| 4242 | void InstructionCodeGeneratorARMVIXL::VisitMul(HMul* mul) { |
| 4243 | LocationSummary* locations = mul->GetLocations(); |
| 4244 | Location out = locations->Out(); |
| 4245 | Location first = locations->InAt(0); |
| 4246 | Location second = locations->InAt(1); |
| 4247 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4248 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4249 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 4250 | break; |
| 4251 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4252 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4253 | vixl32::Register out_hi = HighRegisterFrom(out); |
| 4254 | vixl32::Register out_lo = LowRegisterFrom(out); |
| 4255 | vixl32::Register in1_hi = HighRegisterFrom(first); |
| 4256 | vixl32::Register in1_lo = LowRegisterFrom(first); |
| 4257 | vixl32::Register in2_hi = HighRegisterFrom(second); |
| 4258 | vixl32::Register in2_lo = LowRegisterFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4259 | |
| 4260 | // Extra checks to protect caused by the existence of R1_R2. |
| 4261 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 4262 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4263 | DCHECK(!out_hi.Is(in1_lo)); |
| 4264 | DCHECK(!out_hi.Is(in2_lo)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4265 | |
| 4266 | // input: in1 - 64 bits, in2 - 64 bits |
| 4267 | // output: out |
| 4268 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 4269 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 4270 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 4271 | |
| 4272 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4273 | vixl32::Register temp = temps.Acquire(); |
| 4274 | // temp <- in1.lo * in2.hi |
| 4275 | __ Mul(temp, in1_lo, in2_hi); |
| 4276 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 4277 | __ Mla(out_hi, in1_hi, in2_lo, temp); |
| 4278 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 4279 | __ Umull(out_lo, temp, in1_lo, in2_lo); |
| 4280 | // 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] | 4281 | __ Add(out_hi, out_hi, temp); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4282 | break; |
| 4283 | } |
| 4284 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4285 | case DataType::Type::kFloat32: |
| 4286 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4287 | __ Vmul(OutputVRegister(mul), InputVRegisterAt(mul, 0), InputVRegisterAt(mul, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4288 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4289 | |
| 4290 | default: |
| 4291 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4292 | } |
| 4293 | } |
| 4294 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4295 | void InstructionCodeGeneratorARMVIXL::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 4296 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4297 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4298 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4299 | Location second = instruction->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4300 | DCHECK(second.IsConstant()); |
| 4301 | |
| 4302 | vixl32::Register out = OutputRegister(instruction); |
| 4303 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4304 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4305 | DCHECK(imm == 1 || imm == -1); |
| 4306 | |
| 4307 | if (instruction->IsRem()) { |
| 4308 | __ Mov(out, 0); |
| 4309 | } else { |
| 4310 | if (imm == 1) { |
| 4311 | __ Mov(out, dividend); |
| 4312 | } else { |
| 4313 | __ Rsb(out, dividend, 0); |
| 4314 | } |
| 4315 | } |
| 4316 | } |
| 4317 | |
| 4318 | void InstructionCodeGeneratorARMVIXL::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 4319 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4320 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4321 | |
| 4322 | LocationSummary* locations = instruction->GetLocations(); |
| 4323 | Location second = locations->InAt(1); |
| 4324 | DCHECK(second.IsConstant()); |
| 4325 | |
| 4326 | vixl32::Register out = OutputRegister(instruction); |
| 4327 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4328 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4329 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4330 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 4331 | int ctz_imm = CTZ(abs_imm); |
| 4332 | |
| 4333 | if (ctz_imm == 1) { |
| 4334 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 4335 | } else { |
| 4336 | __ Asr(temp, dividend, 31); |
| 4337 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 4338 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4339 | __ Add(out, temp, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4340 | |
| 4341 | if (instruction->IsDiv()) { |
| 4342 | __ Asr(out, out, ctz_imm); |
| 4343 | if (imm < 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4344 | __ Rsb(out, out, 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4345 | } |
| 4346 | } else { |
| 4347 | __ Ubfx(out, out, 0, ctz_imm); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4348 | __ Sub(out, out, temp); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4349 | } |
| 4350 | } |
| 4351 | |
| 4352 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 4353 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4354 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4355 | |
| 4356 | LocationSummary* locations = instruction->GetLocations(); |
| 4357 | Location second = locations->InAt(1); |
| 4358 | DCHECK(second.IsConstant()); |
| 4359 | |
| 4360 | vixl32::Register out = OutputRegister(instruction); |
| 4361 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4362 | vixl32::Register temp1 = RegisterFrom(locations->GetTemp(0)); |
| 4363 | vixl32::Register temp2 = RegisterFrom(locations->GetTemp(1)); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4364 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4365 | |
| 4366 | int64_t magic; |
| 4367 | int shift; |
| 4368 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 4369 | |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4370 | // TODO(VIXL): Change the static cast to Operand::From() after VIXL is fixed. |
| 4371 | __ Mov(temp1, static_cast<int32_t>(magic)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4372 | __ Smull(temp2, temp1, dividend, temp1); |
| 4373 | |
| 4374 | if (imm > 0 && magic < 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4375 | __ Add(temp1, temp1, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4376 | } else if (imm < 0 && magic > 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4377 | __ Sub(temp1, temp1, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4378 | } |
| 4379 | |
| 4380 | if (shift != 0) { |
| 4381 | __ Asr(temp1, temp1, shift); |
| 4382 | } |
| 4383 | |
| 4384 | if (instruction->IsDiv()) { |
| 4385 | __ Sub(out, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 4386 | } else { |
| 4387 | __ Sub(temp1, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 4388 | // TODO: Strength reduction for mls. |
| 4389 | __ Mov(temp2, imm); |
| 4390 | __ Mls(out, temp1, temp2, dividend); |
| 4391 | } |
| 4392 | } |
| 4393 | |
| 4394 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemConstantIntegral( |
| 4395 | HBinaryOperation* instruction) { |
| 4396 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4397 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4398 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4399 | Location second = instruction->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4400 | DCHECK(second.IsConstant()); |
| 4401 | |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4402 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4403 | if (imm == 0) { |
| 4404 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4405 | } else if (imm == 1 || imm == -1) { |
| 4406 | DivRemOneOrMinusOne(instruction); |
| 4407 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 4408 | DivRemByPowerOfTwo(instruction); |
| 4409 | } else { |
| 4410 | DCHECK(imm <= -2 || imm >= 2); |
| 4411 | GenerateDivRemWithAnyConstant(instruction); |
| 4412 | } |
| 4413 | } |
| 4414 | |
| 4415 | void LocationsBuilderARMVIXL::VisitDiv(HDiv* div) { |
| 4416 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4417 | if (div->GetResultType() == DataType::Type::kInt64) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4418 | // pLdiv runtime call. |
| 4419 | call_kind = LocationSummary::kCallOnMainOnly; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4420 | } else if (div->GetResultType() == DataType::Type::kInt32 && div->InputAt(1)->IsConstant()) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4421 | // sdiv will be replaced by other instruction sequence. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4422 | } else if (div->GetResultType() == DataType::Type::kInt32 && |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4423 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4424 | // pIdivmod runtime call. |
| 4425 | call_kind = LocationSummary::kCallOnMainOnly; |
| 4426 | } |
| 4427 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4428 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4429 | |
| 4430 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4431 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4432 | if (div->InputAt(1)->IsConstant()) { |
| 4433 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4434 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
| 4435 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4436 | int32_t value = Int32ConstantFrom(div->InputAt(1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4437 | if (value == 1 || value == 0 || value == -1) { |
| 4438 | // No temp register required. |
| 4439 | } else { |
| 4440 | locations->AddTemp(Location::RequiresRegister()); |
| 4441 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
| 4442 | locations->AddTemp(Location::RequiresRegister()); |
| 4443 | } |
| 4444 | } |
| 4445 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4446 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4447 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4448 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4449 | } else { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4450 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4451 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4452 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4453 | // 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] | 4454 | // we only need the former. |
| 4455 | locations->SetOut(LocationFrom(r0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4456 | } |
| 4457 | break; |
| 4458 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4459 | case DataType::Type::kInt64: { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4460 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4461 | locations->SetInAt(0, LocationFrom( |
| 4462 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4463 | locations->SetInAt(1, LocationFrom( |
| 4464 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4465 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4466 | break; |
| 4467 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4468 | case DataType::Type::kFloat32: |
| 4469 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4470 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4471 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4472 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4473 | break; |
| 4474 | } |
| 4475 | |
| 4476 | default: |
| 4477 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4478 | } |
| 4479 | } |
| 4480 | |
| 4481 | void InstructionCodeGeneratorARMVIXL::VisitDiv(HDiv* div) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4482 | Location lhs = div->GetLocations()->InAt(0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4483 | Location rhs = div->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4484 | |
| 4485 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4486 | case DataType::Type::kInt32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4487 | if (rhs.IsConstant()) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4488 | GenerateDivRemConstantIntegral(div); |
| 4489 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4490 | __ Sdiv(OutputRegister(div), InputRegisterAt(div, 0), InputRegisterAt(div, 1)); |
| 4491 | } else { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4492 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4493 | DCHECK(calling_convention.GetRegisterAt(0).Is(RegisterFrom(lhs))); |
| 4494 | DCHECK(calling_convention.GetRegisterAt(1).Is(RegisterFrom(rhs))); |
| 4495 | DCHECK(r0.Is(OutputRegister(div))); |
| 4496 | |
| 4497 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
| 4498 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4499 | } |
| 4500 | break; |
| 4501 | } |
| 4502 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4503 | case DataType::Type::kInt64: { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4504 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4505 | DCHECK(calling_convention.GetRegisterAt(0).Is(LowRegisterFrom(lhs))); |
| 4506 | DCHECK(calling_convention.GetRegisterAt(1).Is(HighRegisterFrom(lhs))); |
| 4507 | DCHECK(calling_convention.GetRegisterAt(2).Is(LowRegisterFrom(rhs))); |
| 4508 | DCHECK(calling_convention.GetRegisterAt(3).Is(HighRegisterFrom(rhs))); |
| 4509 | DCHECK(LowRegisterFrom(div->GetLocations()->Out()).Is(r0)); |
| 4510 | DCHECK(HighRegisterFrom(div->GetLocations()->Out()).Is(r1)); |
| 4511 | |
| 4512 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
| 4513 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4514 | break; |
| 4515 | } |
| 4516 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4517 | case DataType::Type::kFloat32: |
| 4518 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4519 | __ Vdiv(OutputVRegister(div), InputVRegisterAt(div, 0), InputVRegisterAt(div, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4520 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4521 | |
| 4522 | default: |
| 4523 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4524 | } |
| 4525 | } |
| 4526 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4527 | void LocationsBuilderARMVIXL::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4528 | DataType::Type type = rem->GetResultType(); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4529 | |
| 4530 | // Most remainders are implemented in the runtime. |
| 4531 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4532 | if (rem->GetResultType() == DataType::Type::kInt32 && rem->InputAt(1)->IsConstant()) { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4533 | // sdiv will be replaced by other instruction sequence. |
| 4534 | call_kind = LocationSummary::kNoCall; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4535 | } else if ((rem->GetResultType() == DataType::Type::kInt32) |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4536 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4537 | // Have hardware divide instruction for int, do it with three instructions. |
| 4538 | call_kind = LocationSummary::kNoCall; |
| 4539 | } |
| 4540 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4541 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4542 | |
| 4543 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4544 | case DataType::Type::kInt32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4545 | if (rem->InputAt(1)->IsConstant()) { |
| 4546 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4547 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
| 4548 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4549 | int32_t value = Int32ConstantFrom(rem->InputAt(1)); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4550 | if (value == 1 || value == 0 || value == -1) { |
| 4551 | // No temp register required. |
| 4552 | } else { |
| 4553 | locations->AddTemp(Location::RequiresRegister()); |
| 4554 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
| 4555 | locations->AddTemp(Location::RequiresRegister()); |
| 4556 | } |
| 4557 | } |
| 4558 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4559 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4560 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4561 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4562 | locations->AddTemp(Location::RequiresRegister()); |
| 4563 | } else { |
| 4564 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4565 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4566 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4567 | // 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] | 4568 | // we only need the latter. |
| 4569 | locations->SetOut(LocationFrom(r1)); |
| 4570 | } |
| 4571 | break; |
| 4572 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4573 | case DataType::Type::kInt64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4574 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4575 | locations->SetInAt(0, LocationFrom( |
| 4576 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4577 | locations->SetInAt(1, LocationFrom( |
| 4578 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4579 | // The runtime helper puts the output in R2,R3. |
| 4580 | locations->SetOut(LocationFrom(r2, r3)); |
| 4581 | break; |
| 4582 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4583 | case DataType::Type::kFloat32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4584 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4585 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 4586 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 4587 | locations->SetOut(LocationFrom(s0)); |
| 4588 | break; |
| 4589 | } |
| 4590 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4591 | case DataType::Type::kFloat64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4592 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4593 | locations->SetInAt(0, LocationFrom( |
| 4594 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 4595 | locations->SetInAt(1, LocationFrom( |
| 4596 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 4597 | locations->SetOut(LocationFrom(s0, s1)); |
| 4598 | break; |
| 4599 | } |
| 4600 | |
| 4601 | default: |
| 4602 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4603 | } |
| 4604 | } |
| 4605 | |
| 4606 | void InstructionCodeGeneratorARMVIXL::VisitRem(HRem* rem) { |
| 4607 | LocationSummary* locations = rem->GetLocations(); |
| 4608 | Location second = locations->InAt(1); |
| 4609 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4610 | DataType::Type type = rem->GetResultType(); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4611 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4612 | case DataType::Type::kInt32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4613 | vixl32::Register reg1 = InputRegisterAt(rem, 0); |
| 4614 | vixl32::Register out_reg = OutputRegister(rem); |
| 4615 | if (second.IsConstant()) { |
| 4616 | GenerateDivRemConstantIntegral(rem); |
| 4617 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4618 | vixl32::Register reg2 = RegisterFrom(second); |
| 4619 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 4620 | |
| 4621 | // temp = reg1 / reg2 (integer division) |
| 4622 | // dest = reg1 - temp * reg2 |
| 4623 | __ Sdiv(temp, reg1, reg2); |
| 4624 | __ Mls(out_reg, temp, reg2, reg1); |
| 4625 | } else { |
| 4626 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4627 | DCHECK(reg1.Is(calling_convention.GetRegisterAt(0))); |
| 4628 | DCHECK(RegisterFrom(second).Is(calling_convention.GetRegisterAt(1))); |
| 4629 | DCHECK(out_reg.Is(r1)); |
| 4630 | |
| 4631 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
| 4632 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
| 4633 | } |
| 4634 | break; |
| 4635 | } |
| 4636 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4637 | case DataType::Type::kInt64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4638 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
| 4639 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 4640 | break; |
| 4641 | } |
| 4642 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4643 | case DataType::Type::kFloat32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4644 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
| 4645 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 4646 | break; |
| 4647 | } |
| 4648 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4649 | case DataType::Type::kFloat64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4650 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
| 4651 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 4652 | break; |
| 4653 | } |
| 4654 | |
| 4655 | default: |
| 4656 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4657 | } |
| 4658 | } |
| 4659 | |
| 4660 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4661 | void LocationsBuilderARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 4662 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4663 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4664 | } |
| 4665 | |
| 4666 | void InstructionCodeGeneratorARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 4667 | DivZeroCheckSlowPathARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4668 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathARMVIXL(instruction); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4669 | codegen_->AddSlowPath(slow_path); |
| 4670 | |
| 4671 | LocationSummary* locations = instruction->GetLocations(); |
| 4672 | Location value = locations->InAt(0); |
| 4673 | |
| 4674 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4675 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4676 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4677 | case DataType::Type::kInt8: |
| 4678 | case DataType::Type::kUint16: |
| 4679 | case DataType::Type::kInt16: |
| 4680 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4681 | if (value.IsRegister()) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 4682 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4683 | } else { |
| 4684 | DCHECK(value.IsConstant()) << value; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4685 | if (Int32ConstantFrom(value) == 0) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4686 | __ B(slow_path->GetEntryLabel()); |
| 4687 | } |
| 4688 | } |
| 4689 | break; |
| 4690 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4691 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4692 | if (value.IsRegisterPair()) { |
| 4693 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4694 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4695 | __ Orrs(temp, LowRegisterFrom(value), HighRegisterFrom(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4696 | __ B(eq, slow_path->GetEntryLabel()); |
| 4697 | } else { |
| 4698 | DCHECK(value.IsConstant()) << value; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4699 | if (Int64ConstantFrom(value) == 0) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4700 | __ B(slow_path->GetEntryLabel()); |
| 4701 | } |
| 4702 | } |
| 4703 | break; |
| 4704 | } |
| 4705 | default: |
| 4706 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4707 | } |
| 4708 | } |
| 4709 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4710 | void InstructionCodeGeneratorARMVIXL::HandleIntegerRotate(HRor* ror) { |
| 4711 | LocationSummary* locations = ror->GetLocations(); |
| 4712 | vixl32::Register in = InputRegisterAt(ror, 0); |
| 4713 | Location rhs = locations->InAt(1); |
| 4714 | vixl32::Register out = OutputRegister(ror); |
| 4715 | |
| 4716 | if (rhs.IsConstant()) { |
| 4717 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 4718 | // so map all rotations to a +ve. equivalent in that range. |
| 4719 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 4720 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 4721 | if (rot) { |
| 4722 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 4723 | // (e.g. left by 2 bits == right by 30.) |
| 4724 | __ Ror(out, in, rot); |
| 4725 | } else if (!out.Is(in)) { |
| 4726 | __ Mov(out, in); |
| 4727 | } |
| 4728 | } else { |
| 4729 | __ Ror(out, in, RegisterFrom(rhs)); |
| 4730 | } |
| 4731 | } |
| 4732 | |
| 4733 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 4734 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 4735 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 4736 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 4737 | void InstructionCodeGeneratorARMVIXL::HandleLongRotate(HRor* ror) { |
| 4738 | LocationSummary* locations = ror->GetLocations(); |
| 4739 | vixl32::Register in_reg_lo = LowRegisterFrom(locations->InAt(0)); |
| 4740 | vixl32::Register in_reg_hi = HighRegisterFrom(locations->InAt(0)); |
| 4741 | Location rhs = locations->InAt(1); |
| 4742 | vixl32::Register out_reg_lo = LowRegisterFrom(locations->Out()); |
| 4743 | vixl32::Register out_reg_hi = HighRegisterFrom(locations->Out()); |
| 4744 | |
| 4745 | if (rhs.IsConstant()) { |
| 4746 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 4747 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
| 4748 | rot &= kMaxLongShiftDistance; |
| 4749 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 4750 | // logic below to a simple pair of binary orr. |
| 4751 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 4752 | if (rot >= kArmBitsPerWord) { |
| 4753 | rot -= kArmBitsPerWord; |
| 4754 | std::swap(in_reg_hi, in_reg_lo); |
| 4755 | } |
| 4756 | // Rotate, or mov to out for zero or word size rotations. |
| 4757 | if (rot != 0u) { |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4758 | __ Lsr(out_reg_hi, in_reg_hi, Operand::From(rot)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4759 | __ 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] | 4760 | __ Lsr(out_reg_lo, in_reg_lo, Operand::From(rot)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4761 | __ Orr(out_reg_lo, out_reg_lo, Operand(in_reg_hi, ShiftType::LSL, kArmBitsPerWord - rot)); |
| 4762 | } else { |
| 4763 | __ Mov(out_reg_lo, in_reg_lo); |
| 4764 | __ Mov(out_reg_hi, in_reg_hi); |
| 4765 | } |
| 4766 | } else { |
| 4767 | vixl32::Register shift_right = RegisterFrom(locations->GetTemp(0)); |
| 4768 | vixl32::Register shift_left = RegisterFrom(locations->GetTemp(1)); |
| 4769 | vixl32::Label end; |
| 4770 | vixl32::Label shift_by_32_plus_shift_right; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4771 | vixl32::Label* final_label = codegen_->GetFinalLabel(ror, &end); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4772 | |
| 4773 | __ And(shift_right, RegisterFrom(rhs), 0x1F); |
| 4774 | __ Lsrs(shift_left, RegisterFrom(rhs), 6); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 4775 | __ Rsb(LeaveFlags, shift_left, shift_right, Operand::From(kArmBitsPerWord)); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 4776 | __ B(cc, &shift_by_32_plus_shift_right, /* far_target */ false); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4777 | |
| 4778 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 4779 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 4780 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 4781 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4782 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 4783 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4784 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 4785 | __ Add(out_reg_lo, out_reg_lo, shift_left); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4786 | __ B(final_label); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4787 | |
| 4788 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 4789 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 4790 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 4791 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 4792 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4793 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 4794 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4795 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 4796 | __ Add(out_reg_lo, out_reg_lo, shift_right); |
| 4797 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4798 | if (end.IsReferenced()) { |
| 4799 | __ Bind(&end); |
| 4800 | } |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4801 | } |
| 4802 | } |
| 4803 | |
| 4804 | void LocationsBuilderARMVIXL::VisitRor(HRor* ror) { |
| 4805 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4806 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4807 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4808 | case DataType::Type::kInt32: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4809 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4810 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 4811 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4812 | break; |
| 4813 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4814 | case DataType::Type::kInt64: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4815 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4816 | if (ror->InputAt(1)->IsConstant()) { |
| 4817 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 4818 | } else { |
| 4819 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4820 | locations->AddTemp(Location::RequiresRegister()); |
| 4821 | locations->AddTemp(Location::RequiresRegister()); |
| 4822 | } |
| 4823 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4824 | break; |
| 4825 | } |
| 4826 | default: |
| 4827 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4828 | } |
| 4829 | } |
| 4830 | |
| 4831 | void InstructionCodeGeneratorARMVIXL::VisitRor(HRor* ror) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4832 | DataType::Type type = ror->GetResultType(); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4833 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4834 | case DataType::Type::kInt32: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4835 | HandleIntegerRotate(ror); |
| 4836 | break; |
| 4837 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4838 | case DataType::Type::kInt64: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4839 | HandleLongRotate(ror); |
| 4840 | break; |
| 4841 | } |
| 4842 | default: |
| 4843 | LOG(FATAL) << "Unexpected operation type " << type; |
| 4844 | UNREACHABLE(); |
| 4845 | } |
| 4846 | } |
| 4847 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4848 | void LocationsBuilderARMVIXL::HandleShift(HBinaryOperation* op) { |
| 4849 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4850 | |
| 4851 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4852 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4853 | |
| 4854 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4855 | case DataType::Type::kInt32: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4856 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4857 | if (op->InputAt(1)->IsConstant()) { |
| 4858 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 4859 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4860 | } else { |
| 4861 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4862 | // Make the output overlap, as it will be used to hold the masked |
| 4863 | // second input. |
| 4864 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4865 | } |
| 4866 | break; |
| 4867 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4868 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4869 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4870 | if (op->InputAt(1)->IsConstant()) { |
| 4871 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 4872 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 4873 | // don't clash with high registers which the register allocator currently guarantees. |
| 4874 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4875 | } else { |
| 4876 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4877 | locations->AddTemp(Location::RequiresRegister()); |
| 4878 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4879 | } |
| 4880 | break; |
| 4881 | } |
| 4882 | default: |
| 4883 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 4884 | } |
| 4885 | } |
| 4886 | |
| 4887 | void InstructionCodeGeneratorARMVIXL::HandleShift(HBinaryOperation* op) { |
| 4888 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4889 | |
| 4890 | LocationSummary* locations = op->GetLocations(); |
| 4891 | Location out = locations->Out(); |
| 4892 | Location first = locations->InAt(0); |
| 4893 | Location second = locations->InAt(1); |
| 4894 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4895 | DataType::Type type = op->GetResultType(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4896 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4897 | case DataType::Type::kInt32: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4898 | vixl32::Register out_reg = OutputRegister(op); |
| 4899 | vixl32::Register first_reg = InputRegisterAt(op, 0); |
| 4900 | if (second.IsRegister()) { |
| 4901 | vixl32::Register second_reg = RegisterFrom(second); |
| 4902 | // ARM doesn't mask the shift count so we need to do it ourselves. |
| 4903 | __ And(out_reg, second_reg, kMaxIntShiftDistance); |
| 4904 | if (op->IsShl()) { |
| 4905 | __ Lsl(out_reg, first_reg, out_reg); |
| 4906 | } else if (op->IsShr()) { |
| 4907 | __ Asr(out_reg, first_reg, out_reg); |
| 4908 | } else { |
| 4909 | __ Lsr(out_reg, first_reg, out_reg); |
| 4910 | } |
| 4911 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4912 | int32_t cst = Int32ConstantFrom(second); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4913 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
| 4914 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
| 4915 | __ Mov(out_reg, first_reg); |
| 4916 | } else if (op->IsShl()) { |
| 4917 | __ Lsl(out_reg, first_reg, shift_value); |
| 4918 | } else if (op->IsShr()) { |
| 4919 | __ Asr(out_reg, first_reg, shift_value); |
| 4920 | } else { |
| 4921 | __ Lsr(out_reg, first_reg, shift_value); |
| 4922 | } |
| 4923 | } |
| 4924 | break; |
| 4925 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4926 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4927 | vixl32::Register o_h = HighRegisterFrom(out); |
| 4928 | vixl32::Register o_l = LowRegisterFrom(out); |
| 4929 | |
| 4930 | vixl32::Register high = HighRegisterFrom(first); |
| 4931 | vixl32::Register low = LowRegisterFrom(first); |
| 4932 | |
| 4933 | if (second.IsRegister()) { |
| 4934 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 4935 | |
| 4936 | vixl32::Register second_reg = RegisterFrom(second); |
| 4937 | |
| 4938 | if (op->IsShl()) { |
| 4939 | __ And(o_l, second_reg, kMaxLongShiftDistance); |
| 4940 | // Shift the high part |
| 4941 | __ Lsl(o_h, high, o_l); |
| 4942 | // Shift the low part and `or` what overflew on the high part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4943 | __ Rsb(temp, o_l, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4944 | __ Lsr(temp, low, temp); |
| 4945 | __ Orr(o_h, o_h, temp); |
| 4946 | // If the shift is > 32 bits, override the high part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4947 | __ Subs(temp, o_l, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4948 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 4949 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 4950 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 4951 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4952 | __ it(pl); |
| 4953 | __ lsl(pl, o_h, low, temp); |
| 4954 | } |
| 4955 | // Shift the low part |
| 4956 | __ Lsl(o_l, low, o_l); |
| 4957 | } else if (op->IsShr()) { |
| 4958 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 4959 | // Shift the low part |
| 4960 | __ Lsr(o_l, low, o_h); |
| 4961 | // Shift the high part and `or` what underflew on the low part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4962 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4963 | __ Lsl(temp, high, temp); |
| 4964 | __ Orr(o_l, o_l, temp); |
| 4965 | // If the shift is > 32 bits, override the low part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4966 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4967 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 4968 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 4969 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 4970 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4971 | __ it(pl); |
| 4972 | __ asr(pl, o_l, high, temp); |
| 4973 | } |
| 4974 | // Shift the high part |
| 4975 | __ Asr(o_h, high, o_h); |
| 4976 | } else { |
| 4977 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 4978 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 4979 | __ Lsr(o_l, low, o_h); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4980 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4981 | __ Lsl(temp, high, temp); |
| 4982 | __ Orr(o_l, o_l, temp); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4983 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4984 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 4985 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 4986 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 4987 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4988 | __ it(pl); |
| 4989 | __ lsr(pl, o_l, high, temp); |
| 4990 | } |
| 4991 | __ Lsr(o_h, high, o_h); |
| 4992 | } |
| 4993 | } else { |
| 4994 | // Register allocator doesn't create partial overlap. |
| 4995 | DCHECK(!o_l.Is(high)); |
| 4996 | DCHECK(!o_h.Is(low)); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4997 | int32_t cst = Int32ConstantFrom(second); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4998 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
| 4999 | if (shift_value > 32) { |
| 5000 | if (op->IsShl()) { |
| 5001 | __ Lsl(o_h, low, shift_value - 32); |
| 5002 | __ Mov(o_l, 0); |
| 5003 | } else if (op->IsShr()) { |
| 5004 | __ Asr(o_l, high, shift_value - 32); |
| 5005 | __ Asr(o_h, high, 31); |
| 5006 | } else { |
| 5007 | __ Lsr(o_l, high, shift_value - 32); |
| 5008 | __ Mov(o_h, 0); |
| 5009 | } |
| 5010 | } else if (shift_value == 32) { |
| 5011 | if (op->IsShl()) { |
| 5012 | __ Mov(o_h, low); |
| 5013 | __ Mov(o_l, 0); |
| 5014 | } else if (op->IsShr()) { |
| 5015 | __ Mov(o_l, high); |
| 5016 | __ Asr(o_h, high, 31); |
| 5017 | } else { |
| 5018 | __ Mov(o_l, high); |
| 5019 | __ Mov(o_h, 0); |
| 5020 | } |
| 5021 | } else if (shift_value == 1) { |
| 5022 | if (op->IsShl()) { |
| 5023 | __ Lsls(o_l, low, 1); |
| 5024 | __ Adc(o_h, high, high); |
| 5025 | } else if (op->IsShr()) { |
| 5026 | __ Asrs(o_h, high, 1); |
| 5027 | __ Rrx(o_l, low); |
| 5028 | } else { |
| 5029 | __ Lsrs(o_h, high, 1); |
| 5030 | __ Rrx(o_l, low); |
| 5031 | } |
| 5032 | } else { |
| 5033 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
| 5034 | if (op->IsShl()) { |
| 5035 | __ Lsl(o_h, high, shift_value); |
| 5036 | __ Orr(o_h, o_h, Operand(low, ShiftType::LSR, 32 - shift_value)); |
| 5037 | __ Lsl(o_l, low, shift_value); |
| 5038 | } else if (op->IsShr()) { |
| 5039 | __ Lsr(o_l, low, shift_value); |
| 5040 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 5041 | __ Asr(o_h, high, shift_value); |
| 5042 | } else { |
| 5043 | __ Lsr(o_l, low, shift_value); |
| 5044 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 5045 | __ Lsr(o_h, high, shift_value); |
| 5046 | } |
| 5047 | } |
| 5048 | } |
| 5049 | break; |
| 5050 | } |
| 5051 | default: |
| 5052 | LOG(FATAL) << "Unexpected operation type " << type; |
| 5053 | UNREACHABLE(); |
| 5054 | } |
| 5055 | } |
| 5056 | |
| 5057 | void LocationsBuilderARMVIXL::VisitShl(HShl* shl) { |
| 5058 | HandleShift(shl); |
| 5059 | } |
| 5060 | |
| 5061 | void InstructionCodeGeneratorARMVIXL::VisitShl(HShl* shl) { |
| 5062 | HandleShift(shl); |
| 5063 | } |
| 5064 | |
| 5065 | void LocationsBuilderARMVIXL::VisitShr(HShr* shr) { |
| 5066 | HandleShift(shr); |
| 5067 | } |
| 5068 | |
| 5069 | void InstructionCodeGeneratorARMVIXL::VisitShr(HShr* shr) { |
| 5070 | HandleShift(shr); |
| 5071 | } |
| 5072 | |
| 5073 | void LocationsBuilderARMVIXL::VisitUShr(HUShr* ushr) { |
| 5074 | HandleShift(ushr); |
| 5075 | } |
| 5076 | |
| 5077 | void InstructionCodeGeneratorARMVIXL::VisitUShr(HUShr* ushr) { |
| 5078 | HandleShift(ushr); |
| 5079 | } |
| 5080 | |
| 5081 | void LocationsBuilderARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5082 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5083 | instruction, LocationSummary::kCallOnMainOnly); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5084 | if (instruction->IsStringAlloc()) { |
| 5085 | locations->AddTemp(LocationFrom(kMethodRegister)); |
| 5086 | } else { |
| 5087 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 5088 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5089 | } |
| 5090 | locations->SetOut(LocationFrom(r0)); |
| 5091 | } |
| 5092 | |
| 5093 | void InstructionCodeGeneratorARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
| 5094 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5095 | // of poisoning the reference. |
| 5096 | if (instruction->IsStringAlloc()) { |
| 5097 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 5098 | vixl32::Register temp = RegisterFrom(instruction->GetLocations()->GetTemp(0)); |
| 5099 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
| 5100 | GetAssembler()->LoadFromOffset(kLoadWord, temp, tr, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 5101 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, code_offset.Int32Value()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5102 | // 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] | 5103 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5104 | vixl32::k16BitT32InstructionSizeInBytes, |
| 5105 | CodeBufferCheckScope::kExactSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5106 | __ blx(lr); |
| 5107 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5108 | } else { |
| 5109 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 5110 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5111 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 5112 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 10); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5113 | } |
| 5114 | |
| 5115 | void LocationsBuilderARMVIXL::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5116 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5117 | instruction, LocationSummary::kCallOnMainOnly); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5118 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5119 | locations->SetOut(LocationFrom(r0)); |
Nicolas Geoffray | 8c7c4f1 | 2017-01-26 10:13:11 +0000 | [diff] [blame] | 5120 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5121 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5122 | } |
| 5123 | |
| 5124 | void InstructionCodeGeneratorARMVIXL::VisitNewArray(HNewArray* instruction) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5125 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5126 | // of poisoning the reference. |
Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 5127 | QuickEntrypointEnum entrypoint = |
| 5128 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 5129 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5130 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 5131 | DCHECK(!codegen_->IsLeafMethod()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 5132 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 11); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5133 | } |
| 5134 | |
| 5135 | void LocationsBuilderARMVIXL::VisitParameterValue(HParameterValue* instruction) { |
| 5136 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5137 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5138 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5139 | if (location.IsStackSlot()) { |
| 5140 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5141 | } else if (location.IsDoubleStackSlot()) { |
| 5142 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5143 | } |
| 5144 | locations->SetOut(location); |
| 5145 | } |
| 5146 | |
| 5147 | void InstructionCodeGeneratorARMVIXL::VisitParameterValue( |
| 5148 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 5149 | // Nothing to do, the parameter is already at its location. |
| 5150 | } |
| 5151 | |
| 5152 | void LocationsBuilderARMVIXL::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5153 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5154 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5155 | locations->SetOut(LocationFrom(kMethodRegister)); |
| 5156 | } |
| 5157 | |
| 5158 | void InstructionCodeGeneratorARMVIXL::VisitCurrentMethod( |
| 5159 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5160 | // Nothing to do, the method is already at its location. |
| 5161 | } |
| 5162 | |
| 5163 | void LocationsBuilderARMVIXL::VisitNot(HNot* not_) { |
| 5164 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5165 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5166 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5167 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5168 | } |
| 5169 | |
| 5170 | void InstructionCodeGeneratorARMVIXL::VisitNot(HNot* not_) { |
| 5171 | LocationSummary* locations = not_->GetLocations(); |
| 5172 | Location out = locations->Out(); |
| 5173 | Location in = locations->InAt(0); |
| 5174 | switch (not_->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5175 | case DataType::Type::kInt32: |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5176 | __ Mvn(OutputRegister(not_), InputRegisterAt(not_, 0)); |
| 5177 | break; |
| 5178 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5179 | case DataType::Type::kInt64: |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5180 | __ Mvn(LowRegisterFrom(out), LowRegisterFrom(in)); |
| 5181 | __ Mvn(HighRegisterFrom(out), HighRegisterFrom(in)); |
| 5182 | break; |
| 5183 | |
| 5184 | default: |
| 5185 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 5186 | } |
| 5187 | } |
| 5188 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5189 | void LocationsBuilderARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5190 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5191 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5192 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5193 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5194 | } |
| 5195 | |
| 5196 | void InstructionCodeGeneratorARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5197 | __ Eor(OutputRegister(bool_not), InputRegister(bool_not), 1); |
| 5198 | } |
| 5199 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5200 | void LocationsBuilderARMVIXL::VisitCompare(HCompare* compare) { |
| 5201 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5202 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5203 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5204 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5205 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5206 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5207 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5208 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5209 | case DataType::Type::kInt32: |
| 5210 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5211 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5212 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5213 | // Output overlaps because it is written before doing the low comparison. |
| 5214 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5215 | break; |
| 5216 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5217 | case DataType::Type::kFloat32: |
| 5218 | case DataType::Type::kFloat64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5219 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5220 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
| 5221 | locations->SetOut(Location::RequiresRegister()); |
| 5222 | break; |
| 5223 | } |
| 5224 | default: |
| 5225 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 5226 | } |
| 5227 | } |
| 5228 | |
| 5229 | void InstructionCodeGeneratorARMVIXL::VisitCompare(HCompare* compare) { |
| 5230 | LocationSummary* locations = compare->GetLocations(); |
| 5231 | vixl32::Register out = OutputRegister(compare); |
| 5232 | Location left = locations->InAt(0); |
| 5233 | Location right = locations->InAt(1); |
| 5234 | |
| 5235 | vixl32::Label less, greater, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5236 | vixl32::Label* final_label = codegen_->GetFinalLabel(compare, &done); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5237 | DataType::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 5238 | vixl32::Condition less_cond = vixl32::Condition::None(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5239 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5240 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5241 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5242 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5243 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5244 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5245 | case DataType::Type::kInt32: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5246 | // Emit move to `out` before the `Cmp`, as `Mov` might affect the status flags. |
| 5247 | __ Mov(out, 0); |
| 5248 | __ Cmp(RegisterFrom(left), RegisterFrom(right)); // Signed compare. |
| 5249 | less_cond = lt; |
| 5250 | break; |
| 5251 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5252 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5253 | __ Cmp(HighRegisterFrom(left), HighRegisterFrom(right)); // Signed compare. |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 5254 | __ B(lt, &less, /* far_target */ false); |
| 5255 | __ B(gt, &greater, /* far_target */ false); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5256 | // Emit move to `out` before the last `Cmp`, as `Mov` might affect the status flags. |
| 5257 | __ Mov(out, 0); |
| 5258 | __ Cmp(LowRegisterFrom(left), LowRegisterFrom(right)); // Unsigned compare. |
| 5259 | less_cond = lo; |
| 5260 | break; |
| 5261 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5262 | case DataType::Type::kFloat32: |
| 5263 | case DataType::Type::kFloat64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5264 | __ Mov(out, 0); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 5265 | GenerateVcmp(compare, codegen_); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5266 | // To branch on the FP compare result we transfer FPSCR to APSR (encoded as PC in VMRS). |
| 5267 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 5268 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
| 5269 | break; |
| 5270 | } |
| 5271 | default: |
| 5272 | LOG(FATAL) << "Unexpected compare type " << type; |
| 5273 | UNREACHABLE(); |
| 5274 | } |
| 5275 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5276 | __ B(eq, final_label, /* far_target */ false); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 5277 | __ B(less_cond, &less, /* far_target */ false); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5278 | |
| 5279 | __ Bind(&greater); |
| 5280 | __ Mov(out, 1); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5281 | __ B(final_label); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5282 | |
| 5283 | __ Bind(&less); |
| 5284 | __ Mov(out, -1); |
| 5285 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5286 | if (done.IsReferenced()) { |
| 5287 | __ Bind(&done); |
| 5288 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5289 | } |
| 5290 | |
| 5291 | void LocationsBuilderARMVIXL::VisitPhi(HPhi* instruction) { |
| 5292 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5293 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5294 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| 5295 | locations->SetInAt(i, Location::Any()); |
| 5296 | } |
| 5297 | locations->SetOut(Location::Any()); |
| 5298 | } |
| 5299 | |
| 5300 | void InstructionCodeGeneratorARMVIXL::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 5301 | LOG(FATAL) << "Unreachable"; |
| 5302 | } |
| 5303 | |
| 5304 | void CodeGeneratorARMVIXL::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 5305 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 5306 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
| 5307 | switch (kind) { |
| 5308 | case MemBarrierKind::kAnyStore: |
| 5309 | case MemBarrierKind::kLoadAny: |
| 5310 | case MemBarrierKind::kAnyAny: { |
| 5311 | flavor = DmbOptions::ISH; |
| 5312 | break; |
| 5313 | } |
| 5314 | case MemBarrierKind::kStoreStore: { |
| 5315 | flavor = DmbOptions::ISHST; |
| 5316 | break; |
| 5317 | } |
| 5318 | default: |
| 5319 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 5320 | } |
| 5321 | __ Dmb(flavor); |
| 5322 | } |
| 5323 | |
| 5324 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicLoad(vixl32::Register addr, |
| 5325 | uint32_t offset, |
| 5326 | vixl32::Register out_lo, |
| 5327 | vixl32::Register out_hi) { |
| 5328 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5329 | if (offset != 0) { |
| 5330 | vixl32::Register temp = temps.Acquire(); |
| 5331 | __ Add(temp, addr, offset); |
| 5332 | addr = temp; |
| 5333 | } |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5334 | __ Ldrexd(out_lo, out_hi, MemOperand(addr)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5335 | } |
| 5336 | |
| 5337 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicStore(vixl32::Register addr, |
| 5338 | uint32_t offset, |
| 5339 | vixl32::Register value_lo, |
| 5340 | vixl32::Register value_hi, |
| 5341 | vixl32::Register temp1, |
| 5342 | vixl32::Register temp2, |
| 5343 | HInstruction* instruction) { |
| 5344 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5345 | vixl32::Label fail; |
| 5346 | if (offset != 0) { |
| 5347 | vixl32::Register temp = temps.Acquire(); |
| 5348 | __ Add(temp, addr, offset); |
| 5349 | addr = temp; |
| 5350 | } |
| 5351 | __ Bind(&fail); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5352 | { |
| 5353 | // Ensure the pc position is recorded immediately after the `ldrexd` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5354 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5355 | vixl32::kMaxInstructionSizeInBytes, |
| 5356 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5357 | // We need a load followed by store. (The address used in a STREX instruction must |
| 5358 | // be the same as the address in the most recently executed LDREX instruction.) |
| 5359 | __ ldrexd(temp1, temp2, MemOperand(addr)); |
| 5360 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5361 | } |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5362 | __ Strexd(temp1, value_lo, value_hi, MemOperand(addr)); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5363 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5364 | } |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5365 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5366 | void LocationsBuilderARMVIXL::HandleFieldSet( |
| 5367 | HInstruction* instruction, const FieldInfo& field_info) { |
| 5368 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5369 | |
| 5370 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5371 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5372 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5373 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5374 | DataType::Type field_type = field_info.GetFieldType(); |
| 5375 | if (DataType::IsFloatingPointType(field_type)) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5376 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5377 | } else { |
| 5378 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5379 | } |
| 5380 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5381 | 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] | 5382 | bool generate_volatile = field_info.IsVolatile() |
| 5383 | && is_wide |
| 5384 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5385 | bool needs_write_barrier = |
| 5386 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 5387 | // Temporary registers for the write barrier. |
| 5388 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
| 5389 | if (needs_write_barrier) { |
| 5390 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
| 5391 | locations->AddTemp(Location::RequiresRegister()); |
| 5392 | } else if (generate_volatile) { |
| 5393 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 5394 | // - registers need to be consecutive |
| 5395 | // - the first register should be even but not R14. |
| 5396 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5397 | // revisit this if we ever enable ARM encoding. |
| 5398 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5399 | |
| 5400 | locations->AddTemp(Location::RequiresRegister()); |
| 5401 | locations->AddTemp(Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5402 | if (field_type == DataType::Type::kFloat64) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5403 | // For doubles we need two more registers to copy the value. |
| 5404 | locations->AddTemp(LocationFrom(r2)); |
| 5405 | locations->AddTemp(LocationFrom(r3)); |
| 5406 | } |
| 5407 | } |
| 5408 | } |
| 5409 | |
| 5410 | void InstructionCodeGeneratorARMVIXL::HandleFieldSet(HInstruction* instruction, |
| 5411 | const FieldInfo& field_info, |
| 5412 | bool value_can_be_null) { |
| 5413 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5414 | |
| 5415 | LocationSummary* locations = instruction->GetLocations(); |
| 5416 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 5417 | Location value = locations->InAt(1); |
| 5418 | |
| 5419 | bool is_volatile = field_info.IsVolatile(); |
| 5420 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5421 | DataType::Type field_type = field_info.GetFieldType(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5422 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5423 | bool needs_write_barrier = |
| 5424 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 5425 | |
| 5426 | if (is_volatile) { |
| 5427 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 5428 | } |
| 5429 | |
| 5430 | switch (field_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5431 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5432 | case DataType::Type::kUint8: |
| 5433 | case DataType::Type::kInt8: |
| 5434 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5435 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5436 | case DataType::Type::kInt32: { |
| 5437 | StoreOperandType operand_type = GetStoreOperandType(field_type); |
| 5438 | GetAssembler()->StoreToOffset(operand_type, RegisterFrom(value), base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5439 | break; |
| 5440 | } |
| 5441 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5442 | case DataType::Type::kReference: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5443 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5444 | // Note that in the case where `value` is a null reference, |
| 5445 | // we do not enter this block, as a null reference does not |
| 5446 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5447 | DCHECK_EQ(field_type, DataType::Type::kReference); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5448 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5449 | __ Mov(temp, RegisterFrom(value)); |
| 5450 | GetAssembler()->PoisonHeapReference(temp); |
| 5451 | GetAssembler()->StoreToOffset(kStoreWord, temp, base, offset); |
| 5452 | } else { |
| 5453 | GetAssembler()->StoreToOffset(kStoreWord, RegisterFrom(value), base, offset); |
| 5454 | } |
| 5455 | break; |
| 5456 | } |
| 5457 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5458 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5459 | if (is_volatile && !atomic_ldrd_strd) { |
| 5460 | GenerateWideAtomicStore(base, |
| 5461 | offset, |
| 5462 | LowRegisterFrom(value), |
| 5463 | HighRegisterFrom(value), |
| 5464 | RegisterFrom(locations->GetTemp(0)), |
| 5465 | RegisterFrom(locations->GetTemp(1)), |
| 5466 | instruction); |
| 5467 | } else { |
| 5468 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), base, offset); |
| 5469 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5470 | } |
| 5471 | break; |
| 5472 | } |
| 5473 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5474 | case DataType::Type::kFloat32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5475 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), base, offset); |
| 5476 | break; |
| 5477 | } |
| 5478 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5479 | case DataType::Type::kFloat64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5480 | vixl32::DRegister value_reg = DRegisterFrom(value); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5481 | if (is_volatile && !atomic_ldrd_strd) { |
| 5482 | vixl32::Register value_reg_lo = RegisterFrom(locations->GetTemp(0)); |
| 5483 | vixl32::Register value_reg_hi = RegisterFrom(locations->GetTemp(1)); |
| 5484 | |
| 5485 | __ Vmov(value_reg_lo, value_reg_hi, value_reg); |
| 5486 | |
| 5487 | GenerateWideAtomicStore(base, |
| 5488 | offset, |
| 5489 | value_reg_lo, |
| 5490 | value_reg_hi, |
| 5491 | RegisterFrom(locations->GetTemp(2)), |
| 5492 | RegisterFrom(locations->GetTemp(3)), |
| 5493 | instruction); |
| 5494 | } else { |
| 5495 | GetAssembler()->StoreDToOffset(value_reg, base, offset); |
| 5496 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5497 | } |
| 5498 | break; |
| 5499 | } |
| 5500 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5501 | case DataType::Type::kVoid: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5502 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5503 | UNREACHABLE(); |
| 5504 | } |
| 5505 | |
| 5506 | // Longs and doubles are handled in the switch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5507 | if (field_type != DataType::Type::kInt64 && field_type != DataType::Type::kFloat64) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5508 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, we |
| 5509 | // should use a scope and the assembler to emit the store instruction to guarantee that we |
| 5510 | // record the pc at the correct position. But the `Assembler` does not automatically handle |
| 5511 | // unencodable offsets. Practically, everything is fine because the helper and VIXL, at the time |
| 5512 | // of writing, do generate the store instruction last. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5513 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5514 | } |
| 5515 | |
| 5516 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5517 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5518 | vixl32::Register card = RegisterFrom(locations->GetTemp(1)); |
| 5519 | codegen_->MarkGCCard(temp, card, base, RegisterFrom(value), value_can_be_null); |
| 5520 | } |
| 5521 | |
| 5522 | if (is_volatile) { |
| 5523 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 5524 | } |
| 5525 | } |
| 5526 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5527 | void LocationsBuilderARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 5528 | const FieldInfo& field_info) { |
| 5529 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 5530 | |
| 5531 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5532 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == DataType::Type::kReference); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5533 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5534 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5535 | object_field_get_with_read_barrier |
| 5536 | ? LocationSummary::kCallOnSlowPath |
| 5537 | : LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5538 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5539 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 5540 | } |
| 5541 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5542 | |
| 5543 | bool volatile_for_double = field_info.IsVolatile() |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5544 | && (field_info.GetFieldType() == DataType::Type::kFloat64) |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5545 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5546 | // The output overlaps in case of volatile long: we don't want the |
| 5547 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 5548 | // object's location. Likewise, in the case of an object field get |
| 5549 | // with read barriers enabled, we do not want the load to overwrite |
| 5550 | // 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] | 5551 | bool overlap = |
| 5552 | (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) || |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5553 | object_field_get_with_read_barrier; |
| 5554 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5555 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5556 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5557 | } else { |
| 5558 | locations->SetOut(Location::RequiresRegister(), |
| 5559 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 5560 | } |
| 5561 | if (volatile_for_double) { |
| 5562 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 5563 | // - registers need to be consecutive |
| 5564 | // - the first register should be even but not R14. |
| 5565 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5566 | // revisit this if we ever enable ARM encoding. |
| 5567 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5568 | locations->AddTemp(Location::RequiresRegister()); |
| 5569 | locations->AddTemp(Location::RequiresRegister()); |
| 5570 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5571 | // We need a temporary register for the read barrier marking slow |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 5572 | // path in CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 5573 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 5574 | !Runtime::Current()->UseJitCompilation()) { |
| 5575 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 5576 | // loads we need a temporary only if the offset is too big. |
| 5577 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 5578 | locations->AddTemp(Location::RequiresRegister()); |
| 5579 | } |
| 5580 | // And we always need the reserved entrypoint register. |
| 5581 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 5582 | } else { |
| 5583 | locations->AddTemp(Location::RequiresRegister()); |
| 5584 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5585 | } |
| 5586 | } |
| 5587 | |
| 5588 | Location LocationsBuilderARMVIXL::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5589 | DCHECK(DataType::IsFloatingPointType(input->GetType())) << input->GetType(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5590 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 5591 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 5592 | return Location::ConstantLocation(input->AsConstant()); |
| 5593 | } else { |
| 5594 | return Location::RequiresFpuRegister(); |
| 5595 | } |
| 5596 | } |
| 5597 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5598 | Location LocationsBuilderARMVIXL::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 5599 | Opcode opcode) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5600 | DCHECK(!DataType::IsFloatingPointType(constant->GetType())); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5601 | if (constant->IsConstant() && |
| 5602 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 5603 | return Location::ConstantLocation(constant->AsConstant()); |
| 5604 | } |
| 5605 | return Location::RequiresRegister(); |
| 5606 | } |
| 5607 | |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 5608 | static bool CanEncode32BitConstantAsImmediate( |
| 5609 | CodeGeneratorARMVIXL* codegen, |
| 5610 | uint32_t value, |
| 5611 | Opcode opcode, |
| 5612 | vixl32::FlagsUpdate flags_update = vixl32::FlagsUpdate::DontCare) { |
| 5613 | ArmVIXLAssembler* assembler = codegen->GetAssembler(); |
| 5614 | if (assembler->ShifterOperandCanHold(opcode, value, flags_update)) { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5615 | return true; |
| 5616 | } |
| 5617 | Opcode neg_opcode = kNoOperand; |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5618 | uint32_t neg_value = 0; |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5619 | switch (opcode) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5620 | case AND: neg_opcode = BIC; neg_value = ~value; break; |
| 5621 | case ORR: neg_opcode = ORN; neg_value = ~value; break; |
| 5622 | case ADD: neg_opcode = SUB; neg_value = -value; break; |
| 5623 | case ADC: neg_opcode = SBC; neg_value = ~value; break; |
| 5624 | case SUB: neg_opcode = ADD; neg_value = -value; break; |
| 5625 | case SBC: neg_opcode = ADC; neg_value = ~value; break; |
| 5626 | case MOV: neg_opcode = MVN; neg_value = ~value; break; |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5627 | default: |
| 5628 | return false; |
| 5629 | } |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5630 | |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 5631 | if (assembler->ShifterOperandCanHold(neg_opcode, neg_value, flags_update)) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5632 | return true; |
| 5633 | } |
| 5634 | |
| 5635 | return opcode == AND && IsPowerOfTwo(value + 1); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5636 | } |
| 5637 | |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 5638 | bool LocationsBuilderARMVIXL::CanEncodeConstantAsImmediate(HConstant* input_cst, Opcode opcode) { |
| 5639 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 5640 | if (DataType::Is64BitType(input_cst->GetType())) { |
| 5641 | Opcode high_opcode = opcode; |
| 5642 | vixl32::FlagsUpdate low_flags_update = vixl32::FlagsUpdate::DontCare; |
| 5643 | switch (opcode) { |
| 5644 | case SUB: |
| 5645 | // Flip the operation to an ADD. |
| 5646 | value = -value; |
| 5647 | opcode = ADD; |
| 5648 | FALLTHROUGH_INTENDED; |
| 5649 | case ADD: |
| 5650 | if (Low32Bits(value) == 0u) { |
| 5651 | return CanEncode32BitConstantAsImmediate(codegen_, High32Bits(value), opcode); |
| 5652 | } |
| 5653 | high_opcode = ADC; |
| 5654 | low_flags_update = vixl32::FlagsUpdate::SetFlags; |
| 5655 | break; |
| 5656 | default: |
| 5657 | break; |
| 5658 | } |
| 5659 | return CanEncode32BitConstantAsImmediate(codegen_, High32Bits(value), high_opcode) && |
| 5660 | CanEncode32BitConstantAsImmediate(codegen_, Low32Bits(value), opcode, low_flags_update); |
| 5661 | } else { |
| 5662 | return CanEncode32BitConstantAsImmediate(codegen_, Low32Bits(value), opcode); |
| 5663 | } |
| 5664 | } |
| 5665 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5666 | void InstructionCodeGeneratorARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 5667 | const FieldInfo& field_info) { |
| 5668 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 5669 | |
| 5670 | LocationSummary* locations = instruction->GetLocations(); |
| 5671 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 5672 | Location out = locations->Out(); |
| 5673 | bool is_volatile = field_info.IsVolatile(); |
| 5674 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5675 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 5676 | DataType::Type load_type = instruction->GetType(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5677 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5678 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5679 | switch (load_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5680 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5681 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5682 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5683 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5684 | case DataType::Type::kInt16: |
| 5685 | case DataType::Type::kInt32: { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5686 | LoadOperandType operand_type = GetLoadOperandType(load_type); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5687 | GetAssembler()->LoadFromOffset(operand_type, RegisterFrom(out), base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5688 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5689 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5690 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5691 | case DataType::Type::kReference: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5692 | // /* HeapReference<Object> */ out = *(base + offset) |
| 5693 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5694 | Location temp_loc = locations->GetTemp(0); |
| 5695 | // Note that a potential implicit null check is handled in this |
| 5696 | // CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier call. |
| 5697 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 5698 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 5699 | if (is_volatile) { |
| 5700 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5701 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5702 | } else { |
| 5703 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(out), base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5704 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5705 | if (is_volatile) { |
| 5706 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5707 | } |
| 5708 | // If read barriers are enabled, emit read barriers other than |
| 5709 | // Baker's using a slow path (and also unpoison the loaded |
| 5710 | // reference, if heap poisoning is enabled). |
| 5711 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, locations->InAt(0), offset); |
| 5712 | } |
| 5713 | break; |
| 5714 | } |
| 5715 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5716 | case DataType::Type::kInt64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5717 | if (is_volatile && !atomic_ldrd_strd) { |
| 5718 | GenerateWideAtomicLoad(base, offset, LowRegisterFrom(out), HighRegisterFrom(out)); |
| 5719 | } else { |
| 5720 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out), base, offset); |
| 5721 | } |
| 5722 | break; |
| 5723 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5724 | case DataType::Type::kFloat32: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5725 | GetAssembler()->LoadSFromOffset(SRegisterFrom(out), base, offset); |
| 5726 | break; |
| 5727 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5728 | case DataType::Type::kFloat64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5729 | vixl32::DRegister out_dreg = DRegisterFrom(out); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5730 | if (is_volatile && !atomic_ldrd_strd) { |
| 5731 | vixl32::Register lo = RegisterFrom(locations->GetTemp(0)); |
| 5732 | vixl32::Register hi = RegisterFrom(locations->GetTemp(1)); |
| 5733 | GenerateWideAtomicLoad(base, offset, lo, hi); |
| 5734 | // TODO(VIXL): Do we need to be immediately after the ldrexd instruction? If so we need a |
| 5735 | // scope. |
| 5736 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5737 | __ Vmov(out_dreg, lo, hi); |
| 5738 | } else { |
| 5739 | GetAssembler()->LoadDFromOffset(out_dreg, base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5740 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5741 | } |
| 5742 | break; |
| 5743 | } |
| 5744 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5745 | case DataType::Type::kVoid: |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5746 | LOG(FATAL) << "Unreachable type " << load_type; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5747 | UNREACHABLE(); |
| 5748 | } |
| 5749 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5750 | if (load_type == DataType::Type::kReference || load_type == DataType::Type::kFloat64) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5751 | // Potential implicit null checks, in the case of reference or |
| 5752 | // double fields, are handled in the previous switch statement. |
| 5753 | } else { |
| 5754 | // Address cases other than reference and double that may require an implicit null check. |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5755 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, we |
| 5756 | // should use a scope and the assembler to emit the load instruction to guarantee that we |
| 5757 | // record the pc at the correct position. But the `Assembler` does not automatically handle |
| 5758 | // unencodable offsets. Practically, everything is fine because the helper and VIXL, at the time |
| 5759 | // of writing, do generate the store instruction last. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5760 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5761 | } |
| 5762 | |
| 5763 | if (is_volatile) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5764 | if (load_type == DataType::Type::kReference) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5765 | // Memory barriers, in the case of references, are also handled |
| 5766 | // in the previous switch statement. |
| 5767 | } else { |
| 5768 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5769 | } |
| 5770 | } |
| 5771 | } |
| 5772 | |
| 5773 | void LocationsBuilderARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5774 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5775 | } |
| 5776 | |
| 5777 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5778 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 5779 | } |
| 5780 | |
| 5781 | void LocationsBuilderARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5782 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5783 | } |
| 5784 | |
| 5785 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5786 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5787 | } |
| 5788 | |
| 5789 | void LocationsBuilderARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5790 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5791 | } |
| 5792 | |
| 5793 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5794 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5795 | } |
| 5796 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5797 | void LocationsBuilderARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5798 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5799 | } |
| 5800 | |
| 5801 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5802 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 5803 | } |
| 5804 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 5805 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 5806 | HUnresolvedInstanceFieldGet* instruction) { |
| 5807 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5808 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5809 | instruction, instruction->GetFieldType(), calling_convention); |
| 5810 | } |
| 5811 | |
| 5812 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 5813 | HUnresolvedInstanceFieldGet* instruction) { |
| 5814 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5815 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5816 | instruction->GetFieldType(), |
| 5817 | instruction->GetFieldIndex(), |
| 5818 | instruction->GetDexPc(), |
| 5819 | calling_convention); |
| 5820 | } |
| 5821 | |
| 5822 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 5823 | HUnresolvedInstanceFieldSet* instruction) { |
| 5824 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5825 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5826 | instruction, instruction->GetFieldType(), calling_convention); |
| 5827 | } |
| 5828 | |
| 5829 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 5830 | HUnresolvedInstanceFieldSet* instruction) { |
| 5831 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5832 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5833 | instruction->GetFieldType(), |
| 5834 | instruction->GetFieldIndex(), |
| 5835 | instruction->GetDexPc(), |
| 5836 | calling_convention); |
| 5837 | } |
| 5838 | |
| 5839 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldGet( |
| 5840 | HUnresolvedStaticFieldGet* instruction) { |
| 5841 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5842 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5843 | instruction, instruction->GetFieldType(), calling_convention); |
| 5844 | } |
| 5845 | |
| 5846 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldGet( |
| 5847 | HUnresolvedStaticFieldGet* instruction) { |
| 5848 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5849 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5850 | instruction->GetFieldType(), |
| 5851 | instruction->GetFieldIndex(), |
| 5852 | instruction->GetDexPc(), |
| 5853 | calling_convention); |
| 5854 | } |
| 5855 | |
| 5856 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldSet( |
| 5857 | HUnresolvedStaticFieldSet* instruction) { |
| 5858 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5859 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5860 | instruction, instruction->GetFieldType(), calling_convention); |
| 5861 | } |
| 5862 | |
| 5863 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldSet( |
| 5864 | HUnresolvedStaticFieldSet* instruction) { |
| 5865 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5866 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5867 | instruction->GetFieldType(), |
| 5868 | instruction->GetFieldIndex(), |
| 5869 | instruction->GetDexPc(), |
| 5870 | calling_convention); |
| 5871 | } |
| 5872 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5873 | void LocationsBuilderARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 5874 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5875 | locations->SetInAt(0, Location::RequiresRegister()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5876 | } |
| 5877 | |
| 5878 | void CodeGeneratorARMVIXL::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5879 | if (CanMoveNullCheckToUser(instruction)) { |
| 5880 | return; |
| 5881 | } |
| 5882 | |
| 5883 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5884 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5885 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5886 | vixl32::kMaxInstructionSizeInBytes, |
| 5887 | CodeBufferCheckScope::kMaximumSize); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5888 | __ ldr(temps.Acquire(), MemOperand(InputRegisterAt(instruction, 0))); |
| 5889 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5890 | } |
| 5891 | |
| 5892 | void CodeGeneratorARMVIXL::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| 5893 | NullCheckSlowPathARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5894 | new (GetScopedAllocator()) NullCheckSlowPathARMVIXL(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5895 | AddSlowPath(slow_path); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5896 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5897 | } |
| 5898 | |
| 5899 | void InstructionCodeGeneratorARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
| 5900 | codegen_->GenerateNullCheck(instruction); |
| 5901 | } |
| 5902 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5903 | void CodeGeneratorARMVIXL::LoadFromShiftedRegOffset(DataType::Type type, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5904 | Location out_loc, |
| 5905 | vixl32::Register base, |
| 5906 | vixl32::Register reg_index, |
| 5907 | vixl32::Condition cond) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5908 | uint32_t shift_count = DataType::SizeShift(type); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5909 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 5910 | |
| 5911 | switch (type) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5912 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5913 | case DataType::Type::kUint8: |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5914 | __ Ldrb(cond, RegisterFrom(out_loc), mem_address); |
| 5915 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5916 | case DataType::Type::kInt8: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5917 | __ Ldrsb(cond, RegisterFrom(out_loc), mem_address); |
| 5918 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5919 | case DataType::Type::kUint16: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5920 | __ Ldrh(cond, RegisterFrom(out_loc), mem_address); |
| 5921 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5922 | case DataType::Type::kInt16: |
| 5923 | __ Ldrsh(cond, RegisterFrom(out_loc), mem_address); |
| 5924 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5925 | case DataType::Type::kReference: |
| 5926 | case DataType::Type::kInt32: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5927 | __ Ldr(cond, RegisterFrom(out_loc), mem_address); |
| 5928 | break; |
| 5929 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5930 | case DataType::Type::kInt64: |
| 5931 | case DataType::Type::kFloat32: |
| 5932 | case DataType::Type::kFloat64: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5933 | default: |
| 5934 | LOG(FATAL) << "Unreachable type " << type; |
| 5935 | UNREACHABLE(); |
| 5936 | } |
| 5937 | } |
| 5938 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5939 | void CodeGeneratorARMVIXL::StoreToShiftedRegOffset(DataType::Type type, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5940 | Location loc, |
| 5941 | vixl32::Register base, |
| 5942 | vixl32::Register reg_index, |
| 5943 | vixl32::Condition cond) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5944 | uint32_t shift_count = DataType::SizeShift(type); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5945 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 5946 | |
| 5947 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5948 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5949 | case DataType::Type::kUint8: |
| 5950 | case DataType::Type::kInt8: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5951 | __ Strb(cond, RegisterFrom(loc), mem_address); |
| 5952 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5953 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5954 | case DataType::Type::kInt16: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5955 | __ Strh(cond, RegisterFrom(loc), mem_address); |
| 5956 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5957 | case DataType::Type::kReference: |
| 5958 | case DataType::Type::kInt32: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5959 | __ Str(cond, RegisterFrom(loc), mem_address); |
| 5960 | break; |
| 5961 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5962 | case DataType::Type::kInt64: |
| 5963 | case DataType::Type::kFloat32: |
| 5964 | case DataType::Type::kFloat64: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5965 | default: |
| 5966 | LOG(FATAL) << "Unreachable type " << type; |
| 5967 | UNREACHABLE(); |
| 5968 | } |
| 5969 | } |
| 5970 | |
| 5971 | void LocationsBuilderARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
| 5972 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5973 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5974 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5975 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5976 | object_array_get_with_read_barrier |
| 5977 | ? LocationSummary::kCallOnSlowPath |
| 5978 | : LocationSummary::kNoCall); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5979 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5980 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5981 | } |
| 5982 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5983 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5984 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5985 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5986 | } else { |
| 5987 | // The output overlaps in the case of an object array get with |
| 5988 | // read barriers enabled: we do not want the move to overwrite the |
| 5989 | // array's location, as we need it to emit the read barrier. |
| 5990 | locations->SetOut( |
| 5991 | Location::RequiresRegister(), |
| 5992 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 5993 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 5994 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5995 | // We need a temporary register for the read barrier marking slow |
| 5996 | // path in CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier. |
| 5997 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 5998 | !Runtime::Current()->UseJitCompilation() && |
| 5999 | instruction->GetIndex()->IsConstant()) { |
| 6000 | // Array loads with constant index are treated as field loads. |
| 6001 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 6002 | // constant index loads we need a temporary only if the offset is too big. |
| 6003 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 6004 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6005 | offset += index << DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6006 | if (offset >= kReferenceLoadMinFarOffset) { |
| 6007 | locations->AddTemp(Location::RequiresRegister()); |
| 6008 | } |
| 6009 | // And we always need the reserved entrypoint register. |
| 6010 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 6011 | } else if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 6012 | !Runtime::Current()->UseJitCompilation() && |
| 6013 | !instruction->GetIndex()->IsConstant()) { |
| 6014 | // We need a non-scratch temporary for the array data pointer. |
| 6015 | locations->AddTemp(Location::RequiresRegister()); |
| 6016 | // And we always need the reserved entrypoint register. |
| 6017 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 6018 | } else { |
| 6019 | locations->AddTemp(Location::RequiresRegister()); |
| 6020 | } |
| 6021 | } else if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 6022 | // Also need a temporary for String compression feature. |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6023 | locations->AddTemp(Location::RequiresRegister()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6024 | } |
| 6025 | } |
| 6026 | |
| 6027 | void InstructionCodeGeneratorARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6028 | LocationSummary* locations = instruction->GetLocations(); |
| 6029 | Location obj_loc = locations->InAt(0); |
| 6030 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 6031 | Location index = locations->InAt(1); |
| 6032 | Location out_loc = locations->Out(); |
| 6033 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6034 | DataType::Type type = instruction->GetType(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6035 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 6036 | instruction->IsStringCharAt(); |
| 6037 | HInstruction* array_instr = instruction->GetArray(); |
| 6038 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6039 | |
| 6040 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6041 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6042 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6043 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6044 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6045 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6046 | case DataType::Type::kInt32: { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6047 | vixl32::Register length; |
| 6048 | if (maybe_compressed_char_at) { |
| 6049 | length = RegisterFrom(locations->GetTemp(0)); |
| 6050 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 6051 | GetAssembler()->LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 6052 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6053 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6054 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6055 | int32_t const_index = Int32ConstantFrom(index); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6056 | if (maybe_compressed_char_at) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6057 | vixl32::Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6058 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6059 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 6060 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6061 | "Expecting 0=compressed, 1=uncompressed"); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 6062 | __ B(cs, &uncompressed_load, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6063 | GetAssembler()->LoadFromOffset(kLoadUnsignedByte, |
| 6064 | RegisterFrom(out_loc), |
| 6065 | obj, |
| 6066 | data_offset + const_index); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6067 | __ B(final_label); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6068 | __ Bind(&uncompressed_load); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6069 | GetAssembler()->LoadFromOffset(GetLoadOperandType(DataType::Type::kUint16), |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6070 | RegisterFrom(out_loc), |
| 6071 | obj, |
| 6072 | data_offset + (const_index << 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6073 | if (done.IsReferenced()) { |
| 6074 | __ Bind(&done); |
| 6075 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6076 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6077 | uint32_t full_offset = data_offset + (const_index << DataType::SizeShift(type)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6078 | |
| 6079 | LoadOperandType load_type = GetLoadOperandType(type); |
| 6080 | GetAssembler()->LoadFromOffset(load_type, RegisterFrom(out_loc), obj, full_offset); |
| 6081 | } |
| 6082 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6083 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6084 | vixl32::Register temp = temps.Acquire(); |
| 6085 | |
| 6086 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6087 | // We do not need to compute the intermediate address from the array: the |
| 6088 | // input instruction has done it already. See the comment in |
| 6089 | // `TryExtractArrayAccessAddress()`. |
| 6090 | if (kIsDebugBuild) { |
| 6091 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6092 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6093 | } |
| 6094 | temp = obj; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6095 | } else { |
| 6096 | __ Add(temp, obj, data_offset); |
| 6097 | } |
| 6098 | if (maybe_compressed_char_at) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6099 | vixl32::Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6100 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6101 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 6102 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6103 | "Expecting 0=compressed, 1=uncompressed"); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 6104 | __ B(cs, &uncompressed_load, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6105 | __ Ldrb(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 0)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6106 | __ B(final_label); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6107 | __ Bind(&uncompressed_load); |
| 6108 | __ Ldrh(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6109 | if (done.IsReferenced()) { |
| 6110 | __ Bind(&done); |
| 6111 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6112 | } else { |
| 6113 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
| 6114 | } |
| 6115 | } |
| 6116 | break; |
| 6117 | } |
| 6118 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6119 | case DataType::Type::kReference: { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6120 | // The read barrier instrumentation of object ArrayGet |
| 6121 | // instructions does not support the HIntermediateAddress |
| 6122 | // instruction. |
| 6123 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 6124 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6125 | static_assert( |
| 6126 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6127 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 6128 | // /* HeapReference<Object> */ out = |
| 6129 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6130 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6131 | Location temp = locations->GetTemp(0); |
| 6132 | // Note that a potential implicit null check is handled in this |
| 6133 | // CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6134 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 6135 | if (index.IsConstant()) { |
| 6136 | // Array load with a constant index can be treated as a field load. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6137 | data_offset += Int32ConstantFrom(index) << DataType::SizeShift(type); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6138 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6139 | out_loc, |
| 6140 | obj, |
| 6141 | data_offset, |
| 6142 | locations->GetTemp(0), |
| 6143 | /* needs_null_check */ false); |
| 6144 | } else { |
| 6145 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 6146 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ false); |
| 6147 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6148 | } else { |
| 6149 | vixl32::Register out = OutputRegister(instruction); |
| 6150 | if (index.IsConstant()) { |
| 6151 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6152 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6153 | GetAssembler()->LoadFromOffset(kLoadWord, out, obj, offset); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6154 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, |
| 6155 | // we should use a scope and the assembler to emit the load instruction to guarantee that |
| 6156 | // we record the pc at the correct position. But the `Assembler` does not automatically |
| 6157 | // handle unencodable offsets. Practically, everything is fine because the helper and |
| 6158 | // VIXL, at the time of writing, do generate the store instruction last. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6159 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6160 | // If read barriers are enabled, emit read barriers other than |
| 6161 | // Baker's using a slow path (and also unpoison the loaded |
| 6162 | // reference, if heap poisoning is enabled). |
| 6163 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 6164 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6165 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6166 | vixl32::Register temp = temps.Acquire(); |
| 6167 | |
| 6168 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6169 | // We do not need to compute the intermediate address from the array: the |
| 6170 | // input instruction has done it already. See the comment in |
| 6171 | // `TryExtractArrayAccessAddress()`. |
| 6172 | if (kIsDebugBuild) { |
| 6173 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6174 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6175 | } |
| 6176 | temp = obj; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6177 | } else { |
| 6178 | __ Add(temp, obj, data_offset); |
| 6179 | } |
| 6180 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6181 | temps.Close(); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6182 | // TODO(VIXL): Use a scope to ensure that we record the pc position immediately after the |
| 6183 | // load instruction. Practically, everything is fine because the helper and VIXL, at the |
| 6184 | // time of writing, do generate the store instruction last. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6185 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6186 | // If read barriers are enabled, emit read barriers other than |
| 6187 | // Baker's using a slow path (and also unpoison the loaded |
| 6188 | // reference, if heap poisoning is enabled). |
| 6189 | codegen_->MaybeGenerateReadBarrierSlow( |
| 6190 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 6191 | } |
| 6192 | } |
| 6193 | break; |
| 6194 | } |
| 6195 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6196 | case DataType::Type::kInt64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6197 | if (index.IsConstant()) { |
| 6198 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6199 | (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6200 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), obj, offset); |
| 6201 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6202 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6203 | vixl32::Register temp = temps.Acquire(); |
| 6204 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6205 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), temp, data_offset); |
| 6206 | } |
| 6207 | break; |
| 6208 | } |
| 6209 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6210 | case DataType::Type::kFloat32: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6211 | vixl32::SRegister out = SRegisterFrom(out_loc); |
| 6212 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6213 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6214 | GetAssembler()->LoadSFromOffset(out, obj, offset); |
| 6215 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6216 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6217 | vixl32::Register temp = temps.Acquire(); |
| 6218 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 6219 | GetAssembler()->LoadSFromOffset(out, temp, data_offset); |
| 6220 | } |
| 6221 | break; |
| 6222 | } |
| 6223 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6224 | case DataType::Type::kFloat64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6225 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6226 | size_t offset = (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6227 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), obj, offset); |
| 6228 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6229 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6230 | vixl32::Register temp = temps.Acquire(); |
| 6231 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6232 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), temp, data_offset); |
| 6233 | } |
| 6234 | break; |
| 6235 | } |
| 6236 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6237 | case DataType::Type::kVoid: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6238 | LOG(FATAL) << "Unreachable type " << type; |
| 6239 | UNREACHABLE(); |
| 6240 | } |
| 6241 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6242 | if (type == DataType::Type::kReference) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6243 | // Potential implicit null checks, in the case of reference |
| 6244 | // arrays, are handled in the previous switch statement. |
| 6245 | } else if (!maybe_compressed_char_at) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6246 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after |
| 6247 | // the preceding load instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6248 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6249 | } |
| 6250 | } |
| 6251 | |
| 6252 | void LocationsBuilderARMVIXL::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6253 | DataType::Type value_type = instruction->GetComponentType(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6254 | |
| 6255 | bool needs_write_barrier = |
| 6256 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 6257 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 6258 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6259 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6260 | instruction, |
| 6261 | may_need_runtime_call_for_type_check ? |
| 6262 | LocationSummary::kCallOnSlowPath : |
| 6263 | LocationSummary::kNoCall); |
| 6264 | |
| 6265 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6266 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6267 | if (DataType::IsFloatingPointType(value_type)) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6268 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 6269 | } else { |
| 6270 | locations->SetInAt(2, Location::RequiresRegister()); |
| 6271 | } |
| 6272 | if (needs_write_barrier) { |
| 6273 | // Temporary registers for the write barrier. |
| 6274 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 6275 | locations->AddTemp(Location::RequiresRegister()); |
| 6276 | } |
| 6277 | } |
| 6278 | |
| 6279 | void InstructionCodeGeneratorARMVIXL::VisitArraySet(HArraySet* instruction) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6280 | LocationSummary* locations = instruction->GetLocations(); |
| 6281 | vixl32::Register array = InputRegisterAt(instruction, 0); |
| 6282 | Location index = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6283 | DataType::Type value_type = instruction->GetComponentType(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6284 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 6285 | bool needs_write_barrier = |
| 6286 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 6287 | uint32_t data_offset = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6288 | mirror::Array::DataOffset(DataType::Size(value_type)).Uint32Value(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6289 | Location value_loc = locations->InAt(2); |
| 6290 | HInstruction* array_instr = instruction->GetArray(); |
| 6291 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6292 | |
| 6293 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6294 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6295 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6296 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6297 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6298 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6299 | case DataType::Type::kInt32: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6300 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6301 | int32_t const_index = Int32ConstantFrom(index); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6302 | uint32_t full_offset = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6303 | data_offset + (const_index << DataType::SizeShift(value_type)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6304 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 6305 | GetAssembler()->StoreToOffset(store_type, RegisterFrom(value_loc), array, full_offset); |
| 6306 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6307 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6308 | vixl32::Register temp = temps.Acquire(); |
| 6309 | |
| 6310 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6311 | // We do not need to compute the intermediate address from the array: the |
| 6312 | // input instruction has done it already. See the comment in |
| 6313 | // `TryExtractArrayAccessAddress()`. |
| 6314 | if (kIsDebugBuild) { |
| 6315 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6316 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6317 | } |
| 6318 | temp = array; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6319 | } else { |
| 6320 | __ Add(temp, array, data_offset); |
| 6321 | } |
| 6322 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 6323 | } |
| 6324 | break; |
| 6325 | } |
| 6326 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6327 | case DataType::Type::kReference: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6328 | vixl32::Register value = RegisterFrom(value_loc); |
| 6329 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 6330 | // See the comment in instruction_simplifier_shared.cc. |
| 6331 | DCHECK(!has_intermediate_address); |
| 6332 | |
| 6333 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 6334 | // Just setting null. |
| 6335 | if (index.IsConstant()) { |
| 6336 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6337 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6338 | GetAssembler()->StoreToOffset(kStoreWord, value, array, offset); |
| 6339 | } else { |
| 6340 | DCHECK(index.IsRegister()) << index; |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6341 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6342 | vixl32::Register temp = temps.Acquire(); |
| 6343 | __ Add(temp, array, data_offset); |
| 6344 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 6345 | } |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6346 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after the preceding |
| 6347 | // store instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6348 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6349 | DCHECK(!needs_write_barrier); |
| 6350 | DCHECK(!may_need_runtime_call_for_type_check); |
| 6351 | break; |
| 6352 | } |
| 6353 | |
| 6354 | DCHECK(needs_write_barrier); |
| 6355 | Location temp1_loc = locations->GetTemp(0); |
| 6356 | vixl32::Register temp1 = RegisterFrom(temp1_loc); |
| 6357 | Location temp2_loc = locations->GetTemp(1); |
| 6358 | vixl32::Register temp2 = RegisterFrom(temp2_loc); |
| 6359 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6360 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6361 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6362 | vixl32::Label done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6363 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6364 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 6365 | |
| 6366 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6367 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathARMVIXL(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6368 | codegen_->AddSlowPath(slow_path); |
| 6369 | if (instruction->GetValueCanBeNull()) { |
| 6370 | vixl32::Label non_zero; |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6371 | __ CompareAndBranchIfNonZero(value, &non_zero); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6372 | if (index.IsConstant()) { |
| 6373 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6374 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6375 | GetAssembler()->StoreToOffset(kStoreWord, value, array, offset); |
| 6376 | } else { |
| 6377 | DCHECK(index.IsRegister()) << index; |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6378 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6379 | vixl32::Register temp = temps.Acquire(); |
| 6380 | __ Add(temp, array, data_offset); |
| 6381 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 6382 | } |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6383 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after the preceding |
| 6384 | // store instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6385 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6386 | __ B(final_label); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6387 | __ Bind(&non_zero); |
| 6388 | } |
| 6389 | |
| 6390 | // Note that when read barriers are enabled, the type checks |
| 6391 | // are performed without read barriers. This is fine, even in |
| 6392 | // the case where a class object is in the from-space after |
| 6393 | // the flip, as a comparison involving such a type would not |
| 6394 | // produce a false positive; it may of course produce a false |
| 6395 | // negative, in which case we would take the ArraySet slow |
| 6396 | // path. |
| 6397 | |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6398 | { |
| 6399 | // Ensure we record the pc position immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6400 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6401 | vixl32::kMaxInstructionSizeInBytes, |
| 6402 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6403 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 6404 | __ ldr(temp1, MemOperand(array, class_offset)); |
| 6405 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6406 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6407 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 6408 | |
| 6409 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 6410 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 6411 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 6412 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 6413 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 6414 | // nor `temp2`, as we are comparing two poisoned references. |
| 6415 | __ Cmp(temp1, temp2); |
| 6416 | |
| 6417 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 6418 | vixl32::Label do_put; |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 6419 | __ B(eq, &do_put, /* far_target */ false); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6420 | // If heap poisoning is enabled, the `temp1` reference has |
| 6421 | // not been unpoisoned yet; unpoison it now. |
| 6422 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 6423 | |
| 6424 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 6425 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 6426 | // If heap poisoning is enabled, no need to unpoison |
| 6427 | // `temp1`, as we are comparing against null below. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6428 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6429 | __ Bind(&do_put); |
| 6430 | } else { |
| 6431 | __ B(ne, slow_path->GetEntryLabel()); |
| 6432 | } |
| 6433 | } |
| 6434 | |
| 6435 | vixl32::Register source = value; |
| 6436 | if (kPoisonHeapReferences) { |
| 6437 | // Note that in the case where `value` is a null reference, |
| 6438 | // we do not enter this block, as a null reference does not |
| 6439 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6440 | DCHECK_EQ(value_type, DataType::Type::kReference); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6441 | __ Mov(temp1, value); |
| 6442 | GetAssembler()->PoisonHeapReference(temp1); |
| 6443 | source = temp1; |
| 6444 | } |
| 6445 | |
| 6446 | if (index.IsConstant()) { |
| 6447 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6448 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6449 | GetAssembler()->StoreToOffset(kStoreWord, source, array, offset); |
| 6450 | } else { |
| 6451 | DCHECK(index.IsRegister()) << index; |
| 6452 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6453 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6454 | vixl32::Register temp = temps.Acquire(); |
| 6455 | __ Add(temp, array, data_offset); |
| 6456 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6457 | LocationFrom(source), |
| 6458 | temp, |
| 6459 | RegisterFrom(index)); |
| 6460 | } |
| 6461 | |
| 6462 | if (!may_need_runtime_call_for_type_check) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6463 | // TODO(VIXL): Ensure we record the pc position immediately after the preceding store |
| 6464 | // instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6465 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6466 | } |
| 6467 | |
| 6468 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 6469 | |
| 6470 | if (done.IsReferenced()) { |
| 6471 | __ Bind(&done); |
| 6472 | } |
| 6473 | |
| 6474 | if (slow_path != nullptr) { |
| 6475 | __ Bind(slow_path->GetExitLabel()); |
| 6476 | } |
| 6477 | |
| 6478 | break; |
| 6479 | } |
| 6480 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6481 | case DataType::Type::kInt64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6482 | Location value = locations->InAt(2); |
| 6483 | if (index.IsConstant()) { |
| 6484 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6485 | (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6486 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), array, offset); |
| 6487 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6488 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6489 | vixl32::Register temp = temps.Acquire(); |
| 6490 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6491 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), temp, data_offset); |
| 6492 | } |
| 6493 | break; |
| 6494 | } |
| 6495 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6496 | case DataType::Type::kFloat32: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6497 | Location value = locations->InAt(2); |
| 6498 | DCHECK(value.IsFpuRegister()); |
| 6499 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6500 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6501 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), array, offset); |
| 6502 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6503 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6504 | vixl32::Register temp = temps.Acquire(); |
| 6505 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 6506 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), temp, data_offset); |
| 6507 | } |
| 6508 | break; |
| 6509 | } |
| 6510 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6511 | case DataType::Type::kFloat64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6512 | Location value = locations->InAt(2); |
| 6513 | DCHECK(value.IsFpuRegisterPair()); |
| 6514 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6515 | size_t offset = (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6516 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), array, offset); |
| 6517 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6518 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6519 | vixl32::Register temp = temps.Acquire(); |
| 6520 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6521 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), temp, data_offset); |
| 6522 | } |
| 6523 | break; |
| 6524 | } |
| 6525 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6526 | case DataType::Type::kVoid: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6527 | LOG(FATAL) << "Unreachable type " << value_type; |
| 6528 | UNREACHABLE(); |
| 6529 | } |
| 6530 | |
| 6531 | // Objects are handled in the switch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6532 | if (value_type != DataType::Type::kReference) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6533 | // TODO(VIXL): Ensure we record the pc position immediately after the preceding store |
| 6534 | // instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6535 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6536 | } |
| 6537 | } |
| 6538 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6539 | void LocationsBuilderARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 6540 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6541 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6542 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6543 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6544 | } |
| 6545 | |
| 6546 | void InstructionCodeGeneratorARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 6547 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| 6548 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 6549 | vixl32::Register out = OutputRegister(instruction); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6550 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6551 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6552 | vixl32::kMaxInstructionSizeInBytes, |
| 6553 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6554 | __ ldr(out, MemOperand(obj, offset)); |
| 6555 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6556 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6557 | // Mask out compression flag from String's array length. |
| 6558 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6559 | __ Lsr(out, out, 1u); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6560 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6561 | } |
| 6562 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6563 | void LocationsBuilderARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6564 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6565 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6566 | |
| 6567 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6568 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 6569 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6570 | } |
| 6571 | |
| 6572 | void InstructionCodeGeneratorARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 6573 | vixl32::Register out = OutputRegister(instruction); |
| 6574 | vixl32::Register first = InputRegisterAt(instruction, 0); |
| 6575 | Location second = instruction->GetLocations()->InAt(1); |
| 6576 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6577 | if (second.IsRegister()) { |
| 6578 | __ Add(out, first, RegisterFrom(second)); |
| 6579 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6580 | __ Add(out, first, Int32ConstantFrom(second)); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6581 | } |
| 6582 | } |
| 6583 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 6584 | void LocationsBuilderARMVIXL::VisitIntermediateAddressIndex( |
| 6585 | HIntermediateAddressIndex* instruction) { |
| 6586 | LOG(FATAL) << "Unreachable " << instruction->GetId(); |
| 6587 | } |
| 6588 | |
| 6589 | void InstructionCodeGeneratorARMVIXL::VisitIntermediateAddressIndex( |
| 6590 | HIntermediateAddressIndex* instruction) { |
| 6591 | LOG(FATAL) << "Unreachable " << instruction->GetId(); |
| 6592 | } |
| 6593 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6594 | void LocationsBuilderARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 6595 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6596 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 6597 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 6598 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(1))); |
| 6599 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6600 | |
| 6601 | HInstruction* index = instruction->InputAt(0); |
| 6602 | HInstruction* length = instruction->InputAt(1); |
| 6603 | // If both index and length are constants we can statically check the bounds. But if at least one |
| 6604 | // of them is not encodable ArmEncodableConstantOrRegister will create |
| 6605 | // Location::RequiresRegister() which is not desired to happen. Instead we create constant |
| 6606 | // locations. |
| 6607 | bool both_const = index->IsConstant() && length->IsConstant(); |
| 6608 | locations->SetInAt(0, both_const |
| 6609 | ? Location::ConstantLocation(index->AsConstant()) |
| 6610 | : ArmEncodableConstantOrRegister(index, CMP)); |
| 6611 | locations->SetInAt(1, both_const |
| 6612 | ? Location::ConstantLocation(length->AsConstant()) |
| 6613 | : ArmEncodableConstantOrRegister(length, CMP)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6614 | } |
| 6615 | |
| 6616 | void InstructionCodeGeneratorARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6617 | LocationSummary* locations = instruction->GetLocations(); |
| 6618 | Location index_loc = locations->InAt(0); |
| 6619 | Location length_loc = locations->InAt(1); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6620 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6621 | if (length_loc.IsConstant()) { |
| 6622 | int32_t length = Int32ConstantFrom(length_loc); |
| 6623 | if (index_loc.IsConstant()) { |
| 6624 | // BCE will remove the bounds check if we are guaranteed to pass. |
| 6625 | int32_t index = Int32ConstantFrom(index_loc); |
| 6626 | if (index < 0 || index >= length) { |
| 6627 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6628 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARMVIXL(instruction); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6629 | codegen_->AddSlowPath(slow_path); |
| 6630 | __ B(slow_path->GetEntryLabel()); |
| 6631 | } else { |
| 6632 | // Some optimization after BCE may have generated this, and we should not |
| 6633 | // generate a bounds check if it is a valid range. |
| 6634 | } |
| 6635 | return; |
| 6636 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6637 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6638 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6639 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARMVIXL(instruction); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6640 | __ Cmp(RegisterFrom(index_loc), length); |
| 6641 | codegen_->AddSlowPath(slow_path); |
| 6642 | __ B(hs, slow_path->GetEntryLabel()); |
| 6643 | } else { |
| 6644 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6645 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARMVIXL(instruction); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6646 | __ Cmp(RegisterFrom(length_loc), InputOperandAt(instruction, 0)); |
| 6647 | codegen_->AddSlowPath(slow_path); |
| 6648 | __ B(ls, slow_path->GetEntryLabel()); |
| 6649 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6650 | } |
| 6651 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6652 | void CodeGeneratorARMVIXL::MarkGCCard(vixl32::Register temp, |
| 6653 | vixl32::Register card, |
| 6654 | vixl32::Register object, |
| 6655 | vixl32::Register value, |
| 6656 | bool can_be_null) { |
| 6657 | vixl32::Label is_null; |
| 6658 | if (can_be_null) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6659 | __ CompareAndBranchIfZero(value, &is_null); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6660 | } |
| 6661 | GetAssembler()->LoadFromOffset( |
| 6662 | kLoadWord, card, tr, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 6663 | __ Lsr(temp, object, Operand::From(gc::accounting::CardTable::kCardShift)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6664 | __ Strb(card, MemOperand(card, temp)); |
| 6665 | if (can_be_null) { |
| 6666 | __ Bind(&is_null); |
| 6667 | } |
| 6668 | } |
| 6669 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6670 | void LocationsBuilderARMVIXL::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 6671 | LOG(FATAL) << "Unreachable"; |
| 6672 | } |
| 6673 | |
| 6674 | void InstructionCodeGeneratorARMVIXL::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 6675 | if (instruction->GetNext()->IsSuspendCheck() && |
| 6676 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 6677 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 6678 | // The back edge will generate the suspend check. |
| 6679 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 6680 | } |
| 6681 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6682 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6683 | } |
| 6684 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6685 | void LocationsBuilderARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6686 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6687 | instruction, LocationSummary::kCallOnSlowPath); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6688 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6689 | } |
| 6690 | |
| 6691 | void InstructionCodeGeneratorARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 6692 | HBasicBlock* block = instruction->GetBlock(); |
| 6693 | if (block->GetLoopInformation() != nullptr) { |
| 6694 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6695 | // The back edge will generate the suspend check. |
| 6696 | return; |
| 6697 | } |
| 6698 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6699 | // The goto will generate the suspend check. |
| 6700 | return; |
| 6701 | } |
| 6702 | GenerateSuspendCheck(instruction, nullptr); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 6703 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 12); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6704 | } |
| 6705 | |
| 6706 | void InstructionCodeGeneratorARMVIXL::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 6707 | HBasicBlock* successor) { |
| 6708 | SuspendCheckSlowPathARMVIXL* slow_path = |
| 6709 | down_cast<SuspendCheckSlowPathARMVIXL*>(instruction->GetSlowPath()); |
| 6710 | if (slow_path == nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6711 | slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6712 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathARMVIXL(instruction, successor); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6713 | instruction->SetSlowPath(slow_path); |
| 6714 | codegen_->AddSlowPath(slow_path); |
| 6715 | if (successor != nullptr) { |
| 6716 | DCHECK(successor->IsLoopHeader()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6717 | } |
| 6718 | } else { |
| 6719 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 6720 | } |
| 6721 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6722 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6723 | vixl32::Register temp = temps.Acquire(); |
| 6724 | GetAssembler()->LoadFromOffset( |
| 6725 | kLoadUnsignedHalfword, temp, tr, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
| 6726 | if (successor == nullptr) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6727 | __ CompareAndBranchIfNonZero(temp, slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6728 | __ Bind(slow_path->GetReturnLabel()); |
| 6729 | } else { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6730 | __ CompareAndBranchIfZero(temp, codegen_->GetLabelOf(successor)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6731 | __ B(slow_path->GetEntryLabel()); |
| 6732 | } |
| 6733 | } |
| 6734 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6735 | ArmVIXLAssembler* ParallelMoveResolverARMVIXL::GetAssembler() const { |
| 6736 | return codegen_->GetAssembler(); |
| 6737 | } |
| 6738 | |
| 6739 | void ParallelMoveResolverARMVIXL::EmitMove(size_t index) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6740 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6741 | MoveOperands* move = moves_[index]; |
| 6742 | Location source = move->GetSource(); |
| 6743 | Location destination = move->GetDestination(); |
| 6744 | |
| 6745 | if (source.IsRegister()) { |
| 6746 | if (destination.IsRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6747 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6748 | } else if (destination.IsFpuRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6749 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6750 | } else { |
| 6751 | DCHECK(destination.IsStackSlot()); |
| 6752 | GetAssembler()->StoreToOffset(kStoreWord, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6753 | RegisterFrom(source), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6754 | sp, |
| 6755 | destination.GetStackIndex()); |
| 6756 | } |
| 6757 | } else if (source.IsStackSlot()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6758 | if (destination.IsRegister()) { |
| 6759 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 6760 | RegisterFrom(destination), |
| 6761 | sp, |
| 6762 | source.GetStackIndex()); |
| 6763 | } else if (destination.IsFpuRegister()) { |
| 6764 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 6765 | } else { |
| 6766 | DCHECK(destination.IsStackSlot()); |
| 6767 | vixl32::Register temp = temps.Acquire(); |
| 6768 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 6769 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6770 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6771 | } else if (source.IsFpuRegister()) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6772 | if (destination.IsRegister()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6773 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6774 | } else if (destination.IsFpuRegister()) { |
| 6775 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 6776 | } else { |
| 6777 | DCHECK(destination.IsStackSlot()); |
| 6778 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 6779 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6780 | } else if (source.IsDoubleStackSlot()) { |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6781 | if (destination.IsDoubleStackSlot()) { |
| 6782 | vixl32::DRegister temp = temps.AcquireD(); |
| 6783 | GetAssembler()->LoadDFromOffset(temp, sp, source.GetStackIndex()); |
| 6784 | GetAssembler()->StoreDToOffset(temp, sp, destination.GetStackIndex()); |
| 6785 | } else if (destination.IsRegisterPair()) { |
| 6786 | DCHECK(ExpectedPairLayout(destination)); |
| 6787 | GetAssembler()->LoadFromOffset( |
| 6788 | kLoadWordPair, LowRegisterFrom(destination), sp, source.GetStackIndex()); |
| 6789 | } else { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6790 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 6791 | GetAssembler()->LoadDFromOffset(DRegisterFrom(destination), sp, source.GetStackIndex()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6792 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6793 | } else if (source.IsRegisterPair()) { |
| 6794 | if (destination.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6795 | __ Mov(LowRegisterFrom(destination), LowRegisterFrom(source)); |
| 6796 | __ Mov(HighRegisterFrom(destination), HighRegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6797 | } else if (destination.IsFpuRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6798 | __ Vmov(DRegisterFrom(destination), LowRegisterFrom(source), HighRegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6799 | } else { |
| 6800 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6801 | DCHECK(ExpectedPairLayout(source)); |
| 6802 | GetAssembler()->StoreToOffset(kStoreWordPair, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6803 | LowRegisterFrom(source), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6804 | sp, |
| 6805 | destination.GetStackIndex()); |
| 6806 | } |
| 6807 | } else if (source.IsFpuRegisterPair()) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6808 | if (destination.IsRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6809 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), DRegisterFrom(source)); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6810 | } else if (destination.IsFpuRegisterPair()) { |
| 6811 | __ Vmov(DRegisterFrom(destination), DRegisterFrom(source)); |
| 6812 | } else { |
| 6813 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6814 | GetAssembler()->StoreDToOffset(DRegisterFrom(source), sp, destination.GetStackIndex()); |
| 6815 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6816 | } else { |
| 6817 | DCHECK(source.IsConstant()) << source; |
| 6818 | HConstant* constant = source.GetConstant(); |
| 6819 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 6820 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
| 6821 | if (destination.IsRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6822 | __ Mov(RegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6823 | } else { |
| 6824 | DCHECK(destination.IsStackSlot()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6825 | vixl32::Register temp = temps.Acquire(); |
| 6826 | __ Mov(temp, value); |
| 6827 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6828 | } |
| 6829 | } else if (constant->IsLongConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6830 | int64_t value = Int64ConstantFrom(source); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6831 | if (destination.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6832 | __ Mov(LowRegisterFrom(destination), Low32Bits(value)); |
| 6833 | __ Mov(HighRegisterFrom(destination), High32Bits(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6834 | } else { |
| 6835 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6836 | vixl32::Register temp = temps.Acquire(); |
| 6837 | __ Mov(temp, Low32Bits(value)); |
| 6838 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6839 | __ Mov(temp, High32Bits(value)); |
| 6840 | GetAssembler()->StoreToOffset(kStoreWord, |
| 6841 | temp, |
| 6842 | sp, |
| 6843 | destination.GetHighStackIndex(kArmWordSize)); |
| 6844 | } |
| 6845 | } else if (constant->IsDoubleConstant()) { |
| 6846 | double value = constant->AsDoubleConstant()->GetValue(); |
| 6847 | if (destination.IsFpuRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6848 | __ Vmov(DRegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6849 | } else { |
| 6850 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6851 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6852 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6853 | __ Mov(temp, Low32Bits(int_value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6854 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6855 | __ Mov(temp, High32Bits(int_value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6856 | GetAssembler()->StoreToOffset(kStoreWord, |
| 6857 | temp, |
| 6858 | sp, |
| 6859 | destination.GetHighStackIndex(kArmWordSize)); |
| 6860 | } |
| 6861 | } else { |
| 6862 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
| 6863 | float value = constant->AsFloatConstant()->GetValue(); |
| 6864 | if (destination.IsFpuRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6865 | __ Vmov(SRegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6866 | } else { |
| 6867 | DCHECK(destination.IsStackSlot()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6868 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6869 | __ Mov(temp, bit_cast<int32_t, float>(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6870 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6871 | } |
| 6872 | } |
| 6873 | } |
| 6874 | } |
| 6875 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6876 | void ParallelMoveResolverARMVIXL::Exchange(vixl32::Register reg, int mem) { |
| 6877 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 6878 | vixl32::Register temp = temps.Acquire(); |
| 6879 | __ Mov(temp, reg); |
| 6880 | GetAssembler()->LoadFromOffset(kLoadWord, reg, sp, mem); |
| 6881 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6882 | } |
| 6883 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6884 | void ParallelMoveResolverARMVIXL::Exchange(int mem1, int mem2) { |
| 6885 | // TODO(VIXL32): Double check the performance of this implementation. |
| 6886 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6887 | vixl32::Register temp1 = temps.Acquire(); |
| 6888 | ScratchRegisterScope ensure_scratch( |
| 6889 | this, temp1.GetCode(), r0.GetCode(), codegen_->GetNumberOfCoreRegisters()); |
| 6890 | vixl32::Register temp2(ensure_scratch.GetRegister()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6891 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6892 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 6893 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, sp, mem1 + stack_offset); |
| 6894 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, sp, mem2 + stack_offset); |
| 6895 | GetAssembler()->StoreToOffset(kStoreWord, temp1, sp, mem2 + stack_offset); |
| 6896 | GetAssembler()->StoreToOffset(kStoreWord, temp2, sp, mem1 + stack_offset); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6897 | } |
| 6898 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6899 | void ParallelMoveResolverARMVIXL::EmitSwap(size_t index) { |
| 6900 | MoveOperands* move = moves_[index]; |
| 6901 | Location source = move->GetSource(); |
| 6902 | Location destination = move->GetDestination(); |
| 6903 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 6904 | |
| 6905 | if (source.IsRegister() && destination.IsRegister()) { |
| 6906 | vixl32::Register temp = temps.Acquire(); |
| 6907 | DCHECK(!RegisterFrom(source).Is(temp)); |
| 6908 | DCHECK(!RegisterFrom(destination).Is(temp)); |
| 6909 | __ Mov(temp, RegisterFrom(destination)); |
| 6910 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 6911 | __ Mov(RegisterFrom(source), temp); |
| 6912 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| 6913 | Exchange(RegisterFrom(source), destination.GetStackIndex()); |
| 6914 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| 6915 | Exchange(RegisterFrom(destination), source.GetStackIndex()); |
| 6916 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 6917 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6918 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6919 | vixl32::Register temp = temps.Acquire(); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 6920 | __ Vmov(temp, SRegisterFrom(source)); |
| 6921 | __ Vmov(SRegisterFrom(source), SRegisterFrom(destination)); |
| 6922 | __ Vmov(SRegisterFrom(destination), temp); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6923 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
| 6924 | vixl32::DRegister temp = temps.AcquireD(); |
| 6925 | __ Vmov(temp, LowRegisterFrom(source), HighRegisterFrom(source)); |
| 6926 | __ Mov(LowRegisterFrom(source), LowRegisterFrom(destination)); |
| 6927 | __ Mov(HighRegisterFrom(source), HighRegisterFrom(destination)); |
| 6928 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), temp); |
| 6929 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
| 6930 | vixl32::Register low_reg = LowRegisterFrom(source.IsRegisterPair() ? source : destination); |
| 6931 | int mem = source.IsRegisterPair() ? destination.GetStackIndex() : source.GetStackIndex(); |
| 6932 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
| 6933 | vixl32::DRegister temp = temps.AcquireD(); |
| 6934 | __ Vmov(temp, low_reg, vixl32::Register(low_reg.GetCode() + 1)); |
| 6935 | GetAssembler()->LoadFromOffset(kLoadWordPair, low_reg, sp, mem); |
| 6936 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
| 6937 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6938 | vixl32::DRegister first = DRegisterFrom(source); |
| 6939 | vixl32::DRegister second = DRegisterFrom(destination); |
| 6940 | vixl32::DRegister temp = temps.AcquireD(); |
| 6941 | __ Vmov(temp, first); |
| 6942 | __ Vmov(first, second); |
| 6943 | __ Vmov(second, temp); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6944 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 6945 | vixl32::DRegister reg = source.IsFpuRegisterPair() |
| 6946 | ? DRegisterFrom(source) |
| 6947 | : DRegisterFrom(destination); |
| 6948 | int mem = source.IsFpuRegisterPair() |
| 6949 | ? destination.GetStackIndex() |
| 6950 | : source.GetStackIndex(); |
| 6951 | vixl32::DRegister temp = temps.AcquireD(); |
| 6952 | __ Vmov(temp, reg); |
| 6953 | GetAssembler()->LoadDFromOffset(reg, sp, mem); |
| 6954 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6955 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 6956 | vixl32::SRegister reg = source.IsFpuRegister() |
| 6957 | ? SRegisterFrom(source) |
| 6958 | : SRegisterFrom(destination); |
| 6959 | int mem = source.IsFpuRegister() |
| 6960 | ? destination.GetStackIndex() |
| 6961 | : source.GetStackIndex(); |
| 6962 | vixl32::Register temp = temps.Acquire(); |
| 6963 | __ Vmov(temp, reg); |
| 6964 | GetAssembler()->LoadSFromOffset(reg, sp, mem); |
| 6965 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6966 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 6967 | vixl32::DRegister temp1 = temps.AcquireD(); |
| 6968 | vixl32::DRegister temp2 = temps.AcquireD(); |
| 6969 | __ Vldr(temp1, MemOperand(sp, source.GetStackIndex())); |
| 6970 | __ Vldr(temp2, MemOperand(sp, destination.GetStackIndex())); |
| 6971 | __ Vstr(temp1, MemOperand(sp, destination.GetStackIndex())); |
| 6972 | __ Vstr(temp2, MemOperand(sp, source.GetStackIndex())); |
| 6973 | } else { |
| 6974 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
| 6975 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6976 | } |
| 6977 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6978 | void ParallelMoveResolverARMVIXL::SpillScratch(int reg) { |
| 6979 | __ Push(vixl32::Register(reg)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6980 | } |
| 6981 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6982 | void ParallelMoveResolverARMVIXL::RestoreScratch(int reg) { |
| 6983 | __ Pop(vixl32::Register(reg)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6984 | } |
| 6985 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6986 | HLoadClass::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadClassKind( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6987 | HLoadClass::LoadKind desired_class_load_kind) { |
| 6988 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6989 | case HLoadClass::LoadKind::kInvalid: |
| 6990 | LOG(FATAL) << "UNREACHABLE"; |
| 6991 | UNREACHABLE(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6992 | case HLoadClass::LoadKind::kReferrersClass: |
| 6993 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6994 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6995 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6996 | case HLoadClass::LoadKind::kBssEntry: |
| 6997 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 6998 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6999 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7000 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7001 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 7002 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7003 | case HLoadClass::LoadKind::kRuntimeCall: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7004 | break; |
| 7005 | } |
| 7006 | return desired_class_load_kind; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7007 | } |
| 7008 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7009 | void LocationsBuilderARMVIXL::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7010 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7011 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7012 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7013 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7014 | cls, |
| 7015 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7016 | LocationFrom(r0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7017 | DCHECK(calling_convention.GetRegisterAt(0).Is(r0)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7018 | return; |
| 7019 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7020 | DCHECK(!cls->NeedsAccessCheck()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7021 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7022 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 7023 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7024 | ? LocationSummary::kCallOnSlowPath |
| 7025 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7026 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7027 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7028 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7029 | } |
| 7030 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7031 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7032 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7033 | } |
| 7034 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7035 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 7036 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 7037 | // Rely on the type resolution or initialization and marking to save everything we need. |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7038 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 7039 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7040 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7041 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 7042 | // that the the kPrimNot result register is the same as the first argument register. |
| 7043 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 7044 | } else { |
| 7045 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7046 | } |
| 7047 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 7048 | if (kUseBakerReadBarrier && kBakerReadBarrierLinkTimeThunksEnableForGcRoots) { |
| 7049 | if (load_kind == HLoadClass::LoadKind::kBssEntry || |
| 7050 | (load_kind == HLoadClass::LoadKind::kReferrersClass && |
| 7051 | !Runtime::Current()->UseJitCompilation())) { |
| 7052 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 7053 | } |
| 7054 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7055 | } |
| 7056 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7057 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7058 | // move. |
| 7059 | void InstructionCodeGeneratorARMVIXL::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7060 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7061 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7062 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 7063 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 13); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7064 | return; |
| 7065 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7066 | DCHECK(!cls->NeedsAccessCheck()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7067 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7068 | LocationSummary* locations = cls->GetLocations(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7069 | Location out_loc = locations->Out(); |
| 7070 | vixl32::Register out = OutputRegister(cls); |
| 7071 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7072 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 7073 | ? kWithoutReadBarrier |
| 7074 | : kCompilerReadBarrierOption; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7075 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7076 | switch (load_kind) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7077 | case HLoadClass::LoadKind::kReferrersClass: { |
| 7078 | DCHECK(!cls->CanCallRuntime()); |
| 7079 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 7080 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 7081 | vixl32::Register current_method = InputRegisterAt(cls, 0); |
| 7082 | GenerateGcRootFieldLoad(cls, |
| 7083 | out_loc, |
| 7084 | current_method, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 7085 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7086 | read_barrier_option); |
| 7087 | break; |
| 7088 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7089 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7090 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7091 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 7092 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 7093 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 7094 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 7095 | break; |
| 7096 | } |
| 7097 | case HLoadClass::LoadKind::kBootImageAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7098 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7099 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 7100 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 7101 | DCHECK_NE(address, 0u); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7102 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7103 | break; |
| 7104 | } |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7105 | case HLoadClass::LoadKind::kBootImageClassTable: { |
| 7106 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7107 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 7108 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 7109 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 7110 | __ Ldr(out, MemOperand(out, /* offset */ 0)); |
| 7111 | // Extract the reference from the slot data, i.e. clear the hash bits. |
| 7112 | int32_t masked_hash = ClassTable::TableSlot::MaskHash( |
| 7113 | ComputeModifiedUtf8Hash(cls->GetDexFile().StringByTypeIdx(cls->GetTypeIndex()))); |
| 7114 | if (masked_hash != 0) { |
| 7115 | __ Sub(out, out, Operand(masked_hash)); |
| 7116 | } |
| 7117 | break; |
| 7118 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7119 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7120 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7121 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 7122 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 7123 | GenerateGcRootFieldLoad(cls, out_loc, out, /* offset */ 0, read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7124 | generate_null_check = true; |
| 7125 | break; |
| 7126 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7127 | case HLoadClass::LoadKind::kJitTableAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7128 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 7129 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7130 | cls->GetClass())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7131 | // /* GcRoot<mirror::Class> */ out = *out |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7132 | GenerateGcRootFieldLoad(cls, out_loc, out, /* offset */ 0, read_barrier_option); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7133 | break; |
| 7134 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7135 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7136 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7137 | LOG(FATAL) << "UNREACHABLE"; |
| 7138 | UNREACHABLE(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7139 | } |
| 7140 | |
| 7141 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 7142 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7143 | LoadClassSlowPathARMVIXL* slow_path = |
| 7144 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARMVIXL( |
| 7145 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7146 | codegen_->AddSlowPath(slow_path); |
| 7147 | if (generate_null_check) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7148 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7149 | } |
| 7150 | if (cls->MustGenerateClinitCheck()) { |
| 7151 | GenerateClassInitializationCheck(slow_path, out); |
| 7152 | } else { |
| 7153 | __ Bind(slow_path->GetExitLabel()); |
| 7154 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 7155 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 14); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7156 | } |
| 7157 | } |
| 7158 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7159 | void LocationsBuilderARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 7160 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7161 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7162 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7163 | if (check->HasUses()) { |
| 7164 | locations->SetOut(Location::SameAsFirstInput()); |
| 7165 | } |
| 7166 | } |
| 7167 | |
| 7168 | void InstructionCodeGeneratorARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 7169 | // We assume the class is not null. |
| 7170 | LoadClassSlowPathARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7171 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARMVIXL(check->GetLoadClass(), |
| 7172 | check, |
| 7173 | check->GetDexPc(), |
| 7174 | /* do_clinit */ true); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7175 | codegen_->AddSlowPath(slow_path); |
| 7176 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 7177 | } |
| 7178 | |
| 7179 | void InstructionCodeGeneratorARMVIXL::GenerateClassInitializationCheck( |
| 7180 | LoadClassSlowPathARMVIXL* slow_path, vixl32::Register class_reg) { |
| 7181 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 7182 | vixl32::Register temp = temps.Acquire(); |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 7183 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 7184 | const size_t status_byte_offset = |
| 7185 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 7186 | constexpr uint32_t shifted_initialized_value = |
| 7187 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
| 7188 | |
| 7189 | GetAssembler()->LoadFromOffset(kLoadUnsignedByte, temp, class_reg, status_byte_offset); |
| 7190 | __ Cmp(temp, shifted_initialized_value); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 7191 | __ B(lo, slow_path->GetEntryLabel()); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7192 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 7193 | // properly. Therefore, we do a memory fence. |
| 7194 | __ Dmb(ISH); |
| 7195 | __ Bind(slow_path->GetExitLabel()); |
| 7196 | } |
| 7197 | |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 7198 | void InstructionCodeGeneratorARMVIXL::GenerateBitstringTypeCheckCompare( |
| 7199 | HTypeCheckInstruction* check, |
| 7200 | vixl32::Register temp, |
| 7201 | vixl32::FlagsUpdate flags_update) { |
| 7202 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 7203 | uint32_t mask = check->GetBitstringMask(); |
| 7204 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 7205 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 7206 | |
| 7207 | // Note that HInstanceOf shall check for zero value in `temp` but HCheckCast needs |
| 7208 | // the Z flag for BNE. This is indicated by the `flags_update` parameter. |
| 7209 | if (mask_bits == 16u) { |
| 7210 | // Load only the bitstring part of the status word. |
| 7211 | __ Ldrh(temp, MemOperand(temp, mirror::Class::StatusOffset().Int32Value())); |
| 7212 | // Check if the bitstring bits are equal to `path_to_root`. |
| 7213 | if (flags_update == SetFlags) { |
| 7214 | __ Cmp(temp, path_to_root); |
| 7215 | } else { |
| 7216 | __ Sub(temp, temp, path_to_root); |
| 7217 | } |
| 7218 | } else { |
| 7219 | // /* uint32_t */ temp = temp->status_ |
| 7220 | __ Ldr(temp, MemOperand(temp, mirror::Class::StatusOffset().Int32Value())); |
| 7221 | if (GetAssembler()->ShifterOperandCanHold(SUB, path_to_root)) { |
| 7222 | // Compare the bitstring bits using SUB. |
| 7223 | __ Sub(temp, temp, path_to_root); |
| 7224 | // Shift out bits that do not contribute to the comparison. |
| 7225 | __ Lsl(flags_update, temp, temp, dchecked_integral_cast<uint32_t>(32u - mask_bits)); |
| 7226 | } else if (IsUint<16>(path_to_root)) { |
| 7227 | if (temp.IsLow()) { |
| 7228 | // Note: Optimized for size but contains one more dependent instruction than necessary. |
| 7229 | // MOVW+SUB(register) would be 8 bytes unless we find a low-reg temporary but the |
| 7230 | // macro assembler would use the high reg IP for the constant by default. |
| 7231 | // Compare the bitstring bits using SUB. |
| 7232 | __ Sub(temp, temp, path_to_root & 0x00ffu); // 16-bit SUB (immediate) T2 |
| 7233 | __ Sub(temp, temp, path_to_root & 0xff00u); // 32-bit SUB (immediate) T3 |
| 7234 | // Shift out bits that do not contribute to the comparison. |
| 7235 | __ Lsl(flags_update, temp, temp, dchecked_integral_cast<uint32_t>(32u - mask_bits)); |
| 7236 | } else { |
| 7237 | // Extract the bitstring bits. |
| 7238 | __ Ubfx(temp, temp, 0, mask_bits); |
| 7239 | // Check if the bitstring bits are equal to `path_to_root`. |
| 7240 | if (flags_update == SetFlags) { |
| 7241 | __ Cmp(temp, path_to_root); |
| 7242 | } else { |
| 7243 | __ Sub(temp, temp, path_to_root); |
| 7244 | } |
| 7245 | } |
| 7246 | } else { |
| 7247 | // Shift out bits that do not contribute to the comparison. |
| 7248 | __ Lsl(temp, temp, dchecked_integral_cast<uint32_t>(32u - mask_bits)); |
| 7249 | // Check if the shifted bitstring bits are equal to `path_to_root << (32u - mask_bits)`. |
| 7250 | if (flags_update == SetFlags) { |
| 7251 | __ Cmp(temp, path_to_root << (32u - mask_bits)); |
| 7252 | } else { |
| 7253 | __ Sub(temp, temp, path_to_root << (32u - mask_bits)); |
| 7254 | } |
| 7255 | } |
| 7256 | } |
| 7257 | } |
| 7258 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7259 | HLoadString::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadStringKind( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7260 | HLoadString::LoadKind desired_string_load_kind) { |
| 7261 | switch (desired_string_load_kind) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7262 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7263 | case HLoadString::LoadKind::kBootImageInternTable: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7264 | case HLoadString::LoadKind::kBssEntry: |
| 7265 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 7266 | break; |
| 7267 | case HLoadString::LoadKind::kJitTableAddress: |
| 7268 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7269 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 7270 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7271 | case HLoadString::LoadKind::kRuntimeCall: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7272 | break; |
| 7273 | } |
| 7274 | return desired_string_load_kind; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7275 | } |
| 7276 | |
| 7277 | void LocationsBuilderARMVIXL::VisitLoadString(HLoadString* load) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7278 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7279 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7280 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7281 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7282 | locations->SetOut(LocationFrom(r0)); |
| 7283 | } else { |
| 7284 | locations->SetOut(Location::RequiresRegister()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7285 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 7286 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7287 | // Rely on the pResolveString and marking to save everything we need, including temps. |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7288 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 7289 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7290 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7291 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 7292 | // that the the kPrimNot result register is the same as the first argument register. |
| 7293 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 7294 | if (kUseBakerReadBarrier && kBakerReadBarrierLinkTimeThunksEnableForGcRoots) { |
| 7295 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 7296 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7297 | } else { |
| 7298 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7299 | } |
| 7300 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7301 | } |
| 7302 | } |
| 7303 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7304 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7305 | // move. |
| 7306 | void InstructionCodeGeneratorARMVIXL::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7307 | LocationSummary* locations = load->GetLocations(); |
| 7308 | Location out_loc = locations->Out(); |
| 7309 | vixl32::Register out = OutputRegister(load); |
| 7310 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 7311 | |
| 7312 | switch (load_kind) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7313 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 7314 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| 7315 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7316 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7317 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7318 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7319 | } |
| 7320 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7321 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 7322 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 7323 | DCHECK_NE(address, 0u); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7324 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7325 | return; |
| 7326 | } |
| 7327 | case HLoadString::LoadKind::kBootImageInternTable: { |
| 7328 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7329 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 7330 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
| 7331 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 7332 | __ Ldr(out, MemOperand(out, /* offset */ 0)); |
| 7333 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7334 | } |
| 7335 | case HLoadString::LoadKind::kBssEntry: { |
| 7336 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7337 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7338 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 7339 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 7340 | GenerateGcRootFieldLoad(load, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7341 | LoadStringSlowPathARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7342 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathARMVIXL(load); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7343 | codegen_->AddSlowPath(slow_path); |
| 7344 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 7345 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 7346 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 15); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7347 | return; |
| 7348 | } |
| 7349 | case HLoadString::LoadKind::kJitTableAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7350 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7351 | load->GetStringIndex(), |
| 7352 | load->GetString())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7353 | // /* GcRoot<mirror::String> */ out = *out |
| 7354 | GenerateGcRootFieldLoad(load, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
| 7355 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7356 | } |
| 7357 | default: |
| 7358 | break; |
| 7359 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7360 | |
| 7361 | // 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] | 7362 | DCHECK_EQ(load->GetLoadKind(), HLoadString::LoadKind::kRuntimeCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7363 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7364 | __ Mov(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7365 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 7366 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 7367 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 16); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7368 | } |
| 7369 | |
| 7370 | static int32_t GetExceptionTlsOffset() { |
| 7371 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
| 7372 | } |
| 7373 | |
| 7374 | void LocationsBuilderARMVIXL::VisitLoadException(HLoadException* load) { |
| 7375 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7376 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7377 | locations->SetOut(Location::RequiresRegister()); |
| 7378 | } |
| 7379 | |
| 7380 | void InstructionCodeGeneratorARMVIXL::VisitLoadException(HLoadException* load) { |
| 7381 | vixl32::Register out = OutputRegister(load); |
| 7382 | GetAssembler()->LoadFromOffset(kLoadWord, out, tr, GetExceptionTlsOffset()); |
| 7383 | } |
| 7384 | |
| 7385 | |
| 7386 | void LocationsBuilderARMVIXL::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7387 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7388 | } |
| 7389 | |
| 7390 | void InstructionCodeGeneratorARMVIXL::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 7391 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 7392 | vixl32::Register temp = temps.Acquire(); |
| 7393 | __ Mov(temp, 0); |
| 7394 | GetAssembler()->StoreToOffset(kStoreWord, temp, tr, GetExceptionTlsOffset()); |
| 7395 | } |
| 7396 | |
| 7397 | void LocationsBuilderARMVIXL::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7398 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7399 | instruction, LocationSummary::kCallOnMainOnly); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7400 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7401 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7402 | } |
| 7403 | |
| 7404 | void InstructionCodeGeneratorARMVIXL::VisitThrow(HThrow* instruction) { |
| 7405 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| 7406 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 7407 | } |
| 7408 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7409 | // Temp is used for read barrier. |
| 7410 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 7411 | if (kEmitCompilerReadBarrier && |
| 7412 | (kUseBakerReadBarrier || |
| 7413 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7414 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7415 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 7416 | return 1; |
| 7417 | } |
| 7418 | return 0; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7419 | } |
| 7420 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7421 | // Interface case has 3 temps, one for holding the number of interfaces, one for the current |
| 7422 | // interface pointer, one for loading the current interface. |
| 7423 | // The other checks have one temp for loading the object's class. |
| 7424 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 7425 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7426 | return 3; |
| 7427 | } |
| 7428 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 7429 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7430 | |
| 7431 | void LocationsBuilderARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 7432 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7433 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7434 | bool baker_read_barrier_slow_path = false; |
| 7435 | switch (type_check_kind) { |
| 7436 | case TypeCheckKind::kExactCheck: |
| 7437 | case TypeCheckKind::kAbstractClassCheck: |
| 7438 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7439 | case TypeCheckKind::kArrayObjectCheck: { |
| 7440 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 7441 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 7442 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7443 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7444 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7445 | case TypeCheckKind::kArrayCheck: |
| 7446 | case TypeCheckKind::kUnresolvedCheck: |
| 7447 | case TypeCheckKind::kInterfaceCheck: |
| 7448 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7449 | break; |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 7450 | case TypeCheckKind::kBitstringCheck: |
| 7451 | break; |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7452 | } |
| 7453 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7454 | LocationSummary* locations = |
| 7455 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7456 | if (baker_read_barrier_slow_path) { |
| 7457 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 7458 | } |
| 7459 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 7460 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7461 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7462 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7463 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 7464 | } else { |
| 7465 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7466 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7467 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 7468 | // Note that TypeCheckSlowPathARM uses this register too. |
| 7469 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7470 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 7471 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 7472 | codegen_->MaybeAddBakerCcEntrypointTempForFields(locations); |
| 7473 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7474 | } |
| 7475 | |
| 7476 | void InstructionCodeGeneratorARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 7477 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7478 | LocationSummary* locations = instruction->GetLocations(); |
| 7479 | Location obj_loc = locations->InAt(0); |
| 7480 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 7481 | vixl32::Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 7482 | ? vixl32::Register() |
| 7483 | : InputRegisterAt(instruction, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7484 | Location out_loc = locations->Out(); |
| 7485 | vixl32::Register out = OutputRegister(instruction); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7486 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7487 | DCHECK_LE(num_temps, 1u); |
| 7488 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7489 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7490 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7491 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7492 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7493 | vixl32::Label done; |
| 7494 | vixl32::Label* const final_label = codegen_->GetFinalLabel(instruction, &done); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7495 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 7496 | |
| 7497 | // Return 0 if `obj` is null. |
| 7498 | // avoid null check if we know obj is not null. |
| 7499 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7500 | DCHECK(!out.Is(obj)); |
| 7501 | __ Mov(out, 0); |
| 7502 | __ CompareAndBranchIfZero(obj, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7503 | } |
| 7504 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7505 | switch (type_check_kind) { |
| 7506 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7507 | ReadBarrierOption read_barrier_option = |
| 7508 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7509 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7510 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7511 | out_loc, |
| 7512 | obj_loc, |
| 7513 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7514 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7515 | read_barrier_option); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7516 | // Classes must be equal for the instanceof to succeed. |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7517 | __ Cmp(out, cls); |
| 7518 | // We speculatively set the result to false without changing the condition |
| 7519 | // flags, which allows us to avoid some branching later. |
| 7520 | __ Mov(LeaveFlags, out, 0); |
| 7521 | |
| 7522 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7523 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7524 | // encoding can be used. |
| 7525 | if (out.IsLow()) { |
| 7526 | // We use the scope because of the IT block that follows. |
| 7527 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7528 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7529 | CodeBufferCheckScope::kExactSize); |
| 7530 | |
| 7531 | __ it(eq); |
| 7532 | __ mov(eq, out, 1); |
| 7533 | } else { |
| 7534 | __ B(ne, final_label, /* far_target */ false); |
| 7535 | __ Mov(out, 1); |
| 7536 | } |
| 7537 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7538 | break; |
| 7539 | } |
| 7540 | |
| 7541 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7542 | ReadBarrierOption read_barrier_option = |
| 7543 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7544 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7545 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7546 | out_loc, |
| 7547 | obj_loc, |
| 7548 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7549 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7550 | read_barrier_option); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7551 | // If the class is abstract, we eagerly fetch the super class of the |
| 7552 | // object to avoid doing a comparison we know will fail. |
| 7553 | vixl32::Label loop; |
| 7554 | __ Bind(&loop); |
| 7555 | // /* HeapReference<Class> */ out = out->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7556 | GenerateReferenceLoadOneRegister(instruction, |
| 7557 | out_loc, |
| 7558 | super_offset, |
| 7559 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7560 | read_barrier_option); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7561 | // 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] | 7562 | __ CompareAndBranchIfZero(out, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7563 | __ Cmp(out, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7564 | __ B(ne, &loop, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7565 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7566 | break; |
| 7567 | } |
| 7568 | |
| 7569 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7570 | ReadBarrierOption read_barrier_option = |
| 7571 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7572 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7573 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7574 | out_loc, |
| 7575 | obj_loc, |
| 7576 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7577 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7578 | read_barrier_option); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7579 | // Walk over the class hierarchy to find a match. |
| 7580 | vixl32::Label loop, success; |
| 7581 | __ Bind(&loop); |
| 7582 | __ Cmp(out, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7583 | __ B(eq, &success, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7584 | // /* HeapReference<Class> */ out = out->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7585 | GenerateReferenceLoadOneRegister(instruction, |
| 7586 | out_loc, |
| 7587 | super_offset, |
| 7588 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7589 | read_barrier_option); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7590 | // This is essentially a null check, but it sets the condition flags to the |
| 7591 | // proper value for the code that follows the loop, i.e. not `eq`. |
| 7592 | __ Cmp(out, 1); |
| 7593 | __ B(hs, &loop, /* far_target */ false); |
| 7594 | |
| 7595 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7596 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7597 | // encoding can be used. |
| 7598 | if (out.IsLow()) { |
| 7599 | // If `out` is null, we use it for the result, and the condition flags |
| 7600 | // have already been set to `ne`, so the IT block that comes afterwards |
| 7601 | // (and which handles the successful case) turns into a NOP (instead of |
| 7602 | // overwriting `out`). |
| 7603 | __ Bind(&success); |
| 7604 | |
| 7605 | // We use the scope because of the IT block that follows. |
| 7606 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7607 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7608 | CodeBufferCheckScope::kExactSize); |
| 7609 | |
| 7610 | // There is only one branch to the `success` label (which is bound to this |
| 7611 | // IT block), and it has the same condition, `eq`, so in that case the MOV |
| 7612 | // is executed. |
| 7613 | __ it(eq); |
| 7614 | __ mov(eq, out, 1); |
| 7615 | } else { |
| 7616 | // 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] | 7617 | __ B(final_label); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7618 | __ Bind(&success); |
| 7619 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7620 | } |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7621 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7622 | break; |
| 7623 | } |
| 7624 | |
| 7625 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7626 | ReadBarrierOption read_barrier_option = |
| 7627 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7628 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7629 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7630 | out_loc, |
| 7631 | obj_loc, |
| 7632 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7633 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7634 | read_barrier_option); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7635 | // Do an exact check. |
| 7636 | vixl32::Label exact_check; |
| 7637 | __ Cmp(out, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7638 | __ B(eq, &exact_check, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7639 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 7640 | // /* HeapReference<Class> */ out = out->component_type_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7641 | GenerateReferenceLoadOneRegister(instruction, |
| 7642 | out_loc, |
| 7643 | component_offset, |
| 7644 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7645 | read_barrier_option); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7646 | // 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] | 7647 | __ CompareAndBranchIfZero(out, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7648 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 7649 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7650 | __ Cmp(out, 0); |
| 7651 | // We speculatively set the result to false without changing the condition |
| 7652 | // flags, which allows us to avoid some branching later. |
| 7653 | __ Mov(LeaveFlags, out, 0); |
| 7654 | |
| 7655 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7656 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7657 | // encoding can be used. |
| 7658 | if (out.IsLow()) { |
| 7659 | __ Bind(&exact_check); |
| 7660 | |
| 7661 | // We use the scope because of the IT block that follows. |
| 7662 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7663 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7664 | CodeBufferCheckScope::kExactSize); |
| 7665 | |
| 7666 | __ it(eq); |
| 7667 | __ mov(eq, out, 1); |
| 7668 | } else { |
| 7669 | __ B(ne, final_label, /* far_target */ false); |
| 7670 | __ Bind(&exact_check); |
| 7671 | __ Mov(out, 1); |
| 7672 | } |
| 7673 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7674 | break; |
| 7675 | } |
| 7676 | |
| 7677 | case TypeCheckKind::kArrayCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7678 | // No read barrier since the slow path will retry upon failure. |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7679 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7680 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7681 | out_loc, |
| 7682 | obj_loc, |
| 7683 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7684 | maybe_temp_loc, |
| 7685 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7686 | __ Cmp(out, cls); |
| 7687 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7688 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
| 7689 | instruction, /* is_fatal */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7690 | codegen_->AddSlowPath(slow_path); |
| 7691 | __ B(ne, slow_path->GetEntryLabel()); |
| 7692 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7693 | break; |
| 7694 | } |
| 7695 | |
| 7696 | case TypeCheckKind::kUnresolvedCheck: |
| 7697 | case TypeCheckKind::kInterfaceCheck: { |
| 7698 | // Note that we indeed only call on slow path, but we always go |
| 7699 | // into the slow path for the unresolved and interface check |
| 7700 | // cases. |
| 7701 | // |
| 7702 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7703 | // entry point without resorting to a type checking slow path |
| 7704 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7705 | // require to assign fixed registers for the inputs of this |
| 7706 | // HInstanceOf instruction (following the runtime calling |
| 7707 | // convention), which might be cluttered by the potential first |
| 7708 | // read barrier emission at the beginning of this method. |
| 7709 | // |
| 7710 | // TODO: Introduce a new runtime entry point taking the object |
| 7711 | // to test (instead of its class) as argument, and let it deal |
| 7712 | // with the read barrier issues. This will let us refactor this |
| 7713 | // case of the `switch` code as it was previously (with a direct |
| 7714 | // call to the runtime not using a type checking slow path). |
| 7715 | // This should also be beneficial for the other cases above. |
| 7716 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7717 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
| 7718 | instruction, /* is_fatal */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7719 | codegen_->AddSlowPath(slow_path); |
| 7720 | __ B(slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7721 | break; |
| 7722 | } |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 7723 | |
| 7724 | case TypeCheckKind::kBitstringCheck: { |
| 7725 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7726 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7727 | out_loc, |
| 7728 | obj_loc, |
| 7729 | class_offset, |
| 7730 | maybe_temp_loc, |
| 7731 | kWithoutReadBarrier); |
| 7732 | |
| 7733 | GenerateBitstringTypeCheckCompare(instruction, out, DontCare); |
| 7734 | // If `out` is a low reg and we would have another low reg temp, we could |
| 7735 | // optimize this as RSBS+ADC, see GenerateConditionWithZero(). |
| 7736 | // |
| 7737 | // Also, in some cases when `out` is a low reg and we're loading a constant to IP |
| 7738 | // it would make sense to use CMP+MOV+IT+MOV instead of SUB+CLZ+LSR as the code size |
| 7739 | // would be the same and we would have fewer direct data dependencies. |
| 7740 | codegen_->GenerateConditionWithZero(kCondEQ, out, out); // CLZ+LSR |
| 7741 | break; |
| 7742 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7743 | } |
| 7744 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7745 | if (done.IsReferenced()) { |
| 7746 | __ Bind(&done); |
| 7747 | } |
| 7748 | |
| 7749 | if (slow_path != nullptr) { |
| 7750 | __ Bind(slow_path->GetExitLabel()); |
| 7751 | } |
| 7752 | } |
| 7753 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7754 | void LocationsBuilderARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7755 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7756 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7757 | LocationSummary* locations = |
| 7758 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7759 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 7760 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7761 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7762 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7763 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 7764 | } else { |
| 7765 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7766 | } |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7767 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7768 | } |
| 7769 | |
| 7770 | void InstructionCodeGeneratorARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
| 7771 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7772 | LocationSummary* locations = instruction->GetLocations(); |
| 7773 | Location obj_loc = locations->InAt(0); |
| 7774 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 7775 | vixl32::Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 7776 | ? vixl32::Register() |
| 7777 | : InputRegisterAt(instruction, 1); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7778 | Location temp_loc = locations->GetTemp(0); |
| 7779 | vixl32::Register temp = RegisterFrom(temp_loc); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7780 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 7781 | DCHECK_LE(num_temps, 3u); |
| 7782 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 7783 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 7784 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7785 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7786 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7787 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 7788 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 7789 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 7790 | const uint32_t object_array_data_offset = |
| 7791 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7792 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7793 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7794 | SlowPathCodeARMVIXL* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7795 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
| 7796 | instruction, is_type_check_slow_path_fatal); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7797 | codegen_->AddSlowPath(type_check_slow_path); |
| 7798 | |
| 7799 | vixl32::Label done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7800 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7801 | // Avoid null check if we know obj is not null. |
| 7802 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7803 | __ CompareAndBranchIfZero(obj, final_label, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7804 | } |
| 7805 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7806 | switch (type_check_kind) { |
| 7807 | case TypeCheckKind::kExactCheck: |
| 7808 | case TypeCheckKind::kArrayCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7809 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7810 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7811 | temp_loc, |
| 7812 | obj_loc, |
| 7813 | class_offset, |
| 7814 | maybe_temp2_loc, |
| 7815 | kWithoutReadBarrier); |
| 7816 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7817 | __ Cmp(temp, cls); |
| 7818 | // Jump to slow path for throwing the exception or doing a |
| 7819 | // more involved array check. |
| 7820 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 7821 | break; |
| 7822 | } |
| 7823 | |
| 7824 | case TypeCheckKind::kAbstractClassCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7825 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7826 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7827 | temp_loc, |
| 7828 | obj_loc, |
| 7829 | class_offset, |
| 7830 | maybe_temp2_loc, |
| 7831 | kWithoutReadBarrier); |
| 7832 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7833 | // If the class is abstract, we eagerly fetch the super class of the |
| 7834 | // object to avoid doing a comparison we know will fail. |
| 7835 | vixl32::Label loop; |
| 7836 | __ Bind(&loop); |
| 7837 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7838 | GenerateReferenceLoadOneRegister(instruction, |
| 7839 | temp_loc, |
| 7840 | super_offset, |
| 7841 | maybe_temp2_loc, |
| 7842 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7843 | |
| 7844 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7845 | // exception. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7846 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7847 | |
| 7848 | // Otherwise, compare the classes. |
| 7849 | __ Cmp(temp, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7850 | __ B(ne, &loop, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7851 | break; |
| 7852 | } |
| 7853 | |
| 7854 | case TypeCheckKind::kClassHierarchyCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7855 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7856 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7857 | temp_loc, |
| 7858 | obj_loc, |
| 7859 | class_offset, |
| 7860 | maybe_temp2_loc, |
| 7861 | kWithoutReadBarrier); |
| 7862 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7863 | // Walk over the class hierarchy to find a match. |
| 7864 | vixl32::Label loop; |
| 7865 | __ Bind(&loop); |
| 7866 | __ Cmp(temp, cls); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7867 | __ B(eq, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7868 | |
| 7869 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7870 | GenerateReferenceLoadOneRegister(instruction, |
| 7871 | temp_loc, |
| 7872 | super_offset, |
| 7873 | maybe_temp2_loc, |
| 7874 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7875 | |
| 7876 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7877 | // exception. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7878 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7879 | // Otherwise, jump to the beginning of the loop. |
| 7880 | __ B(&loop); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7881 | break; |
| 7882 | } |
| 7883 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7884 | case TypeCheckKind::kArrayObjectCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7885 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7886 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7887 | temp_loc, |
| 7888 | obj_loc, |
| 7889 | class_offset, |
| 7890 | maybe_temp2_loc, |
| 7891 | kWithoutReadBarrier); |
| 7892 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7893 | // Do an exact check. |
| 7894 | __ Cmp(temp, cls); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7895 | __ B(eq, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7896 | |
| 7897 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 7898 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7899 | GenerateReferenceLoadOneRegister(instruction, |
| 7900 | temp_loc, |
| 7901 | component_offset, |
| 7902 | maybe_temp2_loc, |
| 7903 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7904 | // 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] | 7905 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7906 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 7907 | // to further check that this component type is not a primitive type. |
| 7908 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7909 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7910 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7911 | break; |
| 7912 | } |
| 7913 | |
| 7914 | case TypeCheckKind::kUnresolvedCheck: |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7915 | // 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] | 7916 | // We cannot directly call the CheckCast runtime entry point |
| 7917 | // without resorting to a type checking slow path here (i.e. by |
| 7918 | // calling InvokeRuntime directly), as it would require to |
| 7919 | // assign fixed registers for the inputs of this HInstanceOf |
| 7920 | // instruction (following the runtime calling convention), which |
| 7921 | // might be cluttered by the potential first read barrier |
| 7922 | // emission at the beginning of this method. |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7923 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7924 | __ B(type_check_slow_path->GetEntryLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7925 | break; |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7926 | |
| 7927 | case TypeCheckKind::kInterfaceCheck: { |
| 7928 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 7929 | // positives by doing this. |
| 7930 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7931 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7932 | temp_loc, |
| 7933 | obj_loc, |
| 7934 | class_offset, |
| 7935 | maybe_temp2_loc, |
| 7936 | kWithoutReadBarrier); |
| 7937 | |
| 7938 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 7939 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7940 | temp_loc, |
| 7941 | temp_loc, |
| 7942 | iftable_offset, |
| 7943 | maybe_temp2_loc, |
| 7944 | kWithoutReadBarrier); |
| 7945 | // Iftable is never null. |
| 7946 | __ Ldr(RegisterFrom(maybe_temp2_loc), MemOperand(temp, array_length_offset)); |
| 7947 | // Loop through the iftable and check if any class matches. |
| 7948 | vixl32::Label start_loop; |
| 7949 | __ Bind(&start_loop); |
| 7950 | __ CompareAndBranchIfZero(RegisterFrom(maybe_temp2_loc), |
| 7951 | type_check_slow_path->GetEntryLabel()); |
| 7952 | __ Ldr(RegisterFrom(maybe_temp3_loc), MemOperand(temp, object_array_data_offset)); |
| 7953 | GetAssembler()->MaybeUnpoisonHeapReference(RegisterFrom(maybe_temp3_loc)); |
| 7954 | // Go to next interface. |
| 7955 | __ Add(temp, temp, Operand::From(2 * kHeapReferenceSize)); |
| 7956 | __ Sub(RegisterFrom(maybe_temp2_loc), RegisterFrom(maybe_temp2_loc), 2); |
| 7957 | // Compare the classes and continue the loop if they do not match. |
| 7958 | __ Cmp(cls, RegisterFrom(maybe_temp3_loc)); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7959 | __ B(ne, &start_loop, /* far_target */ false); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7960 | break; |
| 7961 | } |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 7962 | |
| 7963 | case TypeCheckKind::kBitstringCheck: { |
| 7964 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7965 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7966 | temp_loc, |
| 7967 | obj_loc, |
| 7968 | class_offset, |
| 7969 | maybe_temp2_loc, |
| 7970 | kWithoutReadBarrier); |
| 7971 | |
| 7972 | GenerateBitstringTypeCheckCompare(instruction, temp, SetFlags); |
| 7973 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 7974 | break; |
| 7975 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7976 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7977 | if (done.IsReferenced()) { |
| 7978 | __ Bind(&done); |
| 7979 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7980 | |
| 7981 | __ Bind(type_check_slow_path->GetExitLabel()); |
| 7982 | } |
| 7983 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 7984 | void LocationsBuilderARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7985 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7986 | instruction, LocationSummary::kCallOnMainOnly); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 7987 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7988 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7989 | } |
| 7990 | |
| 7991 | void InstructionCodeGeneratorARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 7992 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 7993 | instruction, |
| 7994 | instruction->GetDexPc()); |
| 7995 | if (instruction->IsEnter()) { |
| 7996 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 7997 | } else { |
| 7998 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 7999 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8000 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 17); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8001 | } |
| 8002 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8003 | void LocationsBuilderARMVIXL::VisitAnd(HAnd* instruction) { |
| 8004 | HandleBitwiseOperation(instruction, AND); |
| 8005 | } |
| 8006 | |
| 8007 | void LocationsBuilderARMVIXL::VisitOr(HOr* instruction) { |
| 8008 | HandleBitwiseOperation(instruction, ORR); |
| 8009 | } |
| 8010 | |
| 8011 | void LocationsBuilderARMVIXL::VisitXor(HXor* instruction) { |
| 8012 | HandleBitwiseOperation(instruction, EOR); |
| 8013 | } |
| 8014 | |
| 8015 | void LocationsBuilderARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
| 8016 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8017 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8018 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 8019 | || instruction->GetResultType() == DataType::Type::kInt64); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8020 | // Note: GVN reorders commutative operations to have the constant on the right hand side. |
| 8021 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8022 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
| 8023 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8024 | } |
| 8025 | |
| 8026 | void InstructionCodeGeneratorARMVIXL::VisitAnd(HAnd* instruction) { |
| 8027 | HandleBitwiseOperation(instruction); |
| 8028 | } |
| 8029 | |
| 8030 | void InstructionCodeGeneratorARMVIXL::VisitOr(HOr* instruction) { |
| 8031 | HandleBitwiseOperation(instruction); |
| 8032 | } |
| 8033 | |
| 8034 | void InstructionCodeGeneratorARMVIXL::VisitXor(HXor* instruction) { |
| 8035 | HandleBitwiseOperation(instruction); |
| 8036 | } |
| 8037 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8038 | void LocationsBuilderARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 8039 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8040 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8041 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 8042 | || instruction->GetResultType() == DataType::Type::kInt64); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8043 | |
| 8044 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8045 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8046 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8047 | } |
| 8048 | |
| 8049 | void InstructionCodeGeneratorARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 8050 | LocationSummary* locations = instruction->GetLocations(); |
| 8051 | Location first = locations->InAt(0); |
| 8052 | Location second = locations->InAt(1); |
| 8053 | Location out = locations->Out(); |
| 8054 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8055 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8056 | vixl32::Register first_reg = RegisterFrom(first); |
| 8057 | vixl32::Register second_reg = RegisterFrom(second); |
| 8058 | vixl32::Register out_reg = RegisterFrom(out); |
| 8059 | |
| 8060 | switch (instruction->GetOpKind()) { |
| 8061 | case HInstruction::kAnd: |
| 8062 | __ Bic(out_reg, first_reg, second_reg); |
| 8063 | break; |
| 8064 | case HInstruction::kOr: |
| 8065 | __ Orn(out_reg, first_reg, second_reg); |
| 8066 | break; |
| 8067 | // There is no EON on arm. |
| 8068 | case HInstruction::kXor: |
| 8069 | default: |
| 8070 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 8071 | UNREACHABLE(); |
| 8072 | } |
| 8073 | return; |
| 8074 | |
| 8075 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8076 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8077 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8078 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8079 | vixl32::Register second_low = LowRegisterFrom(second); |
| 8080 | vixl32::Register second_high = HighRegisterFrom(second); |
| 8081 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8082 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8083 | |
| 8084 | switch (instruction->GetOpKind()) { |
| 8085 | case HInstruction::kAnd: |
| 8086 | __ Bic(out_low, first_low, second_low); |
| 8087 | __ Bic(out_high, first_high, second_high); |
| 8088 | break; |
| 8089 | case HInstruction::kOr: |
| 8090 | __ Orn(out_low, first_low, second_low); |
| 8091 | __ Orn(out_high, first_high, second_high); |
| 8092 | break; |
| 8093 | // There is no EON on arm. |
| 8094 | case HInstruction::kXor: |
| 8095 | default: |
| 8096 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 8097 | UNREACHABLE(); |
| 8098 | } |
| 8099 | } |
| 8100 | } |
| 8101 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8102 | void LocationsBuilderARMVIXL::VisitDataProcWithShifterOp( |
| 8103 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8104 | DCHECK(instruction->GetType() == DataType::Type::kInt32 || |
| 8105 | instruction->GetType() == DataType::Type::kInt64); |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8106 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8107 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8108 | const bool overlap = instruction->GetType() == DataType::Type::kInt64 && |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8109 | HDataProcWithShifterOp::IsExtensionOp(instruction->GetOpKind()); |
| 8110 | |
| 8111 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8112 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8113 | locations->SetOut(Location::RequiresRegister(), |
| 8114 | overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 8115 | } |
| 8116 | |
| 8117 | void InstructionCodeGeneratorARMVIXL::VisitDataProcWithShifterOp( |
| 8118 | HDataProcWithShifterOp* instruction) { |
| 8119 | const LocationSummary* const locations = instruction->GetLocations(); |
| 8120 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 8121 | const HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 8122 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8123 | if (instruction->GetType() == DataType::Type::kInt32) { |
Anton Kirilov | 420ee30 | 2017-02-21 18:10:26 +0000 | [diff] [blame] | 8124 | const vixl32::Register first = InputRegisterAt(instruction, 0); |
| 8125 | const vixl32::Register output = OutputRegister(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8126 | const vixl32::Register second = instruction->InputAt(1)->GetType() == DataType::Type::kInt64 |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8127 | ? LowRegisterFrom(locations->InAt(1)) |
| 8128 | : InputRegisterAt(instruction, 1); |
| 8129 | |
Anton Kirilov | 420ee30 | 2017-02-21 18:10:26 +0000 | [diff] [blame] | 8130 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 8131 | DCHECK_EQ(kind, HInstruction::kAdd); |
| 8132 | |
| 8133 | switch (op_kind) { |
| 8134 | case HDataProcWithShifterOp::kUXTB: |
| 8135 | __ Uxtab(output, first, second); |
| 8136 | break; |
| 8137 | case HDataProcWithShifterOp::kUXTH: |
| 8138 | __ Uxtah(output, first, second); |
| 8139 | break; |
| 8140 | case HDataProcWithShifterOp::kSXTB: |
| 8141 | __ Sxtab(output, first, second); |
| 8142 | break; |
| 8143 | case HDataProcWithShifterOp::kSXTH: |
| 8144 | __ Sxtah(output, first, second); |
| 8145 | break; |
| 8146 | default: |
| 8147 | LOG(FATAL) << "Unexpected operation kind: " << op_kind; |
| 8148 | UNREACHABLE(); |
| 8149 | } |
| 8150 | } else { |
| 8151 | GenerateDataProcInstruction(kind, |
| 8152 | output, |
| 8153 | first, |
| 8154 | Operand(second, |
| 8155 | ShiftFromOpKind(op_kind), |
| 8156 | instruction->GetShiftAmount()), |
| 8157 | codegen_); |
| 8158 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8159 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8160 | DCHECK_EQ(instruction->GetType(), DataType::Type::kInt64); |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8161 | |
| 8162 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 8163 | const vixl32::Register second = InputRegisterAt(instruction, 1); |
| 8164 | |
| 8165 | DCHECK(!LowRegisterFrom(locations->Out()).Is(second)); |
| 8166 | GenerateDataProc(kind, |
| 8167 | locations->Out(), |
| 8168 | locations->InAt(0), |
| 8169 | second, |
| 8170 | Operand(second, ShiftType::ASR, 31), |
| 8171 | codegen_); |
| 8172 | } else { |
| 8173 | GenerateLongDataProc(instruction, codegen_); |
| 8174 | } |
| 8175 | } |
| 8176 | } |
| 8177 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8178 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8179 | void InstructionCodeGeneratorARMVIXL::GenerateAndConst(vixl32::Register out, |
| 8180 | vixl32::Register first, |
| 8181 | uint32_t value) { |
| 8182 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 8183 | if (value == 0xffffffffu) { |
| 8184 | if (!out.Is(first)) { |
| 8185 | __ Mov(out, first); |
| 8186 | } |
| 8187 | return; |
| 8188 | } |
| 8189 | if (value == 0u) { |
| 8190 | __ Mov(out, 0); |
| 8191 | return; |
| 8192 | } |
| 8193 | if (GetAssembler()->ShifterOperandCanHold(AND, value)) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 8194 | __ And(out, first, value); |
| 8195 | } else if (GetAssembler()->ShifterOperandCanHold(BIC, ~value)) { |
| 8196 | __ Bic(out, first, ~value); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8197 | } else { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 8198 | DCHECK(IsPowerOfTwo(value + 1)); |
| 8199 | __ Ubfx(out, first, 0, WhichPowerOf2(value + 1)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8200 | } |
| 8201 | } |
| 8202 | |
| 8203 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8204 | void InstructionCodeGeneratorARMVIXL::GenerateOrrConst(vixl32::Register out, |
| 8205 | vixl32::Register first, |
| 8206 | uint32_t value) { |
| 8207 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 8208 | if (value == 0u) { |
| 8209 | if (!out.Is(first)) { |
| 8210 | __ Mov(out, first); |
| 8211 | } |
| 8212 | return; |
| 8213 | } |
| 8214 | if (value == 0xffffffffu) { |
| 8215 | __ Mvn(out, 0); |
| 8216 | return; |
| 8217 | } |
| 8218 | if (GetAssembler()->ShifterOperandCanHold(ORR, value)) { |
| 8219 | __ Orr(out, first, value); |
| 8220 | } else { |
| 8221 | DCHECK(GetAssembler()->ShifterOperandCanHold(ORN, ~value)); |
| 8222 | __ Orn(out, first, ~value); |
| 8223 | } |
| 8224 | } |
| 8225 | |
| 8226 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8227 | void InstructionCodeGeneratorARMVIXL::GenerateEorConst(vixl32::Register out, |
| 8228 | vixl32::Register first, |
| 8229 | uint32_t value) { |
| 8230 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 8231 | if (value == 0u) { |
| 8232 | if (!out.Is(first)) { |
| 8233 | __ Mov(out, first); |
| 8234 | } |
| 8235 | return; |
| 8236 | } |
| 8237 | __ Eor(out, first, value); |
| 8238 | } |
| 8239 | |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8240 | void InstructionCodeGeneratorARMVIXL::GenerateAddLongConst(Location out, |
| 8241 | Location first, |
| 8242 | uint64_t value) { |
| 8243 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8244 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8245 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8246 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8247 | uint32_t value_low = Low32Bits(value); |
| 8248 | uint32_t value_high = High32Bits(value); |
| 8249 | if (value_low == 0u) { |
| 8250 | if (!out_low.Is(first_low)) { |
| 8251 | __ Mov(out_low, first_low); |
| 8252 | } |
| 8253 | __ Add(out_high, first_high, value_high); |
| 8254 | return; |
| 8255 | } |
| 8256 | __ Adds(out_low, first_low, value_low); |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 8257 | if (GetAssembler()->ShifterOperandCanHold(ADC, value_high)) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8258 | __ Adc(out_high, first_high, value_high); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8259 | } else { |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 8260 | DCHECK(GetAssembler()->ShifterOperandCanHold(SBC, ~value_high)); |
| 8261 | __ Sbc(out_high, first_high, ~value_high); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8262 | } |
| 8263 | } |
| 8264 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8265 | void InstructionCodeGeneratorARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 8266 | LocationSummary* locations = instruction->GetLocations(); |
| 8267 | Location first = locations->InAt(0); |
| 8268 | Location second = locations->InAt(1); |
| 8269 | Location out = locations->Out(); |
| 8270 | |
| 8271 | if (second.IsConstant()) { |
| 8272 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 8273 | uint32_t value_low = Low32Bits(value); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8274 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8275 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 8276 | vixl32::Register out_reg = OutputRegister(instruction); |
| 8277 | if (instruction->IsAnd()) { |
| 8278 | GenerateAndConst(out_reg, first_reg, value_low); |
| 8279 | } else if (instruction->IsOr()) { |
| 8280 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 8281 | } else { |
| 8282 | DCHECK(instruction->IsXor()); |
| 8283 | GenerateEorConst(out_reg, first_reg, value_low); |
| 8284 | } |
| 8285 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8286 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8287 | uint32_t value_high = High32Bits(value); |
| 8288 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8289 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8290 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8291 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8292 | if (instruction->IsAnd()) { |
| 8293 | GenerateAndConst(out_low, first_low, value_low); |
| 8294 | GenerateAndConst(out_high, first_high, value_high); |
| 8295 | } else if (instruction->IsOr()) { |
| 8296 | GenerateOrrConst(out_low, first_low, value_low); |
| 8297 | GenerateOrrConst(out_high, first_high, value_high); |
| 8298 | } else { |
| 8299 | DCHECK(instruction->IsXor()); |
| 8300 | GenerateEorConst(out_low, first_low, value_low); |
| 8301 | GenerateEorConst(out_high, first_high, value_high); |
| 8302 | } |
| 8303 | } |
| 8304 | return; |
| 8305 | } |
| 8306 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8307 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8308 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 8309 | vixl32::Register second_reg = InputRegisterAt(instruction, 1); |
| 8310 | vixl32::Register out_reg = OutputRegister(instruction); |
| 8311 | if (instruction->IsAnd()) { |
| 8312 | __ And(out_reg, first_reg, second_reg); |
| 8313 | } else if (instruction->IsOr()) { |
| 8314 | __ Orr(out_reg, first_reg, second_reg); |
| 8315 | } else { |
| 8316 | DCHECK(instruction->IsXor()); |
| 8317 | __ Eor(out_reg, first_reg, second_reg); |
| 8318 | } |
| 8319 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8320 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8321 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8322 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8323 | vixl32::Register second_low = LowRegisterFrom(second); |
| 8324 | vixl32::Register second_high = HighRegisterFrom(second); |
| 8325 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8326 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8327 | if (instruction->IsAnd()) { |
| 8328 | __ And(out_low, first_low, second_low); |
| 8329 | __ And(out_high, first_high, second_high); |
| 8330 | } else if (instruction->IsOr()) { |
| 8331 | __ Orr(out_low, first_low, second_low); |
| 8332 | __ Orr(out_high, first_high, second_high); |
| 8333 | } else { |
| 8334 | DCHECK(instruction->IsXor()); |
| 8335 | __ Eor(out_low, first_low, second_low); |
| 8336 | __ Eor(out_high, first_high, second_high); |
| 8337 | } |
| 8338 | } |
| 8339 | } |
| 8340 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8341 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadOneRegister( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8342 | HInstruction* instruction, |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8343 | Location out, |
| 8344 | uint32_t offset, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8345 | Location maybe_temp, |
| 8346 | ReadBarrierOption read_barrier_option) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8347 | vixl32::Register out_reg = RegisterFrom(out); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8348 | if (read_barrier_option == kWithReadBarrier) { |
| 8349 | CHECK(kEmitCompilerReadBarrier); |
| 8350 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 8351 | if (kUseBakerReadBarrier) { |
| 8352 | // Load with fast path based Baker's read barrier. |
| 8353 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8354 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 8355 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
| 8356 | } else { |
| 8357 | // Load with slow path based read barrier. |
| 8358 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 8359 | // in the following move operation, as we will need it for the |
| 8360 | // read barrier below. |
| 8361 | __ Mov(RegisterFrom(maybe_temp), out_reg); |
| 8362 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8363 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 8364 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 8365 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8366 | } else { |
| 8367 | // Plain load with no read barrier. |
| 8368 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8369 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 8370 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 8371 | } |
| 8372 | } |
| 8373 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8374 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadTwoRegisters( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8375 | HInstruction* instruction, |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8376 | Location out, |
| 8377 | Location obj, |
| 8378 | uint32_t offset, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8379 | Location maybe_temp, |
| 8380 | ReadBarrierOption read_barrier_option) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8381 | vixl32::Register out_reg = RegisterFrom(out); |
| 8382 | vixl32::Register obj_reg = RegisterFrom(obj); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8383 | if (read_barrier_option == kWithReadBarrier) { |
| 8384 | CHECK(kEmitCompilerReadBarrier); |
| 8385 | if (kUseBakerReadBarrier) { |
| 8386 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 8387 | // Load with fast path based Baker's read barrier. |
| 8388 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8389 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 8390 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
| 8391 | } else { |
| 8392 | // Load with slow path based read barrier. |
| 8393 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8394 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8395 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 8396 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8397 | } else { |
| 8398 | // Plain load with no read barrier. |
| 8399 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8400 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8401 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 8402 | } |
| 8403 | } |
| 8404 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8405 | void InstructionCodeGeneratorARMVIXL::GenerateGcRootFieldLoad( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8406 | HInstruction* instruction, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8407 | Location root, |
| 8408 | vixl32::Register obj, |
| 8409 | uint32_t offset, |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8410 | ReadBarrierOption read_barrier_option) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8411 | vixl32::Register root_reg = RegisterFrom(root); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8412 | if (read_barrier_option == kWithReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8413 | DCHECK(kEmitCompilerReadBarrier); |
| 8414 | if (kUseBakerReadBarrier) { |
| 8415 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8416 | // Baker's read barrier are used. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8417 | if (kBakerReadBarrierLinkTimeThunksEnableForGcRoots && |
| 8418 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8419 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 8420 | // the Marking Register) to decide whether we need to enter |
| 8421 | // the slow path to mark the GC root. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8422 | // |
| 8423 | // We use link-time generated thunks for the slow path. That thunk |
| 8424 | // checks the reference and jumps to the entrypoint if needed. |
| 8425 | // |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8426 | // lr = &return_address; |
| 8427 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8428 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8429 | // goto gc_root_thunk<root_reg>(lr) |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8430 | // } |
| 8431 | // return_address: |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8432 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8433 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8434 | ExcludeIPAndBakerCcEntrypointRegister(&temps, instruction); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8435 | bool narrow = CanEmitNarrowLdr(root_reg, obj, offset); |
| 8436 | uint32_t custom_data = linker::Thumb2RelativePatcher::EncodeBakerReadBarrierGcRootData( |
| 8437 | root_reg.GetCode(), narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8438 | vixl32::Label* bne_label = codegen_->NewBakerReadBarrierPatch(custom_data); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8439 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8440 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), 4 * vixl32::kMaxInstructionSizeInBytes); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8441 | vixl32::Label return_address; |
| 8442 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8443 | __ cmp(mr, Operand(0)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8444 | // Currently the offset is always within range. If that changes, |
| 8445 | // we shall have to split the load the same way as for fields. |
| 8446 | DCHECK_LT(offset, kReferenceLoadMinFarOffset); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8447 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8448 | __ ldr(EncodingSize(narrow ? Narrow : Wide), root_reg, MemOperand(obj, offset)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8449 | EmitPlaceholderBne(codegen_, bne_label); |
| 8450 | __ Bind(&return_address); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8451 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8452 | narrow ? BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_OFFSET |
| 8453 | : BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8454 | } else { |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8455 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 8456 | // the Marking Register) to decide whether we need to enter |
| 8457 | // the slow path to mark the GC root. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8458 | // |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8459 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8460 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8461 | // // Slow path. |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8462 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8463 | // root = entrypoint(root); // root = ReadBarrier::Mark(root); // Entry point call. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8464 | // } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8465 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8466 | // Slow path marking the GC root `root`. The entrypoint will |
| 8467 | // be loaded by the slow path code. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8468 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8469 | new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathARMVIXL(instruction, root); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8470 | codegen_->AddSlowPath(slow_path); |
| 8471 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8472 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8473 | GetAssembler()->LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8474 | static_assert( |
| 8475 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 8476 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 8477 | "have different sizes."); |
| 8478 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 8479 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 8480 | "have different sizes."); |
| 8481 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8482 | __ CompareAndBranchIfNonZero(mr, slow_path->GetEntryLabel()); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8483 | __ Bind(slow_path->GetExitLabel()); |
| 8484 | } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8485 | } else { |
| 8486 | // GC root loaded through a slow path for read barriers other |
| 8487 | // than Baker's. |
| 8488 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 8489 | __ Add(root_reg, obj, offset); |
| 8490 | // /* mirror::Object* */ root = root->Read() |
| 8491 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 8492 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8493 | } else { |
| 8494 | // Plain GC root load with no read barrier. |
| 8495 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8496 | GetAssembler()->LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8497 | // Note that GC roots are not affected by heap poisoning, thus we |
| 8498 | // do not have to unpoison `root_reg` here. |
| 8499 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8500 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 18); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8501 | } |
| 8502 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8503 | void CodeGeneratorARMVIXL::MaybeAddBakerCcEntrypointTempForFields(LocationSummary* locations) { |
| 8504 | DCHECK(kEmitCompilerReadBarrier); |
| 8505 | DCHECK(kUseBakerReadBarrier); |
| 8506 | if (kBakerReadBarrierLinkTimeThunksEnableForFields) { |
| 8507 | if (!Runtime::Current()->UseJitCompilation()) { |
| 8508 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 8509 | } |
| 8510 | } |
| 8511 | } |
| 8512 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8513 | void CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8514 | Location ref, |
| 8515 | vixl32::Register obj, |
| 8516 | uint32_t offset, |
| 8517 | Location temp, |
| 8518 | bool needs_null_check) { |
| 8519 | DCHECK(kEmitCompilerReadBarrier); |
| 8520 | DCHECK(kUseBakerReadBarrier); |
| 8521 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8522 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 8523 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8524 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 8525 | // Marking Register) to decide whether we need to enter the slow |
| 8526 | // path to mark the reference. Then, in the slow path, check the |
| 8527 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 8528 | // decide whether to mark `ref` or not. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8529 | // |
| 8530 | // We use link-time generated thunks for the slow path. That thunk checks |
| 8531 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 8532 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 8533 | // |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8534 | // lr = &gray_return_address; |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8535 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8536 | // goto field_thunk<holder_reg, base_reg>(lr) |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8537 | // } |
| 8538 | // not_gray_return_address: |
| 8539 | // // Original reference load. If the offset is too large to fit |
| 8540 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8541 | // HeapReference<mirror::Object> reference = *(obj+offset); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8542 | // gray_return_address: |
| 8543 | |
| 8544 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8545 | vixl32::Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8546 | bool narrow = CanEmitNarrowLdr(ref_reg, obj, offset); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8547 | vixl32::Register base = obj; |
| 8548 | if (offset >= kReferenceLoadMinFarOffset) { |
| 8549 | base = RegisterFrom(temp); |
| 8550 | DCHECK(!base.Is(kBakerCcEntrypointRegister)); |
| 8551 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 8552 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 8553 | offset &= (kReferenceLoadMinFarOffset - 1u); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8554 | // Use narrow LDR only for small offsets. Generating narrow encoding LDR for the large |
| 8555 | // offsets with `(offset & (kReferenceLoadMinFarOffset - 1u)) < 32u` would most likely |
| 8556 | // increase the overall code size when taking the generated thunks into account. |
| 8557 | DCHECK(!narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8558 | } |
| 8559 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8560 | ExcludeIPAndBakerCcEntrypointRegister(&temps, instruction); |
| 8561 | uint32_t custom_data = linker::Thumb2RelativePatcher::EncodeBakerReadBarrierFieldData( |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8562 | base.GetCode(), obj.GetCode(), narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8563 | vixl32::Label* bne_label = NewBakerReadBarrierPatch(custom_data); |
| 8564 | |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8565 | { |
| 8566 | vixl::EmissionCheckScope guard( |
| 8567 | GetVIXLAssembler(), |
| 8568 | (kPoisonHeapReferences ? 5u : 4u) * vixl32::kMaxInstructionSizeInBytes); |
| 8569 | vixl32::Label return_address; |
| 8570 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8571 | __ cmp(mr, Operand(0)); |
| 8572 | EmitPlaceholderBne(this, bne_label); |
| 8573 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8574 | __ ldr(EncodingSize(narrow ? Narrow : Wide), ref_reg, MemOperand(base, offset)); |
| 8575 | if (needs_null_check) { |
| 8576 | MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8577 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8578 | // Note: We need a specific width for the unpoisoning NEG. |
| 8579 | if (kPoisonHeapReferences) { |
| 8580 | if (narrow) { |
| 8581 | // The only 16-bit encoding is T1 which sets flags outside IT block (i.e. RSBS, not RSB). |
| 8582 | __ rsbs(EncodingSize(Narrow), ref_reg, ref_reg, Operand(0)); |
| 8583 | } else { |
| 8584 | __ rsb(EncodingSize(Wide), ref_reg, ref_reg, Operand(0)); |
| 8585 | } |
| 8586 | } |
| 8587 | __ Bind(&return_address); |
| 8588 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8589 | narrow ? BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_OFFSET |
| 8590 | : BAKER_MARK_INTROSPECTION_FIELD_LDR_WIDE_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8591 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8592 | MaybeGenerateMarkingRegisterCheck(/* code */ 19, /* temp_loc */ LocationFrom(ip)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8593 | return; |
| 8594 | } |
| 8595 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8596 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 8597 | Location no_index = Location::NoLocation(); |
| 8598 | ScaleFactor no_scale_factor = TIMES_1; |
| 8599 | GenerateReferenceLoadWithBakerReadBarrier( |
| 8600 | instruction, ref, obj, offset, no_index, no_scale_factor, temp, needs_null_check); |
Roland Levillain | 6070e88 | 2016-11-03 17:51:58 +0000 | [diff] [blame] | 8601 | } |
| 8602 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8603 | void CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8604 | Location ref, |
| 8605 | vixl32::Register obj, |
| 8606 | uint32_t data_offset, |
| 8607 | Location index, |
| 8608 | Location temp, |
| 8609 | bool needs_null_check) { |
| 8610 | DCHECK(kEmitCompilerReadBarrier); |
| 8611 | DCHECK(kUseBakerReadBarrier); |
| 8612 | |
| 8613 | static_assert( |
| 8614 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 8615 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8616 | ScaleFactor scale_factor = TIMES_4; |
| 8617 | |
| 8618 | if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 8619 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8620 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 8621 | // Marking Register) to decide whether we need to enter the slow |
| 8622 | // path to mark the reference. Then, in the slow path, check the |
| 8623 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 8624 | // decide whether to mark `ref` or not. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8625 | // |
| 8626 | // We use link-time generated thunks for the slow path. That thunk checks |
| 8627 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 8628 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 8629 | // |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8630 | // lr = &gray_return_address; |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8631 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8632 | // goto array_thunk<base_reg>(lr) |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8633 | // } |
| 8634 | // not_gray_return_address: |
| 8635 | // // Original reference load. If the offset is too large to fit |
| 8636 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8637 | // HeapReference<mirror::Object> reference = data[index]; |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8638 | // gray_return_address: |
| 8639 | |
| 8640 | DCHECK(index.IsValid()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8641 | vixl32::Register index_reg = RegisterFrom(index, DataType::Type::kInt32); |
| 8642 | vixl32::Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
| 8643 | vixl32::Register data_reg = RegisterFrom(temp, DataType::Type::kInt32); // Raw pointer. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8644 | DCHECK(!data_reg.Is(kBakerCcEntrypointRegister)); |
| 8645 | |
| 8646 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8647 | ExcludeIPAndBakerCcEntrypointRegister(&temps, instruction); |
| 8648 | uint32_t custom_data = |
| 8649 | linker::Thumb2RelativePatcher::EncodeBakerReadBarrierArrayData(data_reg.GetCode()); |
| 8650 | vixl32::Label* bne_label = NewBakerReadBarrierPatch(custom_data); |
| 8651 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8652 | __ Add(data_reg, obj, Operand(data_offset)); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8653 | { |
| 8654 | vixl::EmissionCheckScope guard( |
| 8655 | GetVIXLAssembler(), |
| 8656 | (kPoisonHeapReferences ? 5u : 4u) * vixl32::kMaxInstructionSizeInBytes); |
| 8657 | vixl32::Label return_address; |
| 8658 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8659 | __ cmp(mr, Operand(0)); |
| 8660 | EmitPlaceholderBne(this, bne_label); |
| 8661 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8662 | __ ldr(ref_reg, MemOperand(data_reg, index_reg, vixl32::LSL, scale_factor)); |
| 8663 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 8664 | // Note: We need a Wide NEG for the unpoisoning. |
| 8665 | if (kPoisonHeapReferences) { |
| 8666 | __ rsb(EncodingSize(Wide), ref_reg, ref_reg, Operand(0)); |
| 8667 | } |
| 8668 | __ Bind(&return_address); |
| 8669 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8670 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8671 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8672 | MaybeGenerateMarkingRegisterCheck(/* code */ 20, /* temp_loc */ LocationFrom(ip)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8673 | return; |
| 8674 | } |
| 8675 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8676 | // /* HeapReference<Object> */ ref = |
| 8677 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8678 | GenerateReferenceLoadWithBakerReadBarrier( |
| 8679 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | 6070e88 | 2016-11-03 17:51:58 +0000 | [diff] [blame] | 8680 | } |
| 8681 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8682 | void CodeGeneratorARMVIXL::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8683 | Location ref, |
| 8684 | vixl32::Register obj, |
| 8685 | uint32_t offset, |
| 8686 | Location index, |
| 8687 | ScaleFactor scale_factor, |
| 8688 | Location temp, |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8689 | bool needs_null_check) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8690 | DCHECK(kEmitCompilerReadBarrier); |
| 8691 | DCHECK(kUseBakerReadBarrier); |
| 8692 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8693 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 8694 | // Marking Register) to decide whether we need to enter the slow |
| 8695 | // path to mark the reference. Then, in the slow path, check the |
| 8696 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 8697 | // decide whether to mark `ref` or not. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8698 | // |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8699 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8700 | // // Slow path. |
| 8701 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8702 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 8703 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 8704 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 8705 | // if (is_gray) { |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8706 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8707 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8708 | // } |
| 8709 | // } else { |
| 8710 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 8711 | // } |
| 8712 | |
| 8713 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 8714 | |
| 8715 | // Slow path marking the object `ref` when the GC is marking. The |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8716 | // entrypoint will be loaded by the slow path code. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8717 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8718 | new (GetScopedAllocator()) LoadReferenceWithBakerReadBarrierSlowPathARMVIXL( |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8719 | instruction, ref, obj, offset, index, scale_factor, needs_null_check, temp_reg); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8720 | AddSlowPath(slow_path); |
| 8721 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8722 | __ CompareAndBranchIfNonZero(mr, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8723 | // Fast path: the GC is not marking: just load the reference. |
| 8724 | GenerateRawReferenceLoad(instruction, ref, obj, offset, index, scale_factor, needs_null_check); |
| 8725 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8726 | MaybeGenerateMarkingRegisterCheck(/* code */ 21); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8727 | } |
| 8728 | |
| 8729 | void CodeGeneratorARMVIXL::UpdateReferenceFieldWithBakerReadBarrier(HInstruction* instruction, |
| 8730 | Location ref, |
| 8731 | vixl32::Register obj, |
| 8732 | Location field_offset, |
| 8733 | Location temp, |
| 8734 | bool needs_null_check, |
| 8735 | vixl32::Register temp2) { |
| 8736 | DCHECK(kEmitCompilerReadBarrier); |
| 8737 | DCHECK(kUseBakerReadBarrier); |
| 8738 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8739 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 8740 | // Marking Register) to decide whether we need to enter the slow |
| 8741 | // path to update the reference field within `obj`. Then, in the |
| 8742 | // slow path, check the gray bit in the lock word of the reference's |
| 8743 | // holder (`obj`) to decide whether to mark `ref` and update the |
| 8744 | // field or not. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8745 | // |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8746 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8747 | // // Slow path. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8748 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8749 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8750 | // HeapReference<mirror::Object> ref = *(obj + field_offset); // Reference load. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8751 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 8752 | // if (is_gray) { |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8753 | // old_ref = ref; |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8754 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8755 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8756 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8757 | // } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8758 | // } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8759 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8760 | vixl32::Register temp_reg = RegisterFrom(temp); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8761 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8762 | // Slow path updating the object reference at address `obj + field_offset` |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8763 | // when the GC is marking. The entrypoint will be loaded by the slow path code. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8764 | SlowPathCodeARMVIXL* slow_path = |
| 8765 | new (GetScopedAllocator()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL( |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8766 | instruction, |
| 8767 | ref, |
| 8768 | obj, |
| 8769 | /* offset */ 0u, |
| 8770 | /* index */ field_offset, |
| 8771 | /* scale_factor */ ScaleFactor::TIMES_1, |
| 8772 | needs_null_check, |
| 8773 | temp_reg, |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8774 | temp2); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8775 | AddSlowPath(slow_path); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8776 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8777 | __ CompareAndBranchIfNonZero(mr, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8778 | // Fast path: the GC is not marking: nothing to do (the field is |
| 8779 | // up-to-date, and we don't need to load the reference). |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8780 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8781 | MaybeGenerateMarkingRegisterCheck(/* code */ 22); |
Roland Levillain | 844e653 | 2016-11-03 16:09:47 +0000 | [diff] [blame] | 8782 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8783 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8784 | void CodeGeneratorARMVIXL::GenerateRawReferenceLoad(HInstruction* instruction, |
| 8785 | Location ref, |
| 8786 | vixl::aarch32::Register obj, |
| 8787 | uint32_t offset, |
| 8788 | Location index, |
| 8789 | ScaleFactor scale_factor, |
| 8790 | bool needs_null_check) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8791 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8792 | vixl32::Register ref_reg = RegisterFrom(ref, type); |
| 8793 | |
| 8794 | // If needed, vixl::EmissionCheckScope guards are used to ensure |
| 8795 | // that no pools are emitted between the load (macro) instruction |
| 8796 | // and MaybeRecordImplicitNullCheck. |
| 8797 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8798 | if (index.IsValid()) { |
| 8799 | // Load types involving an "index": ArrayGet, |
| 8800 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 8801 | // intrinsics. |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8802 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8803 | if (index.IsConstant()) { |
| 8804 | size_t computed_offset = |
| 8805 | (Int32ConstantFrom(index) << scale_factor) + offset; |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8806 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8807 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8808 | if (needs_null_check) { |
| 8809 | MaybeRecordImplicitNullCheck(instruction); |
| 8810 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8811 | } else { |
| 8812 | // Handle the special case of the |
| 8813 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 8814 | // intrinsics, which use a register pair as index ("long |
| 8815 | // offset"), of which only the low part contains data. |
| 8816 | vixl32::Register index_reg = index.IsRegisterPair() |
| 8817 | ? LowRegisterFrom(index) |
| 8818 | : RegisterFrom(index); |
| 8819 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8820 | vixl32::Register temp = temps.Acquire(); |
| 8821 | __ Add(temp, obj, Operand(index_reg, ShiftType::LSL, scale_factor)); |
| 8822 | { |
| 8823 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 8824 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, temp, offset); |
| 8825 | if (needs_null_check) { |
| 8826 | MaybeRecordImplicitNullCheck(instruction); |
| 8827 | } |
| 8828 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8829 | } |
| 8830 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8831 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
| 8832 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8833 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8834 | if (needs_null_check) { |
| 8835 | MaybeRecordImplicitNullCheck(instruction); |
| 8836 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8837 | } |
| 8838 | |
Roland Levillain | 844e653 | 2016-11-03 16:09:47 +0000 | [diff] [blame] | 8839 | // Object* ref = ref_addr->AsMirrorPtr() |
| 8840 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | 844e653 | 2016-11-03 16:09:47 +0000 | [diff] [blame] | 8841 | } |
| 8842 | |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8843 | void CodeGeneratorARMVIXL::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 8844 | // The following condition is a compile-time one, so it does not have a run-time cost. |
| 8845 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && kIsDebugBuild) { |
| 8846 | // The following condition is a run-time one; it is executed after the |
| 8847 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 8848 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 8849 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8850 | vixl32::Register temp = temp_loc.IsValid() ? RegisterFrom(temp_loc) : temps.Acquire(); |
| 8851 | GetAssembler()->GenerateMarkingRegisterCheck(temp, |
| 8852 | kMarkingRegisterCheckBreakCodeBaseCode + code); |
| 8853 | } |
| 8854 | } |
| 8855 | } |
| 8856 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8857 | void CodeGeneratorARMVIXL::GenerateReadBarrierSlow(HInstruction* instruction, |
| 8858 | Location out, |
| 8859 | Location ref, |
| 8860 | Location obj, |
| 8861 | uint32_t offset, |
| 8862 | Location index) { |
| 8863 | DCHECK(kEmitCompilerReadBarrier); |
| 8864 | |
| 8865 | // Insert a slow path based read barrier *after* the reference load. |
| 8866 | // |
| 8867 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 8868 | // reference will be carried out by the runtime within the slow |
| 8869 | // path. |
| 8870 | // |
| 8871 | // Note that `ref` currently does not get unpoisoned (when heap |
| 8872 | // poisoning is enabled), which is alright as the `ref` argument is |
| 8873 | // not used by the artReadBarrierSlow entry point. |
| 8874 | // |
| 8875 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8876 | SlowPathCodeARMVIXL* slow_path = new (GetScopedAllocator()) |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8877 | ReadBarrierForHeapReferenceSlowPathARMVIXL(instruction, out, ref, obj, offset, index); |
| 8878 | AddSlowPath(slow_path); |
| 8879 | |
| 8880 | __ B(slow_path->GetEntryLabel()); |
| 8881 | __ Bind(slow_path->GetExitLabel()); |
| 8882 | } |
| 8883 | |
| 8884 | void CodeGeneratorARMVIXL::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8885 | Location out, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8886 | Location ref, |
| 8887 | Location obj, |
| 8888 | uint32_t offset, |
| 8889 | Location index) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8890 | if (kEmitCompilerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8891 | // Baker's read barriers shall be handled by the fast path |
Roland Levillain | 9983e30 | 2017-07-14 14:34:22 +0100 | [diff] [blame] | 8892 | // (CodeGeneratorARMVIXL::GenerateReferenceLoadWithBakerReadBarrier). |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8893 | DCHECK(!kUseBakerReadBarrier); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8894 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 8895 | // by the runtime within the slow path. |
| 8896 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8897 | } else if (kPoisonHeapReferences) { |
| 8898 | GetAssembler()->UnpoisonHeapReference(RegisterFrom(out)); |
| 8899 | } |
| 8900 | } |
| 8901 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8902 | void CodeGeneratorARMVIXL::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 8903 | Location out, |
| 8904 | Location root) { |
| 8905 | DCHECK(kEmitCompilerReadBarrier); |
| 8906 | |
| 8907 | // Insert a slow path based read barrier *after* the GC root load. |
| 8908 | // |
| 8909 | // Note that GC roots are not affected by heap poisoning, so we do |
| 8910 | // not need to do anything special for this here. |
| 8911 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8912 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathARMVIXL(instruction, out, root); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8913 | AddSlowPath(slow_path); |
| 8914 | |
| 8915 | __ B(slow_path->GetEntryLabel()); |
| 8916 | __ Bind(slow_path->GetExitLabel()); |
| 8917 | } |
| 8918 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8919 | // Check if the desired_dispatch_info is supported. If it is, return it, |
| 8920 | // otherwise return a fall-back info that should be used instead. |
| 8921 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARMVIXL::GetSupportedInvokeStaticOrDirectDispatch( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8922 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 8923 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e807ff7 | 2017-01-23 09:03:12 +0000 | [diff] [blame] | 8924 | return desired_dispatch_info; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8925 | } |
| 8926 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8927 | vixl32::Register CodeGeneratorARMVIXL::GetInvokeStaticOrDirectExtraParameter( |
| 8928 | HInvokeStaticOrDirect* invoke, vixl32::Register temp) { |
| 8929 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 8930 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 8931 | if (!invoke->GetLocations()->Intrinsified()) { |
| 8932 | return RegisterFrom(location); |
| 8933 | } |
| 8934 | // For intrinsics we allow any location, so it may be on the stack. |
| 8935 | if (!location.IsRegister()) { |
| 8936 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, location.GetStackIndex()); |
| 8937 | return temp; |
| 8938 | } |
| 8939 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 8940 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 8941 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 8942 | // simple and more robust approach rather that trying to determine if that's the case. |
| 8943 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Scott Wakeling | d5cd497 | 2017-02-03 11:38:35 +0000 | [diff] [blame] | 8944 | if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(RegisterFrom(location).GetCode())) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8945 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(RegisterFrom(location).GetCode()); |
| 8946 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, stack_offset); |
| 8947 | return temp; |
| 8948 | } |
| 8949 | return RegisterFrom(location); |
| 8950 | } |
| 8951 | |
Vladimir Marko | d254f5c | 2017-06-02 15:18:36 +0000 | [diff] [blame] | 8952 | void CodeGeneratorARMVIXL::GenerateStaticOrDirectCall( |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8953 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8954 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8955 | switch (invoke->GetMethodLoadKind()) { |
| 8956 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 8957 | uint32_t offset = |
| 8958 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 8959 | // temp = thread->string_init_entrypoint |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8960 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp), tr, offset); |
| 8961 | break; |
| 8962 | } |
| 8963 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 8964 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 8965 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 8966 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 8967 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 8968 | PcRelativePatchInfo* labels = NewPcRelativeMethodPatch(invoke->GetTargetMethod()); |
| 8969 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 8970 | EmitMovwMovtPlaceholder(labels, temp_reg); |
| 8971 | break; |
| 8972 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8973 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 8974 | __ Mov(RegisterFrom(temp), Operand::From(invoke->GetMethodAddress())); |
| 8975 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 8976 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
| 8977 | PcRelativePatchInfo* labels = NewMethodBssEntryPatch( |
| 8978 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex())); |
| 8979 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 8980 | EmitMovwMovtPlaceholder(labels, temp_reg); |
| 8981 | GetAssembler()->LoadFromOffset(kLoadWord, temp_reg, temp_reg, /* offset*/ 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8982 | break; |
| 8983 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8984 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 8985 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 8986 | return; // No code pointer retrieval; the runtime performs the call directly. |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8987 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8988 | } |
| 8989 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8990 | switch (invoke->GetCodePtrLocation()) { |
| 8991 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8992 | { |
| 8993 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 8994 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 8995 | vixl32::k32BitT32InstructionSizeInBytes, |
| 8996 | CodeBufferCheckScope::kMaximumSize); |
| 8997 | __ bl(GetFrameEntryLabel()); |
| 8998 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 8999 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9000 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9001 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 9002 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 9003 | GetAssembler()->LoadFromOffset( |
| 9004 | kLoadWord, |
| 9005 | lr, |
| 9006 | RegisterFrom(callee_method), |
| 9007 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9008 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9009 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9010 | // 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] | 9011 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9012 | vixl32::k16BitT32InstructionSizeInBytes, |
| 9013 | CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9014 | // LR() |
| 9015 | __ blx(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9016 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9017 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9018 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9019 | } |
| 9020 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9021 | DCHECK(!IsLeafMethod()); |
| 9022 | } |
| 9023 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9024 | void CodeGeneratorARMVIXL::GenerateVirtualCall( |
| 9025 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9026 | vixl32::Register temp = RegisterFrom(temp_location); |
| 9027 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 9028 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
| 9029 | |
| 9030 | // Use the calling convention instead of the location of the receiver, as |
| 9031 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 9032 | // slow path, the arguments have been moved to the right place, so here we are |
| 9033 | // guaranteed that the receiver is the first register of the calling convention. |
| 9034 | InvokeDexCallingConventionARMVIXL calling_convention; |
| 9035 | vixl32::Register receiver = calling_convention.GetRegisterAt(0); |
| 9036 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9037 | { |
| 9038 | // Make sure the pc is recorded immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 9039 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9040 | vixl32::kMaxInstructionSizeInBytes, |
| 9041 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9042 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 9043 | __ ldr(temp, MemOperand(receiver, class_offset)); |
| 9044 | MaybeRecordImplicitNullCheck(invoke); |
| 9045 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9046 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 9047 | // emit a read barrier for the previous class reference load. |
| 9048 | // However this is not required in practice, as this is an |
| 9049 | // intermediate/temporary reference and because the current |
| 9050 | // concurrent copying collector keeps the from-space memory |
| 9051 | // intact/accessible until the end of the marking phase (the |
| 9052 | // concurrent copying collector may not in the future). |
| 9053 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 9054 | |
| 9055 | // temp = temp->GetMethodAt(method_offset); |
| 9056 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 9057 | kArmPointerSize).Int32Value(); |
| 9058 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 9059 | // LR = temp->GetEntryPoint(); |
| 9060 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9061 | { |
| 9062 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 9063 | // blx in T32 has only 16bit encoding that's why a stricter check for the scope is used. |
| 9064 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9065 | vixl32::k16BitT32InstructionSizeInBytes, |
| 9066 | CodeBufferCheckScope::kExactSize); |
| 9067 | // LR(); |
| 9068 | __ blx(lr); |
| 9069 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 9070 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9071 | } |
| 9072 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9073 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeMethodPatch( |
| 9074 | MethodReference target_method) { |
| 9075 | return NewPcRelativePatch(*target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 9076 | target_method.index, |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9077 | &pc_relative_method_patches_); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9078 | } |
| 9079 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9080 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewMethodBssEntryPatch( |
| 9081 | MethodReference target_method) { |
| 9082 | return NewPcRelativePatch(*target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 9083 | target_method.index, |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9084 | &method_bss_entry_patches_); |
| 9085 | } |
| 9086 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9087 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeTypePatch( |
| 9088 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 9089 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
| 9090 | } |
| 9091 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9092 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewTypeBssEntryPatch( |
| 9093 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 9094 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 9095 | } |
| 9096 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9097 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeStringPatch( |
| 9098 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 9099 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
| 9100 | } |
| 9101 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 9102 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewStringBssEntryPatch( |
| 9103 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 9104 | return NewPcRelativePatch(dex_file, string_index.index_, &string_bss_entry_patches_); |
| 9105 | } |
| 9106 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9107 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativePatch( |
| 9108 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 9109 | patches->emplace_back(dex_file, offset_or_index); |
| 9110 | return &patches->back(); |
| 9111 | } |
| 9112 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9113 | vixl::aarch32::Label* CodeGeneratorARMVIXL::NewBakerReadBarrierPatch(uint32_t custom_data) { |
| 9114 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 9115 | return &baker_read_barrier_patches_.back().label; |
| 9116 | } |
| 9117 | |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9118 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateBootImageAddressLiteral(uint32_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 9119 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9120 | } |
| 9121 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 9122 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitStringLiteral( |
| 9123 | const DexFile& dex_file, |
| 9124 | dex::StringIndex string_index, |
| 9125 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9126 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9127 | return jit_string_patches_.GetOrCreate( |
| 9128 | StringReference(&dex_file, string_index), |
| 9129 | [this]() { |
| 9130 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 9131 | }); |
| 9132 | } |
| 9133 | |
| 9134 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 9135 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 9136 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9137 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9138 | return jit_class_patches_.GetOrCreate( |
| 9139 | TypeReference(&dex_file, type_index), |
| 9140 | [this]() { |
| 9141 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 9142 | }); |
| 9143 | } |
| 9144 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9145 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9146 | inline void CodeGeneratorARMVIXL::EmitPcRelativeLinkerPatches( |
| 9147 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9148 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9149 | for (const PcRelativePatchInfo& info : infos) { |
| 9150 | const DexFile& dex_file = info.target_dex_file; |
| 9151 | size_t offset_or_index = info.offset_or_index; |
| 9152 | DCHECK(info.add_pc_label.IsBound()); |
| 9153 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.GetLocation()); |
| 9154 | // Add MOVW patch. |
| 9155 | DCHECK(info.movw_label.IsBound()); |
| 9156 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.GetLocation()); |
| 9157 | linker_patches->push_back(Factory(movw_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 9158 | // Add MOVT patch. |
| 9159 | DCHECK(info.movt_label.IsBound()); |
| 9160 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.GetLocation()); |
| 9161 | linker_patches->push_back(Factory(movt_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 9162 | } |
| 9163 | } |
| 9164 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9165 | void CodeGeneratorARMVIXL::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9166 | DCHECK(linker_patches->empty()); |
| 9167 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9168 | /* MOVW+MOVT for each entry */ 2u * pc_relative_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9169 | /* MOVW+MOVT for each entry */ 2u * method_bss_entry_patches_.size() + |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9170 | /* MOVW+MOVT for each entry */ 2u * pc_relative_type_patches_.size() + |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9171 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9172 | /* MOVW+MOVT for each entry */ 2u * pc_relative_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 9173 | /* MOVW+MOVT for each entry */ 2u * string_bss_entry_patches_.size() + |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9174 | baker_read_barrier_patches_.size(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9175 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9176 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9177 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 9178 | pc_relative_method_patches_, linker_patches); |
| 9179 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 9180 | pc_relative_type_patches_, linker_patches); |
| 9181 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| 9182 | pc_relative_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9183 | } else { |
| 9184 | DCHECK(pc_relative_method_patches_.empty()); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9185 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeClassTablePatch>( |
| 9186 | pc_relative_type_patches_, linker_patches); |
| 9187 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringInternTablePatch>( |
| 9188 | pc_relative_string_patches_, linker_patches); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9189 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9190 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 9191 | method_bss_entry_patches_, linker_patches); |
| 9192 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 9193 | type_bss_entry_patches_, linker_patches); |
| 9194 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 9195 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9196 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9197 | linker_patches->push_back(linker::LinkerPatch::BakerReadBarrierBranchPatch( |
| 9198 | info.label.GetLocation(), info.custom_data)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9199 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9200 | DCHECK_EQ(size, linker_patches->size()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9201 | } |
| 9202 | |
| 9203 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateUint32Literal( |
| 9204 | uint32_t value, |
| 9205 | Uint32ToLiteralMap* map) { |
| 9206 | return map->GetOrCreate( |
| 9207 | value, |
| 9208 | [this, value]() { |
| 9209 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ value); |
| 9210 | }); |
| 9211 | } |
| 9212 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 9213 | void LocationsBuilderARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 9214 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9215 | new (GetGraph()->GetAllocator()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 9216 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 9217 | Location::RequiresRegister()); |
| 9218 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 9219 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 9220 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 9221 | } |
| 9222 | |
| 9223 | void InstructionCodeGeneratorARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 9224 | vixl32::Register res = OutputRegister(instr); |
| 9225 | vixl32::Register accumulator = |
| 9226 | InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 9227 | vixl32::Register mul_left = |
| 9228 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 9229 | vixl32::Register mul_right = |
| 9230 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
| 9231 | |
| 9232 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 9233 | __ Mla(res, mul_left, mul_right, accumulator); |
| 9234 | } else { |
| 9235 | __ Mls(res, mul_left, mul_right, accumulator); |
| 9236 | } |
| 9237 | } |
| 9238 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9239 | void LocationsBuilderARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9240 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9241 | LOG(FATAL) << "Unreachable"; |
| 9242 | } |
| 9243 | |
| 9244 | void InstructionCodeGeneratorARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9245 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9246 | LOG(FATAL) << "Unreachable"; |
| 9247 | } |
| 9248 | |
| 9249 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 9250 | void LocationsBuilderARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9251 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9252 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9253 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9254 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
| 9255 | codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 9256 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 9257 | if (switch_instr->GetStartValue() != 0) { |
| 9258 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 9259 | } |
| 9260 | } |
| 9261 | } |
| 9262 | |
| 9263 | // TODO(VIXL): Investigate and reach the parity with old arm codegen. |
| 9264 | void InstructionCodeGeneratorARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9265 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 9266 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9267 | LocationSummary* locations = switch_instr->GetLocations(); |
| 9268 | vixl32::Register value_reg = InputRegisterAt(switch_instr, 0); |
| 9269 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 9270 | |
| 9271 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
| 9272 | !codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 9273 | // Create a series of compare/jumps. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9274 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9275 | vixl32::Register temp_reg = temps.Acquire(); |
| 9276 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 9277 | // the immediate, because IP is used as the destination register. For the other |
| 9278 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 9279 | // and they can be encoded in the instruction without making use of IP register. |
| 9280 | __ Adds(temp_reg, value_reg, -lower_bound); |
| 9281 | |
| 9282 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 9283 | // Jump to successors[0] if value == lower_bound. |
| 9284 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 9285 | int32_t last_index = 0; |
| 9286 | for (; num_entries - last_index > 2; last_index += 2) { |
| 9287 | __ Adds(temp_reg, temp_reg, -2); |
| 9288 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 9289 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9290 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 9291 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 9292 | } |
| 9293 | if (num_entries - last_index == 2) { |
| 9294 | // The last missing case_value. |
| 9295 | __ Cmp(temp_reg, 1); |
| 9296 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9297 | } |
| 9298 | |
| 9299 | // And the default for any other value. |
| 9300 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 9301 | __ B(codegen_->GetLabelOf(default_block)); |
| 9302 | } |
| 9303 | } else { |
| 9304 | // Create a table lookup. |
| 9305 | vixl32::Register table_base = RegisterFrom(locations->GetTemp(0)); |
| 9306 | |
| 9307 | JumpTableARMVIXL* jump_table = codegen_->CreateJumpTable(switch_instr); |
| 9308 | |
| 9309 | // Remove the bias. |
| 9310 | vixl32::Register key_reg; |
| 9311 | if (lower_bound != 0) { |
| 9312 | key_reg = RegisterFrom(locations->GetTemp(1)); |
| 9313 | __ Sub(key_reg, value_reg, lower_bound); |
| 9314 | } else { |
| 9315 | key_reg = value_reg; |
| 9316 | } |
| 9317 | |
| 9318 | // Check whether the value is in the table, jump to default block if not. |
| 9319 | __ Cmp(key_reg, num_entries - 1); |
| 9320 | __ B(hi, codegen_->GetLabelOf(default_block)); |
| 9321 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9322 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9323 | vixl32::Register jump_offset = temps.Acquire(); |
| 9324 | |
| 9325 | // Load jump offset from the table. |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9326 | { |
| 9327 | const size_t jump_size = switch_instr->GetNumEntries() * sizeof(int32_t); |
| 9328 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9329 | (vixl32::kMaxInstructionSizeInBytes * 4) + jump_size, |
| 9330 | CodeBufferCheckScope::kMaximumSize); |
| 9331 | __ adr(table_base, jump_table->GetTableStartLabel()); |
| 9332 | __ ldr(jump_offset, MemOperand(table_base, key_reg, vixl32::LSL, 2)); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9333 | |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9334 | // Jump to target block by branching to table_base(pc related) + offset. |
| 9335 | vixl32::Register target_address = table_base; |
| 9336 | __ add(target_address, table_base, jump_offset); |
| 9337 | __ bx(target_address); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 9338 | |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9339 | jump_table->EmitTable(codegen_); |
| 9340 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9341 | } |
| 9342 | } |
| 9343 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9344 | // Copy the result of a call into the given target. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9345 | void CodeGeneratorARMVIXL::MoveFromReturnRegister(Location trg, DataType::Type type) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9346 | if (!trg.IsValid()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9347 | DCHECK_EQ(type, DataType::Type::kVoid); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9348 | return; |
| 9349 | } |
| 9350 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9351 | DCHECK_NE(type, DataType::Type::kVoid); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9352 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9353 | Location return_loc = InvokeDexCallingConventionVisitorARMVIXL().GetReturnLocation(type); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9354 | if (return_loc.Equals(trg)) { |
| 9355 | return; |
| 9356 | } |
| 9357 | |
| 9358 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 9359 | // with the last branch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9360 | if (type == DataType::Type::kInt64) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9361 | TODO_VIXL32(FATAL); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9362 | } else if (type == DataType::Type::kFloat64) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9363 | TODO_VIXL32(FATAL); |
| 9364 | } else { |
| 9365 | // Let the parallel move resolver take care of all of this. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9366 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9367 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 9368 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 9369 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9370 | } |
| 9371 | |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9372 | void LocationsBuilderARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 9373 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9374 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9375 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9376 | locations->SetOut(Location::RequiresRegister()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9377 | } |
| 9378 | |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9379 | void InstructionCodeGeneratorARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 9380 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| 9381 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 9382 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
| 9383 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9384 | OutputRegister(instruction), |
| 9385 | InputRegisterAt(instruction, 0), |
| 9386 | method_offset); |
| 9387 | } else { |
| 9388 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 9389 | instruction->GetIndex(), kArmPointerSize)); |
| 9390 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9391 | OutputRegister(instruction), |
| 9392 | InputRegisterAt(instruction, 0), |
| 9393 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 9394 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9395 | OutputRegister(instruction), |
| 9396 | OutputRegister(instruction), |
| 9397 | method_offset); |
| 9398 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9399 | } |
| 9400 | |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9401 | static void PatchJitRootUse(uint8_t* code, |
| 9402 | const uint8_t* roots_data, |
| 9403 | VIXLUInt32Literal* literal, |
| 9404 | uint64_t index_in_table) { |
| 9405 | DCHECK(literal->IsBound()); |
| 9406 | uint32_t literal_offset = literal->GetLocation(); |
| 9407 | uintptr_t address = |
| 9408 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 9409 | uint8_t* data = code + literal_offset; |
| 9410 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 9411 | } |
| 9412 | |
| 9413 | void CodeGeneratorARMVIXL::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 9414 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9415 | const StringReference& string_reference = entry.first; |
| 9416 | VIXLUInt32Literal* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9417 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9418 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9419 | } |
| 9420 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9421 | const TypeReference& type_reference = entry.first; |
| 9422 | VIXLUInt32Literal* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9423 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9424 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9425 | } |
| 9426 | } |
| 9427 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9428 | void CodeGeneratorARMVIXL::EmitMovwMovtPlaceholder( |
| 9429 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels, |
| 9430 | vixl32::Register out) { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 9431 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9432 | 3 * vixl32::kMaxInstructionSizeInBytes, |
| 9433 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9434 | // TODO(VIXL): Think about using mov instead of movw. |
| 9435 | __ bind(&labels->movw_label); |
| 9436 | __ movw(out, /* placeholder */ 0u); |
| 9437 | __ bind(&labels->movt_label); |
| 9438 | __ movt(out, /* placeholder */ 0u); |
| 9439 | __ bind(&labels->add_pc_label); |
| 9440 | __ add(out, out, pc); |
| 9441 | } |
| 9442 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9443 | #undef __ |
| 9444 | #undef QUICK_ENTRY_POINT |
| 9445 | #undef TODO_VIXL32 |
| 9446 | |
| 9447 | } // namespace arm |
| 9448 | } // namespace art |