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) { |
Nicolas Geoffray | 1a4f3ca | 2018-01-25 14:07:15 +0000 | [diff] [blame] | 2493 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2494 | vixl32::Register temp = temps.Acquire(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 2495 | __ Sub(temp, sp, Operand::From(GetStackOverflowReservedBytes(InstructionSet::kArm))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2496 | // The load must immediately precede RecordPcInfo. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 2497 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2498 | vixl32::kMaxInstructionSizeInBytes, |
| 2499 | CodeBufferCheckScope::kMaximumSize); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2500 | __ ldr(temp, MemOperand(temp)); |
| 2501 | RecordPcInfo(nullptr, 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2502 | } |
| 2503 | |
| 2504 | __ Push(RegisterList(core_spill_mask_)); |
| 2505 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 2506 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(kMethodRegister), |
| 2507 | 0, |
| 2508 | core_spill_mask_, |
| 2509 | kArmWordSize); |
| 2510 | if (fpu_spill_mask_ != 0) { |
| 2511 | uint32_t first = LeastSignificantBit(fpu_spill_mask_); |
| 2512 | |
| 2513 | // Check that list is contiguous. |
| 2514 | DCHECK_EQ(fpu_spill_mask_ >> CTZ(fpu_spill_mask_), ~0u >> (32 - POPCOUNT(fpu_spill_mask_))); |
| 2515 | |
| 2516 | __ Vpush(SRegisterList(vixl32::SRegister(first), POPCOUNT(fpu_spill_mask_))); |
| 2517 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2518 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(s0), 0, fpu_spill_mask_, kArmWordSize); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2519 | } |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 2520 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2521 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 2522 | __ Sub(sp, sp, adjust); |
| 2523 | GetAssembler()->cfi().AdjustCFAOffset(adjust); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 2524 | |
| 2525 | // Save the current method if we need it. Note that we do not |
| 2526 | // do this in HCurrentMethod, as the instruction might have been removed |
| 2527 | // in the SSA graph. |
| 2528 | if (RequiresCurrentMethod()) { |
| 2529 | GetAssembler()->StoreToOffset(kStoreWord, kMethodRegister, sp, 0); |
| 2530 | } |
Nicolas Geoffray | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 2531 | |
| 2532 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 2533 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2534 | vixl32::Register temp = temps.Acquire(); |
| 2535 | // Initialize should_deoptimize flag to 0. |
| 2536 | __ Mov(temp, 0); |
| 2537 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, GetStackOffsetOfShouldDeoptimizeFlag()); |
| 2538 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 2539 | |
| 2540 | MaybeGenerateMarkingRegisterCheck(/* code */ 1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2541 | } |
| 2542 | |
| 2543 | void CodeGeneratorARMVIXL::GenerateFrameExit() { |
| 2544 | if (HasEmptyFrame()) { |
| 2545 | __ Bx(lr); |
| 2546 | return; |
| 2547 | } |
| 2548 | GetAssembler()->cfi().RememberState(); |
| 2549 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 2550 | __ Add(sp, sp, adjust); |
| 2551 | GetAssembler()->cfi().AdjustCFAOffset(-adjust); |
| 2552 | if (fpu_spill_mask_ != 0) { |
| 2553 | uint32_t first = LeastSignificantBit(fpu_spill_mask_); |
| 2554 | |
| 2555 | // Check that list is contiguous. |
| 2556 | DCHECK_EQ(fpu_spill_mask_ >> CTZ(fpu_spill_mask_), ~0u >> (32 - POPCOUNT(fpu_spill_mask_))); |
| 2557 | |
| 2558 | __ Vpop(SRegisterList(vixl32::SRegister(first), POPCOUNT(fpu_spill_mask_))); |
| 2559 | GetAssembler()->cfi().AdjustCFAOffset( |
| 2560 | -static_cast<int>(kArmWordSize) * POPCOUNT(fpu_spill_mask_)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2561 | GetAssembler()->cfi().RestoreMany(DWARFReg(vixl32::SRegister(0)), fpu_spill_mask_); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2562 | } |
| 2563 | // Pop LR into PC to return. |
| 2564 | DCHECK_NE(core_spill_mask_ & (1 << kLrCode), 0U); |
| 2565 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << kLrCode))) | 1 << kPcCode; |
| 2566 | __ Pop(RegisterList(pop_mask)); |
| 2567 | GetAssembler()->cfi().RestoreState(); |
| 2568 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
| 2569 | } |
| 2570 | |
| 2571 | void CodeGeneratorARMVIXL::Bind(HBasicBlock* block) { |
| 2572 | __ Bind(GetLabelOf(block)); |
| 2573 | } |
| 2574 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2575 | Location InvokeDexCallingConventionVisitorARMVIXL::GetNextLocation(DataType::Type type) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2576 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2577 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2578 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2579 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2580 | case DataType::Type::kInt8: |
| 2581 | case DataType::Type::kUint16: |
| 2582 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2583 | case DataType::Type::kInt32: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2584 | uint32_t index = gp_index_++; |
| 2585 | uint32_t stack_index = stack_index_++; |
| 2586 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2587 | return LocationFrom(calling_convention.GetRegisterAt(index)); |
| 2588 | } else { |
| 2589 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2590 | } |
| 2591 | } |
| 2592 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2593 | case DataType::Type::kInt64: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2594 | uint32_t index = gp_index_; |
| 2595 | uint32_t stack_index = stack_index_; |
| 2596 | gp_index_ += 2; |
| 2597 | stack_index_ += 2; |
| 2598 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2599 | if (calling_convention.GetRegisterAt(index).Is(r1)) { |
| 2600 | // Skip R1, and use R2_R3 instead. |
| 2601 | gp_index_++; |
| 2602 | index++; |
| 2603 | } |
| 2604 | } |
| 2605 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2606 | DCHECK_EQ(calling_convention.GetRegisterAt(index).GetCode() + 1, |
| 2607 | calling_convention.GetRegisterAt(index + 1).GetCode()); |
| 2608 | |
| 2609 | return LocationFrom(calling_convention.GetRegisterAt(index), |
| 2610 | calling_convention.GetRegisterAt(index + 1)); |
| 2611 | } else { |
| 2612 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2613 | } |
| 2614 | } |
| 2615 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2616 | case DataType::Type::kFloat32: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2617 | uint32_t stack_index = stack_index_++; |
| 2618 | if (float_index_ % 2 == 0) { |
| 2619 | float_index_ = std::max(double_index_, float_index_); |
| 2620 | } |
| 2621 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 2622 | return LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 2623 | } else { |
| 2624 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2625 | } |
| 2626 | } |
| 2627 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2628 | case DataType::Type::kFloat64: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2629 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 2630 | uint32_t stack_index = stack_index_; |
| 2631 | stack_index_ += 2; |
| 2632 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 2633 | uint32_t index = double_index_; |
| 2634 | double_index_ += 2; |
| 2635 | Location result = LocationFrom( |
| 2636 | calling_convention.GetFpuRegisterAt(index), |
| 2637 | calling_convention.GetFpuRegisterAt(index + 1)); |
| 2638 | DCHECK(ExpectedPairLayout(result)); |
| 2639 | return result; |
| 2640 | } else { |
| 2641 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2642 | } |
| 2643 | } |
| 2644 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2645 | case DataType::Type::kVoid: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2646 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2647 | break; |
| 2648 | } |
| 2649 | return Location::NoLocation(); |
| 2650 | } |
| 2651 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2652 | Location InvokeDexCallingConventionVisitorARMVIXL::GetReturnLocation(DataType::Type type) const { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2653 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2654 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2655 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2656 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2657 | case DataType::Type::kInt8: |
| 2658 | case DataType::Type::kUint16: |
| 2659 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2660 | case DataType::Type::kInt32: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2661 | return LocationFrom(r0); |
| 2662 | } |
| 2663 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2664 | case DataType::Type::kFloat32: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2665 | return LocationFrom(s0); |
| 2666 | } |
| 2667 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2668 | case DataType::Type::kInt64: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2669 | return LocationFrom(r0, r1); |
| 2670 | } |
| 2671 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2672 | case DataType::Type::kFloat64: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2673 | return LocationFrom(s0, s1); |
| 2674 | } |
| 2675 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2676 | case DataType::Type::kVoid: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2677 | return Location::NoLocation(); |
| 2678 | } |
| 2679 | |
| 2680 | UNREACHABLE(); |
| 2681 | } |
| 2682 | |
| 2683 | Location InvokeDexCallingConventionVisitorARMVIXL::GetMethodLocation() const { |
| 2684 | return LocationFrom(kMethodRegister); |
| 2685 | } |
| 2686 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2687 | void CodeGeneratorARMVIXL::Move32(Location destination, Location source) { |
| 2688 | if (source.Equals(destination)) { |
| 2689 | return; |
| 2690 | } |
| 2691 | if (destination.IsRegister()) { |
| 2692 | if (source.IsRegister()) { |
| 2693 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 2694 | } else if (source.IsFpuRegister()) { |
| 2695 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
| 2696 | } else { |
| 2697 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 2698 | RegisterFrom(destination), |
| 2699 | sp, |
| 2700 | source.GetStackIndex()); |
| 2701 | } |
| 2702 | } else if (destination.IsFpuRegister()) { |
| 2703 | if (source.IsRegister()) { |
| 2704 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
| 2705 | } else if (source.IsFpuRegister()) { |
| 2706 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 2707 | } else { |
| 2708 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 2709 | } |
| 2710 | } else { |
| 2711 | DCHECK(destination.IsStackSlot()) << destination; |
| 2712 | if (source.IsRegister()) { |
| 2713 | GetAssembler()->StoreToOffset(kStoreWord, |
| 2714 | RegisterFrom(source), |
| 2715 | sp, |
| 2716 | destination.GetStackIndex()); |
| 2717 | } else if (source.IsFpuRegister()) { |
| 2718 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 2719 | } else { |
| 2720 | DCHECK(source.IsStackSlot()) << source; |
| 2721 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2722 | vixl32::Register temp = temps.Acquire(); |
| 2723 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 2724 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 2725 | } |
| 2726 | } |
| 2727 | } |
| 2728 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2729 | void CodeGeneratorARMVIXL::MoveConstant(Location location, int32_t value) { |
| 2730 | DCHECK(location.IsRegister()); |
| 2731 | __ Mov(RegisterFrom(location), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2732 | } |
| 2733 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2734 | void CodeGeneratorARMVIXL::MoveLocation(Location dst, Location src, DataType::Type dst_type) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2735 | // TODO(VIXL): Maybe refactor to have the 'move' implementation here and use it in |
| 2736 | // `ParallelMoveResolverARMVIXL::EmitMove`, as is done in the `arm64` backend. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2737 | HParallelMove move(GetGraph()->GetAllocator()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2738 | move.AddMove(src, dst, dst_type, nullptr); |
| 2739 | GetMoveResolver()->EmitNativeCode(&move); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2740 | } |
| 2741 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2742 | void CodeGeneratorARMVIXL::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 2743 | if (location.IsRegister()) { |
| 2744 | locations->AddTemp(location); |
| 2745 | } else if (location.IsRegisterPair()) { |
| 2746 | locations->AddTemp(LocationFrom(LowRegisterFrom(location))); |
| 2747 | locations->AddTemp(LocationFrom(HighRegisterFrom(location))); |
| 2748 | } else { |
| 2749 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 2750 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2751 | } |
| 2752 | |
| 2753 | void CodeGeneratorARMVIXL::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2754 | HInstruction* instruction, |
| 2755 | uint32_t dex_pc, |
| 2756 | SlowPathCode* slow_path) { |
| 2757 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2758 | __ Ldr(lr, MemOperand(tr, GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value())); |
| 2759 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 2760 | // 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] | 2761 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2762 | vixl32::k16BitT32InstructionSizeInBytes, |
| 2763 | CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2764 | __ blx(lr); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2765 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2766 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2767 | } |
| 2768 | } |
| 2769 | |
| 2770 | void CodeGeneratorARMVIXL::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2771 | HInstruction* instruction, |
| 2772 | SlowPathCode* slow_path) { |
| 2773 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2774 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2775 | __ Blx(lr); |
| 2776 | } |
| 2777 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2778 | void InstructionCodeGeneratorARMVIXL::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 2779 | if (successor->IsExitBlock()) { |
| 2780 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 2781 | return; // no code needed |
| 2782 | } |
| 2783 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2784 | HBasicBlock* block = got->GetBlock(); |
| 2785 | HInstruction* previous = got->GetPrevious(); |
| 2786 | HLoopInformation* info = block->GetLoopInformation(); |
| 2787 | |
| 2788 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2789 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2790 | return; |
| 2791 | } |
| 2792 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2793 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 2794 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 2); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2795 | } |
| 2796 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 2797 | __ B(codegen_->GetLabelOf(successor)); |
| 2798 | } |
| 2799 | } |
| 2800 | |
| 2801 | void LocationsBuilderARMVIXL::VisitGoto(HGoto* got) { |
| 2802 | got->SetLocations(nullptr); |
| 2803 | } |
| 2804 | |
| 2805 | void InstructionCodeGeneratorARMVIXL::VisitGoto(HGoto* got) { |
| 2806 | HandleGoto(got, got->GetSuccessor()); |
| 2807 | } |
| 2808 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2809 | void LocationsBuilderARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2810 | try_boundary->SetLocations(nullptr); |
| 2811 | } |
| 2812 | |
| 2813 | void InstructionCodeGeneratorARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2814 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2815 | if (!successor->IsExitBlock()) { |
| 2816 | HandleGoto(try_boundary, successor); |
| 2817 | } |
| 2818 | } |
| 2819 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2820 | void LocationsBuilderARMVIXL::VisitExit(HExit* exit) { |
| 2821 | exit->SetLocations(nullptr); |
| 2822 | } |
| 2823 | |
| 2824 | void InstructionCodeGeneratorARMVIXL::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 2825 | } |
| 2826 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2827 | void InstructionCodeGeneratorARMVIXL::GenerateCompareTestAndBranch(HCondition* condition, |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2828 | vixl32::Label* true_target, |
| 2829 | vixl32::Label* false_target, |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2830 | bool is_far_target) { |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2831 | if (true_target == false_target) { |
| 2832 | DCHECK(true_target != nullptr); |
| 2833 | __ B(true_target); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2834 | return; |
| 2835 | } |
| 2836 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2837 | vixl32::Label* non_fallthrough_target; |
| 2838 | bool invert; |
| 2839 | bool emit_both_branches; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2840 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2841 | if (true_target == nullptr) { |
| 2842 | // The true target is fallthrough. |
| 2843 | DCHECK(false_target != nullptr); |
| 2844 | non_fallthrough_target = false_target; |
| 2845 | invert = true; |
| 2846 | emit_both_branches = false; |
| 2847 | } else { |
| 2848 | non_fallthrough_target = true_target; |
| 2849 | invert = false; |
| 2850 | // Either the false target is fallthrough, or there is no fallthrough |
| 2851 | // and both branches must be emitted. |
| 2852 | emit_both_branches = (false_target != nullptr); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2853 | } |
| 2854 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2855 | const auto cond = GenerateTest(condition, invert, codegen_); |
| 2856 | |
| 2857 | __ B(cond.first, non_fallthrough_target, is_far_target); |
| 2858 | |
| 2859 | if (emit_both_branches) { |
| 2860 | // No target falls through, we need to branch. |
| 2861 | __ B(false_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2862 | } |
| 2863 | } |
| 2864 | |
| 2865 | void InstructionCodeGeneratorARMVIXL::GenerateTestAndBranch(HInstruction* instruction, |
| 2866 | size_t condition_input_index, |
| 2867 | vixl32::Label* true_target, |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2868 | vixl32::Label* false_target, |
| 2869 | bool far_target) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2870 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 2871 | |
| 2872 | if (true_target == nullptr && false_target == nullptr) { |
| 2873 | // Nothing to do. The code always falls through. |
| 2874 | return; |
| 2875 | } else if (cond->IsIntConstant()) { |
| 2876 | // Constant condition, statically compared against "true" (integer value 1). |
| 2877 | if (cond->AsIntConstant()->IsTrue()) { |
| 2878 | if (true_target != nullptr) { |
| 2879 | __ B(true_target); |
| 2880 | } |
| 2881 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 2882 | DCHECK(cond->AsIntConstant()->IsFalse()) << Int32ConstantFrom(cond); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2883 | if (false_target != nullptr) { |
| 2884 | __ B(false_target); |
| 2885 | } |
| 2886 | } |
| 2887 | return; |
| 2888 | } |
| 2889 | |
| 2890 | // The following code generates these patterns: |
| 2891 | // (1) true_target == nullptr && false_target != nullptr |
| 2892 | // - opposite condition true => branch to false_target |
| 2893 | // (2) true_target != nullptr && false_target == nullptr |
| 2894 | // - condition true => branch to true_target |
| 2895 | // (3) true_target != nullptr && false_target != nullptr |
| 2896 | // - condition true => branch to true_target |
| 2897 | // - branch to false_target |
| 2898 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 2899 | // Condition has been materialized, compare the output to 0. |
| 2900 | if (kIsDebugBuild) { |
| 2901 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 2902 | DCHECK(cond_val.IsRegister()); |
| 2903 | } |
| 2904 | if (true_target == nullptr) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2905 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, condition_input_index), |
| 2906 | false_target, |
| 2907 | far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2908 | } else { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2909 | __ CompareAndBranchIfNonZero(InputRegisterAt(instruction, condition_input_index), |
| 2910 | true_target, |
| 2911 | far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2912 | } |
| 2913 | } else { |
| 2914 | // Condition has not been materialized. Use its inputs as the comparison and |
| 2915 | // its condition as the branch condition. |
| 2916 | HCondition* condition = cond->AsCondition(); |
| 2917 | |
| 2918 | // If this is a long or FP comparison that has been folded into |
| 2919 | // the HCondition, generate the comparison directly. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2920 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 2921 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2922 | GenerateCompareTestAndBranch(condition, true_target, false_target, far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2923 | return; |
| 2924 | } |
| 2925 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2926 | vixl32::Label* non_fallthrough_target; |
| 2927 | vixl32::Condition arm_cond = vixl32::Condition::None(); |
| 2928 | const vixl32::Register left = InputRegisterAt(cond, 0); |
| 2929 | const Operand right = InputOperandAt(cond, 1); |
| 2930 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2931 | if (true_target == nullptr) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2932 | arm_cond = ARMCondition(condition->GetOppositeCondition()); |
| 2933 | non_fallthrough_target = false_target; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2934 | } else { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2935 | arm_cond = ARMCondition(condition->GetCondition()); |
| 2936 | non_fallthrough_target = true_target; |
| 2937 | } |
| 2938 | |
| 2939 | if (right.IsImmediate() && right.GetImmediate() == 0 && (arm_cond.Is(ne) || arm_cond.Is(eq))) { |
| 2940 | if (arm_cond.Is(eq)) { |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2941 | __ CompareAndBranchIfZero(left, non_fallthrough_target, far_target); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2942 | } else { |
| 2943 | DCHECK(arm_cond.Is(ne)); |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2944 | __ CompareAndBranchIfNonZero(left, non_fallthrough_target, far_target); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2945 | } |
| 2946 | } else { |
| 2947 | __ Cmp(left, right); |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2948 | __ B(arm_cond, non_fallthrough_target, far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2949 | } |
| 2950 | } |
| 2951 | |
| 2952 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 2953 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 2954 | if (true_target != nullptr && false_target != nullptr) { |
| 2955 | __ B(false_target); |
| 2956 | } |
| 2957 | } |
| 2958 | |
| 2959 | void LocationsBuilderARMVIXL::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2960 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2961 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| 2962 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2963 | } |
| 2964 | } |
| 2965 | |
| 2966 | void InstructionCodeGeneratorARMVIXL::VisitIf(HIf* if_instr) { |
| 2967 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 2968 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2969 | vixl32::Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 2970 | nullptr : codegen_->GetLabelOf(true_successor); |
| 2971 | vixl32::Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 2972 | nullptr : codegen_->GetLabelOf(false_successor); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2973 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
| 2974 | } |
| 2975 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2976 | void LocationsBuilderARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2977 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2978 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 2979 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 2980 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2981 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 2982 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2983 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| 2984 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2985 | } |
| 2986 | } |
| 2987 | |
| 2988 | void InstructionCodeGeneratorARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2989 | SlowPathCodeARMVIXL* slow_path = |
| 2990 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARMVIXL>(deoptimize); |
| 2991 | GenerateTestAndBranch(deoptimize, |
| 2992 | /* condition_input_index */ 0, |
| 2993 | slow_path->GetEntryLabel(), |
| 2994 | /* false_target */ nullptr); |
| 2995 | } |
| 2996 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2997 | void LocationsBuilderARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2998 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2999 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3000 | locations->SetOut(Location::RequiresRegister()); |
| 3001 | } |
| 3002 | |
| 3003 | void InstructionCodeGeneratorARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3004 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3005 | OutputRegister(flag), |
| 3006 | sp, |
| 3007 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 3008 | } |
| 3009 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3010 | void LocationsBuilderARMVIXL::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3011 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3012 | const bool is_floating_point = DataType::IsFloatingPointType(select->GetType()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3013 | |
| 3014 | if (is_floating_point) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3015 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3016 | locations->SetInAt(1, Location::FpuRegisterOrConstant(select->GetTrueValue())); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3017 | } else { |
| 3018 | locations->SetInAt(0, Location::RequiresRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3019 | locations->SetInAt(1, Arm8BitEncodableConstantOrRegister(select->GetTrueValue())); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3020 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3021 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3022 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3023 | locations->SetInAt(2, Location::RegisterOrConstant(select->GetCondition())); |
| 3024 | // The code generator handles overlap with the values, but not with the condition. |
| 3025 | locations->SetOut(Location::SameAsFirstInput()); |
| 3026 | } else if (is_floating_point) { |
| 3027 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3028 | } else { |
| 3029 | if (!locations->InAt(1).IsConstant()) { |
| 3030 | locations->SetInAt(0, Arm8BitEncodableConstantOrRegister(select->GetFalseValue())); |
| 3031 | } |
| 3032 | |
| 3033 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3034 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3035 | } |
| 3036 | |
| 3037 | void InstructionCodeGeneratorARMVIXL::VisitSelect(HSelect* select) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3038 | HInstruction* const condition = select->GetCondition(); |
| 3039 | const LocationSummary* const locations = select->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3040 | const DataType::Type type = select->GetType(); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3041 | const Location first = locations->InAt(0); |
| 3042 | const Location out = locations->Out(); |
| 3043 | const Location second = locations->InAt(1); |
| 3044 | Location src; |
| 3045 | |
| 3046 | if (condition->IsIntConstant()) { |
| 3047 | if (condition->AsIntConstant()->IsFalse()) { |
| 3048 | src = first; |
| 3049 | } else { |
| 3050 | src = second; |
| 3051 | } |
| 3052 | |
| 3053 | codegen_->MoveLocation(out, src, type); |
| 3054 | return; |
| 3055 | } |
| 3056 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3057 | if (!DataType::IsFloatingPointType(type)) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3058 | bool invert = false; |
| 3059 | |
| 3060 | if (out.Equals(second)) { |
| 3061 | src = first; |
| 3062 | invert = true; |
| 3063 | } else if (out.Equals(first)) { |
| 3064 | src = second; |
| 3065 | } else if (second.IsConstant()) { |
| 3066 | DCHECK(CanEncodeConstantAs8BitImmediate(second.GetConstant())); |
| 3067 | src = second; |
| 3068 | } else if (first.IsConstant()) { |
| 3069 | DCHECK(CanEncodeConstantAs8BitImmediate(first.GetConstant())); |
| 3070 | src = first; |
| 3071 | invert = true; |
| 3072 | } else { |
| 3073 | src = second; |
| 3074 | } |
| 3075 | |
| 3076 | if (CanGenerateConditionalMove(out, src)) { |
| 3077 | if (!out.Equals(first) && !out.Equals(second)) { |
| 3078 | codegen_->MoveLocation(out, src.Equals(first) ? second : first, type); |
| 3079 | } |
| 3080 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3081 | std::pair<vixl32::Condition, vixl32::Condition> cond(eq, ne); |
| 3082 | |
| 3083 | if (IsBooleanValueOrMaterializedCondition(condition)) { |
| 3084 | __ Cmp(InputRegisterAt(select, 2), 0); |
| 3085 | cond = invert ? std::make_pair(eq, ne) : std::make_pair(ne, eq); |
| 3086 | } else { |
| 3087 | cond = GenerateTest(condition->AsCondition(), invert, codegen_); |
| 3088 | } |
| 3089 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3090 | const size_t instr_count = out.IsRegisterPair() ? 4 : 2; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3091 | // We use the scope because of the IT block that follows. |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3092 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 3093 | instr_count * vixl32::k16BitT32InstructionSizeInBytes, |
| 3094 | CodeBufferCheckScope::kExactSize); |
| 3095 | |
| 3096 | if (out.IsRegister()) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3097 | __ it(cond.first); |
| 3098 | __ mov(cond.first, RegisterFrom(out), OperandFrom(src, type)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3099 | } else { |
| 3100 | DCHECK(out.IsRegisterPair()); |
| 3101 | |
| 3102 | Operand operand_high(0); |
| 3103 | Operand operand_low(0); |
| 3104 | |
| 3105 | if (src.IsConstant()) { |
| 3106 | const int64_t value = Int64ConstantFrom(src); |
| 3107 | |
| 3108 | operand_high = High32Bits(value); |
| 3109 | operand_low = Low32Bits(value); |
| 3110 | } else { |
| 3111 | DCHECK(src.IsRegisterPair()); |
| 3112 | operand_high = HighRegisterFrom(src); |
| 3113 | operand_low = LowRegisterFrom(src); |
| 3114 | } |
| 3115 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3116 | __ it(cond.first); |
| 3117 | __ mov(cond.first, LowRegisterFrom(out), operand_low); |
| 3118 | __ it(cond.first); |
| 3119 | __ mov(cond.first, HighRegisterFrom(out), operand_high); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3120 | } |
| 3121 | |
| 3122 | return; |
| 3123 | } |
| 3124 | } |
| 3125 | |
| 3126 | vixl32::Label* false_target = nullptr; |
| 3127 | vixl32::Label* true_target = nullptr; |
| 3128 | vixl32::Label select_end; |
| 3129 | vixl32::Label* const target = codegen_->GetFinalLabel(select, &select_end); |
| 3130 | |
| 3131 | if (out.Equals(second)) { |
| 3132 | true_target = target; |
| 3133 | src = first; |
| 3134 | } else { |
| 3135 | false_target = target; |
| 3136 | src = second; |
| 3137 | |
| 3138 | if (!out.Equals(first)) { |
| 3139 | codegen_->MoveLocation(out, first, type); |
| 3140 | } |
| 3141 | } |
| 3142 | |
| 3143 | GenerateTestAndBranch(select, 2, true_target, false_target, /* far_target */ false); |
| 3144 | codegen_->MoveLocation(out, src, type); |
| 3145 | |
| 3146 | if (select_end.IsReferenced()) { |
| 3147 | __ Bind(&select_end); |
| 3148 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3149 | } |
| 3150 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 3151 | void LocationsBuilderARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3152 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 3153 | } |
| 3154 | |
| 3155 | void InstructionCodeGeneratorARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3156 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| 3157 | } |
| 3158 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3159 | void CodeGeneratorARMVIXL::GenerateNop() { |
| 3160 | __ Nop(); |
| 3161 | } |
| 3162 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3163 | // `temp` is an extra temporary register that is used for some conditions; |
| 3164 | // callers may not specify it, in which case the method will use a scratch |
| 3165 | // register instead. |
| 3166 | void CodeGeneratorARMVIXL::GenerateConditionWithZero(IfCondition condition, |
| 3167 | vixl32::Register out, |
| 3168 | vixl32::Register in, |
| 3169 | vixl32::Register temp) { |
| 3170 | switch (condition) { |
| 3171 | case kCondEQ: |
| 3172 | // x <= 0 iff x == 0 when the comparison is unsigned. |
| 3173 | case kCondBE: |
| 3174 | if (!temp.IsValid() || (out.IsLow() && !out.Is(in))) { |
| 3175 | temp = out; |
| 3176 | } |
| 3177 | |
| 3178 | // Avoid 32-bit instructions if possible; note that `in` and `temp` must be |
| 3179 | // different as well. |
| 3180 | if (in.IsLow() && temp.IsLow() && !in.Is(temp)) { |
| 3181 | // temp = - in; only 0 sets the carry flag. |
| 3182 | __ Rsbs(temp, in, 0); |
| 3183 | |
| 3184 | if (out.Is(in)) { |
| 3185 | std::swap(in, temp); |
| 3186 | } |
| 3187 | |
| 3188 | // out = - in + in + carry = carry |
| 3189 | __ Adc(out, temp, in); |
| 3190 | } else { |
| 3191 | // If `in` is 0, then it has 32 leading zeros, and less than that otherwise. |
| 3192 | __ Clz(out, in); |
| 3193 | // Any number less than 32 logically shifted right by 5 bits results in 0; |
| 3194 | // the same operation on 32 yields 1. |
| 3195 | __ Lsr(out, out, 5); |
| 3196 | } |
| 3197 | |
| 3198 | break; |
| 3199 | case kCondNE: |
| 3200 | // x > 0 iff x != 0 when the comparison is unsigned. |
| 3201 | case kCondA: { |
| 3202 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3203 | |
| 3204 | if (out.Is(in)) { |
| 3205 | if (!temp.IsValid() || in.Is(temp)) { |
| 3206 | temp = temps.Acquire(); |
| 3207 | } |
| 3208 | } else if (!temp.IsValid() || !temp.IsLow()) { |
| 3209 | temp = out; |
| 3210 | } |
| 3211 | |
| 3212 | // temp = in - 1; only 0 does not set the carry flag. |
| 3213 | __ Subs(temp, in, 1); |
| 3214 | // out = in + ~temp + carry = in + (-(in - 1) - 1) + carry = in - in + 1 - 1 + carry = carry |
| 3215 | __ Sbc(out, in, temp); |
| 3216 | break; |
| 3217 | } |
| 3218 | case kCondGE: |
| 3219 | __ Mvn(out, in); |
| 3220 | in = out; |
| 3221 | FALLTHROUGH_INTENDED; |
| 3222 | case kCondLT: |
| 3223 | // We only care about the sign bit. |
| 3224 | __ Lsr(out, in, 31); |
| 3225 | break; |
| 3226 | case kCondAE: |
| 3227 | // Trivially true. |
| 3228 | __ Mov(out, 1); |
| 3229 | break; |
| 3230 | case kCondB: |
| 3231 | // Trivially false. |
| 3232 | __ Mov(out, 0); |
| 3233 | break; |
| 3234 | default: |
| 3235 | LOG(FATAL) << "Unexpected condition " << condition; |
| 3236 | UNREACHABLE(); |
| 3237 | } |
| 3238 | } |
| 3239 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3240 | void LocationsBuilderARMVIXL::HandleCondition(HCondition* cond) { |
| 3241 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3242 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3243 | // Handle the long/FP comparisons made in instruction simplification. |
| 3244 | switch (cond->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3245 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3246 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3247 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 3248 | if (!cond->IsEmittedAtUseSite()) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3249 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3250 | } |
| 3251 | break; |
| 3252 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3253 | case DataType::Type::kFloat32: |
| 3254 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3255 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 3256 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3257 | if (!cond->IsEmittedAtUseSite()) { |
| 3258 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3259 | } |
| 3260 | break; |
| 3261 | |
| 3262 | default: |
| 3263 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3264 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 3265 | if (!cond->IsEmittedAtUseSite()) { |
| 3266 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3267 | } |
| 3268 | } |
| 3269 | } |
| 3270 | |
| 3271 | void InstructionCodeGeneratorARMVIXL::HandleCondition(HCondition* cond) { |
| 3272 | if (cond->IsEmittedAtUseSite()) { |
| 3273 | return; |
| 3274 | } |
| 3275 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3276 | const DataType::Type type = cond->GetLeft()->GetType(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3277 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3278 | if (DataType::IsFloatingPointType(type)) { |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3279 | GenerateConditionGeneric(cond, codegen_); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3280 | return; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3281 | } |
| 3282 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3283 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3284 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3285 | const IfCondition condition = cond->GetCondition(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3286 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3287 | // A condition with only one boolean input, or two boolean inputs without being equality or |
| 3288 | // inequality results from transformations done by the instruction simplifier, and is handled |
| 3289 | // as a regular condition with integral inputs. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3290 | if (type == DataType::Type::kBool && |
| 3291 | cond->GetRight()->GetType() == DataType::Type::kBool && |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3292 | (condition == kCondEQ || condition == kCondNE)) { |
| 3293 | vixl32::Register left = InputRegisterAt(cond, 0); |
| 3294 | const vixl32::Register out = OutputRegister(cond); |
| 3295 | const Location right_loc = cond->GetLocations()->InAt(1); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3296 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3297 | // The constant case is handled by the instruction simplifier. |
| 3298 | DCHECK(!right_loc.IsConstant()); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3299 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3300 | vixl32::Register right = RegisterFrom(right_loc); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3301 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3302 | // Avoid 32-bit instructions if possible. |
| 3303 | if (out.Is(right)) { |
| 3304 | std::swap(left, right); |
| 3305 | } |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3306 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3307 | __ Eor(out, left, right); |
| 3308 | |
| 3309 | if (condition == kCondEQ) { |
| 3310 | __ Eor(out, out, 1); |
| 3311 | } |
| 3312 | |
| 3313 | return; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3314 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 3315 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3316 | GenerateConditionIntegralOrNonPrimitive(cond, codegen_); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3317 | } |
| 3318 | |
| 3319 | void LocationsBuilderARMVIXL::VisitEqual(HEqual* comp) { |
| 3320 | HandleCondition(comp); |
| 3321 | } |
| 3322 | |
| 3323 | void InstructionCodeGeneratorARMVIXL::VisitEqual(HEqual* comp) { |
| 3324 | HandleCondition(comp); |
| 3325 | } |
| 3326 | |
| 3327 | void LocationsBuilderARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 3328 | HandleCondition(comp); |
| 3329 | } |
| 3330 | |
| 3331 | void InstructionCodeGeneratorARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 3332 | HandleCondition(comp); |
| 3333 | } |
| 3334 | |
| 3335 | void LocationsBuilderARMVIXL::VisitLessThan(HLessThan* comp) { |
| 3336 | HandleCondition(comp); |
| 3337 | } |
| 3338 | |
| 3339 | void InstructionCodeGeneratorARMVIXL::VisitLessThan(HLessThan* comp) { |
| 3340 | HandleCondition(comp); |
| 3341 | } |
| 3342 | |
| 3343 | void LocationsBuilderARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 3344 | HandleCondition(comp); |
| 3345 | } |
| 3346 | |
| 3347 | void InstructionCodeGeneratorARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 3348 | HandleCondition(comp); |
| 3349 | } |
| 3350 | |
| 3351 | void LocationsBuilderARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 3352 | HandleCondition(comp); |
| 3353 | } |
| 3354 | |
| 3355 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 3356 | HandleCondition(comp); |
| 3357 | } |
| 3358 | |
| 3359 | void LocationsBuilderARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 3360 | HandleCondition(comp); |
| 3361 | } |
| 3362 | |
| 3363 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 3364 | HandleCondition(comp); |
| 3365 | } |
| 3366 | |
| 3367 | void LocationsBuilderARMVIXL::VisitBelow(HBelow* comp) { |
| 3368 | HandleCondition(comp); |
| 3369 | } |
| 3370 | |
| 3371 | void InstructionCodeGeneratorARMVIXL::VisitBelow(HBelow* comp) { |
| 3372 | HandleCondition(comp); |
| 3373 | } |
| 3374 | |
| 3375 | void LocationsBuilderARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 3376 | HandleCondition(comp); |
| 3377 | } |
| 3378 | |
| 3379 | void InstructionCodeGeneratorARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 3380 | HandleCondition(comp); |
| 3381 | } |
| 3382 | |
| 3383 | void LocationsBuilderARMVIXL::VisitAbove(HAbove* comp) { |
| 3384 | HandleCondition(comp); |
| 3385 | } |
| 3386 | |
| 3387 | void InstructionCodeGeneratorARMVIXL::VisitAbove(HAbove* comp) { |
| 3388 | HandleCondition(comp); |
| 3389 | } |
| 3390 | |
| 3391 | void LocationsBuilderARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 3392 | HandleCondition(comp); |
| 3393 | } |
| 3394 | |
| 3395 | void InstructionCodeGeneratorARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 3396 | HandleCondition(comp); |
| 3397 | } |
| 3398 | |
| 3399 | void LocationsBuilderARMVIXL::VisitIntConstant(HIntConstant* constant) { |
| 3400 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3401 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3402 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3403 | } |
| 3404 | |
| 3405 | void InstructionCodeGeneratorARMVIXL::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 3406 | // Will be generated at use site. |
| 3407 | } |
| 3408 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3409 | void LocationsBuilderARMVIXL::VisitNullConstant(HNullConstant* constant) { |
| 3410 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3411 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3412 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3413 | } |
| 3414 | |
| 3415 | void InstructionCodeGeneratorARMVIXL::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 3416 | // Will be generated at use site. |
| 3417 | } |
| 3418 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3419 | void LocationsBuilderARMVIXL::VisitLongConstant(HLongConstant* constant) { |
| 3420 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3421 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3422 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3423 | } |
| 3424 | |
| 3425 | void InstructionCodeGeneratorARMVIXL::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 3426 | // Will be generated at use site. |
| 3427 | } |
| 3428 | |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3429 | void LocationsBuilderARMVIXL::VisitFloatConstant(HFloatConstant* constant) { |
| 3430 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3431 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3432 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3433 | } |
| 3434 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3435 | void InstructionCodeGeneratorARMVIXL::VisitFloatConstant( |
| 3436 | HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3437 | // Will be generated at use site. |
| 3438 | } |
| 3439 | |
| 3440 | void LocationsBuilderARMVIXL::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3441 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3442 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3443 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3444 | } |
| 3445 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3446 | void InstructionCodeGeneratorARMVIXL::VisitDoubleConstant( |
| 3447 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3448 | // Will be generated at use site. |
| 3449 | } |
| 3450 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 3451 | void LocationsBuilderARMVIXL::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 3452 | constructor_fence->SetLocations(nullptr); |
| 3453 | } |
| 3454 | |
| 3455 | void InstructionCodeGeneratorARMVIXL::VisitConstructorFence( |
| 3456 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 3457 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 3458 | } |
| 3459 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3460 | void LocationsBuilderARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3461 | memory_barrier->SetLocations(nullptr); |
| 3462 | } |
| 3463 | |
| 3464 | void InstructionCodeGeneratorARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3465 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 3466 | } |
| 3467 | |
| 3468 | void LocationsBuilderARMVIXL::VisitReturnVoid(HReturnVoid* ret) { |
| 3469 | ret->SetLocations(nullptr); |
| 3470 | } |
| 3471 | |
| 3472 | void InstructionCodeGeneratorARMVIXL::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 3473 | codegen_->GenerateFrameExit(); |
| 3474 | } |
| 3475 | |
| 3476 | void LocationsBuilderARMVIXL::VisitReturn(HReturn* ret) { |
| 3477 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3478 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3479 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
| 3480 | } |
| 3481 | |
| 3482 | void InstructionCodeGeneratorARMVIXL::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 3483 | codegen_->GenerateFrameExit(); |
| 3484 | } |
| 3485 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3486 | void LocationsBuilderARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3487 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3488 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3489 | // the method_idx. |
| 3490 | HandleInvoke(invoke); |
| 3491 | } |
| 3492 | |
| 3493 | void InstructionCodeGeneratorARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3494 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3495 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 3); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3496 | } |
| 3497 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3498 | void LocationsBuilderARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3499 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3500 | // art::PrepareForRegisterAllocation. |
| 3501 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 3502 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3503 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3504 | if (intrinsic.TryDispatch(invoke)) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3505 | return; |
| 3506 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3507 | |
| 3508 | HandleInvoke(invoke); |
| 3509 | } |
| 3510 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3511 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARMVIXL* codegen) { |
| 3512 | if (invoke->GetLocations()->Intrinsified()) { |
| 3513 | IntrinsicCodeGeneratorARMVIXL intrinsic(codegen); |
| 3514 | intrinsic.Dispatch(invoke); |
| 3515 | return true; |
| 3516 | } |
| 3517 | return false; |
| 3518 | } |
| 3519 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3520 | void InstructionCodeGeneratorARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3521 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3522 | // art::PrepareForRegisterAllocation. |
| 3523 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 3524 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3525 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3526 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 4); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3527 | return; |
| 3528 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3529 | |
| 3530 | LocationSummary* locations = invoke->GetLocations(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3531 | codegen_->GenerateStaticOrDirectCall( |
| 3532 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3533 | |
| 3534 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 5); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3535 | } |
| 3536 | |
| 3537 | void LocationsBuilderARMVIXL::HandleInvoke(HInvoke* invoke) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3538 | InvokeDexCallingConventionVisitorARMVIXL calling_convention_visitor; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3539 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 3540 | } |
| 3541 | |
| 3542 | void LocationsBuilderARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3543 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3544 | if (intrinsic.TryDispatch(invoke)) { |
| 3545 | return; |
| 3546 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3547 | |
| 3548 | HandleInvoke(invoke); |
| 3549 | } |
| 3550 | |
| 3551 | void InstructionCodeGeneratorARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3552 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3553 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 6); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3554 | return; |
| 3555 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3556 | |
| 3557 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3558 | DCHECK(!codegen_->IsLeafMethod()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3559 | |
| 3560 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 7); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3561 | } |
| 3562 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3563 | void LocationsBuilderARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3564 | HandleInvoke(invoke); |
| 3565 | // Add the hidden argument. |
| 3566 | invoke->GetLocations()->AddTemp(LocationFrom(r12)); |
| 3567 | } |
| 3568 | |
| 3569 | void InstructionCodeGeneratorARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3570 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 3571 | LocationSummary* locations = invoke->GetLocations(); |
| 3572 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 3573 | vixl32::Register hidden_reg = RegisterFrom(locations->GetTemp(1)); |
| 3574 | Location receiver = locations->InAt(0); |
| 3575 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3576 | |
| 3577 | DCHECK(!receiver.IsStackSlot()); |
| 3578 | |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3579 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
| 3580 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 3581 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 3582 | vixl32::kMaxInstructionSizeInBytes, |
| 3583 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3584 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 3585 | __ ldr(temp, MemOperand(RegisterFrom(receiver), class_offset)); |
| 3586 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 3587 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3588 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3589 | // emit a read barrier for the previous class reference load. |
| 3590 | // However this is not required in practice, as this is an |
| 3591 | // intermediate/temporary reference and because the current |
| 3592 | // concurrent copying collector keeps the from-space memory |
| 3593 | // intact/accessible until the end of the marking phase (the |
| 3594 | // concurrent copying collector may not in the future). |
| 3595 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 3596 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3597 | temp, |
| 3598 | temp, |
| 3599 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 3600 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 3601 | invoke->GetImtIndex(), kArmPointerSize)); |
| 3602 | // temp = temp->GetImtEntryAt(method_offset); |
| 3603 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 3604 | uint32_t entry_point = |
| 3605 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
| 3606 | // LR = temp->GetEntryPoint(); |
| 3607 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
| 3608 | |
| 3609 | // Set the hidden (in r12) argument. It is done here, right before a BLX to prevent other |
| 3610 | // instruction from clobbering it as they might use r12 as a scratch register. |
| 3611 | DCHECK(hidden_reg.Is(r12)); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3612 | |
| 3613 | { |
| 3614 | // The VIXL macro assembler may clobber any of the scratch registers that are available to it, |
| 3615 | // so it checks if the application is using them (by passing them to the macro assembler |
| 3616 | // methods). The following application of UseScratchRegisterScope corrects VIXL's notion of |
| 3617 | // what is available, and is the opposite of the standard usage: Instead of requesting a |
| 3618 | // temporary location, it imposes an external constraint (i.e. a specific register is reserved |
| 3619 | // for the hidden argument). Note that this works even if VIXL needs a scratch register itself |
| 3620 | // (to materialize the constant), since the destination register becomes available for such use |
| 3621 | // internally for the duration of the macro instruction. |
| 3622 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3623 | temps.Exclude(hidden_reg); |
| 3624 | __ Mov(hidden_reg, invoke->GetDexMethodIndex()); |
| 3625 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3626 | { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3627 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 3628 | // 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] | 3629 | ExactAssemblyScope aas(GetVIXLAssembler(), |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3630 | vixl32::k16BitT32InstructionSizeInBytes, |
| 3631 | CodeBufferCheckScope::kExactSize); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3632 | // LR(); |
| 3633 | __ blx(lr); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3634 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3635 | DCHECK(!codegen_->IsLeafMethod()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3636 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3637 | |
| 3638 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 8); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3639 | } |
| 3640 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3641 | void LocationsBuilderARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3642 | HandleInvoke(invoke); |
| 3643 | } |
| 3644 | |
| 3645 | void InstructionCodeGeneratorARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3646 | codegen_->GenerateInvokePolymorphicCall(invoke); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3647 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 9); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3648 | } |
| 3649 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3650 | void LocationsBuilderARMVIXL::VisitNeg(HNeg* neg) { |
| 3651 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3652 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3653 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3654 | case DataType::Type::kInt32: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3655 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3656 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3657 | break; |
| 3658 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3659 | case DataType::Type::kInt64: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3660 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3661 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3662 | break; |
| 3663 | } |
| 3664 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3665 | case DataType::Type::kFloat32: |
| 3666 | case DataType::Type::kFloat64: |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3667 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3668 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3669 | break; |
| 3670 | |
| 3671 | default: |
| 3672 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3673 | } |
| 3674 | } |
| 3675 | |
| 3676 | void InstructionCodeGeneratorARMVIXL::VisitNeg(HNeg* neg) { |
| 3677 | LocationSummary* locations = neg->GetLocations(); |
| 3678 | Location out = locations->Out(); |
| 3679 | Location in = locations->InAt(0); |
| 3680 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3681 | case DataType::Type::kInt32: |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3682 | __ Rsb(OutputRegister(neg), InputRegisterAt(neg, 0), 0); |
| 3683 | break; |
| 3684 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3685 | case DataType::Type::kInt64: |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3686 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 3687 | __ Rsbs(LowRegisterFrom(out), LowRegisterFrom(in), 0); |
| 3688 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 3689 | // instruction here, as it does not exist in the Thumb-2 |
| 3690 | // instruction set. We use the following approach |
| 3691 | // using SBC and SUB instead. |
| 3692 | // |
| 3693 | // out.hi = -C |
| 3694 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(out)); |
| 3695 | // out.hi = out.hi - in.hi |
| 3696 | __ Sub(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(in)); |
| 3697 | break; |
| 3698 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3699 | case DataType::Type::kFloat32: |
| 3700 | case DataType::Type::kFloat64: |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 3701 | __ Vneg(OutputVRegister(neg), InputVRegister(neg)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3702 | break; |
| 3703 | |
| 3704 | default: |
| 3705 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3706 | } |
| 3707 | } |
| 3708 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3709 | void LocationsBuilderARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3710 | DataType::Type result_type = conversion->GetResultType(); |
| 3711 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3712 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 3713 | << input_type << " -> " << result_type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3714 | |
| 3715 | // The float-to-long, double-to-long and long-to-float type conversions |
| 3716 | // rely on a call to the runtime. |
| 3717 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3718 | (((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) |
| 3719 | && result_type == DataType::Type::kInt64) |
| 3720 | || (input_type == DataType::Type::kInt64 && result_type == DataType::Type::kFloat32)) |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3721 | ? LocationSummary::kCallOnMainOnly |
| 3722 | : LocationSummary::kNoCall; |
| 3723 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3724 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3725 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3726 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3727 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3728 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3729 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3730 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3731 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 3732 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3733 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3734 | break; |
| 3735 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3736 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3737 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3738 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3739 | locations->SetInAt(0, Location::Any()); |
| 3740 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3741 | break; |
| 3742 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3743 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3744 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3745 | locations->SetOut(Location::RequiresRegister()); |
| 3746 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3747 | break; |
| 3748 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3749 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3750 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3751 | locations->SetOut(Location::RequiresRegister()); |
| 3752 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3753 | break; |
| 3754 | |
| 3755 | default: |
| 3756 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3757 | << " to " << result_type; |
| 3758 | } |
| 3759 | break; |
| 3760 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3761 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3762 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3763 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3764 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3765 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3766 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3767 | case DataType::Type::kInt16: |
| 3768 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3769 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3770 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3771 | break; |
| 3772 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3773 | case DataType::Type::kFloat32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3774 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3775 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 3776 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3777 | break; |
| 3778 | } |
| 3779 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3780 | case DataType::Type::kFloat64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3781 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3782 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0), |
| 3783 | calling_convention.GetFpuRegisterAt(1))); |
| 3784 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3785 | break; |
| 3786 | } |
| 3787 | |
| 3788 | default: |
| 3789 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3790 | << " to " << result_type; |
| 3791 | } |
| 3792 | break; |
| 3793 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3794 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3795 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3796 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3797 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3798 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3799 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3800 | case DataType::Type::kInt16: |
| 3801 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3802 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3803 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3804 | break; |
| 3805 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3806 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3807 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3808 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0), |
| 3809 | calling_convention.GetRegisterAt(1))); |
| 3810 | locations->SetOut(LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3811 | break; |
| 3812 | } |
| 3813 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3814 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3815 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3816 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3817 | break; |
| 3818 | |
| 3819 | default: |
| 3820 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3821 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3822 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3823 | break; |
| 3824 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3825 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3826 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3827 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3828 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3829 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3830 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3831 | case DataType::Type::kInt16: |
| 3832 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3833 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3834 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3835 | break; |
| 3836 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3837 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3838 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3839 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3840 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3841 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3842 | break; |
| 3843 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3844 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3845 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3846 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3847 | break; |
| 3848 | |
| 3849 | default: |
| 3850 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3851 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3852 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3853 | break; |
| 3854 | |
| 3855 | default: |
| 3856 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3857 | << " to " << result_type; |
| 3858 | } |
| 3859 | } |
| 3860 | |
| 3861 | void InstructionCodeGeneratorARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
| 3862 | LocationSummary* locations = conversion->GetLocations(); |
| 3863 | Location out = locations->Out(); |
| 3864 | Location in = locations->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3865 | DataType::Type result_type = conversion->GetResultType(); |
| 3866 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3867 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 3868 | << input_type << " -> " << result_type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3869 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3870 | case DataType::Type::kUint8: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3871 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3872 | case DataType::Type::kInt8: |
| 3873 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3874 | case DataType::Type::kInt16: |
| 3875 | case DataType::Type::kInt32: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3876 | __ Ubfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 8); |
| 3877 | break; |
| 3878 | case DataType::Type::kInt64: |
| 3879 | __ Ubfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 8); |
| 3880 | break; |
| 3881 | |
| 3882 | default: |
| 3883 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3884 | << " to " << result_type; |
| 3885 | } |
| 3886 | break; |
| 3887 | |
| 3888 | case DataType::Type::kInt8: |
| 3889 | switch (input_type) { |
| 3890 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3891 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3892 | case DataType::Type::kInt16: |
| 3893 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3894 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 8); |
| 3895 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3896 | case DataType::Type::kInt64: |
| 3897 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 8); |
| 3898 | break; |
| 3899 | |
| 3900 | default: |
| 3901 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3902 | << " to " << result_type; |
| 3903 | } |
| 3904 | break; |
| 3905 | |
| 3906 | case DataType::Type::kUint16: |
| 3907 | switch (input_type) { |
| 3908 | case DataType::Type::kInt8: |
| 3909 | case DataType::Type::kInt16: |
| 3910 | case DataType::Type::kInt32: |
| 3911 | __ Ubfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 3912 | break; |
| 3913 | case DataType::Type::kInt64: |
| 3914 | __ Ubfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
| 3915 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3916 | |
| 3917 | default: |
| 3918 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3919 | << " to " << result_type; |
| 3920 | } |
| 3921 | break; |
| 3922 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3923 | case DataType::Type::kInt16: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3924 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3925 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3926 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3927 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 3928 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3929 | case DataType::Type::kInt64: |
| 3930 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
| 3931 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3932 | |
| 3933 | default: |
| 3934 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3935 | << " to " << result_type; |
| 3936 | } |
| 3937 | break; |
| 3938 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3939 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3940 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3941 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3942 | DCHECK(out.IsRegister()); |
| 3943 | if (in.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3944 | __ Mov(OutputRegister(conversion), LowRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3945 | } else if (in.IsDoubleStackSlot()) { |
| 3946 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3947 | OutputRegister(conversion), |
| 3948 | sp, |
| 3949 | in.GetStackIndex()); |
| 3950 | } else { |
| 3951 | DCHECK(in.IsConstant()); |
| 3952 | DCHECK(in.GetConstant()->IsLongConstant()); |
Vladimir Marko | ba1a48e | 2017-04-13 11:50:14 +0100 | [diff] [blame] | 3953 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3954 | __ Mov(OutputRegister(conversion), static_cast<int32_t>(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3955 | } |
| 3956 | break; |
| 3957 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3958 | case DataType::Type::kFloat32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3959 | vixl32::SRegister temp = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3960 | __ Vcvt(S32, F32, temp, InputSRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3961 | __ Vmov(OutputRegister(conversion), temp); |
| 3962 | break; |
| 3963 | } |
| 3964 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3965 | case DataType::Type::kFloat64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3966 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3967 | __ Vcvt(S32, F64, temp_s, DRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3968 | __ Vmov(OutputRegister(conversion), temp_s); |
| 3969 | break; |
| 3970 | } |
| 3971 | |
| 3972 | default: |
| 3973 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3974 | << " to " << result_type; |
| 3975 | } |
| 3976 | break; |
| 3977 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3978 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3979 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3980 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3981 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3982 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3983 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3984 | case DataType::Type::kInt16: |
| 3985 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3986 | DCHECK(out.IsRegisterPair()); |
| 3987 | DCHECK(in.IsRegister()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3988 | __ Mov(LowRegisterFrom(out), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3989 | // Sign extension. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3990 | __ Asr(HighRegisterFrom(out), LowRegisterFrom(out), 31); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3991 | break; |
| 3992 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3993 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3994 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
| 3995 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 3996 | break; |
| 3997 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3998 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3999 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
| 4000 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 4001 | break; |
| 4002 | |
| 4003 | default: |
| 4004 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4005 | << " to " << result_type; |
| 4006 | } |
| 4007 | break; |
| 4008 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4009 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4010 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4011 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4012 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4013 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4014 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4015 | case DataType::Type::kInt16: |
| 4016 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4017 | __ Vmov(OutputSRegister(conversion), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4018 | __ Vcvt(F32, S32, OutputSRegister(conversion), OutputSRegister(conversion)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4019 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4020 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4021 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4022 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
| 4023 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 4024 | break; |
| 4025 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4026 | case DataType::Type::kFloat64: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4027 | __ Vcvt(F32, F64, OutputSRegister(conversion), DRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4028 | break; |
| 4029 | |
| 4030 | default: |
| 4031 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4032 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 4033 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4034 | break; |
| 4035 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4036 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4037 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4038 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4039 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4040 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4041 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4042 | case DataType::Type::kInt16: |
| 4043 | case DataType::Type::kInt32: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4044 | __ Vmov(LowSRegisterFrom(out), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4045 | __ Vcvt(F64, S32, DRegisterFrom(out), LowSRegisterFrom(out)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4046 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4047 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4048 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4049 | vixl32::Register low = LowRegisterFrom(in); |
| 4050 | vixl32::Register high = HighRegisterFrom(in); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4051 | vixl32::SRegister out_s = LowSRegisterFrom(out); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4052 | vixl32::DRegister out_d = DRegisterFrom(out); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4053 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4054 | vixl32::DRegister temp_d = DRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4055 | vixl32::DRegister constant_d = DRegisterFrom(locations->GetTemp(1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4056 | |
| 4057 | // temp_d = int-to-double(high) |
| 4058 | __ Vmov(temp_s, high); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4059 | __ Vcvt(F64, S32, temp_d, temp_s); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4060 | // constant_d = k2Pow32EncodingForDouble |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4061 | __ Vmov(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4062 | // out_d = unsigned-to-double(low) |
| 4063 | __ Vmov(out_s, low); |
| 4064 | __ Vcvt(F64, U32, out_d, out_s); |
| 4065 | // out_d += temp_d * constant_d |
| 4066 | __ Vmla(F64, out_d, temp_d, constant_d); |
| 4067 | break; |
| 4068 | } |
| 4069 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4070 | case DataType::Type::kFloat32: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4071 | __ Vcvt(F64, F32, DRegisterFrom(out), InputSRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4072 | break; |
| 4073 | |
| 4074 | default: |
| 4075 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4076 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 4077 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4078 | break; |
| 4079 | |
| 4080 | default: |
| 4081 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4082 | << " to " << result_type; |
| 4083 | } |
| 4084 | } |
| 4085 | |
| 4086 | void LocationsBuilderARMVIXL::VisitAdd(HAdd* add) { |
| 4087 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4088 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4089 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4090 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4091 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4092 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 4093 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4094 | break; |
| 4095 | } |
| 4096 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4097 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4098 | locations->SetInAt(0, Location::RequiresRegister()); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4099 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4100 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4101 | break; |
| 4102 | } |
| 4103 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4104 | case DataType::Type::kFloat32: |
| 4105 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4106 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4107 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4108 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4109 | break; |
| 4110 | } |
| 4111 | |
| 4112 | default: |
| 4113 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 4114 | } |
| 4115 | } |
| 4116 | |
| 4117 | void InstructionCodeGeneratorARMVIXL::VisitAdd(HAdd* add) { |
| 4118 | LocationSummary* locations = add->GetLocations(); |
| 4119 | Location out = locations->Out(); |
| 4120 | Location first = locations->InAt(0); |
| 4121 | Location second = locations->InAt(1); |
| 4122 | |
| 4123 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4124 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4125 | __ Add(OutputRegister(add), InputRegisterAt(add, 0), InputOperandAt(add, 1)); |
| 4126 | } |
| 4127 | break; |
| 4128 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4129 | case DataType::Type::kInt64: { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4130 | if (second.IsConstant()) { |
| 4131 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 4132 | GenerateAddLongConst(out, first, value); |
| 4133 | } else { |
| 4134 | DCHECK(second.IsRegisterPair()); |
| 4135 | __ Adds(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 4136 | __ Adc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 4137 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4138 | break; |
| 4139 | } |
| 4140 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4141 | case DataType::Type::kFloat32: |
| 4142 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4143 | __ Vadd(OutputVRegister(add), InputVRegisterAt(add, 0), InputVRegisterAt(add, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4144 | break; |
| 4145 | |
| 4146 | default: |
| 4147 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 4148 | } |
| 4149 | } |
| 4150 | |
| 4151 | void LocationsBuilderARMVIXL::VisitSub(HSub* sub) { |
| 4152 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4153 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4154 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4155 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4156 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4157 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
| 4158 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4159 | break; |
| 4160 | } |
| 4161 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4162 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4163 | locations->SetInAt(0, Location::RequiresRegister()); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4164 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4165 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4166 | break; |
| 4167 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4168 | case DataType::Type::kFloat32: |
| 4169 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4170 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4171 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4172 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4173 | break; |
| 4174 | } |
| 4175 | default: |
| 4176 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 4177 | } |
| 4178 | } |
| 4179 | |
| 4180 | void InstructionCodeGeneratorARMVIXL::VisitSub(HSub* sub) { |
| 4181 | LocationSummary* locations = sub->GetLocations(); |
| 4182 | Location out = locations->Out(); |
| 4183 | Location first = locations->InAt(0); |
| 4184 | Location second = locations->InAt(1); |
| 4185 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4186 | case DataType::Type::kInt32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4187 | __ Sub(OutputRegister(sub), InputRegisterAt(sub, 0), InputOperandAt(sub, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4188 | break; |
| 4189 | } |
| 4190 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4191 | case DataType::Type::kInt64: { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4192 | if (second.IsConstant()) { |
| 4193 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 4194 | GenerateAddLongConst(out, first, -value); |
| 4195 | } else { |
| 4196 | DCHECK(second.IsRegisterPair()); |
| 4197 | __ Subs(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 4198 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 4199 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4200 | break; |
| 4201 | } |
| 4202 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4203 | case DataType::Type::kFloat32: |
| 4204 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4205 | __ Vsub(OutputVRegister(sub), InputVRegisterAt(sub, 0), InputVRegisterAt(sub, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4206 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4207 | |
| 4208 | default: |
| 4209 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 4210 | } |
| 4211 | } |
| 4212 | |
| 4213 | void LocationsBuilderARMVIXL::VisitMul(HMul* mul) { |
| 4214 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4215 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4216 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4217 | case DataType::Type::kInt32: |
| 4218 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4219 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4220 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4221 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4222 | break; |
| 4223 | } |
| 4224 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4225 | case DataType::Type::kFloat32: |
| 4226 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4227 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4228 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4229 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4230 | break; |
| 4231 | } |
| 4232 | |
| 4233 | default: |
| 4234 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4235 | } |
| 4236 | } |
| 4237 | |
| 4238 | void InstructionCodeGeneratorARMVIXL::VisitMul(HMul* mul) { |
| 4239 | LocationSummary* locations = mul->GetLocations(); |
| 4240 | Location out = locations->Out(); |
| 4241 | Location first = locations->InAt(0); |
| 4242 | Location second = locations->InAt(1); |
| 4243 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4244 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4245 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 4246 | break; |
| 4247 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4248 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4249 | vixl32::Register out_hi = HighRegisterFrom(out); |
| 4250 | vixl32::Register out_lo = LowRegisterFrom(out); |
| 4251 | vixl32::Register in1_hi = HighRegisterFrom(first); |
| 4252 | vixl32::Register in1_lo = LowRegisterFrom(first); |
| 4253 | vixl32::Register in2_hi = HighRegisterFrom(second); |
| 4254 | vixl32::Register in2_lo = LowRegisterFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4255 | |
| 4256 | // Extra checks to protect caused by the existence of R1_R2. |
| 4257 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 4258 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4259 | DCHECK(!out_hi.Is(in1_lo)); |
| 4260 | DCHECK(!out_hi.Is(in2_lo)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4261 | |
| 4262 | // input: in1 - 64 bits, in2 - 64 bits |
| 4263 | // output: out |
| 4264 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 4265 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 4266 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 4267 | |
| 4268 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4269 | vixl32::Register temp = temps.Acquire(); |
| 4270 | // temp <- in1.lo * in2.hi |
| 4271 | __ Mul(temp, in1_lo, in2_hi); |
| 4272 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 4273 | __ Mla(out_hi, in1_hi, in2_lo, temp); |
| 4274 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 4275 | __ Umull(out_lo, temp, in1_lo, in2_lo); |
| 4276 | // 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] | 4277 | __ Add(out_hi, out_hi, temp); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4278 | break; |
| 4279 | } |
| 4280 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4281 | case DataType::Type::kFloat32: |
| 4282 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4283 | __ Vmul(OutputVRegister(mul), InputVRegisterAt(mul, 0), InputVRegisterAt(mul, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4284 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4285 | |
| 4286 | default: |
| 4287 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4288 | } |
| 4289 | } |
| 4290 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4291 | void InstructionCodeGeneratorARMVIXL::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 4292 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4293 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4294 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4295 | Location second = instruction->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4296 | DCHECK(second.IsConstant()); |
| 4297 | |
| 4298 | vixl32::Register out = OutputRegister(instruction); |
| 4299 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4300 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4301 | DCHECK(imm == 1 || imm == -1); |
| 4302 | |
| 4303 | if (instruction->IsRem()) { |
| 4304 | __ Mov(out, 0); |
| 4305 | } else { |
| 4306 | if (imm == 1) { |
| 4307 | __ Mov(out, dividend); |
| 4308 | } else { |
| 4309 | __ Rsb(out, dividend, 0); |
| 4310 | } |
| 4311 | } |
| 4312 | } |
| 4313 | |
| 4314 | void InstructionCodeGeneratorARMVIXL::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 4315 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4316 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4317 | |
| 4318 | LocationSummary* locations = instruction->GetLocations(); |
| 4319 | Location second = locations->InAt(1); |
| 4320 | DCHECK(second.IsConstant()); |
| 4321 | |
| 4322 | vixl32::Register out = OutputRegister(instruction); |
| 4323 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4324 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4325 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4326 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 4327 | int ctz_imm = CTZ(abs_imm); |
| 4328 | |
| 4329 | if (ctz_imm == 1) { |
| 4330 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 4331 | } else { |
| 4332 | __ Asr(temp, dividend, 31); |
| 4333 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 4334 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4335 | __ Add(out, temp, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4336 | |
| 4337 | if (instruction->IsDiv()) { |
| 4338 | __ Asr(out, out, ctz_imm); |
| 4339 | if (imm < 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4340 | __ Rsb(out, out, 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4341 | } |
| 4342 | } else { |
| 4343 | __ Ubfx(out, out, 0, ctz_imm); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4344 | __ Sub(out, out, temp); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4345 | } |
| 4346 | } |
| 4347 | |
| 4348 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 4349 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4350 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4351 | |
| 4352 | LocationSummary* locations = instruction->GetLocations(); |
| 4353 | Location second = locations->InAt(1); |
| 4354 | DCHECK(second.IsConstant()); |
| 4355 | |
| 4356 | vixl32::Register out = OutputRegister(instruction); |
| 4357 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4358 | vixl32::Register temp1 = RegisterFrom(locations->GetTemp(0)); |
| 4359 | vixl32::Register temp2 = RegisterFrom(locations->GetTemp(1)); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4360 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4361 | |
| 4362 | int64_t magic; |
| 4363 | int shift; |
| 4364 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 4365 | |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4366 | // TODO(VIXL): Change the static cast to Operand::From() after VIXL is fixed. |
| 4367 | __ Mov(temp1, static_cast<int32_t>(magic)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4368 | __ Smull(temp2, temp1, dividend, temp1); |
| 4369 | |
| 4370 | if (imm > 0 && magic < 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4371 | __ Add(temp1, temp1, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4372 | } else if (imm < 0 && magic > 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4373 | __ Sub(temp1, temp1, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4374 | } |
| 4375 | |
| 4376 | if (shift != 0) { |
| 4377 | __ Asr(temp1, temp1, shift); |
| 4378 | } |
| 4379 | |
| 4380 | if (instruction->IsDiv()) { |
| 4381 | __ Sub(out, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 4382 | } else { |
| 4383 | __ Sub(temp1, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 4384 | // TODO: Strength reduction for mls. |
| 4385 | __ Mov(temp2, imm); |
| 4386 | __ Mls(out, temp1, temp2, dividend); |
| 4387 | } |
| 4388 | } |
| 4389 | |
| 4390 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemConstantIntegral( |
| 4391 | HBinaryOperation* instruction) { |
| 4392 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4393 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4394 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4395 | Location second = instruction->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4396 | DCHECK(second.IsConstant()); |
| 4397 | |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4398 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4399 | if (imm == 0) { |
| 4400 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4401 | } else if (imm == 1 || imm == -1) { |
| 4402 | DivRemOneOrMinusOne(instruction); |
| 4403 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 4404 | DivRemByPowerOfTwo(instruction); |
| 4405 | } else { |
| 4406 | DCHECK(imm <= -2 || imm >= 2); |
| 4407 | GenerateDivRemWithAnyConstant(instruction); |
| 4408 | } |
| 4409 | } |
| 4410 | |
| 4411 | void LocationsBuilderARMVIXL::VisitDiv(HDiv* div) { |
| 4412 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4413 | if (div->GetResultType() == DataType::Type::kInt64) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4414 | // pLdiv runtime call. |
| 4415 | call_kind = LocationSummary::kCallOnMainOnly; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4416 | } else if (div->GetResultType() == DataType::Type::kInt32 && div->InputAt(1)->IsConstant()) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4417 | // sdiv will be replaced by other instruction sequence. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4418 | } else if (div->GetResultType() == DataType::Type::kInt32 && |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4419 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4420 | // pIdivmod runtime call. |
| 4421 | call_kind = LocationSummary::kCallOnMainOnly; |
| 4422 | } |
| 4423 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4424 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4425 | |
| 4426 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4427 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4428 | if (div->InputAt(1)->IsConstant()) { |
| 4429 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4430 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
| 4431 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4432 | int32_t value = Int32ConstantFrom(div->InputAt(1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4433 | if (value == 1 || value == 0 || value == -1) { |
| 4434 | // No temp register required. |
| 4435 | } else { |
| 4436 | locations->AddTemp(Location::RequiresRegister()); |
| 4437 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
| 4438 | locations->AddTemp(Location::RequiresRegister()); |
| 4439 | } |
| 4440 | } |
| 4441 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4442 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4443 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4444 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4445 | } else { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4446 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4447 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4448 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4449 | // 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] | 4450 | // we only need the former. |
| 4451 | locations->SetOut(LocationFrom(r0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4452 | } |
| 4453 | break; |
| 4454 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4455 | case DataType::Type::kInt64: { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4456 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4457 | locations->SetInAt(0, LocationFrom( |
| 4458 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4459 | locations->SetInAt(1, LocationFrom( |
| 4460 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4461 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4462 | break; |
| 4463 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4464 | case DataType::Type::kFloat32: |
| 4465 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4466 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4467 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4468 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4469 | break; |
| 4470 | } |
| 4471 | |
| 4472 | default: |
| 4473 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4474 | } |
| 4475 | } |
| 4476 | |
| 4477 | void InstructionCodeGeneratorARMVIXL::VisitDiv(HDiv* div) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4478 | Location lhs = div->GetLocations()->InAt(0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4479 | Location rhs = div->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4480 | |
| 4481 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4482 | case DataType::Type::kInt32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4483 | if (rhs.IsConstant()) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4484 | GenerateDivRemConstantIntegral(div); |
| 4485 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4486 | __ Sdiv(OutputRegister(div), InputRegisterAt(div, 0), InputRegisterAt(div, 1)); |
| 4487 | } else { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4488 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4489 | DCHECK(calling_convention.GetRegisterAt(0).Is(RegisterFrom(lhs))); |
| 4490 | DCHECK(calling_convention.GetRegisterAt(1).Is(RegisterFrom(rhs))); |
| 4491 | DCHECK(r0.Is(OutputRegister(div))); |
| 4492 | |
| 4493 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
| 4494 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4495 | } |
| 4496 | break; |
| 4497 | } |
| 4498 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4499 | case DataType::Type::kInt64: { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4500 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4501 | DCHECK(calling_convention.GetRegisterAt(0).Is(LowRegisterFrom(lhs))); |
| 4502 | DCHECK(calling_convention.GetRegisterAt(1).Is(HighRegisterFrom(lhs))); |
| 4503 | DCHECK(calling_convention.GetRegisterAt(2).Is(LowRegisterFrom(rhs))); |
| 4504 | DCHECK(calling_convention.GetRegisterAt(3).Is(HighRegisterFrom(rhs))); |
| 4505 | DCHECK(LowRegisterFrom(div->GetLocations()->Out()).Is(r0)); |
| 4506 | DCHECK(HighRegisterFrom(div->GetLocations()->Out()).Is(r1)); |
| 4507 | |
| 4508 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
| 4509 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4510 | break; |
| 4511 | } |
| 4512 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4513 | case DataType::Type::kFloat32: |
| 4514 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4515 | __ Vdiv(OutputVRegister(div), InputVRegisterAt(div, 0), InputVRegisterAt(div, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4516 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4517 | |
| 4518 | default: |
| 4519 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4520 | } |
| 4521 | } |
| 4522 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4523 | void LocationsBuilderARMVIXL::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4524 | DataType::Type type = rem->GetResultType(); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4525 | |
| 4526 | // Most remainders are implemented in the runtime. |
| 4527 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4528 | if (rem->GetResultType() == DataType::Type::kInt32 && rem->InputAt(1)->IsConstant()) { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4529 | // sdiv will be replaced by other instruction sequence. |
| 4530 | call_kind = LocationSummary::kNoCall; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4531 | } else if ((rem->GetResultType() == DataType::Type::kInt32) |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4532 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4533 | // Have hardware divide instruction for int, do it with three instructions. |
| 4534 | call_kind = LocationSummary::kNoCall; |
| 4535 | } |
| 4536 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4537 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4538 | |
| 4539 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4540 | case DataType::Type::kInt32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4541 | if (rem->InputAt(1)->IsConstant()) { |
| 4542 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4543 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
| 4544 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4545 | int32_t value = Int32ConstantFrom(rem->InputAt(1)); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4546 | if (value == 1 || value == 0 || value == -1) { |
| 4547 | // No temp register required. |
| 4548 | } else { |
| 4549 | locations->AddTemp(Location::RequiresRegister()); |
| 4550 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
| 4551 | locations->AddTemp(Location::RequiresRegister()); |
| 4552 | } |
| 4553 | } |
| 4554 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4555 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4556 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4557 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4558 | locations->AddTemp(Location::RequiresRegister()); |
| 4559 | } else { |
| 4560 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4561 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4562 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4563 | // Note: divmod will compute both the quotient and the remainder as the pair R0 and R1, but |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4564 | // we only need the latter. |
| 4565 | locations->SetOut(LocationFrom(r1)); |
| 4566 | } |
| 4567 | break; |
| 4568 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4569 | case DataType::Type::kInt64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4570 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4571 | locations->SetInAt(0, LocationFrom( |
| 4572 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4573 | locations->SetInAt(1, LocationFrom( |
| 4574 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4575 | // The runtime helper puts the output in R2,R3. |
| 4576 | locations->SetOut(LocationFrom(r2, r3)); |
| 4577 | break; |
| 4578 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4579 | case DataType::Type::kFloat32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4580 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4581 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 4582 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 4583 | locations->SetOut(LocationFrom(s0)); |
| 4584 | break; |
| 4585 | } |
| 4586 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4587 | case DataType::Type::kFloat64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4588 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4589 | locations->SetInAt(0, LocationFrom( |
| 4590 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 4591 | locations->SetInAt(1, LocationFrom( |
| 4592 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 4593 | locations->SetOut(LocationFrom(s0, s1)); |
| 4594 | break; |
| 4595 | } |
| 4596 | |
| 4597 | default: |
| 4598 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4599 | } |
| 4600 | } |
| 4601 | |
| 4602 | void InstructionCodeGeneratorARMVIXL::VisitRem(HRem* rem) { |
| 4603 | LocationSummary* locations = rem->GetLocations(); |
| 4604 | Location second = locations->InAt(1); |
| 4605 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4606 | DataType::Type type = rem->GetResultType(); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4607 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4608 | case DataType::Type::kInt32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4609 | vixl32::Register reg1 = InputRegisterAt(rem, 0); |
| 4610 | vixl32::Register out_reg = OutputRegister(rem); |
| 4611 | if (second.IsConstant()) { |
| 4612 | GenerateDivRemConstantIntegral(rem); |
| 4613 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4614 | vixl32::Register reg2 = RegisterFrom(second); |
| 4615 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 4616 | |
| 4617 | // temp = reg1 / reg2 (integer division) |
| 4618 | // dest = reg1 - temp * reg2 |
| 4619 | __ Sdiv(temp, reg1, reg2); |
| 4620 | __ Mls(out_reg, temp, reg2, reg1); |
| 4621 | } else { |
| 4622 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4623 | DCHECK(reg1.Is(calling_convention.GetRegisterAt(0))); |
| 4624 | DCHECK(RegisterFrom(second).Is(calling_convention.GetRegisterAt(1))); |
| 4625 | DCHECK(out_reg.Is(r1)); |
| 4626 | |
| 4627 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
| 4628 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
| 4629 | } |
| 4630 | break; |
| 4631 | } |
| 4632 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4633 | case DataType::Type::kInt64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4634 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
| 4635 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 4636 | break; |
| 4637 | } |
| 4638 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4639 | case DataType::Type::kFloat32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4640 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
| 4641 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 4642 | break; |
| 4643 | } |
| 4644 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4645 | case DataType::Type::kFloat64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4646 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
| 4647 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 4648 | break; |
| 4649 | } |
| 4650 | |
| 4651 | default: |
| 4652 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4653 | } |
| 4654 | } |
| 4655 | |
| 4656 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4657 | void LocationsBuilderARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 4658 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4659 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4660 | } |
| 4661 | |
| 4662 | void InstructionCodeGeneratorARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 4663 | DivZeroCheckSlowPathARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4664 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathARMVIXL(instruction); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4665 | codegen_->AddSlowPath(slow_path); |
| 4666 | |
| 4667 | LocationSummary* locations = instruction->GetLocations(); |
| 4668 | Location value = locations->InAt(0); |
| 4669 | |
| 4670 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4671 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4672 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4673 | case DataType::Type::kInt8: |
| 4674 | case DataType::Type::kUint16: |
| 4675 | case DataType::Type::kInt16: |
| 4676 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4677 | if (value.IsRegister()) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 4678 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4679 | } else { |
| 4680 | DCHECK(value.IsConstant()) << value; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4681 | if (Int32ConstantFrom(value) == 0) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4682 | __ B(slow_path->GetEntryLabel()); |
| 4683 | } |
| 4684 | } |
| 4685 | break; |
| 4686 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4687 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4688 | if (value.IsRegisterPair()) { |
| 4689 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4690 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4691 | __ Orrs(temp, LowRegisterFrom(value), HighRegisterFrom(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4692 | __ B(eq, slow_path->GetEntryLabel()); |
| 4693 | } else { |
| 4694 | DCHECK(value.IsConstant()) << value; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4695 | if (Int64ConstantFrom(value) == 0) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4696 | __ B(slow_path->GetEntryLabel()); |
| 4697 | } |
| 4698 | } |
| 4699 | break; |
| 4700 | } |
| 4701 | default: |
| 4702 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4703 | } |
| 4704 | } |
| 4705 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4706 | void InstructionCodeGeneratorARMVIXL::HandleIntegerRotate(HRor* ror) { |
| 4707 | LocationSummary* locations = ror->GetLocations(); |
| 4708 | vixl32::Register in = InputRegisterAt(ror, 0); |
| 4709 | Location rhs = locations->InAt(1); |
| 4710 | vixl32::Register out = OutputRegister(ror); |
| 4711 | |
| 4712 | if (rhs.IsConstant()) { |
| 4713 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 4714 | // so map all rotations to a +ve. equivalent in that range. |
| 4715 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 4716 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 4717 | if (rot) { |
| 4718 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 4719 | // (e.g. left by 2 bits == right by 30.) |
| 4720 | __ Ror(out, in, rot); |
| 4721 | } else if (!out.Is(in)) { |
| 4722 | __ Mov(out, in); |
| 4723 | } |
| 4724 | } else { |
| 4725 | __ Ror(out, in, RegisterFrom(rhs)); |
| 4726 | } |
| 4727 | } |
| 4728 | |
| 4729 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 4730 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 4731 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 4732 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 4733 | void InstructionCodeGeneratorARMVIXL::HandleLongRotate(HRor* ror) { |
| 4734 | LocationSummary* locations = ror->GetLocations(); |
| 4735 | vixl32::Register in_reg_lo = LowRegisterFrom(locations->InAt(0)); |
| 4736 | vixl32::Register in_reg_hi = HighRegisterFrom(locations->InAt(0)); |
| 4737 | Location rhs = locations->InAt(1); |
| 4738 | vixl32::Register out_reg_lo = LowRegisterFrom(locations->Out()); |
| 4739 | vixl32::Register out_reg_hi = HighRegisterFrom(locations->Out()); |
| 4740 | |
| 4741 | if (rhs.IsConstant()) { |
| 4742 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 4743 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
| 4744 | rot &= kMaxLongShiftDistance; |
| 4745 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 4746 | // logic below to a simple pair of binary orr. |
| 4747 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 4748 | if (rot >= kArmBitsPerWord) { |
| 4749 | rot -= kArmBitsPerWord; |
| 4750 | std::swap(in_reg_hi, in_reg_lo); |
| 4751 | } |
| 4752 | // Rotate, or mov to out for zero or word size rotations. |
| 4753 | if (rot != 0u) { |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4754 | __ Lsr(out_reg_hi, in_reg_hi, Operand::From(rot)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4755 | __ 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] | 4756 | __ Lsr(out_reg_lo, in_reg_lo, Operand::From(rot)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4757 | __ Orr(out_reg_lo, out_reg_lo, Operand(in_reg_hi, ShiftType::LSL, kArmBitsPerWord - rot)); |
| 4758 | } else { |
| 4759 | __ Mov(out_reg_lo, in_reg_lo); |
| 4760 | __ Mov(out_reg_hi, in_reg_hi); |
| 4761 | } |
| 4762 | } else { |
| 4763 | vixl32::Register shift_right = RegisterFrom(locations->GetTemp(0)); |
| 4764 | vixl32::Register shift_left = RegisterFrom(locations->GetTemp(1)); |
| 4765 | vixl32::Label end; |
| 4766 | vixl32::Label shift_by_32_plus_shift_right; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4767 | vixl32::Label* final_label = codegen_->GetFinalLabel(ror, &end); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4768 | |
| 4769 | __ And(shift_right, RegisterFrom(rhs), 0x1F); |
| 4770 | __ Lsrs(shift_left, RegisterFrom(rhs), 6); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 4771 | __ Rsb(LeaveFlags, shift_left, shift_right, Operand::From(kArmBitsPerWord)); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 4772 | __ B(cc, &shift_by_32_plus_shift_right, /* far_target */ false); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4773 | |
| 4774 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 4775 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 4776 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 4777 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4778 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 4779 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4780 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 4781 | __ Add(out_reg_lo, out_reg_lo, shift_left); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4782 | __ B(final_label); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4783 | |
| 4784 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 4785 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 4786 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 4787 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 4788 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4789 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 4790 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4791 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 4792 | __ Add(out_reg_lo, out_reg_lo, shift_right); |
| 4793 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4794 | if (end.IsReferenced()) { |
| 4795 | __ Bind(&end); |
| 4796 | } |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4797 | } |
| 4798 | } |
| 4799 | |
| 4800 | void LocationsBuilderARMVIXL::VisitRor(HRor* ror) { |
| 4801 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4802 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4803 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4804 | case DataType::Type::kInt32: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4805 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4806 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 4807 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4808 | break; |
| 4809 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4810 | case DataType::Type::kInt64: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4811 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4812 | if (ror->InputAt(1)->IsConstant()) { |
| 4813 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 4814 | } else { |
| 4815 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4816 | locations->AddTemp(Location::RequiresRegister()); |
| 4817 | locations->AddTemp(Location::RequiresRegister()); |
| 4818 | } |
| 4819 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4820 | break; |
| 4821 | } |
| 4822 | default: |
| 4823 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4824 | } |
| 4825 | } |
| 4826 | |
| 4827 | void InstructionCodeGeneratorARMVIXL::VisitRor(HRor* ror) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4828 | DataType::Type type = ror->GetResultType(); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4829 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4830 | case DataType::Type::kInt32: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4831 | HandleIntegerRotate(ror); |
| 4832 | break; |
| 4833 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4834 | case DataType::Type::kInt64: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4835 | HandleLongRotate(ror); |
| 4836 | break; |
| 4837 | } |
| 4838 | default: |
| 4839 | LOG(FATAL) << "Unexpected operation type " << type; |
| 4840 | UNREACHABLE(); |
| 4841 | } |
| 4842 | } |
| 4843 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4844 | void LocationsBuilderARMVIXL::HandleShift(HBinaryOperation* op) { |
| 4845 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4846 | |
| 4847 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4848 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4849 | |
| 4850 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4851 | case DataType::Type::kInt32: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4852 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4853 | if (op->InputAt(1)->IsConstant()) { |
| 4854 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 4855 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4856 | } else { |
| 4857 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4858 | // Make the output overlap, as it will be used to hold the masked |
| 4859 | // second input. |
| 4860 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4861 | } |
| 4862 | break; |
| 4863 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4864 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4865 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4866 | if (op->InputAt(1)->IsConstant()) { |
| 4867 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 4868 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 4869 | // don't clash with high registers which the register allocator currently guarantees. |
| 4870 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4871 | } else { |
| 4872 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4873 | locations->AddTemp(Location::RequiresRegister()); |
| 4874 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4875 | } |
| 4876 | break; |
| 4877 | } |
| 4878 | default: |
| 4879 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 4880 | } |
| 4881 | } |
| 4882 | |
| 4883 | void InstructionCodeGeneratorARMVIXL::HandleShift(HBinaryOperation* op) { |
| 4884 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4885 | |
| 4886 | LocationSummary* locations = op->GetLocations(); |
| 4887 | Location out = locations->Out(); |
| 4888 | Location first = locations->InAt(0); |
| 4889 | Location second = locations->InAt(1); |
| 4890 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4891 | DataType::Type type = op->GetResultType(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4892 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4893 | case DataType::Type::kInt32: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4894 | vixl32::Register out_reg = OutputRegister(op); |
| 4895 | vixl32::Register first_reg = InputRegisterAt(op, 0); |
| 4896 | if (second.IsRegister()) { |
| 4897 | vixl32::Register second_reg = RegisterFrom(second); |
| 4898 | // ARM doesn't mask the shift count so we need to do it ourselves. |
| 4899 | __ And(out_reg, second_reg, kMaxIntShiftDistance); |
| 4900 | if (op->IsShl()) { |
| 4901 | __ Lsl(out_reg, first_reg, out_reg); |
| 4902 | } else if (op->IsShr()) { |
| 4903 | __ Asr(out_reg, first_reg, out_reg); |
| 4904 | } else { |
| 4905 | __ Lsr(out_reg, first_reg, out_reg); |
| 4906 | } |
| 4907 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4908 | int32_t cst = Int32ConstantFrom(second); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4909 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
| 4910 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
| 4911 | __ Mov(out_reg, first_reg); |
| 4912 | } else if (op->IsShl()) { |
| 4913 | __ Lsl(out_reg, first_reg, shift_value); |
| 4914 | } else if (op->IsShr()) { |
| 4915 | __ Asr(out_reg, first_reg, shift_value); |
| 4916 | } else { |
| 4917 | __ Lsr(out_reg, first_reg, shift_value); |
| 4918 | } |
| 4919 | } |
| 4920 | break; |
| 4921 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4922 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4923 | vixl32::Register o_h = HighRegisterFrom(out); |
| 4924 | vixl32::Register o_l = LowRegisterFrom(out); |
| 4925 | |
| 4926 | vixl32::Register high = HighRegisterFrom(first); |
| 4927 | vixl32::Register low = LowRegisterFrom(first); |
| 4928 | |
| 4929 | if (second.IsRegister()) { |
| 4930 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 4931 | |
| 4932 | vixl32::Register second_reg = RegisterFrom(second); |
| 4933 | |
| 4934 | if (op->IsShl()) { |
| 4935 | __ And(o_l, second_reg, kMaxLongShiftDistance); |
| 4936 | // Shift the high part |
| 4937 | __ Lsl(o_h, high, o_l); |
| 4938 | // Shift the low part and `or` what overflew on the high part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4939 | __ Rsb(temp, o_l, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4940 | __ Lsr(temp, low, temp); |
| 4941 | __ Orr(o_h, o_h, temp); |
| 4942 | // If the shift is > 32 bits, override the high part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4943 | __ Subs(temp, o_l, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4944 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 4945 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 4946 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 4947 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4948 | __ it(pl); |
| 4949 | __ lsl(pl, o_h, low, temp); |
| 4950 | } |
| 4951 | // Shift the low part |
| 4952 | __ Lsl(o_l, low, o_l); |
| 4953 | } else if (op->IsShr()) { |
| 4954 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 4955 | // Shift the low part |
| 4956 | __ Lsr(o_l, low, o_h); |
| 4957 | // Shift the high part and `or` what underflew on the low part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4958 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4959 | __ Lsl(temp, high, temp); |
| 4960 | __ Orr(o_l, o_l, temp); |
| 4961 | // If the shift is > 32 bits, override the low part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4962 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4963 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 4964 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 4965 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 4966 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4967 | __ it(pl); |
| 4968 | __ asr(pl, o_l, high, temp); |
| 4969 | } |
| 4970 | // Shift the high part |
| 4971 | __ Asr(o_h, high, o_h); |
| 4972 | } else { |
| 4973 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 4974 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 4975 | __ Lsr(o_l, low, o_h); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4976 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4977 | __ Lsl(temp, high, temp); |
| 4978 | __ Orr(o_l, o_l, temp); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4979 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4980 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 4981 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 4982 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 4983 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4984 | __ it(pl); |
| 4985 | __ lsr(pl, o_l, high, temp); |
| 4986 | } |
| 4987 | __ Lsr(o_h, high, o_h); |
| 4988 | } |
| 4989 | } else { |
| 4990 | // Register allocator doesn't create partial overlap. |
| 4991 | DCHECK(!o_l.Is(high)); |
| 4992 | DCHECK(!o_h.Is(low)); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4993 | int32_t cst = Int32ConstantFrom(second); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4994 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
| 4995 | if (shift_value > 32) { |
| 4996 | if (op->IsShl()) { |
| 4997 | __ Lsl(o_h, low, shift_value - 32); |
| 4998 | __ Mov(o_l, 0); |
| 4999 | } else if (op->IsShr()) { |
| 5000 | __ Asr(o_l, high, shift_value - 32); |
| 5001 | __ Asr(o_h, high, 31); |
| 5002 | } else { |
| 5003 | __ Lsr(o_l, high, shift_value - 32); |
| 5004 | __ Mov(o_h, 0); |
| 5005 | } |
| 5006 | } else if (shift_value == 32) { |
| 5007 | if (op->IsShl()) { |
| 5008 | __ Mov(o_h, low); |
| 5009 | __ Mov(o_l, 0); |
| 5010 | } else if (op->IsShr()) { |
| 5011 | __ Mov(o_l, high); |
| 5012 | __ Asr(o_h, high, 31); |
| 5013 | } else { |
| 5014 | __ Mov(o_l, high); |
| 5015 | __ Mov(o_h, 0); |
| 5016 | } |
| 5017 | } else if (shift_value == 1) { |
| 5018 | if (op->IsShl()) { |
| 5019 | __ Lsls(o_l, low, 1); |
| 5020 | __ Adc(o_h, high, high); |
| 5021 | } else if (op->IsShr()) { |
| 5022 | __ Asrs(o_h, high, 1); |
| 5023 | __ Rrx(o_l, low); |
| 5024 | } else { |
| 5025 | __ Lsrs(o_h, high, 1); |
| 5026 | __ Rrx(o_l, low); |
| 5027 | } |
| 5028 | } else { |
| 5029 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
| 5030 | if (op->IsShl()) { |
| 5031 | __ Lsl(o_h, high, shift_value); |
| 5032 | __ Orr(o_h, o_h, Operand(low, ShiftType::LSR, 32 - shift_value)); |
| 5033 | __ Lsl(o_l, low, shift_value); |
| 5034 | } else if (op->IsShr()) { |
| 5035 | __ Lsr(o_l, low, shift_value); |
| 5036 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 5037 | __ Asr(o_h, high, shift_value); |
| 5038 | } else { |
| 5039 | __ Lsr(o_l, low, shift_value); |
| 5040 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 5041 | __ Lsr(o_h, high, shift_value); |
| 5042 | } |
| 5043 | } |
| 5044 | } |
| 5045 | break; |
| 5046 | } |
| 5047 | default: |
| 5048 | LOG(FATAL) << "Unexpected operation type " << type; |
| 5049 | UNREACHABLE(); |
| 5050 | } |
| 5051 | } |
| 5052 | |
| 5053 | void LocationsBuilderARMVIXL::VisitShl(HShl* shl) { |
| 5054 | HandleShift(shl); |
| 5055 | } |
| 5056 | |
| 5057 | void InstructionCodeGeneratorARMVIXL::VisitShl(HShl* shl) { |
| 5058 | HandleShift(shl); |
| 5059 | } |
| 5060 | |
| 5061 | void LocationsBuilderARMVIXL::VisitShr(HShr* shr) { |
| 5062 | HandleShift(shr); |
| 5063 | } |
| 5064 | |
| 5065 | void InstructionCodeGeneratorARMVIXL::VisitShr(HShr* shr) { |
| 5066 | HandleShift(shr); |
| 5067 | } |
| 5068 | |
| 5069 | void LocationsBuilderARMVIXL::VisitUShr(HUShr* ushr) { |
| 5070 | HandleShift(ushr); |
| 5071 | } |
| 5072 | |
| 5073 | void InstructionCodeGeneratorARMVIXL::VisitUShr(HUShr* ushr) { |
| 5074 | HandleShift(ushr); |
| 5075 | } |
| 5076 | |
| 5077 | void LocationsBuilderARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5078 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5079 | instruction, LocationSummary::kCallOnMainOnly); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5080 | if (instruction->IsStringAlloc()) { |
| 5081 | locations->AddTemp(LocationFrom(kMethodRegister)); |
| 5082 | } else { |
| 5083 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 5084 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5085 | } |
| 5086 | locations->SetOut(LocationFrom(r0)); |
| 5087 | } |
| 5088 | |
| 5089 | void InstructionCodeGeneratorARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
| 5090 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5091 | // of poisoning the reference. |
| 5092 | if (instruction->IsStringAlloc()) { |
| 5093 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 5094 | vixl32::Register temp = RegisterFrom(instruction->GetLocations()->GetTemp(0)); |
| 5095 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
| 5096 | GetAssembler()->LoadFromOffset(kLoadWord, temp, tr, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 5097 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, code_offset.Int32Value()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5098 | // 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] | 5099 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5100 | vixl32::k16BitT32InstructionSizeInBytes, |
| 5101 | CodeBufferCheckScope::kExactSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5102 | __ blx(lr); |
| 5103 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5104 | } else { |
| 5105 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 5106 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5107 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 5108 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 10); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5109 | } |
| 5110 | |
| 5111 | void LocationsBuilderARMVIXL::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5112 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5113 | instruction, LocationSummary::kCallOnMainOnly); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5114 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5115 | locations->SetOut(LocationFrom(r0)); |
Nicolas Geoffray | 8c7c4f1 | 2017-01-26 10:13:11 +0000 | [diff] [blame] | 5116 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5117 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5118 | } |
| 5119 | |
| 5120 | void InstructionCodeGeneratorARMVIXL::VisitNewArray(HNewArray* instruction) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5121 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5122 | // of poisoning the reference. |
Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 5123 | QuickEntrypointEnum entrypoint = |
| 5124 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 5125 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5126 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 5127 | DCHECK(!codegen_->IsLeafMethod()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 5128 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 11); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5129 | } |
| 5130 | |
| 5131 | void LocationsBuilderARMVIXL::VisitParameterValue(HParameterValue* instruction) { |
| 5132 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5133 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5134 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5135 | if (location.IsStackSlot()) { |
| 5136 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5137 | } else if (location.IsDoubleStackSlot()) { |
| 5138 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5139 | } |
| 5140 | locations->SetOut(location); |
| 5141 | } |
| 5142 | |
| 5143 | void InstructionCodeGeneratorARMVIXL::VisitParameterValue( |
| 5144 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 5145 | // Nothing to do, the parameter is already at its location. |
| 5146 | } |
| 5147 | |
| 5148 | void LocationsBuilderARMVIXL::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5149 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5150 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5151 | locations->SetOut(LocationFrom(kMethodRegister)); |
| 5152 | } |
| 5153 | |
| 5154 | void InstructionCodeGeneratorARMVIXL::VisitCurrentMethod( |
| 5155 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5156 | // Nothing to do, the method is already at its location. |
| 5157 | } |
| 5158 | |
| 5159 | void LocationsBuilderARMVIXL::VisitNot(HNot* not_) { |
| 5160 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5161 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5162 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5163 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5164 | } |
| 5165 | |
| 5166 | void InstructionCodeGeneratorARMVIXL::VisitNot(HNot* not_) { |
| 5167 | LocationSummary* locations = not_->GetLocations(); |
| 5168 | Location out = locations->Out(); |
| 5169 | Location in = locations->InAt(0); |
| 5170 | switch (not_->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5171 | case DataType::Type::kInt32: |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5172 | __ Mvn(OutputRegister(not_), InputRegisterAt(not_, 0)); |
| 5173 | break; |
| 5174 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5175 | case DataType::Type::kInt64: |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5176 | __ Mvn(LowRegisterFrom(out), LowRegisterFrom(in)); |
| 5177 | __ Mvn(HighRegisterFrom(out), HighRegisterFrom(in)); |
| 5178 | break; |
| 5179 | |
| 5180 | default: |
| 5181 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 5182 | } |
| 5183 | } |
| 5184 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5185 | void LocationsBuilderARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5186 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5187 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5188 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5189 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5190 | } |
| 5191 | |
| 5192 | void InstructionCodeGeneratorARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5193 | __ Eor(OutputRegister(bool_not), InputRegister(bool_not), 1); |
| 5194 | } |
| 5195 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5196 | void LocationsBuilderARMVIXL::VisitCompare(HCompare* compare) { |
| 5197 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5198 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5199 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5200 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5201 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5202 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5203 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5204 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5205 | case DataType::Type::kInt32: |
| 5206 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5207 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5208 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5209 | // Output overlaps because it is written before doing the low comparison. |
| 5210 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5211 | break; |
| 5212 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5213 | case DataType::Type::kFloat32: |
| 5214 | case DataType::Type::kFloat64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5215 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5216 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
| 5217 | locations->SetOut(Location::RequiresRegister()); |
| 5218 | break; |
| 5219 | } |
| 5220 | default: |
| 5221 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 5222 | } |
| 5223 | } |
| 5224 | |
| 5225 | void InstructionCodeGeneratorARMVIXL::VisitCompare(HCompare* compare) { |
| 5226 | LocationSummary* locations = compare->GetLocations(); |
| 5227 | vixl32::Register out = OutputRegister(compare); |
| 5228 | Location left = locations->InAt(0); |
| 5229 | Location right = locations->InAt(1); |
| 5230 | |
| 5231 | vixl32::Label less, greater, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5232 | vixl32::Label* final_label = codegen_->GetFinalLabel(compare, &done); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5233 | DataType::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 5234 | vixl32::Condition less_cond = vixl32::Condition::None(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5235 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5236 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5237 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5238 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5239 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5240 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5241 | case DataType::Type::kInt32: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5242 | // Emit move to `out` before the `Cmp`, as `Mov` might affect the status flags. |
| 5243 | __ Mov(out, 0); |
| 5244 | __ Cmp(RegisterFrom(left), RegisterFrom(right)); // Signed compare. |
| 5245 | less_cond = lt; |
| 5246 | break; |
| 5247 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5248 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5249 | __ Cmp(HighRegisterFrom(left), HighRegisterFrom(right)); // Signed compare. |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 5250 | __ B(lt, &less, /* far_target */ false); |
| 5251 | __ B(gt, &greater, /* far_target */ false); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5252 | // Emit move to `out` before the last `Cmp`, as `Mov` might affect the status flags. |
| 5253 | __ Mov(out, 0); |
| 5254 | __ Cmp(LowRegisterFrom(left), LowRegisterFrom(right)); // Unsigned compare. |
| 5255 | less_cond = lo; |
| 5256 | break; |
| 5257 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5258 | case DataType::Type::kFloat32: |
| 5259 | case DataType::Type::kFloat64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5260 | __ Mov(out, 0); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 5261 | GenerateVcmp(compare, codegen_); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5262 | // To branch on the FP compare result we transfer FPSCR to APSR (encoded as PC in VMRS). |
| 5263 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 5264 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
| 5265 | break; |
| 5266 | } |
| 5267 | default: |
| 5268 | LOG(FATAL) << "Unexpected compare type " << type; |
| 5269 | UNREACHABLE(); |
| 5270 | } |
| 5271 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5272 | __ B(eq, final_label, /* far_target */ false); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 5273 | __ B(less_cond, &less, /* far_target */ false); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5274 | |
| 5275 | __ Bind(&greater); |
| 5276 | __ Mov(out, 1); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5277 | __ B(final_label); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5278 | |
| 5279 | __ Bind(&less); |
| 5280 | __ Mov(out, -1); |
| 5281 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5282 | if (done.IsReferenced()) { |
| 5283 | __ Bind(&done); |
| 5284 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5285 | } |
| 5286 | |
| 5287 | void LocationsBuilderARMVIXL::VisitPhi(HPhi* instruction) { |
| 5288 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5289 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5290 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| 5291 | locations->SetInAt(i, Location::Any()); |
| 5292 | } |
| 5293 | locations->SetOut(Location::Any()); |
| 5294 | } |
| 5295 | |
| 5296 | void InstructionCodeGeneratorARMVIXL::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 5297 | LOG(FATAL) << "Unreachable"; |
| 5298 | } |
| 5299 | |
| 5300 | void CodeGeneratorARMVIXL::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 5301 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 5302 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
| 5303 | switch (kind) { |
| 5304 | case MemBarrierKind::kAnyStore: |
| 5305 | case MemBarrierKind::kLoadAny: |
| 5306 | case MemBarrierKind::kAnyAny: { |
| 5307 | flavor = DmbOptions::ISH; |
| 5308 | break; |
| 5309 | } |
| 5310 | case MemBarrierKind::kStoreStore: { |
| 5311 | flavor = DmbOptions::ISHST; |
| 5312 | break; |
| 5313 | } |
| 5314 | default: |
| 5315 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 5316 | } |
| 5317 | __ Dmb(flavor); |
| 5318 | } |
| 5319 | |
| 5320 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicLoad(vixl32::Register addr, |
| 5321 | uint32_t offset, |
| 5322 | vixl32::Register out_lo, |
| 5323 | vixl32::Register out_hi) { |
| 5324 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5325 | if (offset != 0) { |
| 5326 | vixl32::Register temp = temps.Acquire(); |
| 5327 | __ Add(temp, addr, offset); |
| 5328 | addr = temp; |
| 5329 | } |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5330 | __ Ldrexd(out_lo, out_hi, MemOperand(addr)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5331 | } |
| 5332 | |
| 5333 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicStore(vixl32::Register addr, |
| 5334 | uint32_t offset, |
| 5335 | vixl32::Register value_lo, |
| 5336 | vixl32::Register value_hi, |
| 5337 | vixl32::Register temp1, |
| 5338 | vixl32::Register temp2, |
| 5339 | HInstruction* instruction) { |
| 5340 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5341 | vixl32::Label fail; |
| 5342 | if (offset != 0) { |
| 5343 | vixl32::Register temp = temps.Acquire(); |
| 5344 | __ Add(temp, addr, offset); |
| 5345 | addr = temp; |
| 5346 | } |
| 5347 | __ Bind(&fail); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5348 | { |
| 5349 | // Ensure the pc position is recorded immediately after the `ldrexd` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5350 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5351 | vixl32::kMaxInstructionSizeInBytes, |
| 5352 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5353 | // We need a load followed by store. (The address used in a STREX instruction must |
| 5354 | // be the same as the address in the most recently executed LDREX instruction.) |
| 5355 | __ ldrexd(temp1, temp2, MemOperand(addr)); |
| 5356 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5357 | } |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5358 | __ Strexd(temp1, value_lo, value_hi, MemOperand(addr)); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5359 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5360 | } |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5361 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5362 | void LocationsBuilderARMVIXL::HandleFieldSet( |
| 5363 | HInstruction* instruction, const FieldInfo& field_info) { |
| 5364 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5365 | |
| 5366 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5367 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5368 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5369 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5370 | DataType::Type field_type = field_info.GetFieldType(); |
| 5371 | if (DataType::IsFloatingPointType(field_type)) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5372 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5373 | } else { |
| 5374 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5375 | } |
| 5376 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5377 | 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] | 5378 | bool generate_volatile = field_info.IsVolatile() |
| 5379 | && is_wide |
| 5380 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5381 | bool needs_write_barrier = |
| 5382 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 5383 | // Temporary registers for the write barrier. |
| 5384 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
| 5385 | if (needs_write_barrier) { |
| 5386 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
| 5387 | locations->AddTemp(Location::RequiresRegister()); |
| 5388 | } else if (generate_volatile) { |
| 5389 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 5390 | // - registers need to be consecutive |
| 5391 | // - the first register should be even but not R14. |
| 5392 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5393 | // revisit this if we ever enable ARM encoding. |
| 5394 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5395 | |
| 5396 | locations->AddTemp(Location::RequiresRegister()); |
| 5397 | locations->AddTemp(Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5398 | if (field_type == DataType::Type::kFloat64) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5399 | // For doubles we need two more registers to copy the value. |
| 5400 | locations->AddTemp(LocationFrom(r2)); |
| 5401 | locations->AddTemp(LocationFrom(r3)); |
| 5402 | } |
| 5403 | } |
| 5404 | } |
| 5405 | |
| 5406 | void InstructionCodeGeneratorARMVIXL::HandleFieldSet(HInstruction* instruction, |
| 5407 | const FieldInfo& field_info, |
| 5408 | bool value_can_be_null) { |
| 5409 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5410 | |
| 5411 | LocationSummary* locations = instruction->GetLocations(); |
| 5412 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 5413 | Location value = locations->InAt(1); |
| 5414 | |
| 5415 | bool is_volatile = field_info.IsVolatile(); |
| 5416 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5417 | DataType::Type field_type = field_info.GetFieldType(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5418 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5419 | bool needs_write_barrier = |
| 5420 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 5421 | |
| 5422 | if (is_volatile) { |
| 5423 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 5424 | } |
| 5425 | |
| 5426 | switch (field_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5427 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5428 | case DataType::Type::kUint8: |
| 5429 | case DataType::Type::kInt8: |
| 5430 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5431 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5432 | case DataType::Type::kInt32: { |
| 5433 | StoreOperandType operand_type = GetStoreOperandType(field_type); |
| 5434 | GetAssembler()->StoreToOffset(operand_type, RegisterFrom(value), base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5435 | break; |
| 5436 | } |
| 5437 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5438 | case DataType::Type::kReference: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5439 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5440 | // Note that in the case where `value` is a null reference, |
| 5441 | // we do not enter this block, as a null reference does not |
| 5442 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5443 | DCHECK_EQ(field_type, DataType::Type::kReference); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5444 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5445 | __ Mov(temp, RegisterFrom(value)); |
| 5446 | GetAssembler()->PoisonHeapReference(temp); |
| 5447 | GetAssembler()->StoreToOffset(kStoreWord, temp, base, offset); |
| 5448 | } else { |
| 5449 | GetAssembler()->StoreToOffset(kStoreWord, RegisterFrom(value), base, offset); |
| 5450 | } |
| 5451 | break; |
| 5452 | } |
| 5453 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5454 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5455 | if (is_volatile && !atomic_ldrd_strd) { |
| 5456 | GenerateWideAtomicStore(base, |
| 5457 | offset, |
| 5458 | LowRegisterFrom(value), |
| 5459 | HighRegisterFrom(value), |
| 5460 | RegisterFrom(locations->GetTemp(0)), |
| 5461 | RegisterFrom(locations->GetTemp(1)), |
| 5462 | instruction); |
| 5463 | } else { |
| 5464 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), base, offset); |
| 5465 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5466 | } |
| 5467 | break; |
| 5468 | } |
| 5469 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5470 | case DataType::Type::kFloat32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5471 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), base, offset); |
| 5472 | break; |
| 5473 | } |
| 5474 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5475 | case DataType::Type::kFloat64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5476 | vixl32::DRegister value_reg = DRegisterFrom(value); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5477 | if (is_volatile && !atomic_ldrd_strd) { |
| 5478 | vixl32::Register value_reg_lo = RegisterFrom(locations->GetTemp(0)); |
| 5479 | vixl32::Register value_reg_hi = RegisterFrom(locations->GetTemp(1)); |
| 5480 | |
| 5481 | __ Vmov(value_reg_lo, value_reg_hi, value_reg); |
| 5482 | |
| 5483 | GenerateWideAtomicStore(base, |
| 5484 | offset, |
| 5485 | value_reg_lo, |
| 5486 | value_reg_hi, |
| 5487 | RegisterFrom(locations->GetTemp(2)), |
| 5488 | RegisterFrom(locations->GetTemp(3)), |
| 5489 | instruction); |
| 5490 | } else { |
| 5491 | GetAssembler()->StoreDToOffset(value_reg, base, offset); |
| 5492 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5493 | } |
| 5494 | break; |
| 5495 | } |
| 5496 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5497 | case DataType::Type::kVoid: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5498 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5499 | UNREACHABLE(); |
| 5500 | } |
| 5501 | |
| 5502 | // Longs and doubles are handled in the switch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5503 | if (field_type != DataType::Type::kInt64 && field_type != DataType::Type::kFloat64) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5504 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, we |
| 5505 | // should use a scope and the assembler to emit the store instruction to guarantee that we |
| 5506 | // record the pc at the correct position. But the `Assembler` does not automatically handle |
| 5507 | // unencodable offsets. Practically, everything is fine because the helper and VIXL, at the time |
| 5508 | // of writing, do generate the store instruction last. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5509 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5510 | } |
| 5511 | |
| 5512 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5513 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5514 | vixl32::Register card = RegisterFrom(locations->GetTemp(1)); |
| 5515 | codegen_->MarkGCCard(temp, card, base, RegisterFrom(value), value_can_be_null); |
| 5516 | } |
| 5517 | |
| 5518 | if (is_volatile) { |
| 5519 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 5520 | } |
| 5521 | } |
| 5522 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5523 | void LocationsBuilderARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 5524 | const FieldInfo& field_info) { |
| 5525 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 5526 | |
| 5527 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5528 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == DataType::Type::kReference); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5529 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5530 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5531 | object_field_get_with_read_barrier |
| 5532 | ? LocationSummary::kCallOnSlowPath |
| 5533 | : LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5534 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5535 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 5536 | } |
| 5537 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5538 | |
| 5539 | bool volatile_for_double = field_info.IsVolatile() |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5540 | && (field_info.GetFieldType() == DataType::Type::kFloat64) |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5541 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5542 | // The output overlaps in case of volatile long: we don't want the |
| 5543 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 5544 | // object's location. Likewise, in the case of an object field get |
| 5545 | // with read barriers enabled, we do not want the load to overwrite |
| 5546 | // 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] | 5547 | bool overlap = |
| 5548 | (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) || |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5549 | object_field_get_with_read_barrier; |
| 5550 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5551 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5552 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5553 | } else { |
| 5554 | locations->SetOut(Location::RequiresRegister(), |
| 5555 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 5556 | } |
| 5557 | if (volatile_for_double) { |
| 5558 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 5559 | // - registers need to be consecutive |
| 5560 | // - the first register should be even but not R14. |
| 5561 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5562 | // revisit this if we ever enable ARM encoding. |
| 5563 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5564 | locations->AddTemp(Location::RequiresRegister()); |
| 5565 | locations->AddTemp(Location::RequiresRegister()); |
| 5566 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5567 | // We need a temporary register for the read barrier marking slow |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 5568 | // path in CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 5569 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 5570 | !Runtime::Current()->UseJitCompilation()) { |
| 5571 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 5572 | // loads we need a temporary only if the offset is too big. |
| 5573 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 5574 | locations->AddTemp(Location::RequiresRegister()); |
| 5575 | } |
| 5576 | // And we always need the reserved entrypoint register. |
| 5577 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 5578 | } else { |
| 5579 | locations->AddTemp(Location::RequiresRegister()); |
| 5580 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5581 | } |
| 5582 | } |
| 5583 | |
| 5584 | Location LocationsBuilderARMVIXL::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5585 | DCHECK(DataType::IsFloatingPointType(input->GetType())) << input->GetType(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5586 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 5587 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 5588 | return Location::ConstantLocation(input->AsConstant()); |
| 5589 | } else { |
| 5590 | return Location::RequiresFpuRegister(); |
| 5591 | } |
| 5592 | } |
| 5593 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5594 | Location LocationsBuilderARMVIXL::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 5595 | Opcode opcode) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5596 | DCHECK(!DataType::IsFloatingPointType(constant->GetType())); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5597 | if (constant->IsConstant() && |
| 5598 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 5599 | return Location::ConstantLocation(constant->AsConstant()); |
| 5600 | } |
| 5601 | return Location::RequiresRegister(); |
| 5602 | } |
| 5603 | |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 5604 | static bool CanEncode32BitConstantAsImmediate( |
| 5605 | CodeGeneratorARMVIXL* codegen, |
| 5606 | uint32_t value, |
| 5607 | Opcode opcode, |
| 5608 | vixl32::FlagsUpdate flags_update = vixl32::FlagsUpdate::DontCare) { |
| 5609 | ArmVIXLAssembler* assembler = codegen->GetAssembler(); |
| 5610 | if (assembler->ShifterOperandCanHold(opcode, value, flags_update)) { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5611 | return true; |
| 5612 | } |
| 5613 | Opcode neg_opcode = kNoOperand; |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5614 | uint32_t neg_value = 0; |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5615 | switch (opcode) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5616 | case AND: neg_opcode = BIC; neg_value = ~value; break; |
| 5617 | case ORR: neg_opcode = ORN; neg_value = ~value; break; |
| 5618 | case ADD: neg_opcode = SUB; neg_value = -value; break; |
| 5619 | case ADC: neg_opcode = SBC; neg_value = ~value; break; |
| 5620 | case SUB: neg_opcode = ADD; neg_value = -value; break; |
| 5621 | case SBC: neg_opcode = ADC; neg_value = ~value; break; |
| 5622 | case MOV: neg_opcode = MVN; neg_value = ~value; break; |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5623 | default: |
| 5624 | return false; |
| 5625 | } |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5626 | |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 5627 | if (assembler->ShifterOperandCanHold(neg_opcode, neg_value, flags_update)) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5628 | return true; |
| 5629 | } |
| 5630 | |
| 5631 | return opcode == AND && IsPowerOfTwo(value + 1); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5632 | } |
| 5633 | |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 5634 | bool LocationsBuilderARMVIXL::CanEncodeConstantAsImmediate(HConstant* input_cst, Opcode opcode) { |
| 5635 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 5636 | if (DataType::Is64BitType(input_cst->GetType())) { |
| 5637 | Opcode high_opcode = opcode; |
| 5638 | vixl32::FlagsUpdate low_flags_update = vixl32::FlagsUpdate::DontCare; |
| 5639 | switch (opcode) { |
| 5640 | case SUB: |
| 5641 | // Flip the operation to an ADD. |
| 5642 | value = -value; |
| 5643 | opcode = ADD; |
| 5644 | FALLTHROUGH_INTENDED; |
| 5645 | case ADD: |
| 5646 | if (Low32Bits(value) == 0u) { |
| 5647 | return CanEncode32BitConstantAsImmediate(codegen_, High32Bits(value), opcode); |
| 5648 | } |
| 5649 | high_opcode = ADC; |
| 5650 | low_flags_update = vixl32::FlagsUpdate::SetFlags; |
| 5651 | break; |
| 5652 | default: |
| 5653 | break; |
| 5654 | } |
| 5655 | return CanEncode32BitConstantAsImmediate(codegen_, High32Bits(value), high_opcode) && |
| 5656 | CanEncode32BitConstantAsImmediate(codegen_, Low32Bits(value), opcode, low_flags_update); |
| 5657 | } else { |
| 5658 | return CanEncode32BitConstantAsImmediate(codegen_, Low32Bits(value), opcode); |
| 5659 | } |
| 5660 | } |
| 5661 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5662 | void InstructionCodeGeneratorARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 5663 | const FieldInfo& field_info) { |
| 5664 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 5665 | |
| 5666 | LocationSummary* locations = instruction->GetLocations(); |
| 5667 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 5668 | Location out = locations->Out(); |
| 5669 | bool is_volatile = field_info.IsVolatile(); |
| 5670 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5671 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 5672 | DataType::Type load_type = instruction->GetType(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5673 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5674 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5675 | switch (load_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5676 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5677 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5678 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5679 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5680 | case DataType::Type::kInt16: |
| 5681 | case DataType::Type::kInt32: { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5682 | LoadOperandType operand_type = GetLoadOperandType(load_type); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5683 | GetAssembler()->LoadFromOffset(operand_type, RegisterFrom(out), base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5684 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5685 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5686 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5687 | case DataType::Type::kReference: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5688 | // /* HeapReference<Object> */ out = *(base + offset) |
| 5689 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5690 | Location temp_loc = locations->GetTemp(0); |
| 5691 | // Note that a potential implicit null check is handled in this |
| 5692 | // CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier call. |
| 5693 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 5694 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 5695 | if (is_volatile) { |
| 5696 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5697 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5698 | } else { |
| 5699 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(out), base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5700 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5701 | if (is_volatile) { |
| 5702 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5703 | } |
| 5704 | // If read barriers are enabled, emit read barriers other than |
| 5705 | // Baker's using a slow path (and also unpoison the loaded |
| 5706 | // reference, if heap poisoning is enabled). |
| 5707 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, locations->InAt(0), offset); |
| 5708 | } |
| 5709 | break; |
| 5710 | } |
| 5711 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5712 | case DataType::Type::kInt64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5713 | if (is_volatile && !atomic_ldrd_strd) { |
| 5714 | GenerateWideAtomicLoad(base, offset, LowRegisterFrom(out), HighRegisterFrom(out)); |
| 5715 | } else { |
| 5716 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out), base, offset); |
| 5717 | } |
| 5718 | break; |
| 5719 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5720 | case DataType::Type::kFloat32: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5721 | GetAssembler()->LoadSFromOffset(SRegisterFrom(out), base, offset); |
| 5722 | break; |
| 5723 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5724 | case DataType::Type::kFloat64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5725 | vixl32::DRegister out_dreg = DRegisterFrom(out); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5726 | if (is_volatile && !atomic_ldrd_strd) { |
| 5727 | vixl32::Register lo = RegisterFrom(locations->GetTemp(0)); |
| 5728 | vixl32::Register hi = RegisterFrom(locations->GetTemp(1)); |
| 5729 | GenerateWideAtomicLoad(base, offset, lo, hi); |
| 5730 | // TODO(VIXL): Do we need to be immediately after the ldrexd instruction? If so we need a |
| 5731 | // scope. |
| 5732 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5733 | __ Vmov(out_dreg, lo, hi); |
| 5734 | } else { |
| 5735 | GetAssembler()->LoadDFromOffset(out_dreg, base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5736 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5737 | } |
| 5738 | break; |
| 5739 | } |
| 5740 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5741 | case DataType::Type::kVoid: |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5742 | LOG(FATAL) << "Unreachable type " << load_type; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5743 | UNREACHABLE(); |
| 5744 | } |
| 5745 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5746 | if (load_type == DataType::Type::kReference || load_type == DataType::Type::kFloat64) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5747 | // Potential implicit null checks, in the case of reference or |
| 5748 | // double fields, are handled in the previous switch statement. |
| 5749 | } else { |
| 5750 | // 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] | 5751 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, we |
| 5752 | // should use a scope and the assembler to emit the load instruction to guarantee that we |
| 5753 | // record the pc at the correct position. But the `Assembler` does not automatically handle |
| 5754 | // unencodable offsets. Practically, everything is fine because the helper and VIXL, at the time |
| 5755 | // of writing, do generate the store instruction last. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5756 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5757 | } |
| 5758 | |
| 5759 | if (is_volatile) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5760 | if (load_type == DataType::Type::kReference) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5761 | // Memory barriers, in the case of references, are also handled |
| 5762 | // in the previous switch statement. |
| 5763 | } else { |
| 5764 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5765 | } |
| 5766 | } |
| 5767 | } |
| 5768 | |
| 5769 | void LocationsBuilderARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5770 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5771 | } |
| 5772 | |
| 5773 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5774 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 5775 | } |
| 5776 | |
| 5777 | void LocationsBuilderARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5778 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5779 | } |
| 5780 | |
| 5781 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5782 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5783 | } |
| 5784 | |
| 5785 | void LocationsBuilderARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5786 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5787 | } |
| 5788 | |
| 5789 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5790 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5791 | } |
| 5792 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5793 | void LocationsBuilderARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5794 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5795 | } |
| 5796 | |
| 5797 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5798 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 5799 | } |
| 5800 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 5801 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 5802 | HUnresolvedInstanceFieldGet* instruction) { |
| 5803 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5804 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5805 | instruction, instruction->GetFieldType(), calling_convention); |
| 5806 | } |
| 5807 | |
| 5808 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 5809 | HUnresolvedInstanceFieldGet* instruction) { |
| 5810 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5811 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5812 | instruction->GetFieldType(), |
| 5813 | instruction->GetFieldIndex(), |
| 5814 | instruction->GetDexPc(), |
| 5815 | calling_convention); |
| 5816 | } |
| 5817 | |
| 5818 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 5819 | HUnresolvedInstanceFieldSet* instruction) { |
| 5820 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5821 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5822 | instruction, instruction->GetFieldType(), calling_convention); |
| 5823 | } |
| 5824 | |
| 5825 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 5826 | HUnresolvedInstanceFieldSet* instruction) { |
| 5827 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5828 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5829 | instruction->GetFieldType(), |
| 5830 | instruction->GetFieldIndex(), |
| 5831 | instruction->GetDexPc(), |
| 5832 | calling_convention); |
| 5833 | } |
| 5834 | |
| 5835 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldGet( |
| 5836 | HUnresolvedStaticFieldGet* instruction) { |
| 5837 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5838 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5839 | instruction, instruction->GetFieldType(), calling_convention); |
| 5840 | } |
| 5841 | |
| 5842 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldGet( |
| 5843 | HUnresolvedStaticFieldGet* instruction) { |
| 5844 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5845 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5846 | instruction->GetFieldType(), |
| 5847 | instruction->GetFieldIndex(), |
| 5848 | instruction->GetDexPc(), |
| 5849 | calling_convention); |
| 5850 | } |
| 5851 | |
| 5852 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldSet( |
| 5853 | HUnresolvedStaticFieldSet* instruction) { |
| 5854 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5855 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5856 | instruction, instruction->GetFieldType(), calling_convention); |
| 5857 | } |
| 5858 | |
| 5859 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldSet( |
| 5860 | HUnresolvedStaticFieldSet* instruction) { |
| 5861 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5862 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5863 | instruction->GetFieldType(), |
| 5864 | instruction->GetFieldIndex(), |
| 5865 | instruction->GetDexPc(), |
| 5866 | calling_convention); |
| 5867 | } |
| 5868 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5869 | void LocationsBuilderARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 5870 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5871 | locations->SetInAt(0, Location::RequiresRegister()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5872 | } |
| 5873 | |
| 5874 | void CodeGeneratorARMVIXL::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5875 | if (CanMoveNullCheckToUser(instruction)) { |
| 5876 | return; |
| 5877 | } |
| 5878 | |
| 5879 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5880 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5881 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5882 | vixl32::kMaxInstructionSizeInBytes, |
| 5883 | CodeBufferCheckScope::kMaximumSize); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5884 | __ ldr(temps.Acquire(), MemOperand(InputRegisterAt(instruction, 0))); |
| 5885 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5886 | } |
| 5887 | |
| 5888 | void CodeGeneratorARMVIXL::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| 5889 | NullCheckSlowPathARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5890 | new (GetScopedAllocator()) NullCheckSlowPathARMVIXL(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5891 | AddSlowPath(slow_path); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5892 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5893 | } |
| 5894 | |
| 5895 | void InstructionCodeGeneratorARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
| 5896 | codegen_->GenerateNullCheck(instruction); |
| 5897 | } |
| 5898 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5899 | void CodeGeneratorARMVIXL::LoadFromShiftedRegOffset(DataType::Type type, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5900 | Location out_loc, |
| 5901 | vixl32::Register base, |
| 5902 | vixl32::Register reg_index, |
| 5903 | vixl32::Condition cond) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5904 | uint32_t shift_count = DataType::SizeShift(type); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5905 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 5906 | |
| 5907 | switch (type) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5908 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5909 | case DataType::Type::kUint8: |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5910 | __ Ldrb(cond, RegisterFrom(out_loc), mem_address); |
| 5911 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5912 | case DataType::Type::kInt8: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5913 | __ Ldrsb(cond, RegisterFrom(out_loc), mem_address); |
| 5914 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5915 | case DataType::Type::kUint16: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5916 | __ Ldrh(cond, RegisterFrom(out_loc), mem_address); |
| 5917 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5918 | case DataType::Type::kInt16: |
| 5919 | __ Ldrsh(cond, RegisterFrom(out_loc), mem_address); |
| 5920 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5921 | case DataType::Type::kReference: |
| 5922 | case DataType::Type::kInt32: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5923 | __ Ldr(cond, RegisterFrom(out_loc), mem_address); |
| 5924 | break; |
| 5925 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5926 | case DataType::Type::kInt64: |
| 5927 | case DataType::Type::kFloat32: |
| 5928 | case DataType::Type::kFloat64: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5929 | default: |
| 5930 | LOG(FATAL) << "Unreachable type " << type; |
| 5931 | UNREACHABLE(); |
| 5932 | } |
| 5933 | } |
| 5934 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5935 | void CodeGeneratorARMVIXL::StoreToShiftedRegOffset(DataType::Type type, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5936 | Location loc, |
| 5937 | vixl32::Register base, |
| 5938 | vixl32::Register reg_index, |
| 5939 | vixl32::Condition cond) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5940 | uint32_t shift_count = DataType::SizeShift(type); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5941 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 5942 | |
| 5943 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5944 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5945 | case DataType::Type::kUint8: |
| 5946 | case DataType::Type::kInt8: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5947 | __ Strb(cond, RegisterFrom(loc), mem_address); |
| 5948 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5949 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5950 | case DataType::Type::kInt16: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5951 | __ Strh(cond, RegisterFrom(loc), mem_address); |
| 5952 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5953 | case DataType::Type::kReference: |
| 5954 | case DataType::Type::kInt32: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5955 | __ Str(cond, RegisterFrom(loc), mem_address); |
| 5956 | break; |
| 5957 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5958 | case DataType::Type::kInt64: |
| 5959 | case DataType::Type::kFloat32: |
| 5960 | case DataType::Type::kFloat64: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5961 | default: |
| 5962 | LOG(FATAL) << "Unreachable type " << type; |
| 5963 | UNREACHABLE(); |
| 5964 | } |
| 5965 | } |
| 5966 | |
| 5967 | void LocationsBuilderARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
| 5968 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5969 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5970 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5971 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5972 | object_array_get_with_read_barrier |
| 5973 | ? LocationSummary::kCallOnSlowPath |
| 5974 | : LocationSummary::kNoCall); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5975 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5976 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5977 | } |
| 5978 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5979 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5980 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5981 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5982 | } else { |
| 5983 | // The output overlaps in the case of an object array get with |
| 5984 | // read barriers enabled: we do not want the move to overwrite the |
| 5985 | // array's location, as we need it to emit the read barrier. |
| 5986 | locations->SetOut( |
| 5987 | Location::RequiresRegister(), |
| 5988 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 5989 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 5990 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5991 | // We need a temporary register for the read barrier marking slow |
| 5992 | // path in CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier. |
| 5993 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 5994 | !Runtime::Current()->UseJitCompilation() && |
| 5995 | instruction->GetIndex()->IsConstant()) { |
| 5996 | // Array loads with constant index are treated as field loads. |
| 5997 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 5998 | // constant index loads we need a temporary only if the offset is too big. |
| 5999 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 6000 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6001 | offset += index << DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6002 | if (offset >= kReferenceLoadMinFarOffset) { |
| 6003 | locations->AddTemp(Location::RequiresRegister()); |
| 6004 | } |
| 6005 | // And we always need the reserved entrypoint register. |
| 6006 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 6007 | } else if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 6008 | !Runtime::Current()->UseJitCompilation() && |
| 6009 | !instruction->GetIndex()->IsConstant()) { |
| 6010 | // We need a non-scratch temporary for the array data pointer. |
| 6011 | locations->AddTemp(Location::RequiresRegister()); |
| 6012 | // And we always need the reserved entrypoint register. |
| 6013 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 6014 | } else { |
| 6015 | locations->AddTemp(Location::RequiresRegister()); |
| 6016 | } |
| 6017 | } else if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 6018 | // Also need a temporary for String compression feature. |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6019 | locations->AddTemp(Location::RequiresRegister()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6020 | } |
| 6021 | } |
| 6022 | |
| 6023 | void InstructionCodeGeneratorARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6024 | LocationSummary* locations = instruction->GetLocations(); |
| 6025 | Location obj_loc = locations->InAt(0); |
| 6026 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 6027 | Location index = locations->InAt(1); |
| 6028 | Location out_loc = locations->Out(); |
| 6029 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6030 | DataType::Type type = instruction->GetType(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6031 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 6032 | instruction->IsStringCharAt(); |
| 6033 | HInstruction* array_instr = instruction->GetArray(); |
| 6034 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6035 | |
| 6036 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6037 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6038 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6039 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6040 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6041 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6042 | case DataType::Type::kInt32: { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6043 | vixl32::Register length; |
| 6044 | if (maybe_compressed_char_at) { |
| 6045 | length = RegisterFrom(locations->GetTemp(0)); |
| 6046 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 6047 | GetAssembler()->LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 6048 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6049 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6050 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6051 | int32_t const_index = Int32ConstantFrom(index); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6052 | if (maybe_compressed_char_at) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6053 | vixl32::Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6054 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6055 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 6056 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6057 | "Expecting 0=compressed, 1=uncompressed"); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 6058 | __ B(cs, &uncompressed_load, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6059 | GetAssembler()->LoadFromOffset(kLoadUnsignedByte, |
| 6060 | RegisterFrom(out_loc), |
| 6061 | obj, |
| 6062 | data_offset + const_index); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6063 | __ B(final_label); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6064 | __ Bind(&uncompressed_load); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6065 | GetAssembler()->LoadFromOffset(GetLoadOperandType(DataType::Type::kUint16), |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6066 | RegisterFrom(out_loc), |
| 6067 | obj, |
| 6068 | data_offset + (const_index << 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6069 | if (done.IsReferenced()) { |
| 6070 | __ Bind(&done); |
| 6071 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6072 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6073 | uint32_t full_offset = data_offset + (const_index << DataType::SizeShift(type)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6074 | |
| 6075 | LoadOperandType load_type = GetLoadOperandType(type); |
| 6076 | GetAssembler()->LoadFromOffset(load_type, RegisterFrom(out_loc), obj, full_offset); |
| 6077 | } |
| 6078 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6079 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6080 | vixl32::Register temp = temps.Acquire(); |
| 6081 | |
| 6082 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6083 | // We do not need to compute the intermediate address from the array: the |
| 6084 | // input instruction has done it already. See the comment in |
| 6085 | // `TryExtractArrayAccessAddress()`. |
| 6086 | if (kIsDebugBuild) { |
| 6087 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6088 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6089 | } |
| 6090 | temp = obj; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6091 | } else { |
| 6092 | __ Add(temp, obj, data_offset); |
| 6093 | } |
| 6094 | if (maybe_compressed_char_at) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6095 | vixl32::Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6096 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6097 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 6098 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6099 | "Expecting 0=compressed, 1=uncompressed"); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 6100 | __ B(cs, &uncompressed_load, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6101 | __ Ldrb(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 0)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6102 | __ B(final_label); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6103 | __ Bind(&uncompressed_load); |
| 6104 | __ Ldrh(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6105 | if (done.IsReferenced()) { |
| 6106 | __ Bind(&done); |
| 6107 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6108 | } else { |
| 6109 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
| 6110 | } |
| 6111 | } |
| 6112 | break; |
| 6113 | } |
| 6114 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6115 | case DataType::Type::kReference: { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6116 | // The read barrier instrumentation of object ArrayGet |
| 6117 | // instructions does not support the HIntermediateAddress |
| 6118 | // instruction. |
| 6119 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 6120 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6121 | static_assert( |
| 6122 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6123 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 6124 | // /* HeapReference<Object> */ out = |
| 6125 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6126 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6127 | Location temp = locations->GetTemp(0); |
| 6128 | // Note that a potential implicit null check is handled in this |
| 6129 | // CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6130 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 6131 | if (index.IsConstant()) { |
| 6132 | // 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] | 6133 | data_offset += Int32ConstantFrom(index) << DataType::SizeShift(type); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6134 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6135 | out_loc, |
| 6136 | obj, |
| 6137 | data_offset, |
| 6138 | locations->GetTemp(0), |
| 6139 | /* needs_null_check */ false); |
| 6140 | } else { |
| 6141 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 6142 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ false); |
| 6143 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6144 | } else { |
| 6145 | vixl32::Register out = OutputRegister(instruction); |
| 6146 | if (index.IsConstant()) { |
| 6147 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6148 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6149 | GetAssembler()->LoadFromOffset(kLoadWord, out, obj, offset); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6150 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, |
| 6151 | // we should use a scope and the assembler to emit the load instruction to guarantee that |
| 6152 | // we record the pc at the correct position. But the `Assembler` does not automatically |
| 6153 | // handle unencodable offsets. Practically, everything is fine because the helper and |
| 6154 | // VIXL, at the time of writing, do generate the store instruction last. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6155 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6156 | // If read barriers are enabled, emit read barriers other than |
| 6157 | // Baker's using a slow path (and also unpoison the loaded |
| 6158 | // reference, if heap poisoning is enabled). |
| 6159 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 6160 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6161 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6162 | vixl32::Register temp = temps.Acquire(); |
| 6163 | |
| 6164 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6165 | // We do not need to compute the intermediate address from the array: the |
| 6166 | // input instruction has done it already. See the comment in |
| 6167 | // `TryExtractArrayAccessAddress()`. |
| 6168 | if (kIsDebugBuild) { |
| 6169 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6170 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6171 | } |
| 6172 | temp = obj; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6173 | } else { |
| 6174 | __ Add(temp, obj, data_offset); |
| 6175 | } |
| 6176 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6177 | temps.Close(); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6178 | // TODO(VIXL): Use a scope to ensure that we record the pc position immediately after the |
| 6179 | // load instruction. Practically, everything is fine because the helper and VIXL, at the |
| 6180 | // time of writing, do generate the store instruction last. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6181 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6182 | // If read barriers are enabled, emit read barriers other than |
| 6183 | // Baker's using a slow path (and also unpoison the loaded |
| 6184 | // reference, if heap poisoning is enabled). |
| 6185 | codegen_->MaybeGenerateReadBarrierSlow( |
| 6186 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 6187 | } |
| 6188 | } |
| 6189 | break; |
| 6190 | } |
| 6191 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6192 | case DataType::Type::kInt64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6193 | if (index.IsConstant()) { |
| 6194 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6195 | (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6196 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), obj, offset); |
| 6197 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6198 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6199 | vixl32::Register temp = temps.Acquire(); |
| 6200 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6201 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), temp, data_offset); |
| 6202 | } |
| 6203 | break; |
| 6204 | } |
| 6205 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6206 | case DataType::Type::kFloat32: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6207 | vixl32::SRegister out = SRegisterFrom(out_loc); |
| 6208 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6209 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6210 | GetAssembler()->LoadSFromOffset(out, obj, offset); |
| 6211 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6212 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6213 | vixl32::Register temp = temps.Acquire(); |
| 6214 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 6215 | GetAssembler()->LoadSFromOffset(out, temp, data_offset); |
| 6216 | } |
| 6217 | break; |
| 6218 | } |
| 6219 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6220 | case DataType::Type::kFloat64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6221 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6222 | size_t offset = (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6223 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), obj, offset); |
| 6224 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6225 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6226 | vixl32::Register temp = temps.Acquire(); |
| 6227 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6228 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), temp, data_offset); |
| 6229 | } |
| 6230 | break; |
| 6231 | } |
| 6232 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6233 | case DataType::Type::kVoid: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6234 | LOG(FATAL) << "Unreachable type " << type; |
| 6235 | UNREACHABLE(); |
| 6236 | } |
| 6237 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6238 | if (type == DataType::Type::kReference) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6239 | // Potential implicit null checks, in the case of reference |
| 6240 | // arrays, are handled in the previous switch statement. |
| 6241 | } else if (!maybe_compressed_char_at) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6242 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after |
| 6243 | // the preceding load instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6244 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6245 | } |
| 6246 | } |
| 6247 | |
| 6248 | void LocationsBuilderARMVIXL::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6249 | DataType::Type value_type = instruction->GetComponentType(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6250 | |
| 6251 | bool needs_write_barrier = |
| 6252 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 6253 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 6254 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6255 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6256 | instruction, |
| 6257 | may_need_runtime_call_for_type_check ? |
| 6258 | LocationSummary::kCallOnSlowPath : |
| 6259 | LocationSummary::kNoCall); |
| 6260 | |
| 6261 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6262 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6263 | if (DataType::IsFloatingPointType(value_type)) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6264 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 6265 | } else { |
| 6266 | locations->SetInAt(2, Location::RequiresRegister()); |
| 6267 | } |
| 6268 | if (needs_write_barrier) { |
| 6269 | // Temporary registers for the write barrier. |
| 6270 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 6271 | locations->AddTemp(Location::RequiresRegister()); |
| 6272 | } |
| 6273 | } |
| 6274 | |
| 6275 | void InstructionCodeGeneratorARMVIXL::VisitArraySet(HArraySet* instruction) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6276 | LocationSummary* locations = instruction->GetLocations(); |
| 6277 | vixl32::Register array = InputRegisterAt(instruction, 0); |
| 6278 | Location index = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6279 | DataType::Type value_type = instruction->GetComponentType(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6280 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 6281 | bool needs_write_barrier = |
| 6282 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 6283 | uint32_t data_offset = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6284 | mirror::Array::DataOffset(DataType::Size(value_type)).Uint32Value(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6285 | Location value_loc = locations->InAt(2); |
| 6286 | HInstruction* array_instr = instruction->GetArray(); |
| 6287 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6288 | |
| 6289 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6290 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6291 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6292 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6293 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6294 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6295 | case DataType::Type::kInt32: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6296 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6297 | int32_t const_index = Int32ConstantFrom(index); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6298 | uint32_t full_offset = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6299 | data_offset + (const_index << DataType::SizeShift(value_type)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6300 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 6301 | GetAssembler()->StoreToOffset(store_type, RegisterFrom(value_loc), array, full_offset); |
| 6302 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6303 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6304 | vixl32::Register temp = temps.Acquire(); |
| 6305 | |
| 6306 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6307 | // We do not need to compute the intermediate address from the array: the |
| 6308 | // input instruction has done it already. See the comment in |
| 6309 | // `TryExtractArrayAccessAddress()`. |
| 6310 | if (kIsDebugBuild) { |
| 6311 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6312 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6313 | } |
| 6314 | temp = array; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6315 | } else { |
| 6316 | __ Add(temp, array, data_offset); |
| 6317 | } |
| 6318 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 6319 | } |
| 6320 | break; |
| 6321 | } |
| 6322 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6323 | case DataType::Type::kReference: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6324 | vixl32::Register value = RegisterFrom(value_loc); |
| 6325 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 6326 | // See the comment in instruction_simplifier_shared.cc. |
| 6327 | DCHECK(!has_intermediate_address); |
| 6328 | |
| 6329 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 6330 | // Just setting null. |
| 6331 | if (index.IsConstant()) { |
| 6332 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6333 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6334 | GetAssembler()->StoreToOffset(kStoreWord, value, array, offset); |
| 6335 | } else { |
| 6336 | DCHECK(index.IsRegister()) << index; |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6337 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6338 | vixl32::Register temp = temps.Acquire(); |
| 6339 | __ Add(temp, array, data_offset); |
| 6340 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 6341 | } |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6342 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after the preceding |
| 6343 | // store instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6344 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6345 | DCHECK(!needs_write_barrier); |
| 6346 | DCHECK(!may_need_runtime_call_for_type_check); |
| 6347 | break; |
| 6348 | } |
| 6349 | |
| 6350 | DCHECK(needs_write_barrier); |
| 6351 | Location temp1_loc = locations->GetTemp(0); |
| 6352 | vixl32::Register temp1 = RegisterFrom(temp1_loc); |
| 6353 | Location temp2_loc = locations->GetTemp(1); |
| 6354 | vixl32::Register temp2 = RegisterFrom(temp2_loc); |
| 6355 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6356 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6357 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6358 | vixl32::Label done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6359 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6360 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 6361 | |
| 6362 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6363 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathARMVIXL(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6364 | codegen_->AddSlowPath(slow_path); |
| 6365 | if (instruction->GetValueCanBeNull()) { |
| 6366 | vixl32::Label non_zero; |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6367 | __ CompareAndBranchIfNonZero(value, &non_zero); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6368 | if (index.IsConstant()) { |
| 6369 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6370 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6371 | GetAssembler()->StoreToOffset(kStoreWord, value, array, offset); |
| 6372 | } else { |
| 6373 | DCHECK(index.IsRegister()) << index; |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6374 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6375 | vixl32::Register temp = temps.Acquire(); |
| 6376 | __ Add(temp, array, data_offset); |
| 6377 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 6378 | } |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6379 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after the preceding |
| 6380 | // store instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6381 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6382 | __ B(final_label); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6383 | __ Bind(&non_zero); |
| 6384 | } |
| 6385 | |
| 6386 | // Note that when read barriers are enabled, the type checks |
| 6387 | // are performed without read barriers. This is fine, even in |
| 6388 | // the case where a class object is in the from-space after |
| 6389 | // the flip, as a comparison involving such a type would not |
| 6390 | // produce a false positive; it may of course produce a false |
| 6391 | // negative, in which case we would take the ArraySet slow |
| 6392 | // path. |
| 6393 | |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6394 | { |
| 6395 | // Ensure we record the pc position immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6396 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6397 | vixl32::kMaxInstructionSizeInBytes, |
| 6398 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6399 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 6400 | __ ldr(temp1, MemOperand(array, class_offset)); |
| 6401 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6402 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6403 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 6404 | |
| 6405 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 6406 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 6407 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 6408 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 6409 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 6410 | // nor `temp2`, as we are comparing two poisoned references. |
| 6411 | __ Cmp(temp1, temp2); |
| 6412 | |
| 6413 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 6414 | vixl32::Label do_put; |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 6415 | __ B(eq, &do_put, /* far_target */ false); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6416 | // If heap poisoning is enabled, the `temp1` reference has |
| 6417 | // not been unpoisoned yet; unpoison it now. |
| 6418 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 6419 | |
| 6420 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 6421 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 6422 | // If heap poisoning is enabled, no need to unpoison |
| 6423 | // `temp1`, as we are comparing against null below. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6424 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6425 | __ Bind(&do_put); |
| 6426 | } else { |
| 6427 | __ B(ne, slow_path->GetEntryLabel()); |
| 6428 | } |
| 6429 | } |
| 6430 | |
| 6431 | vixl32::Register source = value; |
| 6432 | if (kPoisonHeapReferences) { |
| 6433 | // Note that in the case where `value` is a null reference, |
| 6434 | // we do not enter this block, as a null reference does not |
| 6435 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6436 | DCHECK_EQ(value_type, DataType::Type::kReference); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6437 | __ Mov(temp1, value); |
| 6438 | GetAssembler()->PoisonHeapReference(temp1); |
| 6439 | source = temp1; |
| 6440 | } |
| 6441 | |
| 6442 | if (index.IsConstant()) { |
| 6443 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6444 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6445 | GetAssembler()->StoreToOffset(kStoreWord, source, array, offset); |
| 6446 | } else { |
| 6447 | DCHECK(index.IsRegister()) << index; |
| 6448 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6449 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6450 | vixl32::Register temp = temps.Acquire(); |
| 6451 | __ Add(temp, array, data_offset); |
| 6452 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6453 | LocationFrom(source), |
| 6454 | temp, |
| 6455 | RegisterFrom(index)); |
| 6456 | } |
| 6457 | |
| 6458 | if (!may_need_runtime_call_for_type_check) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6459 | // TODO(VIXL): Ensure we record the pc position immediately after the preceding store |
| 6460 | // instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6461 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6462 | } |
| 6463 | |
| 6464 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 6465 | |
| 6466 | if (done.IsReferenced()) { |
| 6467 | __ Bind(&done); |
| 6468 | } |
| 6469 | |
| 6470 | if (slow_path != nullptr) { |
| 6471 | __ Bind(slow_path->GetExitLabel()); |
| 6472 | } |
| 6473 | |
| 6474 | break; |
| 6475 | } |
| 6476 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6477 | case DataType::Type::kInt64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6478 | Location value = locations->InAt(2); |
| 6479 | if (index.IsConstant()) { |
| 6480 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6481 | (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6482 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), array, offset); |
| 6483 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6484 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6485 | vixl32::Register temp = temps.Acquire(); |
| 6486 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6487 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), temp, data_offset); |
| 6488 | } |
| 6489 | break; |
| 6490 | } |
| 6491 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6492 | case DataType::Type::kFloat32: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6493 | Location value = locations->InAt(2); |
| 6494 | DCHECK(value.IsFpuRegister()); |
| 6495 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6496 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6497 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), array, offset); |
| 6498 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6499 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6500 | vixl32::Register temp = temps.Acquire(); |
| 6501 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 6502 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), temp, data_offset); |
| 6503 | } |
| 6504 | break; |
| 6505 | } |
| 6506 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6507 | case DataType::Type::kFloat64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6508 | Location value = locations->InAt(2); |
| 6509 | DCHECK(value.IsFpuRegisterPair()); |
| 6510 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6511 | size_t offset = (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6512 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), array, offset); |
| 6513 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6514 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6515 | vixl32::Register temp = temps.Acquire(); |
| 6516 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6517 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), temp, data_offset); |
| 6518 | } |
| 6519 | break; |
| 6520 | } |
| 6521 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6522 | case DataType::Type::kVoid: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6523 | LOG(FATAL) << "Unreachable type " << value_type; |
| 6524 | UNREACHABLE(); |
| 6525 | } |
| 6526 | |
| 6527 | // Objects are handled in the switch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6528 | if (value_type != DataType::Type::kReference) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6529 | // TODO(VIXL): Ensure we record the pc position immediately after the preceding store |
| 6530 | // instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6531 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6532 | } |
| 6533 | } |
| 6534 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6535 | void LocationsBuilderARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 6536 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6537 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6538 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6539 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6540 | } |
| 6541 | |
| 6542 | void InstructionCodeGeneratorARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 6543 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| 6544 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 6545 | vixl32::Register out = OutputRegister(instruction); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6546 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6547 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6548 | vixl32::kMaxInstructionSizeInBytes, |
| 6549 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6550 | __ ldr(out, MemOperand(obj, offset)); |
| 6551 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6552 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6553 | // Mask out compression flag from String's array length. |
| 6554 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6555 | __ Lsr(out, out, 1u); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6556 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6557 | } |
| 6558 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6559 | void LocationsBuilderARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6560 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6561 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6562 | |
| 6563 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6564 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 6565 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6566 | } |
| 6567 | |
| 6568 | void InstructionCodeGeneratorARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 6569 | vixl32::Register out = OutputRegister(instruction); |
| 6570 | vixl32::Register first = InputRegisterAt(instruction, 0); |
| 6571 | Location second = instruction->GetLocations()->InAt(1); |
| 6572 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6573 | if (second.IsRegister()) { |
| 6574 | __ Add(out, first, RegisterFrom(second)); |
| 6575 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6576 | __ Add(out, first, Int32ConstantFrom(second)); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6577 | } |
| 6578 | } |
| 6579 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 6580 | void LocationsBuilderARMVIXL::VisitIntermediateAddressIndex( |
| 6581 | HIntermediateAddressIndex* instruction) { |
| 6582 | LOG(FATAL) << "Unreachable " << instruction->GetId(); |
| 6583 | } |
| 6584 | |
| 6585 | void InstructionCodeGeneratorARMVIXL::VisitIntermediateAddressIndex( |
| 6586 | HIntermediateAddressIndex* instruction) { |
| 6587 | LOG(FATAL) << "Unreachable " << instruction->GetId(); |
| 6588 | } |
| 6589 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6590 | void LocationsBuilderARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 6591 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6592 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 6593 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 6594 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(1))); |
| 6595 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6596 | |
| 6597 | HInstruction* index = instruction->InputAt(0); |
| 6598 | HInstruction* length = instruction->InputAt(1); |
| 6599 | // If both index and length are constants we can statically check the bounds. But if at least one |
| 6600 | // of them is not encodable ArmEncodableConstantOrRegister will create |
| 6601 | // Location::RequiresRegister() which is not desired to happen. Instead we create constant |
| 6602 | // locations. |
| 6603 | bool both_const = index->IsConstant() && length->IsConstant(); |
| 6604 | locations->SetInAt(0, both_const |
| 6605 | ? Location::ConstantLocation(index->AsConstant()) |
| 6606 | : ArmEncodableConstantOrRegister(index, CMP)); |
| 6607 | locations->SetInAt(1, both_const |
| 6608 | ? Location::ConstantLocation(length->AsConstant()) |
| 6609 | : ArmEncodableConstantOrRegister(length, CMP)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6610 | } |
| 6611 | |
| 6612 | void InstructionCodeGeneratorARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6613 | LocationSummary* locations = instruction->GetLocations(); |
| 6614 | Location index_loc = locations->InAt(0); |
| 6615 | Location length_loc = locations->InAt(1); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6616 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6617 | if (length_loc.IsConstant()) { |
| 6618 | int32_t length = Int32ConstantFrom(length_loc); |
| 6619 | if (index_loc.IsConstant()) { |
| 6620 | // BCE will remove the bounds check if we are guaranteed to pass. |
| 6621 | int32_t index = Int32ConstantFrom(index_loc); |
| 6622 | if (index < 0 || index >= length) { |
| 6623 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6624 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARMVIXL(instruction); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6625 | codegen_->AddSlowPath(slow_path); |
| 6626 | __ B(slow_path->GetEntryLabel()); |
| 6627 | } else { |
| 6628 | // Some optimization after BCE may have generated this, and we should not |
| 6629 | // generate a bounds check if it is a valid range. |
| 6630 | } |
| 6631 | return; |
| 6632 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6633 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6634 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6635 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARMVIXL(instruction); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6636 | __ Cmp(RegisterFrom(index_loc), length); |
| 6637 | codegen_->AddSlowPath(slow_path); |
| 6638 | __ B(hs, slow_path->GetEntryLabel()); |
| 6639 | } else { |
| 6640 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6641 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARMVIXL(instruction); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6642 | __ Cmp(RegisterFrom(length_loc), InputOperandAt(instruction, 0)); |
| 6643 | codegen_->AddSlowPath(slow_path); |
| 6644 | __ B(ls, slow_path->GetEntryLabel()); |
| 6645 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6646 | } |
| 6647 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6648 | void CodeGeneratorARMVIXL::MarkGCCard(vixl32::Register temp, |
| 6649 | vixl32::Register card, |
| 6650 | vixl32::Register object, |
| 6651 | vixl32::Register value, |
| 6652 | bool can_be_null) { |
| 6653 | vixl32::Label is_null; |
| 6654 | if (can_be_null) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6655 | __ CompareAndBranchIfZero(value, &is_null); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6656 | } |
| 6657 | GetAssembler()->LoadFromOffset( |
| 6658 | kLoadWord, card, tr, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 6659 | __ Lsr(temp, object, Operand::From(gc::accounting::CardTable::kCardShift)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6660 | __ Strb(card, MemOperand(card, temp)); |
| 6661 | if (can_be_null) { |
| 6662 | __ Bind(&is_null); |
| 6663 | } |
| 6664 | } |
| 6665 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6666 | void LocationsBuilderARMVIXL::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 6667 | LOG(FATAL) << "Unreachable"; |
| 6668 | } |
| 6669 | |
| 6670 | void InstructionCodeGeneratorARMVIXL::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 6671 | if (instruction->GetNext()->IsSuspendCheck() && |
| 6672 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 6673 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 6674 | // The back edge will generate the suspend check. |
| 6675 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 6676 | } |
| 6677 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6678 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6679 | } |
| 6680 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6681 | void LocationsBuilderARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6682 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6683 | instruction, LocationSummary::kCallOnSlowPath); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6684 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6685 | } |
| 6686 | |
| 6687 | void InstructionCodeGeneratorARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 6688 | HBasicBlock* block = instruction->GetBlock(); |
| 6689 | if (block->GetLoopInformation() != nullptr) { |
| 6690 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6691 | // The back edge will generate the suspend check. |
| 6692 | return; |
| 6693 | } |
| 6694 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6695 | // The goto will generate the suspend check. |
| 6696 | return; |
| 6697 | } |
| 6698 | GenerateSuspendCheck(instruction, nullptr); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 6699 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 12); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6700 | } |
| 6701 | |
| 6702 | void InstructionCodeGeneratorARMVIXL::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 6703 | HBasicBlock* successor) { |
| 6704 | SuspendCheckSlowPathARMVIXL* slow_path = |
| 6705 | down_cast<SuspendCheckSlowPathARMVIXL*>(instruction->GetSlowPath()); |
| 6706 | if (slow_path == nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6707 | slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6708 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathARMVIXL(instruction, successor); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6709 | instruction->SetSlowPath(slow_path); |
| 6710 | codegen_->AddSlowPath(slow_path); |
| 6711 | if (successor != nullptr) { |
| 6712 | DCHECK(successor->IsLoopHeader()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6713 | } |
| 6714 | } else { |
| 6715 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 6716 | } |
| 6717 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6718 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6719 | vixl32::Register temp = temps.Acquire(); |
| 6720 | GetAssembler()->LoadFromOffset( |
| 6721 | kLoadUnsignedHalfword, temp, tr, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
| 6722 | if (successor == nullptr) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6723 | __ CompareAndBranchIfNonZero(temp, slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6724 | __ Bind(slow_path->GetReturnLabel()); |
| 6725 | } else { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6726 | __ CompareAndBranchIfZero(temp, codegen_->GetLabelOf(successor)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6727 | __ B(slow_path->GetEntryLabel()); |
| 6728 | } |
| 6729 | } |
| 6730 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6731 | ArmVIXLAssembler* ParallelMoveResolverARMVIXL::GetAssembler() const { |
| 6732 | return codegen_->GetAssembler(); |
| 6733 | } |
| 6734 | |
| 6735 | void ParallelMoveResolverARMVIXL::EmitMove(size_t index) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6736 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6737 | MoveOperands* move = moves_[index]; |
| 6738 | Location source = move->GetSource(); |
| 6739 | Location destination = move->GetDestination(); |
| 6740 | |
| 6741 | if (source.IsRegister()) { |
| 6742 | if (destination.IsRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6743 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6744 | } else if (destination.IsFpuRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6745 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6746 | } else { |
| 6747 | DCHECK(destination.IsStackSlot()); |
| 6748 | GetAssembler()->StoreToOffset(kStoreWord, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6749 | RegisterFrom(source), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6750 | sp, |
| 6751 | destination.GetStackIndex()); |
| 6752 | } |
| 6753 | } else if (source.IsStackSlot()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6754 | if (destination.IsRegister()) { |
| 6755 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 6756 | RegisterFrom(destination), |
| 6757 | sp, |
| 6758 | source.GetStackIndex()); |
| 6759 | } else if (destination.IsFpuRegister()) { |
| 6760 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 6761 | } else { |
| 6762 | DCHECK(destination.IsStackSlot()); |
| 6763 | vixl32::Register temp = temps.Acquire(); |
| 6764 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 6765 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6766 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6767 | } else if (source.IsFpuRegister()) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6768 | if (destination.IsRegister()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6769 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6770 | } else if (destination.IsFpuRegister()) { |
| 6771 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 6772 | } else { |
| 6773 | DCHECK(destination.IsStackSlot()); |
| 6774 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 6775 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6776 | } else if (source.IsDoubleStackSlot()) { |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6777 | if (destination.IsDoubleStackSlot()) { |
| 6778 | vixl32::DRegister temp = temps.AcquireD(); |
| 6779 | GetAssembler()->LoadDFromOffset(temp, sp, source.GetStackIndex()); |
| 6780 | GetAssembler()->StoreDToOffset(temp, sp, destination.GetStackIndex()); |
| 6781 | } else if (destination.IsRegisterPair()) { |
| 6782 | DCHECK(ExpectedPairLayout(destination)); |
| 6783 | GetAssembler()->LoadFromOffset( |
| 6784 | kLoadWordPair, LowRegisterFrom(destination), sp, source.GetStackIndex()); |
| 6785 | } else { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6786 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 6787 | GetAssembler()->LoadDFromOffset(DRegisterFrom(destination), sp, source.GetStackIndex()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6788 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6789 | } else if (source.IsRegisterPair()) { |
| 6790 | if (destination.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6791 | __ Mov(LowRegisterFrom(destination), LowRegisterFrom(source)); |
| 6792 | __ Mov(HighRegisterFrom(destination), HighRegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6793 | } else if (destination.IsFpuRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6794 | __ Vmov(DRegisterFrom(destination), LowRegisterFrom(source), HighRegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6795 | } else { |
| 6796 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6797 | DCHECK(ExpectedPairLayout(source)); |
| 6798 | GetAssembler()->StoreToOffset(kStoreWordPair, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6799 | LowRegisterFrom(source), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6800 | sp, |
| 6801 | destination.GetStackIndex()); |
| 6802 | } |
| 6803 | } else if (source.IsFpuRegisterPair()) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6804 | if (destination.IsRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6805 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), DRegisterFrom(source)); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6806 | } else if (destination.IsFpuRegisterPair()) { |
| 6807 | __ Vmov(DRegisterFrom(destination), DRegisterFrom(source)); |
| 6808 | } else { |
| 6809 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6810 | GetAssembler()->StoreDToOffset(DRegisterFrom(source), sp, destination.GetStackIndex()); |
| 6811 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6812 | } else { |
| 6813 | DCHECK(source.IsConstant()) << source; |
| 6814 | HConstant* constant = source.GetConstant(); |
| 6815 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 6816 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
| 6817 | if (destination.IsRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6818 | __ Mov(RegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6819 | } else { |
| 6820 | DCHECK(destination.IsStackSlot()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6821 | vixl32::Register temp = temps.Acquire(); |
| 6822 | __ Mov(temp, value); |
| 6823 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6824 | } |
| 6825 | } else if (constant->IsLongConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6826 | int64_t value = Int64ConstantFrom(source); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6827 | if (destination.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6828 | __ Mov(LowRegisterFrom(destination), Low32Bits(value)); |
| 6829 | __ Mov(HighRegisterFrom(destination), High32Bits(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6830 | } else { |
| 6831 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6832 | vixl32::Register temp = temps.Acquire(); |
| 6833 | __ Mov(temp, Low32Bits(value)); |
| 6834 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6835 | __ Mov(temp, High32Bits(value)); |
| 6836 | GetAssembler()->StoreToOffset(kStoreWord, |
| 6837 | temp, |
| 6838 | sp, |
| 6839 | destination.GetHighStackIndex(kArmWordSize)); |
| 6840 | } |
| 6841 | } else if (constant->IsDoubleConstant()) { |
| 6842 | double value = constant->AsDoubleConstant()->GetValue(); |
| 6843 | if (destination.IsFpuRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6844 | __ Vmov(DRegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6845 | } else { |
| 6846 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6847 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6848 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6849 | __ Mov(temp, Low32Bits(int_value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6850 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6851 | __ Mov(temp, High32Bits(int_value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6852 | GetAssembler()->StoreToOffset(kStoreWord, |
| 6853 | temp, |
| 6854 | sp, |
| 6855 | destination.GetHighStackIndex(kArmWordSize)); |
| 6856 | } |
| 6857 | } else { |
| 6858 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
| 6859 | float value = constant->AsFloatConstant()->GetValue(); |
| 6860 | if (destination.IsFpuRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6861 | __ Vmov(SRegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6862 | } else { |
| 6863 | DCHECK(destination.IsStackSlot()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6864 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6865 | __ Mov(temp, bit_cast<int32_t, float>(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6866 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6867 | } |
| 6868 | } |
| 6869 | } |
| 6870 | } |
| 6871 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6872 | void ParallelMoveResolverARMVIXL::Exchange(vixl32::Register reg, int mem) { |
| 6873 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 6874 | vixl32::Register temp = temps.Acquire(); |
| 6875 | __ Mov(temp, reg); |
| 6876 | GetAssembler()->LoadFromOffset(kLoadWord, reg, sp, mem); |
| 6877 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6878 | } |
| 6879 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6880 | void ParallelMoveResolverARMVIXL::Exchange(int mem1, int mem2) { |
| 6881 | // TODO(VIXL32): Double check the performance of this implementation. |
| 6882 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6883 | vixl32::Register temp1 = temps.Acquire(); |
| 6884 | ScratchRegisterScope ensure_scratch( |
| 6885 | this, temp1.GetCode(), r0.GetCode(), codegen_->GetNumberOfCoreRegisters()); |
| 6886 | vixl32::Register temp2(ensure_scratch.GetRegister()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6887 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6888 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 6889 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, sp, mem1 + stack_offset); |
| 6890 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, sp, mem2 + stack_offset); |
| 6891 | GetAssembler()->StoreToOffset(kStoreWord, temp1, sp, mem2 + stack_offset); |
| 6892 | GetAssembler()->StoreToOffset(kStoreWord, temp2, sp, mem1 + stack_offset); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6893 | } |
| 6894 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6895 | void ParallelMoveResolverARMVIXL::EmitSwap(size_t index) { |
| 6896 | MoveOperands* move = moves_[index]; |
| 6897 | Location source = move->GetSource(); |
| 6898 | Location destination = move->GetDestination(); |
| 6899 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 6900 | |
| 6901 | if (source.IsRegister() && destination.IsRegister()) { |
| 6902 | vixl32::Register temp = temps.Acquire(); |
| 6903 | DCHECK(!RegisterFrom(source).Is(temp)); |
| 6904 | DCHECK(!RegisterFrom(destination).Is(temp)); |
| 6905 | __ Mov(temp, RegisterFrom(destination)); |
| 6906 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 6907 | __ Mov(RegisterFrom(source), temp); |
| 6908 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| 6909 | Exchange(RegisterFrom(source), destination.GetStackIndex()); |
| 6910 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| 6911 | Exchange(RegisterFrom(destination), source.GetStackIndex()); |
| 6912 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 6913 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6914 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6915 | vixl32::Register temp = temps.Acquire(); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 6916 | __ Vmov(temp, SRegisterFrom(source)); |
| 6917 | __ Vmov(SRegisterFrom(source), SRegisterFrom(destination)); |
| 6918 | __ Vmov(SRegisterFrom(destination), temp); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6919 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
| 6920 | vixl32::DRegister temp = temps.AcquireD(); |
| 6921 | __ Vmov(temp, LowRegisterFrom(source), HighRegisterFrom(source)); |
| 6922 | __ Mov(LowRegisterFrom(source), LowRegisterFrom(destination)); |
| 6923 | __ Mov(HighRegisterFrom(source), HighRegisterFrom(destination)); |
| 6924 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), temp); |
| 6925 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
| 6926 | vixl32::Register low_reg = LowRegisterFrom(source.IsRegisterPair() ? source : destination); |
| 6927 | int mem = source.IsRegisterPair() ? destination.GetStackIndex() : source.GetStackIndex(); |
| 6928 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
| 6929 | vixl32::DRegister temp = temps.AcquireD(); |
| 6930 | __ Vmov(temp, low_reg, vixl32::Register(low_reg.GetCode() + 1)); |
| 6931 | GetAssembler()->LoadFromOffset(kLoadWordPair, low_reg, sp, mem); |
| 6932 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
| 6933 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6934 | vixl32::DRegister first = DRegisterFrom(source); |
| 6935 | vixl32::DRegister second = DRegisterFrom(destination); |
| 6936 | vixl32::DRegister temp = temps.AcquireD(); |
| 6937 | __ Vmov(temp, first); |
| 6938 | __ Vmov(first, second); |
| 6939 | __ Vmov(second, temp); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6940 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 6941 | vixl32::DRegister reg = source.IsFpuRegisterPair() |
| 6942 | ? DRegisterFrom(source) |
| 6943 | : DRegisterFrom(destination); |
| 6944 | int mem = source.IsFpuRegisterPair() |
| 6945 | ? destination.GetStackIndex() |
| 6946 | : source.GetStackIndex(); |
| 6947 | vixl32::DRegister temp = temps.AcquireD(); |
| 6948 | __ Vmov(temp, reg); |
| 6949 | GetAssembler()->LoadDFromOffset(reg, sp, mem); |
| 6950 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6951 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 6952 | vixl32::SRegister reg = source.IsFpuRegister() |
| 6953 | ? SRegisterFrom(source) |
| 6954 | : SRegisterFrom(destination); |
| 6955 | int mem = source.IsFpuRegister() |
| 6956 | ? destination.GetStackIndex() |
| 6957 | : source.GetStackIndex(); |
| 6958 | vixl32::Register temp = temps.Acquire(); |
| 6959 | __ Vmov(temp, reg); |
| 6960 | GetAssembler()->LoadSFromOffset(reg, sp, mem); |
| 6961 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6962 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 6963 | vixl32::DRegister temp1 = temps.AcquireD(); |
| 6964 | vixl32::DRegister temp2 = temps.AcquireD(); |
| 6965 | __ Vldr(temp1, MemOperand(sp, source.GetStackIndex())); |
| 6966 | __ Vldr(temp2, MemOperand(sp, destination.GetStackIndex())); |
| 6967 | __ Vstr(temp1, MemOperand(sp, destination.GetStackIndex())); |
| 6968 | __ Vstr(temp2, MemOperand(sp, source.GetStackIndex())); |
| 6969 | } else { |
| 6970 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
| 6971 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6972 | } |
| 6973 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6974 | void ParallelMoveResolverARMVIXL::SpillScratch(int reg) { |
| 6975 | __ Push(vixl32::Register(reg)); |
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::RestoreScratch(int reg) { |
| 6979 | __ Pop(vixl32::Register(reg)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6980 | } |
| 6981 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6982 | HLoadClass::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadClassKind( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6983 | HLoadClass::LoadKind desired_class_load_kind) { |
| 6984 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6985 | case HLoadClass::LoadKind::kInvalid: |
| 6986 | LOG(FATAL) << "UNREACHABLE"; |
| 6987 | UNREACHABLE(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6988 | case HLoadClass::LoadKind::kReferrersClass: |
| 6989 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6990 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6991 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6992 | case HLoadClass::LoadKind::kBssEntry: |
| 6993 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 6994 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6995 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6996 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6997 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6998 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6999 | case HLoadClass::LoadKind::kRuntimeCall: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7000 | break; |
| 7001 | } |
| 7002 | return desired_class_load_kind; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7003 | } |
| 7004 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7005 | void LocationsBuilderARMVIXL::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7006 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7007 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7008 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7009 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7010 | cls, |
| 7011 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7012 | LocationFrom(r0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7013 | DCHECK(calling_convention.GetRegisterAt(0).Is(r0)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7014 | return; |
| 7015 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7016 | DCHECK(!cls->NeedsAccessCheck()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7017 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7018 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 7019 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7020 | ? LocationSummary::kCallOnSlowPath |
| 7021 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7022 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7023 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7024 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7025 | } |
| 7026 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7027 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7028 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7029 | } |
| 7030 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7031 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 7032 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 7033 | // 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] | 7034 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 7035 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7036 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7037 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 7038 | // that the the kPrimNot result register is the same as the first argument register. |
| 7039 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 7040 | } else { |
| 7041 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7042 | } |
| 7043 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 7044 | if (kUseBakerReadBarrier && kBakerReadBarrierLinkTimeThunksEnableForGcRoots) { |
| 7045 | if (load_kind == HLoadClass::LoadKind::kBssEntry || |
| 7046 | (load_kind == HLoadClass::LoadKind::kReferrersClass && |
| 7047 | !Runtime::Current()->UseJitCompilation())) { |
| 7048 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 7049 | } |
| 7050 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7051 | } |
| 7052 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7053 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7054 | // move. |
| 7055 | void InstructionCodeGeneratorARMVIXL::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7056 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7057 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7058 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 7059 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 13); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7060 | return; |
| 7061 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7062 | DCHECK(!cls->NeedsAccessCheck()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7063 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7064 | LocationSummary* locations = cls->GetLocations(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7065 | Location out_loc = locations->Out(); |
| 7066 | vixl32::Register out = OutputRegister(cls); |
| 7067 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7068 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 7069 | ? kWithoutReadBarrier |
| 7070 | : kCompilerReadBarrierOption; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7071 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7072 | switch (load_kind) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7073 | case HLoadClass::LoadKind::kReferrersClass: { |
| 7074 | DCHECK(!cls->CanCallRuntime()); |
| 7075 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 7076 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 7077 | vixl32::Register current_method = InputRegisterAt(cls, 0); |
| 7078 | GenerateGcRootFieldLoad(cls, |
| 7079 | out_loc, |
| 7080 | current_method, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 7081 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7082 | read_barrier_option); |
| 7083 | break; |
| 7084 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7085 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7086 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7087 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 7088 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 7089 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 7090 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 7091 | break; |
| 7092 | } |
| 7093 | case HLoadClass::LoadKind::kBootImageAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7094 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7095 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 7096 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 7097 | DCHECK_NE(address, 0u); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7098 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7099 | break; |
| 7100 | } |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7101 | case HLoadClass::LoadKind::kBootImageClassTable: { |
| 7102 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7103 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 7104 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 7105 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 7106 | __ Ldr(out, MemOperand(out, /* offset */ 0)); |
| 7107 | // Extract the reference from the slot data, i.e. clear the hash bits. |
| 7108 | int32_t masked_hash = ClassTable::TableSlot::MaskHash( |
| 7109 | ComputeModifiedUtf8Hash(cls->GetDexFile().StringByTypeIdx(cls->GetTypeIndex()))); |
| 7110 | if (masked_hash != 0) { |
| 7111 | __ Sub(out, out, Operand(masked_hash)); |
| 7112 | } |
| 7113 | break; |
| 7114 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7115 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7116 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7117 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 7118 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 7119 | GenerateGcRootFieldLoad(cls, out_loc, out, /* offset */ 0, read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7120 | generate_null_check = true; |
| 7121 | break; |
| 7122 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7123 | case HLoadClass::LoadKind::kJitTableAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7124 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 7125 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7126 | cls->GetClass())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7127 | // /* GcRoot<mirror::Class> */ out = *out |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7128 | GenerateGcRootFieldLoad(cls, out_loc, out, /* offset */ 0, read_barrier_option); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7129 | break; |
| 7130 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7131 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7132 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7133 | LOG(FATAL) << "UNREACHABLE"; |
| 7134 | UNREACHABLE(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7135 | } |
| 7136 | |
| 7137 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 7138 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7139 | LoadClassSlowPathARMVIXL* slow_path = |
| 7140 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARMVIXL( |
| 7141 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7142 | codegen_->AddSlowPath(slow_path); |
| 7143 | if (generate_null_check) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7144 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7145 | } |
| 7146 | if (cls->MustGenerateClinitCheck()) { |
| 7147 | GenerateClassInitializationCheck(slow_path, out); |
| 7148 | } else { |
| 7149 | __ Bind(slow_path->GetExitLabel()); |
| 7150 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 7151 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 14); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7152 | } |
| 7153 | } |
| 7154 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7155 | void LocationsBuilderARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 7156 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7157 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7158 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7159 | if (check->HasUses()) { |
| 7160 | locations->SetOut(Location::SameAsFirstInput()); |
| 7161 | } |
| 7162 | } |
| 7163 | |
| 7164 | void InstructionCodeGeneratorARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 7165 | // We assume the class is not null. |
| 7166 | LoadClassSlowPathARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7167 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARMVIXL(check->GetLoadClass(), |
| 7168 | check, |
| 7169 | check->GetDexPc(), |
| 7170 | /* do_clinit */ true); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7171 | codegen_->AddSlowPath(slow_path); |
| 7172 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 7173 | } |
| 7174 | |
| 7175 | void InstructionCodeGeneratorARMVIXL::GenerateClassInitializationCheck( |
| 7176 | LoadClassSlowPathARMVIXL* slow_path, vixl32::Register class_reg) { |
| 7177 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 7178 | vixl32::Register temp = temps.Acquire(); |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 7179 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 7180 | const size_t status_byte_offset = |
| 7181 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 7182 | constexpr uint32_t shifted_initialized_value = |
| 7183 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
| 7184 | |
| 7185 | GetAssembler()->LoadFromOffset(kLoadUnsignedByte, temp, class_reg, status_byte_offset); |
| 7186 | __ Cmp(temp, shifted_initialized_value); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 7187 | __ B(lo, slow_path->GetEntryLabel()); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7188 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 7189 | // properly. Therefore, we do a memory fence. |
| 7190 | __ Dmb(ISH); |
| 7191 | __ Bind(slow_path->GetExitLabel()); |
| 7192 | } |
| 7193 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7194 | HLoadString::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadStringKind( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7195 | HLoadString::LoadKind desired_string_load_kind) { |
| 7196 | switch (desired_string_load_kind) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7197 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7198 | case HLoadString::LoadKind::kBootImageInternTable: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7199 | case HLoadString::LoadKind::kBssEntry: |
| 7200 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 7201 | break; |
| 7202 | case HLoadString::LoadKind::kJitTableAddress: |
| 7203 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7204 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 7205 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7206 | case HLoadString::LoadKind::kRuntimeCall: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7207 | break; |
| 7208 | } |
| 7209 | return desired_string_load_kind; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7210 | } |
| 7211 | |
| 7212 | void LocationsBuilderARMVIXL::VisitLoadString(HLoadString* load) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7213 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7214 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7215 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7216 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7217 | locations->SetOut(LocationFrom(r0)); |
| 7218 | } else { |
| 7219 | locations->SetOut(Location::RequiresRegister()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7220 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 7221 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7222 | // 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] | 7223 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 7224 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7225 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7226 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 7227 | // that the the kPrimNot result register is the same as the first argument register. |
| 7228 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 7229 | if (kUseBakerReadBarrier && kBakerReadBarrierLinkTimeThunksEnableForGcRoots) { |
| 7230 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 7231 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7232 | } else { |
| 7233 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7234 | } |
| 7235 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7236 | } |
| 7237 | } |
| 7238 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7239 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7240 | // move. |
| 7241 | void InstructionCodeGeneratorARMVIXL::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7242 | LocationSummary* locations = load->GetLocations(); |
| 7243 | Location out_loc = locations->Out(); |
| 7244 | vixl32::Register out = OutputRegister(load); |
| 7245 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 7246 | |
| 7247 | switch (load_kind) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7248 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 7249 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| 7250 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7251 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7252 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7253 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7254 | } |
| 7255 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7256 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 7257 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 7258 | DCHECK_NE(address, 0u); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7259 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7260 | return; |
| 7261 | } |
| 7262 | case HLoadString::LoadKind::kBootImageInternTable: { |
| 7263 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7264 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 7265 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
| 7266 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 7267 | __ Ldr(out, MemOperand(out, /* offset */ 0)); |
| 7268 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7269 | } |
| 7270 | case HLoadString::LoadKind::kBssEntry: { |
| 7271 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7272 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7273 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 7274 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 7275 | GenerateGcRootFieldLoad(load, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7276 | LoadStringSlowPathARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7277 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathARMVIXL(load); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7278 | codegen_->AddSlowPath(slow_path); |
| 7279 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 7280 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 7281 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 15); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7282 | return; |
| 7283 | } |
| 7284 | case HLoadString::LoadKind::kJitTableAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7285 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7286 | load->GetStringIndex(), |
| 7287 | load->GetString())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7288 | // /* GcRoot<mirror::String> */ out = *out |
| 7289 | GenerateGcRootFieldLoad(load, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
| 7290 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7291 | } |
| 7292 | default: |
| 7293 | break; |
| 7294 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7295 | |
| 7296 | // 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] | 7297 | DCHECK_EQ(load->GetLoadKind(), HLoadString::LoadKind::kRuntimeCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7298 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7299 | __ Mov(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7300 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 7301 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 7302 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 16); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7303 | } |
| 7304 | |
| 7305 | static int32_t GetExceptionTlsOffset() { |
| 7306 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
| 7307 | } |
| 7308 | |
| 7309 | void LocationsBuilderARMVIXL::VisitLoadException(HLoadException* load) { |
| 7310 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7311 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7312 | locations->SetOut(Location::RequiresRegister()); |
| 7313 | } |
| 7314 | |
| 7315 | void InstructionCodeGeneratorARMVIXL::VisitLoadException(HLoadException* load) { |
| 7316 | vixl32::Register out = OutputRegister(load); |
| 7317 | GetAssembler()->LoadFromOffset(kLoadWord, out, tr, GetExceptionTlsOffset()); |
| 7318 | } |
| 7319 | |
| 7320 | |
| 7321 | void LocationsBuilderARMVIXL::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7322 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7323 | } |
| 7324 | |
| 7325 | void InstructionCodeGeneratorARMVIXL::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 7326 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 7327 | vixl32::Register temp = temps.Acquire(); |
| 7328 | __ Mov(temp, 0); |
| 7329 | GetAssembler()->StoreToOffset(kStoreWord, temp, tr, GetExceptionTlsOffset()); |
| 7330 | } |
| 7331 | |
| 7332 | void LocationsBuilderARMVIXL::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7333 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7334 | instruction, LocationSummary::kCallOnMainOnly); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7335 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7336 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7337 | } |
| 7338 | |
| 7339 | void InstructionCodeGeneratorARMVIXL::VisitThrow(HThrow* instruction) { |
| 7340 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| 7341 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 7342 | } |
| 7343 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7344 | // Temp is used for read barrier. |
| 7345 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 7346 | if (kEmitCompilerReadBarrier && |
| 7347 | (kUseBakerReadBarrier || |
| 7348 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7349 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7350 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 7351 | return 1; |
| 7352 | } |
| 7353 | return 0; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7354 | } |
| 7355 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7356 | // Interface case has 3 temps, one for holding the number of interfaces, one for the current |
| 7357 | // interface pointer, one for loading the current interface. |
| 7358 | // The other checks have one temp for loading the object's class. |
| 7359 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 7360 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7361 | return 3; |
| 7362 | } |
| 7363 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 7364 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7365 | |
| 7366 | void LocationsBuilderARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 7367 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7368 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7369 | bool baker_read_barrier_slow_path = false; |
| 7370 | switch (type_check_kind) { |
| 7371 | case TypeCheckKind::kExactCheck: |
| 7372 | case TypeCheckKind::kAbstractClassCheck: |
| 7373 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7374 | case TypeCheckKind::kArrayObjectCheck: { |
| 7375 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 7376 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 7377 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7378 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7379 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7380 | case TypeCheckKind::kArrayCheck: |
| 7381 | case TypeCheckKind::kUnresolvedCheck: |
| 7382 | case TypeCheckKind::kInterfaceCheck: |
| 7383 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7384 | break; |
| 7385 | } |
| 7386 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7387 | LocationSummary* locations = |
| 7388 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7389 | if (baker_read_barrier_slow_path) { |
| 7390 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 7391 | } |
| 7392 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7393 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7394 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 7395 | // Note that TypeCheckSlowPathARM uses this register too. |
| 7396 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7397 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 7398 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 7399 | codegen_->MaybeAddBakerCcEntrypointTempForFields(locations); |
| 7400 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7401 | } |
| 7402 | |
| 7403 | void InstructionCodeGeneratorARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 7404 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7405 | LocationSummary* locations = instruction->GetLocations(); |
| 7406 | Location obj_loc = locations->InAt(0); |
| 7407 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 7408 | vixl32::Register cls = InputRegisterAt(instruction, 1); |
| 7409 | Location out_loc = locations->Out(); |
| 7410 | vixl32::Register out = OutputRegister(instruction); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7411 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7412 | DCHECK_LE(num_temps, 1u); |
| 7413 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7414 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7415 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7416 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7417 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7418 | vixl32::Label done; |
| 7419 | vixl32::Label* const final_label = codegen_->GetFinalLabel(instruction, &done); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7420 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 7421 | |
| 7422 | // Return 0 if `obj` is null. |
| 7423 | // avoid null check if we know obj is not null. |
| 7424 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7425 | DCHECK(!out.Is(obj)); |
| 7426 | __ Mov(out, 0); |
| 7427 | __ CompareAndBranchIfZero(obj, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7428 | } |
| 7429 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7430 | switch (type_check_kind) { |
| 7431 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7432 | ReadBarrierOption read_barrier_option = |
| 7433 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7434 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7435 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7436 | out_loc, |
| 7437 | obj_loc, |
| 7438 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7439 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7440 | read_barrier_option); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7441 | // Classes must be equal for the instanceof to succeed. |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7442 | __ Cmp(out, cls); |
| 7443 | // We speculatively set the result to false without changing the condition |
| 7444 | // flags, which allows us to avoid some branching later. |
| 7445 | __ Mov(LeaveFlags, out, 0); |
| 7446 | |
| 7447 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7448 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7449 | // encoding can be used. |
| 7450 | if (out.IsLow()) { |
| 7451 | // We use the scope because of the IT block that follows. |
| 7452 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7453 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7454 | CodeBufferCheckScope::kExactSize); |
| 7455 | |
| 7456 | __ it(eq); |
| 7457 | __ mov(eq, out, 1); |
| 7458 | } else { |
| 7459 | __ B(ne, final_label, /* far_target */ false); |
| 7460 | __ Mov(out, 1); |
| 7461 | } |
| 7462 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7463 | break; |
| 7464 | } |
| 7465 | |
| 7466 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7467 | ReadBarrierOption read_barrier_option = |
| 7468 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7469 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7470 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7471 | out_loc, |
| 7472 | obj_loc, |
| 7473 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7474 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7475 | read_barrier_option); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7476 | // If the class is abstract, we eagerly fetch the super class of the |
| 7477 | // object to avoid doing a comparison we know will fail. |
| 7478 | vixl32::Label loop; |
| 7479 | __ Bind(&loop); |
| 7480 | // /* HeapReference<Class> */ out = out->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7481 | GenerateReferenceLoadOneRegister(instruction, |
| 7482 | out_loc, |
| 7483 | super_offset, |
| 7484 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7485 | read_barrier_option); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7486 | // 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] | 7487 | __ CompareAndBranchIfZero(out, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7488 | __ Cmp(out, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7489 | __ B(ne, &loop, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7490 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7491 | break; |
| 7492 | } |
| 7493 | |
| 7494 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7495 | ReadBarrierOption read_barrier_option = |
| 7496 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7497 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7498 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7499 | out_loc, |
| 7500 | obj_loc, |
| 7501 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7502 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7503 | read_barrier_option); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7504 | // Walk over the class hierarchy to find a match. |
| 7505 | vixl32::Label loop, success; |
| 7506 | __ Bind(&loop); |
| 7507 | __ Cmp(out, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7508 | __ B(eq, &success, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7509 | // /* HeapReference<Class> */ out = out->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7510 | GenerateReferenceLoadOneRegister(instruction, |
| 7511 | out_loc, |
| 7512 | super_offset, |
| 7513 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7514 | read_barrier_option); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7515 | // This is essentially a null check, but it sets the condition flags to the |
| 7516 | // proper value for the code that follows the loop, i.e. not `eq`. |
| 7517 | __ Cmp(out, 1); |
| 7518 | __ B(hs, &loop, /* far_target */ false); |
| 7519 | |
| 7520 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7521 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7522 | // encoding can be used. |
| 7523 | if (out.IsLow()) { |
| 7524 | // If `out` is null, we use it for the result, and the condition flags |
| 7525 | // have already been set to `ne`, so the IT block that comes afterwards |
| 7526 | // (and which handles the successful case) turns into a NOP (instead of |
| 7527 | // overwriting `out`). |
| 7528 | __ Bind(&success); |
| 7529 | |
| 7530 | // We use the scope because of the IT block that follows. |
| 7531 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7532 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7533 | CodeBufferCheckScope::kExactSize); |
| 7534 | |
| 7535 | // There is only one branch to the `success` label (which is bound to this |
| 7536 | // IT block), and it has the same condition, `eq`, so in that case the MOV |
| 7537 | // is executed. |
| 7538 | __ it(eq); |
| 7539 | __ mov(eq, out, 1); |
| 7540 | } else { |
| 7541 | // 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] | 7542 | __ B(final_label); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7543 | __ Bind(&success); |
| 7544 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7545 | } |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7546 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7547 | break; |
| 7548 | } |
| 7549 | |
| 7550 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7551 | ReadBarrierOption read_barrier_option = |
| 7552 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7553 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7554 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7555 | out_loc, |
| 7556 | obj_loc, |
| 7557 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7558 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7559 | read_barrier_option); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7560 | // Do an exact check. |
| 7561 | vixl32::Label exact_check; |
| 7562 | __ Cmp(out, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7563 | __ B(eq, &exact_check, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7564 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 7565 | // /* HeapReference<Class> */ out = out->component_type_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7566 | GenerateReferenceLoadOneRegister(instruction, |
| 7567 | out_loc, |
| 7568 | component_offset, |
| 7569 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7570 | read_barrier_option); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7571 | // 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] | 7572 | __ CompareAndBranchIfZero(out, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7573 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 7574 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7575 | __ Cmp(out, 0); |
| 7576 | // We speculatively set the result to false without changing the condition |
| 7577 | // flags, which allows us to avoid some branching later. |
| 7578 | __ Mov(LeaveFlags, out, 0); |
| 7579 | |
| 7580 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7581 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7582 | // encoding can be used. |
| 7583 | if (out.IsLow()) { |
| 7584 | __ Bind(&exact_check); |
| 7585 | |
| 7586 | // We use the scope because of the IT block that follows. |
| 7587 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7588 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7589 | CodeBufferCheckScope::kExactSize); |
| 7590 | |
| 7591 | __ it(eq); |
| 7592 | __ mov(eq, out, 1); |
| 7593 | } else { |
| 7594 | __ B(ne, final_label, /* far_target */ false); |
| 7595 | __ Bind(&exact_check); |
| 7596 | __ Mov(out, 1); |
| 7597 | } |
| 7598 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7599 | break; |
| 7600 | } |
| 7601 | |
| 7602 | case TypeCheckKind::kArrayCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7603 | // No read barrier since the slow path will retry upon failure. |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7604 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7605 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7606 | out_loc, |
| 7607 | obj_loc, |
| 7608 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7609 | maybe_temp_loc, |
| 7610 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7611 | __ Cmp(out, cls); |
| 7612 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7613 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
| 7614 | instruction, /* is_fatal */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7615 | codegen_->AddSlowPath(slow_path); |
| 7616 | __ B(ne, slow_path->GetEntryLabel()); |
| 7617 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7618 | break; |
| 7619 | } |
| 7620 | |
| 7621 | case TypeCheckKind::kUnresolvedCheck: |
| 7622 | case TypeCheckKind::kInterfaceCheck: { |
| 7623 | // Note that we indeed only call on slow path, but we always go |
| 7624 | // into the slow path for the unresolved and interface check |
| 7625 | // cases. |
| 7626 | // |
| 7627 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7628 | // entry point without resorting to a type checking slow path |
| 7629 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7630 | // require to assign fixed registers for the inputs of this |
| 7631 | // HInstanceOf instruction (following the runtime calling |
| 7632 | // convention), which might be cluttered by the potential first |
| 7633 | // read barrier emission at the beginning of this method. |
| 7634 | // |
| 7635 | // TODO: Introduce a new runtime entry point taking the object |
| 7636 | // to test (instead of its class) as argument, and let it deal |
| 7637 | // with the read barrier issues. This will let us refactor this |
| 7638 | // case of the `switch` code as it was previously (with a direct |
| 7639 | // call to the runtime not using a type checking slow path). |
| 7640 | // This should also be beneficial for the other cases above. |
| 7641 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7642 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
| 7643 | instruction, /* is_fatal */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7644 | codegen_->AddSlowPath(slow_path); |
| 7645 | __ B(slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7646 | break; |
| 7647 | } |
| 7648 | } |
| 7649 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7650 | if (done.IsReferenced()) { |
| 7651 | __ Bind(&done); |
| 7652 | } |
| 7653 | |
| 7654 | if (slow_path != nullptr) { |
| 7655 | __ Bind(slow_path->GetExitLabel()); |
| 7656 | } |
| 7657 | } |
| 7658 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7659 | void LocationsBuilderARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7660 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7661 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7662 | LocationSummary* locations = |
| 7663 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7664 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7665 | locations->SetInAt(1, Location::RequiresRegister()); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7666 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7667 | } |
| 7668 | |
| 7669 | void InstructionCodeGeneratorARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
| 7670 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7671 | LocationSummary* locations = instruction->GetLocations(); |
| 7672 | Location obj_loc = locations->InAt(0); |
| 7673 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 7674 | vixl32::Register cls = InputRegisterAt(instruction, 1); |
| 7675 | Location temp_loc = locations->GetTemp(0); |
| 7676 | vixl32::Register temp = RegisterFrom(temp_loc); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7677 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 7678 | DCHECK_LE(num_temps, 3u); |
| 7679 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 7680 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 7681 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7682 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7683 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7684 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 7685 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 7686 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 7687 | const uint32_t object_array_data_offset = |
| 7688 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7689 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7690 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7691 | SlowPathCodeARMVIXL* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7692 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
| 7693 | instruction, is_type_check_slow_path_fatal); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7694 | codegen_->AddSlowPath(type_check_slow_path); |
| 7695 | |
| 7696 | vixl32::Label done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7697 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7698 | // Avoid null check if we know obj is not null. |
| 7699 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7700 | __ CompareAndBranchIfZero(obj, final_label, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7701 | } |
| 7702 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7703 | switch (type_check_kind) { |
| 7704 | case TypeCheckKind::kExactCheck: |
| 7705 | case TypeCheckKind::kArrayCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7706 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7707 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7708 | temp_loc, |
| 7709 | obj_loc, |
| 7710 | class_offset, |
| 7711 | maybe_temp2_loc, |
| 7712 | kWithoutReadBarrier); |
| 7713 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7714 | __ Cmp(temp, cls); |
| 7715 | // Jump to slow path for throwing the exception or doing a |
| 7716 | // more involved array check. |
| 7717 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 7718 | break; |
| 7719 | } |
| 7720 | |
| 7721 | case TypeCheckKind::kAbstractClassCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7722 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7723 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7724 | temp_loc, |
| 7725 | obj_loc, |
| 7726 | class_offset, |
| 7727 | maybe_temp2_loc, |
| 7728 | kWithoutReadBarrier); |
| 7729 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7730 | // If the class is abstract, we eagerly fetch the super class of the |
| 7731 | // object to avoid doing a comparison we know will fail. |
| 7732 | vixl32::Label loop; |
| 7733 | __ Bind(&loop); |
| 7734 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7735 | GenerateReferenceLoadOneRegister(instruction, |
| 7736 | temp_loc, |
| 7737 | super_offset, |
| 7738 | maybe_temp2_loc, |
| 7739 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7740 | |
| 7741 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7742 | // exception. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7743 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7744 | |
| 7745 | // Otherwise, compare the classes. |
| 7746 | __ Cmp(temp, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7747 | __ B(ne, &loop, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7748 | break; |
| 7749 | } |
| 7750 | |
| 7751 | case TypeCheckKind::kClassHierarchyCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7752 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7753 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7754 | temp_loc, |
| 7755 | obj_loc, |
| 7756 | class_offset, |
| 7757 | maybe_temp2_loc, |
| 7758 | kWithoutReadBarrier); |
| 7759 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7760 | // Walk over the class hierarchy to find a match. |
| 7761 | vixl32::Label loop; |
| 7762 | __ Bind(&loop); |
| 7763 | __ Cmp(temp, cls); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7764 | __ B(eq, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7765 | |
| 7766 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7767 | GenerateReferenceLoadOneRegister(instruction, |
| 7768 | temp_loc, |
| 7769 | super_offset, |
| 7770 | maybe_temp2_loc, |
| 7771 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7772 | |
| 7773 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7774 | // exception. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7775 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7776 | // Otherwise, jump to the beginning of the loop. |
| 7777 | __ B(&loop); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7778 | break; |
| 7779 | } |
| 7780 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7781 | case TypeCheckKind::kArrayObjectCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7782 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7783 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7784 | temp_loc, |
| 7785 | obj_loc, |
| 7786 | class_offset, |
| 7787 | maybe_temp2_loc, |
| 7788 | kWithoutReadBarrier); |
| 7789 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7790 | // Do an exact check. |
| 7791 | __ Cmp(temp, cls); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7792 | __ B(eq, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7793 | |
| 7794 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 7795 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7796 | GenerateReferenceLoadOneRegister(instruction, |
| 7797 | temp_loc, |
| 7798 | component_offset, |
| 7799 | maybe_temp2_loc, |
| 7800 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7801 | // 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] | 7802 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7803 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 7804 | // to further check that this component type is not a primitive type. |
| 7805 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7806 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7807 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7808 | break; |
| 7809 | } |
| 7810 | |
| 7811 | case TypeCheckKind::kUnresolvedCheck: |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7812 | // 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] | 7813 | // We cannot directly call the CheckCast runtime entry point |
| 7814 | // without resorting to a type checking slow path here (i.e. by |
| 7815 | // calling InvokeRuntime directly), as it would require to |
| 7816 | // assign fixed registers for the inputs of this HInstanceOf |
| 7817 | // instruction (following the runtime calling convention), which |
| 7818 | // might be cluttered by the potential first read barrier |
| 7819 | // emission at the beginning of this method. |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7820 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7821 | __ B(type_check_slow_path->GetEntryLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7822 | break; |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7823 | |
| 7824 | case TypeCheckKind::kInterfaceCheck: { |
| 7825 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 7826 | // positives by doing this. |
| 7827 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7828 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7829 | temp_loc, |
| 7830 | obj_loc, |
| 7831 | class_offset, |
| 7832 | maybe_temp2_loc, |
| 7833 | kWithoutReadBarrier); |
| 7834 | |
| 7835 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 7836 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7837 | temp_loc, |
| 7838 | temp_loc, |
| 7839 | iftable_offset, |
| 7840 | maybe_temp2_loc, |
| 7841 | kWithoutReadBarrier); |
| 7842 | // Iftable is never null. |
| 7843 | __ Ldr(RegisterFrom(maybe_temp2_loc), MemOperand(temp, array_length_offset)); |
| 7844 | // Loop through the iftable and check if any class matches. |
| 7845 | vixl32::Label start_loop; |
| 7846 | __ Bind(&start_loop); |
| 7847 | __ CompareAndBranchIfZero(RegisterFrom(maybe_temp2_loc), |
| 7848 | type_check_slow_path->GetEntryLabel()); |
| 7849 | __ Ldr(RegisterFrom(maybe_temp3_loc), MemOperand(temp, object_array_data_offset)); |
| 7850 | GetAssembler()->MaybeUnpoisonHeapReference(RegisterFrom(maybe_temp3_loc)); |
| 7851 | // Go to next interface. |
| 7852 | __ Add(temp, temp, Operand::From(2 * kHeapReferenceSize)); |
| 7853 | __ Sub(RegisterFrom(maybe_temp2_loc), RegisterFrom(maybe_temp2_loc), 2); |
| 7854 | // Compare the classes and continue the loop if they do not match. |
| 7855 | __ Cmp(cls, RegisterFrom(maybe_temp3_loc)); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7856 | __ B(ne, &start_loop, /* far_target */ false); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7857 | break; |
| 7858 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7859 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7860 | if (done.IsReferenced()) { |
| 7861 | __ Bind(&done); |
| 7862 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7863 | |
| 7864 | __ Bind(type_check_slow_path->GetExitLabel()); |
| 7865 | } |
| 7866 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 7867 | void LocationsBuilderARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7868 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7869 | instruction, LocationSummary::kCallOnMainOnly); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 7870 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7871 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7872 | } |
| 7873 | |
| 7874 | void InstructionCodeGeneratorARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 7875 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 7876 | instruction, |
| 7877 | instruction->GetDexPc()); |
| 7878 | if (instruction->IsEnter()) { |
| 7879 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 7880 | } else { |
| 7881 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 7882 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 7883 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 17); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 7884 | } |
| 7885 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 7886 | void LocationsBuilderARMVIXL::VisitAnd(HAnd* instruction) { |
| 7887 | HandleBitwiseOperation(instruction, AND); |
| 7888 | } |
| 7889 | |
| 7890 | void LocationsBuilderARMVIXL::VisitOr(HOr* instruction) { |
| 7891 | HandleBitwiseOperation(instruction, ORR); |
| 7892 | } |
| 7893 | |
| 7894 | void LocationsBuilderARMVIXL::VisitXor(HXor* instruction) { |
| 7895 | HandleBitwiseOperation(instruction, EOR); |
| 7896 | } |
| 7897 | |
| 7898 | void LocationsBuilderARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
| 7899 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7900 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7901 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 7902 | || instruction->GetResultType() == DataType::Type::kInt64); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 7903 | // Note: GVN reorders commutative operations to have the constant on the right hand side. |
| 7904 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7905 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
| 7906 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7907 | } |
| 7908 | |
| 7909 | void InstructionCodeGeneratorARMVIXL::VisitAnd(HAnd* instruction) { |
| 7910 | HandleBitwiseOperation(instruction); |
| 7911 | } |
| 7912 | |
| 7913 | void InstructionCodeGeneratorARMVIXL::VisitOr(HOr* instruction) { |
| 7914 | HandleBitwiseOperation(instruction); |
| 7915 | } |
| 7916 | |
| 7917 | void InstructionCodeGeneratorARMVIXL::VisitXor(HXor* instruction) { |
| 7918 | HandleBitwiseOperation(instruction); |
| 7919 | } |
| 7920 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 7921 | void LocationsBuilderARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 7922 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7923 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7924 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 7925 | || instruction->GetResultType() == DataType::Type::kInt64); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 7926 | |
| 7927 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7928 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7929 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7930 | } |
| 7931 | |
| 7932 | void InstructionCodeGeneratorARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 7933 | LocationSummary* locations = instruction->GetLocations(); |
| 7934 | Location first = locations->InAt(0); |
| 7935 | Location second = locations->InAt(1); |
| 7936 | Location out = locations->Out(); |
| 7937 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7938 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 7939 | vixl32::Register first_reg = RegisterFrom(first); |
| 7940 | vixl32::Register second_reg = RegisterFrom(second); |
| 7941 | vixl32::Register out_reg = RegisterFrom(out); |
| 7942 | |
| 7943 | switch (instruction->GetOpKind()) { |
| 7944 | case HInstruction::kAnd: |
| 7945 | __ Bic(out_reg, first_reg, second_reg); |
| 7946 | break; |
| 7947 | case HInstruction::kOr: |
| 7948 | __ Orn(out_reg, first_reg, second_reg); |
| 7949 | break; |
| 7950 | // There is no EON on arm. |
| 7951 | case HInstruction::kXor: |
| 7952 | default: |
| 7953 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 7954 | UNREACHABLE(); |
| 7955 | } |
| 7956 | return; |
| 7957 | |
| 7958 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7959 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 7960 | vixl32::Register first_low = LowRegisterFrom(first); |
| 7961 | vixl32::Register first_high = HighRegisterFrom(first); |
| 7962 | vixl32::Register second_low = LowRegisterFrom(second); |
| 7963 | vixl32::Register second_high = HighRegisterFrom(second); |
| 7964 | vixl32::Register out_low = LowRegisterFrom(out); |
| 7965 | vixl32::Register out_high = HighRegisterFrom(out); |
| 7966 | |
| 7967 | switch (instruction->GetOpKind()) { |
| 7968 | case HInstruction::kAnd: |
| 7969 | __ Bic(out_low, first_low, second_low); |
| 7970 | __ Bic(out_high, first_high, second_high); |
| 7971 | break; |
| 7972 | case HInstruction::kOr: |
| 7973 | __ Orn(out_low, first_low, second_low); |
| 7974 | __ Orn(out_high, first_high, second_high); |
| 7975 | break; |
| 7976 | // There is no EON on arm. |
| 7977 | case HInstruction::kXor: |
| 7978 | default: |
| 7979 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 7980 | UNREACHABLE(); |
| 7981 | } |
| 7982 | } |
| 7983 | } |
| 7984 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 7985 | void LocationsBuilderARMVIXL::VisitDataProcWithShifterOp( |
| 7986 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7987 | DCHECK(instruction->GetType() == DataType::Type::kInt32 || |
| 7988 | instruction->GetType() == DataType::Type::kInt64); |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 7989 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7990 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7991 | const bool overlap = instruction->GetType() == DataType::Type::kInt64 && |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 7992 | HDataProcWithShifterOp::IsExtensionOp(instruction->GetOpKind()); |
| 7993 | |
| 7994 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7995 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7996 | locations->SetOut(Location::RequiresRegister(), |
| 7997 | overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 7998 | } |
| 7999 | |
| 8000 | void InstructionCodeGeneratorARMVIXL::VisitDataProcWithShifterOp( |
| 8001 | HDataProcWithShifterOp* instruction) { |
| 8002 | const LocationSummary* const locations = instruction->GetLocations(); |
| 8003 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 8004 | const HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 8005 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8006 | if (instruction->GetType() == DataType::Type::kInt32) { |
Anton Kirilov | 420ee30 | 2017-02-21 18:10:26 +0000 | [diff] [blame] | 8007 | const vixl32::Register first = InputRegisterAt(instruction, 0); |
| 8008 | const vixl32::Register output = OutputRegister(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8009 | const vixl32::Register second = instruction->InputAt(1)->GetType() == DataType::Type::kInt64 |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8010 | ? LowRegisterFrom(locations->InAt(1)) |
| 8011 | : InputRegisterAt(instruction, 1); |
| 8012 | |
Anton Kirilov | 420ee30 | 2017-02-21 18:10:26 +0000 | [diff] [blame] | 8013 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 8014 | DCHECK_EQ(kind, HInstruction::kAdd); |
| 8015 | |
| 8016 | switch (op_kind) { |
| 8017 | case HDataProcWithShifterOp::kUXTB: |
| 8018 | __ Uxtab(output, first, second); |
| 8019 | break; |
| 8020 | case HDataProcWithShifterOp::kUXTH: |
| 8021 | __ Uxtah(output, first, second); |
| 8022 | break; |
| 8023 | case HDataProcWithShifterOp::kSXTB: |
| 8024 | __ Sxtab(output, first, second); |
| 8025 | break; |
| 8026 | case HDataProcWithShifterOp::kSXTH: |
| 8027 | __ Sxtah(output, first, second); |
| 8028 | break; |
| 8029 | default: |
| 8030 | LOG(FATAL) << "Unexpected operation kind: " << op_kind; |
| 8031 | UNREACHABLE(); |
| 8032 | } |
| 8033 | } else { |
| 8034 | GenerateDataProcInstruction(kind, |
| 8035 | output, |
| 8036 | first, |
| 8037 | Operand(second, |
| 8038 | ShiftFromOpKind(op_kind), |
| 8039 | instruction->GetShiftAmount()), |
| 8040 | codegen_); |
| 8041 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8042 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8043 | DCHECK_EQ(instruction->GetType(), DataType::Type::kInt64); |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8044 | |
| 8045 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 8046 | const vixl32::Register second = InputRegisterAt(instruction, 1); |
| 8047 | |
| 8048 | DCHECK(!LowRegisterFrom(locations->Out()).Is(second)); |
| 8049 | GenerateDataProc(kind, |
| 8050 | locations->Out(), |
| 8051 | locations->InAt(0), |
| 8052 | second, |
| 8053 | Operand(second, ShiftType::ASR, 31), |
| 8054 | codegen_); |
| 8055 | } else { |
| 8056 | GenerateLongDataProc(instruction, codegen_); |
| 8057 | } |
| 8058 | } |
| 8059 | } |
| 8060 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8061 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8062 | void InstructionCodeGeneratorARMVIXL::GenerateAndConst(vixl32::Register out, |
| 8063 | vixl32::Register first, |
| 8064 | uint32_t value) { |
| 8065 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 8066 | if (value == 0xffffffffu) { |
| 8067 | if (!out.Is(first)) { |
| 8068 | __ Mov(out, first); |
| 8069 | } |
| 8070 | return; |
| 8071 | } |
| 8072 | if (value == 0u) { |
| 8073 | __ Mov(out, 0); |
| 8074 | return; |
| 8075 | } |
| 8076 | if (GetAssembler()->ShifterOperandCanHold(AND, value)) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 8077 | __ And(out, first, value); |
| 8078 | } else if (GetAssembler()->ShifterOperandCanHold(BIC, ~value)) { |
| 8079 | __ Bic(out, first, ~value); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8080 | } else { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 8081 | DCHECK(IsPowerOfTwo(value + 1)); |
| 8082 | __ Ubfx(out, first, 0, WhichPowerOf2(value + 1)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8083 | } |
| 8084 | } |
| 8085 | |
| 8086 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8087 | void InstructionCodeGeneratorARMVIXL::GenerateOrrConst(vixl32::Register out, |
| 8088 | vixl32::Register first, |
| 8089 | uint32_t value) { |
| 8090 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 8091 | if (value == 0u) { |
| 8092 | if (!out.Is(first)) { |
| 8093 | __ Mov(out, first); |
| 8094 | } |
| 8095 | return; |
| 8096 | } |
| 8097 | if (value == 0xffffffffu) { |
| 8098 | __ Mvn(out, 0); |
| 8099 | return; |
| 8100 | } |
| 8101 | if (GetAssembler()->ShifterOperandCanHold(ORR, value)) { |
| 8102 | __ Orr(out, first, value); |
| 8103 | } else { |
| 8104 | DCHECK(GetAssembler()->ShifterOperandCanHold(ORN, ~value)); |
| 8105 | __ Orn(out, first, ~value); |
| 8106 | } |
| 8107 | } |
| 8108 | |
| 8109 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8110 | void InstructionCodeGeneratorARMVIXL::GenerateEorConst(vixl32::Register out, |
| 8111 | vixl32::Register first, |
| 8112 | uint32_t value) { |
| 8113 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 8114 | if (value == 0u) { |
| 8115 | if (!out.Is(first)) { |
| 8116 | __ Mov(out, first); |
| 8117 | } |
| 8118 | return; |
| 8119 | } |
| 8120 | __ Eor(out, first, value); |
| 8121 | } |
| 8122 | |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8123 | void InstructionCodeGeneratorARMVIXL::GenerateAddLongConst(Location out, |
| 8124 | Location first, |
| 8125 | uint64_t value) { |
| 8126 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8127 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8128 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8129 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8130 | uint32_t value_low = Low32Bits(value); |
| 8131 | uint32_t value_high = High32Bits(value); |
| 8132 | if (value_low == 0u) { |
| 8133 | if (!out_low.Is(first_low)) { |
| 8134 | __ Mov(out_low, first_low); |
| 8135 | } |
| 8136 | __ Add(out_high, first_high, value_high); |
| 8137 | return; |
| 8138 | } |
| 8139 | __ Adds(out_low, first_low, value_low); |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 8140 | if (GetAssembler()->ShifterOperandCanHold(ADC, value_high)) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8141 | __ Adc(out_high, first_high, value_high); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8142 | } else { |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 8143 | DCHECK(GetAssembler()->ShifterOperandCanHold(SBC, ~value_high)); |
| 8144 | __ Sbc(out_high, first_high, ~value_high); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8145 | } |
| 8146 | } |
| 8147 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8148 | void InstructionCodeGeneratorARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 8149 | LocationSummary* locations = instruction->GetLocations(); |
| 8150 | Location first = locations->InAt(0); |
| 8151 | Location second = locations->InAt(1); |
| 8152 | Location out = locations->Out(); |
| 8153 | |
| 8154 | if (second.IsConstant()) { |
| 8155 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 8156 | uint32_t value_low = Low32Bits(value); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8157 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8158 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 8159 | vixl32::Register out_reg = OutputRegister(instruction); |
| 8160 | if (instruction->IsAnd()) { |
| 8161 | GenerateAndConst(out_reg, first_reg, value_low); |
| 8162 | } else if (instruction->IsOr()) { |
| 8163 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 8164 | } else { |
| 8165 | DCHECK(instruction->IsXor()); |
| 8166 | GenerateEorConst(out_reg, first_reg, value_low); |
| 8167 | } |
| 8168 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8169 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8170 | uint32_t value_high = High32Bits(value); |
| 8171 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8172 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8173 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8174 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8175 | if (instruction->IsAnd()) { |
| 8176 | GenerateAndConst(out_low, first_low, value_low); |
| 8177 | GenerateAndConst(out_high, first_high, value_high); |
| 8178 | } else if (instruction->IsOr()) { |
| 8179 | GenerateOrrConst(out_low, first_low, value_low); |
| 8180 | GenerateOrrConst(out_high, first_high, value_high); |
| 8181 | } else { |
| 8182 | DCHECK(instruction->IsXor()); |
| 8183 | GenerateEorConst(out_low, first_low, value_low); |
| 8184 | GenerateEorConst(out_high, first_high, value_high); |
| 8185 | } |
| 8186 | } |
| 8187 | return; |
| 8188 | } |
| 8189 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8190 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8191 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 8192 | vixl32::Register second_reg = InputRegisterAt(instruction, 1); |
| 8193 | vixl32::Register out_reg = OutputRegister(instruction); |
| 8194 | if (instruction->IsAnd()) { |
| 8195 | __ And(out_reg, first_reg, second_reg); |
| 8196 | } else if (instruction->IsOr()) { |
| 8197 | __ Orr(out_reg, first_reg, second_reg); |
| 8198 | } else { |
| 8199 | DCHECK(instruction->IsXor()); |
| 8200 | __ Eor(out_reg, first_reg, second_reg); |
| 8201 | } |
| 8202 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8203 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8204 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8205 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8206 | vixl32::Register second_low = LowRegisterFrom(second); |
| 8207 | vixl32::Register second_high = HighRegisterFrom(second); |
| 8208 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8209 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8210 | if (instruction->IsAnd()) { |
| 8211 | __ And(out_low, first_low, second_low); |
| 8212 | __ And(out_high, first_high, second_high); |
| 8213 | } else if (instruction->IsOr()) { |
| 8214 | __ Orr(out_low, first_low, second_low); |
| 8215 | __ Orr(out_high, first_high, second_high); |
| 8216 | } else { |
| 8217 | DCHECK(instruction->IsXor()); |
| 8218 | __ Eor(out_low, first_low, second_low); |
| 8219 | __ Eor(out_high, first_high, second_high); |
| 8220 | } |
| 8221 | } |
| 8222 | } |
| 8223 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8224 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadOneRegister( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8225 | HInstruction* instruction, |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8226 | Location out, |
| 8227 | uint32_t offset, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8228 | Location maybe_temp, |
| 8229 | ReadBarrierOption read_barrier_option) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8230 | vixl32::Register out_reg = RegisterFrom(out); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8231 | if (read_barrier_option == kWithReadBarrier) { |
| 8232 | CHECK(kEmitCompilerReadBarrier); |
| 8233 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 8234 | if (kUseBakerReadBarrier) { |
| 8235 | // Load with fast path based Baker's read barrier. |
| 8236 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8237 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 8238 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
| 8239 | } else { |
| 8240 | // Load with slow path based read barrier. |
| 8241 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 8242 | // in the following move operation, as we will need it for the |
| 8243 | // read barrier below. |
| 8244 | __ Mov(RegisterFrom(maybe_temp), out_reg); |
| 8245 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8246 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 8247 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 8248 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8249 | } else { |
| 8250 | // Plain load with no read barrier. |
| 8251 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8252 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 8253 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 8254 | } |
| 8255 | } |
| 8256 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8257 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadTwoRegisters( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8258 | HInstruction* instruction, |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8259 | Location out, |
| 8260 | Location obj, |
| 8261 | uint32_t offset, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8262 | Location maybe_temp, |
| 8263 | ReadBarrierOption read_barrier_option) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8264 | vixl32::Register out_reg = RegisterFrom(out); |
| 8265 | vixl32::Register obj_reg = RegisterFrom(obj); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8266 | if (read_barrier_option == kWithReadBarrier) { |
| 8267 | CHECK(kEmitCompilerReadBarrier); |
| 8268 | if (kUseBakerReadBarrier) { |
| 8269 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 8270 | // Load with fast path based Baker's read barrier. |
| 8271 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8272 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 8273 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
| 8274 | } else { |
| 8275 | // Load with slow path based read barrier. |
| 8276 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8277 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8278 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 8279 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8280 | } else { |
| 8281 | // Plain load with no read barrier. |
| 8282 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8283 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8284 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 8285 | } |
| 8286 | } |
| 8287 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8288 | void InstructionCodeGeneratorARMVIXL::GenerateGcRootFieldLoad( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8289 | HInstruction* instruction, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8290 | Location root, |
| 8291 | vixl32::Register obj, |
| 8292 | uint32_t offset, |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8293 | ReadBarrierOption read_barrier_option) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8294 | vixl32::Register root_reg = RegisterFrom(root); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8295 | if (read_barrier_option == kWithReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8296 | DCHECK(kEmitCompilerReadBarrier); |
| 8297 | if (kUseBakerReadBarrier) { |
| 8298 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8299 | // Baker's read barrier are used. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8300 | if (kBakerReadBarrierLinkTimeThunksEnableForGcRoots && |
| 8301 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8302 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 8303 | // the Marking Register) to decide whether we need to enter |
| 8304 | // the slow path to mark the GC root. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8305 | // |
| 8306 | // We use link-time generated thunks for the slow path. That thunk |
| 8307 | // checks the reference and jumps to the entrypoint if needed. |
| 8308 | // |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8309 | // lr = &return_address; |
| 8310 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8311 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8312 | // goto gc_root_thunk<root_reg>(lr) |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8313 | // } |
| 8314 | // return_address: |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8315 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8316 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8317 | ExcludeIPAndBakerCcEntrypointRegister(&temps, instruction); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8318 | bool narrow = CanEmitNarrowLdr(root_reg, obj, offset); |
| 8319 | uint32_t custom_data = linker::Thumb2RelativePatcher::EncodeBakerReadBarrierGcRootData( |
| 8320 | root_reg.GetCode(), narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8321 | vixl32::Label* bne_label = codegen_->NewBakerReadBarrierPatch(custom_data); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8322 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8323 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), 4 * vixl32::kMaxInstructionSizeInBytes); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8324 | vixl32::Label return_address; |
| 8325 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8326 | __ cmp(mr, Operand(0)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8327 | // Currently the offset is always within range. If that changes, |
| 8328 | // we shall have to split the load the same way as for fields. |
| 8329 | DCHECK_LT(offset, kReferenceLoadMinFarOffset); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8330 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8331 | __ ldr(EncodingSize(narrow ? Narrow : Wide), root_reg, MemOperand(obj, offset)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8332 | EmitPlaceholderBne(codegen_, bne_label); |
| 8333 | __ Bind(&return_address); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8334 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8335 | narrow ? BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_OFFSET |
| 8336 | : BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8337 | } else { |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8338 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 8339 | // the Marking Register) to decide whether we need to enter |
| 8340 | // the slow path to mark the GC root. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8341 | // |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8342 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8343 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8344 | // // Slow path. |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8345 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8346 | // root = entrypoint(root); // root = ReadBarrier::Mark(root); // Entry point call. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8347 | // } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8348 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8349 | // Slow path marking the GC root `root`. The entrypoint will |
| 8350 | // be loaded by the slow path code. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8351 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8352 | new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathARMVIXL(instruction, root); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8353 | codegen_->AddSlowPath(slow_path); |
| 8354 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8355 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8356 | GetAssembler()->LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8357 | static_assert( |
| 8358 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 8359 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 8360 | "have different sizes."); |
| 8361 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 8362 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 8363 | "have different sizes."); |
| 8364 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8365 | __ CompareAndBranchIfNonZero(mr, slow_path->GetEntryLabel()); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8366 | __ Bind(slow_path->GetExitLabel()); |
| 8367 | } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8368 | } else { |
| 8369 | // GC root loaded through a slow path for read barriers other |
| 8370 | // than Baker's. |
| 8371 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 8372 | __ Add(root_reg, obj, offset); |
| 8373 | // /* mirror::Object* */ root = root->Read() |
| 8374 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 8375 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8376 | } else { |
| 8377 | // Plain GC root load with no read barrier. |
| 8378 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8379 | GetAssembler()->LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8380 | // Note that GC roots are not affected by heap poisoning, thus we |
| 8381 | // do not have to unpoison `root_reg` here. |
| 8382 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8383 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 18); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8384 | } |
| 8385 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8386 | void CodeGeneratorARMVIXL::MaybeAddBakerCcEntrypointTempForFields(LocationSummary* locations) { |
| 8387 | DCHECK(kEmitCompilerReadBarrier); |
| 8388 | DCHECK(kUseBakerReadBarrier); |
| 8389 | if (kBakerReadBarrierLinkTimeThunksEnableForFields) { |
| 8390 | if (!Runtime::Current()->UseJitCompilation()) { |
| 8391 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 8392 | } |
| 8393 | } |
| 8394 | } |
| 8395 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8396 | void CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8397 | Location ref, |
| 8398 | vixl32::Register obj, |
| 8399 | uint32_t offset, |
| 8400 | Location temp, |
| 8401 | bool needs_null_check) { |
| 8402 | DCHECK(kEmitCompilerReadBarrier); |
| 8403 | DCHECK(kUseBakerReadBarrier); |
| 8404 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8405 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 8406 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8407 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 8408 | // Marking Register) to decide whether we need to enter the slow |
| 8409 | // path to mark the reference. Then, in the slow path, check the |
| 8410 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 8411 | // decide whether to mark `ref` or not. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8412 | // |
| 8413 | // We use link-time generated thunks for the slow path. That thunk checks |
| 8414 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 8415 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 8416 | // |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8417 | // lr = &gray_return_address; |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8418 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8419 | // goto field_thunk<holder_reg, base_reg>(lr) |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8420 | // } |
| 8421 | // not_gray_return_address: |
| 8422 | // // Original reference load. If the offset is too large to fit |
| 8423 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8424 | // HeapReference<mirror::Object> reference = *(obj+offset); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8425 | // gray_return_address: |
| 8426 | |
| 8427 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8428 | vixl32::Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8429 | bool narrow = CanEmitNarrowLdr(ref_reg, obj, offset); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8430 | vixl32::Register base = obj; |
| 8431 | if (offset >= kReferenceLoadMinFarOffset) { |
| 8432 | base = RegisterFrom(temp); |
| 8433 | DCHECK(!base.Is(kBakerCcEntrypointRegister)); |
| 8434 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 8435 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 8436 | offset &= (kReferenceLoadMinFarOffset - 1u); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8437 | // Use narrow LDR only for small offsets. Generating narrow encoding LDR for the large |
| 8438 | // offsets with `(offset & (kReferenceLoadMinFarOffset - 1u)) < 32u` would most likely |
| 8439 | // increase the overall code size when taking the generated thunks into account. |
| 8440 | DCHECK(!narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8441 | } |
| 8442 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8443 | ExcludeIPAndBakerCcEntrypointRegister(&temps, instruction); |
| 8444 | uint32_t custom_data = linker::Thumb2RelativePatcher::EncodeBakerReadBarrierFieldData( |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8445 | base.GetCode(), obj.GetCode(), narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8446 | vixl32::Label* bne_label = NewBakerReadBarrierPatch(custom_data); |
| 8447 | |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8448 | { |
| 8449 | vixl::EmissionCheckScope guard( |
| 8450 | GetVIXLAssembler(), |
| 8451 | (kPoisonHeapReferences ? 5u : 4u) * vixl32::kMaxInstructionSizeInBytes); |
| 8452 | vixl32::Label return_address; |
| 8453 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8454 | __ cmp(mr, Operand(0)); |
| 8455 | EmitPlaceholderBne(this, bne_label); |
| 8456 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8457 | __ ldr(EncodingSize(narrow ? Narrow : Wide), ref_reg, MemOperand(base, offset)); |
| 8458 | if (needs_null_check) { |
| 8459 | MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8460 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8461 | // Note: We need a specific width for the unpoisoning NEG. |
| 8462 | if (kPoisonHeapReferences) { |
| 8463 | if (narrow) { |
| 8464 | // The only 16-bit encoding is T1 which sets flags outside IT block (i.e. RSBS, not RSB). |
| 8465 | __ rsbs(EncodingSize(Narrow), ref_reg, ref_reg, Operand(0)); |
| 8466 | } else { |
| 8467 | __ rsb(EncodingSize(Wide), ref_reg, ref_reg, Operand(0)); |
| 8468 | } |
| 8469 | } |
| 8470 | __ Bind(&return_address); |
| 8471 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8472 | narrow ? BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_OFFSET |
| 8473 | : BAKER_MARK_INTROSPECTION_FIELD_LDR_WIDE_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8474 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8475 | MaybeGenerateMarkingRegisterCheck(/* code */ 19, /* temp_loc */ LocationFrom(ip)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8476 | return; |
| 8477 | } |
| 8478 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8479 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 8480 | Location no_index = Location::NoLocation(); |
| 8481 | ScaleFactor no_scale_factor = TIMES_1; |
| 8482 | GenerateReferenceLoadWithBakerReadBarrier( |
| 8483 | 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] | 8484 | } |
| 8485 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8486 | void CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8487 | Location ref, |
| 8488 | vixl32::Register obj, |
| 8489 | uint32_t data_offset, |
| 8490 | Location index, |
| 8491 | Location temp, |
| 8492 | bool needs_null_check) { |
| 8493 | DCHECK(kEmitCompilerReadBarrier); |
| 8494 | DCHECK(kUseBakerReadBarrier); |
| 8495 | |
| 8496 | static_assert( |
| 8497 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 8498 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8499 | ScaleFactor scale_factor = TIMES_4; |
| 8500 | |
| 8501 | if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 8502 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8503 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 8504 | // Marking Register) to decide whether we need to enter the slow |
| 8505 | // path to mark the reference. Then, in the slow path, check the |
| 8506 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 8507 | // decide whether to mark `ref` or not. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8508 | // |
| 8509 | // We use link-time generated thunks for the slow path. That thunk checks |
| 8510 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 8511 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 8512 | // |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8513 | // lr = &gray_return_address; |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8514 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8515 | // goto array_thunk<base_reg>(lr) |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8516 | // } |
| 8517 | // not_gray_return_address: |
| 8518 | // // Original reference load. If the offset is too large to fit |
| 8519 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8520 | // HeapReference<mirror::Object> reference = data[index]; |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8521 | // gray_return_address: |
| 8522 | |
| 8523 | DCHECK(index.IsValid()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8524 | vixl32::Register index_reg = RegisterFrom(index, DataType::Type::kInt32); |
| 8525 | vixl32::Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
| 8526 | vixl32::Register data_reg = RegisterFrom(temp, DataType::Type::kInt32); // Raw pointer. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8527 | DCHECK(!data_reg.Is(kBakerCcEntrypointRegister)); |
| 8528 | |
| 8529 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8530 | ExcludeIPAndBakerCcEntrypointRegister(&temps, instruction); |
| 8531 | uint32_t custom_data = |
| 8532 | linker::Thumb2RelativePatcher::EncodeBakerReadBarrierArrayData(data_reg.GetCode()); |
| 8533 | vixl32::Label* bne_label = NewBakerReadBarrierPatch(custom_data); |
| 8534 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8535 | __ Add(data_reg, obj, Operand(data_offset)); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8536 | { |
| 8537 | vixl::EmissionCheckScope guard( |
| 8538 | GetVIXLAssembler(), |
| 8539 | (kPoisonHeapReferences ? 5u : 4u) * vixl32::kMaxInstructionSizeInBytes); |
| 8540 | vixl32::Label return_address; |
| 8541 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8542 | __ cmp(mr, Operand(0)); |
| 8543 | EmitPlaceholderBne(this, bne_label); |
| 8544 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8545 | __ ldr(ref_reg, MemOperand(data_reg, index_reg, vixl32::LSL, scale_factor)); |
| 8546 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 8547 | // Note: We need a Wide NEG for the unpoisoning. |
| 8548 | if (kPoisonHeapReferences) { |
| 8549 | __ rsb(EncodingSize(Wide), ref_reg, ref_reg, Operand(0)); |
| 8550 | } |
| 8551 | __ Bind(&return_address); |
| 8552 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8553 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8554 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8555 | MaybeGenerateMarkingRegisterCheck(/* code */ 20, /* temp_loc */ LocationFrom(ip)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8556 | return; |
| 8557 | } |
| 8558 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8559 | // /* HeapReference<Object> */ ref = |
| 8560 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8561 | GenerateReferenceLoadWithBakerReadBarrier( |
| 8562 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | 6070e88 | 2016-11-03 17:51:58 +0000 | [diff] [blame] | 8563 | } |
| 8564 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8565 | void CodeGeneratorARMVIXL::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8566 | Location ref, |
| 8567 | vixl32::Register obj, |
| 8568 | uint32_t offset, |
| 8569 | Location index, |
| 8570 | ScaleFactor scale_factor, |
| 8571 | Location temp, |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8572 | bool needs_null_check) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8573 | DCHECK(kEmitCompilerReadBarrier); |
| 8574 | DCHECK(kUseBakerReadBarrier); |
| 8575 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8576 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 8577 | // Marking Register) to decide whether we need to enter the slow |
| 8578 | // path to mark the reference. Then, in the slow path, check the |
| 8579 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 8580 | // decide whether to mark `ref` or not. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8581 | // |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8582 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8583 | // // Slow path. |
| 8584 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8585 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 8586 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 8587 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 8588 | // if (is_gray) { |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8589 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8590 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8591 | // } |
| 8592 | // } else { |
| 8593 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 8594 | // } |
| 8595 | |
| 8596 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 8597 | |
| 8598 | // Slow path marking the object `ref` when the GC is marking. The |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8599 | // entrypoint will be loaded by the slow path code. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8600 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8601 | new (GetScopedAllocator()) LoadReferenceWithBakerReadBarrierSlowPathARMVIXL( |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8602 | instruction, ref, obj, offset, index, scale_factor, needs_null_check, temp_reg); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8603 | AddSlowPath(slow_path); |
| 8604 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8605 | __ CompareAndBranchIfNonZero(mr, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8606 | // Fast path: the GC is not marking: just load the reference. |
| 8607 | GenerateRawReferenceLoad(instruction, ref, obj, offset, index, scale_factor, needs_null_check); |
| 8608 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8609 | MaybeGenerateMarkingRegisterCheck(/* code */ 21); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8610 | } |
| 8611 | |
| 8612 | void CodeGeneratorARMVIXL::UpdateReferenceFieldWithBakerReadBarrier(HInstruction* instruction, |
| 8613 | Location ref, |
| 8614 | vixl32::Register obj, |
| 8615 | Location field_offset, |
| 8616 | Location temp, |
| 8617 | bool needs_null_check, |
| 8618 | vixl32::Register temp2) { |
| 8619 | DCHECK(kEmitCompilerReadBarrier); |
| 8620 | DCHECK(kUseBakerReadBarrier); |
| 8621 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8622 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 8623 | // Marking Register) to decide whether we need to enter the slow |
| 8624 | // path to update the reference field within `obj`. Then, in the |
| 8625 | // slow path, check the gray bit in the lock word of the reference's |
| 8626 | // holder (`obj`) to decide whether to mark `ref` and update the |
| 8627 | // field or not. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8628 | // |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8629 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8630 | // // Slow path. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8631 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8632 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8633 | // HeapReference<mirror::Object> ref = *(obj + field_offset); // Reference load. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8634 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 8635 | // if (is_gray) { |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8636 | // old_ref = ref; |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8637 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8638 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8639 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8640 | // } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8641 | // } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8642 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8643 | vixl32::Register temp_reg = RegisterFrom(temp); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8644 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8645 | // Slow path updating the object reference at address `obj + field_offset` |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8646 | // 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] | 8647 | SlowPathCodeARMVIXL* slow_path = |
| 8648 | new (GetScopedAllocator()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL( |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8649 | instruction, |
| 8650 | ref, |
| 8651 | obj, |
| 8652 | /* offset */ 0u, |
| 8653 | /* index */ field_offset, |
| 8654 | /* scale_factor */ ScaleFactor::TIMES_1, |
| 8655 | needs_null_check, |
| 8656 | temp_reg, |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8657 | temp2); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8658 | AddSlowPath(slow_path); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8659 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8660 | __ CompareAndBranchIfNonZero(mr, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8661 | // Fast path: the GC is not marking: nothing to do (the field is |
| 8662 | // up-to-date, and we don't need to load the reference). |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8663 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8664 | MaybeGenerateMarkingRegisterCheck(/* code */ 22); |
Roland Levillain | 844e653 | 2016-11-03 16:09:47 +0000 | [diff] [blame] | 8665 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8666 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8667 | void CodeGeneratorARMVIXL::GenerateRawReferenceLoad(HInstruction* instruction, |
| 8668 | Location ref, |
| 8669 | vixl::aarch32::Register obj, |
| 8670 | uint32_t offset, |
| 8671 | Location index, |
| 8672 | ScaleFactor scale_factor, |
| 8673 | bool needs_null_check) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8674 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8675 | vixl32::Register ref_reg = RegisterFrom(ref, type); |
| 8676 | |
| 8677 | // If needed, vixl::EmissionCheckScope guards are used to ensure |
| 8678 | // that no pools are emitted between the load (macro) instruction |
| 8679 | // and MaybeRecordImplicitNullCheck. |
| 8680 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8681 | if (index.IsValid()) { |
| 8682 | // Load types involving an "index": ArrayGet, |
| 8683 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 8684 | // intrinsics. |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8685 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8686 | if (index.IsConstant()) { |
| 8687 | size_t computed_offset = |
| 8688 | (Int32ConstantFrom(index) << scale_factor) + offset; |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8689 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8690 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8691 | if (needs_null_check) { |
| 8692 | MaybeRecordImplicitNullCheck(instruction); |
| 8693 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8694 | } else { |
| 8695 | // Handle the special case of the |
| 8696 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 8697 | // intrinsics, which use a register pair as index ("long |
| 8698 | // offset"), of which only the low part contains data. |
| 8699 | vixl32::Register index_reg = index.IsRegisterPair() |
| 8700 | ? LowRegisterFrom(index) |
| 8701 | : RegisterFrom(index); |
| 8702 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8703 | vixl32::Register temp = temps.Acquire(); |
| 8704 | __ Add(temp, obj, Operand(index_reg, ShiftType::LSL, scale_factor)); |
| 8705 | { |
| 8706 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 8707 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, temp, offset); |
| 8708 | if (needs_null_check) { |
| 8709 | MaybeRecordImplicitNullCheck(instruction); |
| 8710 | } |
| 8711 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8712 | } |
| 8713 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8714 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
| 8715 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8716 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8717 | if (needs_null_check) { |
| 8718 | MaybeRecordImplicitNullCheck(instruction); |
| 8719 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8720 | } |
| 8721 | |
Roland Levillain | 844e653 | 2016-11-03 16:09:47 +0000 | [diff] [blame] | 8722 | // Object* ref = ref_addr->AsMirrorPtr() |
| 8723 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | 844e653 | 2016-11-03 16:09:47 +0000 | [diff] [blame] | 8724 | } |
| 8725 | |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8726 | void CodeGeneratorARMVIXL::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 8727 | // The following condition is a compile-time one, so it does not have a run-time cost. |
| 8728 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && kIsDebugBuild) { |
| 8729 | // The following condition is a run-time one; it is executed after the |
| 8730 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 8731 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 8732 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8733 | vixl32::Register temp = temp_loc.IsValid() ? RegisterFrom(temp_loc) : temps.Acquire(); |
| 8734 | GetAssembler()->GenerateMarkingRegisterCheck(temp, |
| 8735 | kMarkingRegisterCheckBreakCodeBaseCode + code); |
| 8736 | } |
| 8737 | } |
| 8738 | } |
| 8739 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8740 | void CodeGeneratorARMVIXL::GenerateReadBarrierSlow(HInstruction* instruction, |
| 8741 | Location out, |
| 8742 | Location ref, |
| 8743 | Location obj, |
| 8744 | uint32_t offset, |
| 8745 | Location index) { |
| 8746 | DCHECK(kEmitCompilerReadBarrier); |
| 8747 | |
| 8748 | // Insert a slow path based read barrier *after* the reference load. |
| 8749 | // |
| 8750 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 8751 | // reference will be carried out by the runtime within the slow |
| 8752 | // path. |
| 8753 | // |
| 8754 | // Note that `ref` currently does not get unpoisoned (when heap |
| 8755 | // poisoning is enabled), which is alright as the `ref` argument is |
| 8756 | // not used by the artReadBarrierSlow entry point. |
| 8757 | // |
| 8758 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8759 | SlowPathCodeARMVIXL* slow_path = new (GetScopedAllocator()) |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8760 | ReadBarrierForHeapReferenceSlowPathARMVIXL(instruction, out, ref, obj, offset, index); |
| 8761 | AddSlowPath(slow_path); |
| 8762 | |
| 8763 | __ B(slow_path->GetEntryLabel()); |
| 8764 | __ Bind(slow_path->GetExitLabel()); |
| 8765 | } |
| 8766 | |
| 8767 | void CodeGeneratorARMVIXL::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8768 | Location out, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8769 | Location ref, |
| 8770 | Location obj, |
| 8771 | uint32_t offset, |
| 8772 | Location index) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8773 | if (kEmitCompilerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8774 | // Baker's read barriers shall be handled by the fast path |
Roland Levillain | 9983e30 | 2017-07-14 14:34:22 +0100 | [diff] [blame] | 8775 | // (CodeGeneratorARMVIXL::GenerateReferenceLoadWithBakerReadBarrier). |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8776 | DCHECK(!kUseBakerReadBarrier); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8777 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 8778 | // by the runtime within the slow path. |
| 8779 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8780 | } else if (kPoisonHeapReferences) { |
| 8781 | GetAssembler()->UnpoisonHeapReference(RegisterFrom(out)); |
| 8782 | } |
| 8783 | } |
| 8784 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8785 | void CodeGeneratorARMVIXL::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 8786 | Location out, |
| 8787 | Location root) { |
| 8788 | DCHECK(kEmitCompilerReadBarrier); |
| 8789 | |
| 8790 | // Insert a slow path based read barrier *after* the GC root load. |
| 8791 | // |
| 8792 | // Note that GC roots are not affected by heap poisoning, so we do |
| 8793 | // not need to do anything special for this here. |
| 8794 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8795 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathARMVIXL(instruction, out, root); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8796 | AddSlowPath(slow_path); |
| 8797 | |
| 8798 | __ B(slow_path->GetEntryLabel()); |
| 8799 | __ Bind(slow_path->GetExitLabel()); |
| 8800 | } |
| 8801 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8802 | // Check if the desired_dispatch_info is supported. If it is, return it, |
| 8803 | // otherwise return a fall-back info that should be used instead. |
| 8804 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARMVIXL::GetSupportedInvokeStaticOrDirectDispatch( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8805 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 8806 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e807ff7 | 2017-01-23 09:03:12 +0000 | [diff] [blame] | 8807 | return desired_dispatch_info; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8808 | } |
| 8809 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8810 | vixl32::Register CodeGeneratorARMVIXL::GetInvokeStaticOrDirectExtraParameter( |
| 8811 | HInvokeStaticOrDirect* invoke, vixl32::Register temp) { |
| 8812 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 8813 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 8814 | if (!invoke->GetLocations()->Intrinsified()) { |
| 8815 | return RegisterFrom(location); |
| 8816 | } |
| 8817 | // For intrinsics we allow any location, so it may be on the stack. |
| 8818 | if (!location.IsRegister()) { |
| 8819 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, location.GetStackIndex()); |
| 8820 | return temp; |
| 8821 | } |
| 8822 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 8823 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 8824 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 8825 | // simple and more robust approach rather that trying to determine if that's the case. |
| 8826 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Scott Wakeling | d5cd497 | 2017-02-03 11:38:35 +0000 | [diff] [blame] | 8827 | if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(RegisterFrom(location).GetCode())) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8828 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(RegisterFrom(location).GetCode()); |
| 8829 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, stack_offset); |
| 8830 | return temp; |
| 8831 | } |
| 8832 | return RegisterFrom(location); |
| 8833 | } |
| 8834 | |
Vladimir Marko | d254f5c | 2017-06-02 15:18:36 +0000 | [diff] [blame] | 8835 | void CodeGeneratorARMVIXL::GenerateStaticOrDirectCall( |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8836 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8837 | 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] | 8838 | switch (invoke->GetMethodLoadKind()) { |
| 8839 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 8840 | uint32_t offset = |
| 8841 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 8842 | // temp = thread->string_init_entrypoint |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8843 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp), tr, offset); |
| 8844 | break; |
| 8845 | } |
| 8846 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 8847 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 8848 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 8849 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 8850 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 8851 | PcRelativePatchInfo* labels = NewPcRelativeMethodPatch(invoke->GetTargetMethod()); |
| 8852 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 8853 | EmitMovwMovtPlaceholder(labels, temp_reg); |
| 8854 | break; |
| 8855 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8856 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 8857 | __ Mov(RegisterFrom(temp), Operand::From(invoke->GetMethodAddress())); |
| 8858 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 8859 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
| 8860 | PcRelativePatchInfo* labels = NewMethodBssEntryPatch( |
| 8861 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex())); |
| 8862 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 8863 | EmitMovwMovtPlaceholder(labels, temp_reg); |
| 8864 | GetAssembler()->LoadFromOffset(kLoadWord, temp_reg, temp_reg, /* offset*/ 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8865 | break; |
| 8866 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8867 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 8868 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 8869 | return; // No code pointer retrieval; the runtime performs the call directly. |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8870 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8871 | } |
| 8872 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8873 | switch (invoke->GetCodePtrLocation()) { |
| 8874 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8875 | { |
| 8876 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 8877 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 8878 | vixl32::k32BitT32InstructionSizeInBytes, |
| 8879 | CodeBufferCheckScope::kMaximumSize); |
| 8880 | __ bl(GetFrameEntryLabel()); |
| 8881 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 8882 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8883 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8884 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 8885 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 8886 | GetAssembler()->LoadFromOffset( |
| 8887 | kLoadWord, |
| 8888 | lr, |
| 8889 | RegisterFrom(callee_method), |
| 8890 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8891 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8892 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8893 | // 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] | 8894 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 8895 | vixl32::k16BitT32InstructionSizeInBytes, |
| 8896 | CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8897 | // LR() |
| 8898 | __ blx(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8899 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8900 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8901 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8902 | } |
| 8903 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8904 | DCHECK(!IsLeafMethod()); |
| 8905 | } |
| 8906 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8907 | void CodeGeneratorARMVIXL::GenerateVirtualCall( |
| 8908 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8909 | vixl32::Register temp = RegisterFrom(temp_location); |
| 8910 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 8911 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
| 8912 | |
| 8913 | // Use the calling convention instead of the location of the receiver, as |
| 8914 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 8915 | // slow path, the arguments have been moved to the right place, so here we are |
| 8916 | // guaranteed that the receiver is the first register of the calling convention. |
| 8917 | InvokeDexCallingConventionARMVIXL calling_convention; |
| 8918 | vixl32::Register receiver = calling_convention.GetRegisterAt(0); |
| 8919 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8920 | { |
| 8921 | // Make sure the pc is recorded immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 8922 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 8923 | vixl32::kMaxInstructionSizeInBytes, |
| 8924 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8925 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 8926 | __ ldr(temp, MemOperand(receiver, class_offset)); |
| 8927 | MaybeRecordImplicitNullCheck(invoke); |
| 8928 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8929 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 8930 | // emit a read barrier for the previous class reference load. |
| 8931 | // However this is not required in practice, as this is an |
| 8932 | // intermediate/temporary reference and because the current |
| 8933 | // concurrent copying collector keeps the from-space memory |
| 8934 | // intact/accessible until the end of the marking phase (the |
| 8935 | // concurrent copying collector may not in the future). |
| 8936 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 8937 | |
| 8938 | // temp = temp->GetMethodAt(method_offset); |
| 8939 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 8940 | kArmPointerSize).Int32Value(); |
| 8941 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 8942 | // LR = temp->GetEntryPoint(); |
| 8943 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8944 | { |
| 8945 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 8946 | // blx in T32 has only 16bit encoding that's why a stricter check for the scope is used. |
| 8947 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 8948 | vixl32::k16BitT32InstructionSizeInBytes, |
| 8949 | CodeBufferCheckScope::kExactSize); |
| 8950 | // LR(); |
| 8951 | __ blx(lr); |
| 8952 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 8953 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8954 | } |
| 8955 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 8956 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeMethodPatch( |
| 8957 | MethodReference target_method) { |
| 8958 | return NewPcRelativePatch(*target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 8959 | target_method.index, |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 8960 | &pc_relative_method_patches_); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8961 | } |
| 8962 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 8963 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewMethodBssEntryPatch( |
| 8964 | MethodReference target_method) { |
| 8965 | return NewPcRelativePatch(*target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 8966 | target_method.index, |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 8967 | &method_bss_entry_patches_); |
| 8968 | } |
| 8969 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8970 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeTypePatch( |
| 8971 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 8972 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
| 8973 | } |
| 8974 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8975 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewTypeBssEntryPatch( |
| 8976 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 8977 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 8978 | } |
| 8979 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 8980 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeStringPatch( |
| 8981 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 8982 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
| 8983 | } |
| 8984 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8985 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewStringBssEntryPatch( |
| 8986 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 8987 | return NewPcRelativePatch(dex_file, string_index.index_, &string_bss_entry_patches_); |
| 8988 | } |
| 8989 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8990 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativePatch( |
| 8991 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 8992 | patches->emplace_back(dex_file, offset_or_index); |
| 8993 | return &patches->back(); |
| 8994 | } |
| 8995 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8996 | vixl::aarch32::Label* CodeGeneratorARMVIXL::NewBakerReadBarrierPatch(uint32_t custom_data) { |
| 8997 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 8998 | return &baker_read_barrier_patches_.back().label; |
| 8999 | } |
| 9000 | |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9001 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateBootImageAddressLiteral(uint32_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 9002 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9003 | } |
| 9004 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 9005 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitStringLiteral( |
| 9006 | const DexFile& dex_file, |
| 9007 | dex::StringIndex string_index, |
| 9008 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9009 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9010 | return jit_string_patches_.GetOrCreate( |
| 9011 | StringReference(&dex_file, string_index), |
| 9012 | [this]() { |
| 9013 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 9014 | }); |
| 9015 | } |
| 9016 | |
| 9017 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 9018 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 9019 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9020 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9021 | return jit_class_patches_.GetOrCreate( |
| 9022 | TypeReference(&dex_file, type_index), |
| 9023 | [this]() { |
| 9024 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 9025 | }); |
| 9026 | } |
| 9027 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9028 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9029 | inline void CodeGeneratorARMVIXL::EmitPcRelativeLinkerPatches( |
| 9030 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9031 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9032 | for (const PcRelativePatchInfo& info : infos) { |
| 9033 | const DexFile& dex_file = info.target_dex_file; |
| 9034 | size_t offset_or_index = info.offset_or_index; |
| 9035 | DCHECK(info.add_pc_label.IsBound()); |
| 9036 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.GetLocation()); |
| 9037 | // Add MOVW patch. |
| 9038 | DCHECK(info.movw_label.IsBound()); |
| 9039 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.GetLocation()); |
| 9040 | linker_patches->push_back(Factory(movw_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 9041 | // Add MOVT patch. |
| 9042 | DCHECK(info.movt_label.IsBound()); |
| 9043 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.GetLocation()); |
| 9044 | linker_patches->push_back(Factory(movt_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 9045 | } |
| 9046 | } |
| 9047 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9048 | void CodeGeneratorARMVIXL::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9049 | DCHECK(linker_patches->empty()); |
| 9050 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9051 | /* MOVW+MOVT for each entry */ 2u * pc_relative_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9052 | /* MOVW+MOVT for each entry */ 2u * method_bss_entry_patches_.size() + |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9053 | /* MOVW+MOVT for each entry */ 2u * pc_relative_type_patches_.size() + |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9054 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9055 | /* MOVW+MOVT for each entry */ 2u * pc_relative_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 9056 | /* MOVW+MOVT for each entry */ 2u * string_bss_entry_patches_.size() + |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9057 | baker_read_barrier_patches_.size(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9058 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9059 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9060 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 9061 | pc_relative_method_patches_, linker_patches); |
| 9062 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 9063 | pc_relative_type_patches_, linker_patches); |
| 9064 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| 9065 | pc_relative_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9066 | } else { |
| 9067 | DCHECK(pc_relative_method_patches_.empty()); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9068 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeClassTablePatch>( |
| 9069 | pc_relative_type_patches_, linker_patches); |
| 9070 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringInternTablePatch>( |
| 9071 | pc_relative_string_patches_, linker_patches); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9072 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9073 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 9074 | method_bss_entry_patches_, linker_patches); |
| 9075 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 9076 | type_bss_entry_patches_, linker_patches); |
| 9077 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 9078 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9079 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9080 | linker_patches->push_back(linker::LinkerPatch::BakerReadBarrierBranchPatch( |
| 9081 | info.label.GetLocation(), info.custom_data)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9082 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9083 | DCHECK_EQ(size, linker_patches->size()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9084 | } |
| 9085 | |
| 9086 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateUint32Literal( |
| 9087 | uint32_t value, |
| 9088 | Uint32ToLiteralMap* map) { |
| 9089 | return map->GetOrCreate( |
| 9090 | value, |
| 9091 | [this, value]() { |
| 9092 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ value); |
| 9093 | }); |
| 9094 | } |
| 9095 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 9096 | void LocationsBuilderARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 9097 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9098 | new (GetGraph()->GetAllocator()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 9099 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 9100 | Location::RequiresRegister()); |
| 9101 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 9102 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 9103 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 9104 | } |
| 9105 | |
| 9106 | void InstructionCodeGeneratorARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 9107 | vixl32::Register res = OutputRegister(instr); |
| 9108 | vixl32::Register accumulator = |
| 9109 | InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 9110 | vixl32::Register mul_left = |
| 9111 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 9112 | vixl32::Register mul_right = |
| 9113 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
| 9114 | |
| 9115 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 9116 | __ Mla(res, mul_left, mul_right, accumulator); |
| 9117 | } else { |
| 9118 | __ Mls(res, mul_left, mul_right, accumulator); |
| 9119 | } |
| 9120 | } |
| 9121 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9122 | void LocationsBuilderARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9123 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9124 | LOG(FATAL) << "Unreachable"; |
| 9125 | } |
| 9126 | |
| 9127 | void InstructionCodeGeneratorARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9128 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9129 | LOG(FATAL) << "Unreachable"; |
| 9130 | } |
| 9131 | |
| 9132 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 9133 | void LocationsBuilderARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9134 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9135 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9136 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9137 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
| 9138 | codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 9139 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 9140 | if (switch_instr->GetStartValue() != 0) { |
| 9141 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 9142 | } |
| 9143 | } |
| 9144 | } |
| 9145 | |
| 9146 | // TODO(VIXL): Investigate and reach the parity with old arm codegen. |
| 9147 | void InstructionCodeGeneratorARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9148 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 9149 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9150 | LocationSummary* locations = switch_instr->GetLocations(); |
| 9151 | vixl32::Register value_reg = InputRegisterAt(switch_instr, 0); |
| 9152 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 9153 | |
| 9154 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
| 9155 | !codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 9156 | // Create a series of compare/jumps. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9157 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9158 | vixl32::Register temp_reg = temps.Acquire(); |
| 9159 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 9160 | // the immediate, because IP is used as the destination register. For the other |
| 9161 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 9162 | // and they can be encoded in the instruction without making use of IP register. |
| 9163 | __ Adds(temp_reg, value_reg, -lower_bound); |
| 9164 | |
| 9165 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 9166 | // Jump to successors[0] if value == lower_bound. |
| 9167 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 9168 | int32_t last_index = 0; |
| 9169 | for (; num_entries - last_index > 2; last_index += 2) { |
| 9170 | __ Adds(temp_reg, temp_reg, -2); |
| 9171 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 9172 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9173 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 9174 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 9175 | } |
| 9176 | if (num_entries - last_index == 2) { |
| 9177 | // The last missing case_value. |
| 9178 | __ Cmp(temp_reg, 1); |
| 9179 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9180 | } |
| 9181 | |
| 9182 | // And the default for any other value. |
| 9183 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 9184 | __ B(codegen_->GetLabelOf(default_block)); |
| 9185 | } |
| 9186 | } else { |
| 9187 | // Create a table lookup. |
| 9188 | vixl32::Register table_base = RegisterFrom(locations->GetTemp(0)); |
| 9189 | |
| 9190 | JumpTableARMVIXL* jump_table = codegen_->CreateJumpTable(switch_instr); |
| 9191 | |
| 9192 | // Remove the bias. |
| 9193 | vixl32::Register key_reg; |
| 9194 | if (lower_bound != 0) { |
| 9195 | key_reg = RegisterFrom(locations->GetTemp(1)); |
| 9196 | __ Sub(key_reg, value_reg, lower_bound); |
| 9197 | } else { |
| 9198 | key_reg = value_reg; |
| 9199 | } |
| 9200 | |
| 9201 | // Check whether the value is in the table, jump to default block if not. |
| 9202 | __ Cmp(key_reg, num_entries - 1); |
| 9203 | __ B(hi, codegen_->GetLabelOf(default_block)); |
| 9204 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9205 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9206 | vixl32::Register jump_offset = temps.Acquire(); |
| 9207 | |
| 9208 | // Load jump offset from the table. |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9209 | { |
| 9210 | const size_t jump_size = switch_instr->GetNumEntries() * sizeof(int32_t); |
| 9211 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9212 | (vixl32::kMaxInstructionSizeInBytes * 4) + jump_size, |
| 9213 | CodeBufferCheckScope::kMaximumSize); |
| 9214 | __ adr(table_base, jump_table->GetTableStartLabel()); |
| 9215 | __ ldr(jump_offset, MemOperand(table_base, key_reg, vixl32::LSL, 2)); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9216 | |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9217 | // Jump to target block by branching to table_base(pc related) + offset. |
| 9218 | vixl32::Register target_address = table_base; |
| 9219 | __ add(target_address, table_base, jump_offset); |
| 9220 | __ bx(target_address); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 9221 | |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9222 | jump_table->EmitTable(codegen_); |
| 9223 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9224 | } |
| 9225 | } |
| 9226 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9227 | // Copy the result of a call into the given target. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9228 | void CodeGeneratorARMVIXL::MoveFromReturnRegister(Location trg, DataType::Type type) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9229 | if (!trg.IsValid()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9230 | DCHECK_EQ(type, DataType::Type::kVoid); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9231 | return; |
| 9232 | } |
| 9233 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9234 | DCHECK_NE(type, DataType::Type::kVoid); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9235 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9236 | Location return_loc = InvokeDexCallingConventionVisitorARMVIXL().GetReturnLocation(type); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9237 | if (return_loc.Equals(trg)) { |
| 9238 | return; |
| 9239 | } |
| 9240 | |
| 9241 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 9242 | // with the last branch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9243 | if (type == DataType::Type::kInt64) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9244 | TODO_VIXL32(FATAL); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9245 | } else if (type == DataType::Type::kFloat64) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9246 | TODO_VIXL32(FATAL); |
| 9247 | } else { |
| 9248 | // Let the parallel move resolver take care of all of this. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9249 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9250 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 9251 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 9252 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9253 | } |
| 9254 | |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9255 | void LocationsBuilderARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 9256 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9257 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9258 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9259 | locations->SetOut(Location::RequiresRegister()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9260 | } |
| 9261 | |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9262 | void InstructionCodeGeneratorARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 9263 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| 9264 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 9265 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
| 9266 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9267 | OutputRegister(instruction), |
| 9268 | InputRegisterAt(instruction, 0), |
| 9269 | method_offset); |
| 9270 | } else { |
| 9271 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 9272 | instruction->GetIndex(), kArmPointerSize)); |
| 9273 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9274 | OutputRegister(instruction), |
| 9275 | InputRegisterAt(instruction, 0), |
| 9276 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 9277 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9278 | OutputRegister(instruction), |
| 9279 | OutputRegister(instruction), |
| 9280 | method_offset); |
| 9281 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9282 | } |
| 9283 | |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9284 | static void PatchJitRootUse(uint8_t* code, |
| 9285 | const uint8_t* roots_data, |
| 9286 | VIXLUInt32Literal* literal, |
| 9287 | uint64_t index_in_table) { |
| 9288 | DCHECK(literal->IsBound()); |
| 9289 | uint32_t literal_offset = literal->GetLocation(); |
| 9290 | uintptr_t address = |
| 9291 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 9292 | uint8_t* data = code + literal_offset; |
| 9293 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 9294 | } |
| 9295 | |
| 9296 | void CodeGeneratorARMVIXL::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 9297 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9298 | const StringReference& string_reference = entry.first; |
| 9299 | VIXLUInt32Literal* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9300 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9301 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9302 | } |
| 9303 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9304 | const TypeReference& type_reference = entry.first; |
| 9305 | VIXLUInt32Literal* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9306 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9307 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9308 | } |
| 9309 | } |
| 9310 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9311 | void CodeGeneratorARMVIXL::EmitMovwMovtPlaceholder( |
| 9312 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels, |
| 9313 | vixl32::Register out) { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 9314 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9315 | 3 * vixl32::kMaxInstructionSizeInBytes, |
| 9316 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9317 | // TODO(VIXL): Think about using mov instead of movw. |
| 9318 | __ bind(&labels->movw_label); |
| 9319 | __ movw(out, /* placeholder */ 0u); |
| 9320 | __ bind(&labels->movt_label); |
| 9321 | __ movt(out, /* placeholder */ 0u); |
| 9322 | __ bind(&labels->add_pc_label); |
| 9323 | __ add(out, out, pc); |
| 9324 | } |
| 9325 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9326 | #undef __ |
| 9327 | #undef QUICK_ENTRY_POINT |
| 9328 | #undef TODO_VIXL32 |
| 9329 | |
| 9330 | } // namespace arm |
| 9331 | } // namespace art |