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(); |
| 535 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 536 | |
| 537 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 538 | __ Bind(GetEntryLabel()); |
| 539 | SaveLiveRegisters(codegen, locations); |
| 540 | |
| 541 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 542 | // For HLoadClass/kBssEntry/kSaveEverything, make sure we preserve the address of the entry. |
| 543 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 544 | bool is_load_class_bss_entry = |
| 545 | (cls_ == instruction_) && (cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry); |
| 546 | vixl32::Register entry_address; |
| 547 | if (is_load_class_bss_entry && call_saves_everything_except_r0) { |
| 548 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 549 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
| 550 | // the kSaveEverything call. |
| 551 | bool temp_is_r0 = temp.Is(calling_convention.GetRegisterAt(0)); |
| 552 | entry_address = temp_is_r0 ? RegisterFrom(out) : temp; |
| 553 | DCHECK(!entry_address.Is(calling_convention.GetRegisterAt(0))); |
| 554 | if (temp_is_r0) { |
| 555 | __ Mov(entry_address, temp); |
| 556 | } |
| 557 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 558 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 559 | __ Mov(calling_convention.GetRegisterAt(0), type_index.index_); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 560 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 561 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 562 | arm_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 563 | if (do_clinit_) { |
| 564 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 565 | } else { |
| 566 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 567 | } |
| 568 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 569 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
| 570 | if (is_load_class_bss_entry) { |
| 571 | if (call_saves_everything_except_r0) { |
| 572 | // The class entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 573 | __ Str(r0, MemOperand(entry_address)); |
| 574 | } else { |
| 575 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
| 576 | UseScratchRegisterScope temps( |
| 577 | down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 578 | vixl32::Register temp = temps.Acquire(); |
| 579 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 580 | arm_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index); |
| 581 | arm_codegen->EmitMovwMovtPlaceholder(labels, temp); |
| 582 | __ Str(r0, MemOperand(temp)); |
| 583 | } |
| 584 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 585 | // Move the class to the desired location. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 586 | if (out.IsValid()) { |
| 587 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 588 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
| 589 | } |
| 590 | RestoreLiveRegisters(codegen, locations); |
| 591 | __ B(GetExitLabel()); |
| 592 | } |
| 593 | |
| 594 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARMVIXL"; } |
| 595 | |
| 596 | private: |
| 597 | // The class this slow path will load. |
| 598 | HLoadClass* const cls_; |
| 599 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 600 | // The dex PC of `at_`. |
| 601 | const uint32_t dex_pc_; |
| 602 | |
| 603 | // Whether to initialize the class. |
| 604 | const bool do_clinit_; |
| 605 | |
| 606 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARMVIXL); |
| 607 | }; |
| 608 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 609 | class LoadStringSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 610 | public: |
| 611 | explicit LoadStringSlowPathARMVIXL(HLoadString* instruction) |
| 612 | : SlowPathCodeARMVIXL(instruction) {} |
| 613 | |
| 614 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 615 | DCHECK(instruction_->IsLoadString()); |
| 616 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 617 | LocationSummary* locations = instruction_->GetLocations(); |
| 618 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 619 | HLoadString* load = instruction_->AsLoadString(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 620 | const dex::StringIndex string_index = load->GetStringIndex(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 621 | vixl32::Register out = OutputRegister(load); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 622 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
| 623 | |
| 624 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 625 | __ Bind(GetEntryLabel()); |
| 626 | SaveLiveRegisters(codegen, locations); |
| 627 | |
| 628 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 629 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 630 | // the kSaveEverything call. |
| 631 | vixl32::Register entry_address; |
| 632 | if (call_saves_everything_except_r0) { |
| 633 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 634 | bool temp_is_r0 = (temp.Is(calling_convention.GetRegisterAt(0))); |
| 635 | entry_address = temp_is_r0 ? out : temp; |
| 636 | DCHECK(!entry_address.Is(calling_convention.GetRegisterAt(0))); |
| 637 | if (temp_is_r0) { |
| 638 | __ Mov(entry_address, temp); |
| 639 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 640 | } |
| 641 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 642 | __ Mov(calling_convention.GetRegisterAt(0), string_index.index_); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 643 | arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 644 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 645 | |
| 646 | // Store the resolved String to the .bss entry. |
| 647 | if (call_saves_everything_except_r0) { |
| 648 | // The string entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 649 | __ Str(r0, MemOperand(entry_address)); |
| 650 | } else { |
| 651 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 652 | UseScratchRegisterScope temps( |
| 653 | down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 654 | vixl32::Register temp = temps.Acquire(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 655 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 656 | arm_codegen->NewStringBssEntryPatch(load->GetDexFile(), string_index); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 657 | arm_codegen->EmitMovwMovtPlaceholder(labels, temp); |
| 658 | __ Str(r0, MemOperand(temp)); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
| 662 | RestoreLiveRegisters(codegen, locations); |
| 663 | |
| 664 | __ B(GetExitLabel()); |
| 665 | } |
| 666 | |
| 667 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARMVIXL"; } |
| 668 | |
| 669 | private: |
| 670 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARMVIXL); |
| 671 | }; |
| 672 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 673 | class TypeCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 674 | public: |
| 675 | TypeCheckSlowPathARMVIXL(HInstruction* instruction, bool is_fatal) |
| 676 | : SlowPathCodeARMVIXL(instruction), is_fatal_(is_fatal) {} |
| 677 | |
| 678 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 679 | LocationSummary* locations = instruction_->GetLocations(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 680 | DCHECK(instruction_->IsCheckCast() |
| 681 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 682 | |
| 683 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 684 | __ Bind(GetEntryLabel()); |
| 685 | |
| 686 | if (!is_fatal_) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 687 | SaveLiveRegisters(codegen, locations); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 691 | // move resolver. |
| 692 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 693 | |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 694 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 695 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 696 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 697 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 698 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 699 | DataType::Type::kReference); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 700 | if (instruction_->IsInstanceOf()) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 701 | arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
| 702 | instruction_, |
| 703 | instruction_->GetDexPc(), |
| 704 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 705 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 706 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 707 | } else { |
| 708 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 709 | arm_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 710 | instruction_, |
| 711 | instruction_->GetDexPc(), |
| 712 | this); |
| 713 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | if (!is_fatal_) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 717 | RestoreLiveRegisters(codegen, locations); |
| 718 | __ B(GetExitLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 719 | } |
| 720 | } |
| 721 | |
| 722 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARMVIXL"; } |
| 723 | |
| 724 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 725 | |
| 726 | private: |
| 727 | const bool is_fatal_; |
| 728 | |
| 729 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARMVIXL); |
| 730 | }; |
| 731 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 732 | class DeoptimizationSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 733 | public: |
| 734 | explicit DeoptimizationSlowPathARMVIXL(HDeoptimize* instruction) |
| 735 | : SlowPathCodeARMVIXL(instruction) {} |
| 736 | |
| 737 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 738 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 739 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 740 | LocationSummary* locations = instruction_->GetLocations(); |
| 741 | SaveLiveRegisters(codegen, locations); |
| 742 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 743 | __ Mov(calling_convention.GetRegisterAt(0), |
| 744 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
| 745 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 746 | arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 747 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARMVIXL"; } |
| 751 | |
| 752 | private: |
| 753 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARMVIXL); |
| 754 | }; |
| 755 | |
| 756 | class ArraySetSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 757 | public: |
| 758 | explicit ArraySetSlowPathARMVIXL(HInstruction* instruction) : SlowPathCodeARMVIXL(instruction) {} |
| 759 | |
| 760 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 761 | LocationSummary* locations = instruction_->GetLocations(); |
| 762 | __ Bind(GetEntryLabel()); |
| 763 | SaveLiveRegisters(codegen, locations); |
| 764 | |
| 765 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 766 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 767 | parallel_move.AddMove( |
| 768 | locations->InAt(0), |
| 769 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 770 | DataType::Type::kReference, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 771 | nullptr); |
| 772 | parallel_move.AddMove( |
| 773 | locations->InAt(1), |
| 774 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 775 | DataType::Type::kInt32, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 776 | nullptr); |
| 777 | parallel_move.AddMove( |
| 778 | locations->InAt(2), |
| 779 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 780 | DataType::Type::kReference, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 781 | nullptr); |
| 782 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 783 | |
| 784 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 785 | arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| 786 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 787 | RestoreLiveRegisters(codegen, locations); |
| 788 | __ B(GetExitLabel()); |
| 789 | } |
| 790 | |
| 791 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARMVIXL"; } |
| 792 | |
| 793 | private: |
| 794 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARMVIXL); |
| 795 | }; |
| 796 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 797 | // Abstract base class for read barrier slow paths marking a reference |
| 798 | // `ref`. |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 799 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 800 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 801 | // barrier marking runtime entry point to be invoked or an empty |
| 802 | // location; in the latter case, the read barrier marking runtime |
| 803 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 804 | class ReadBarrierMarkSlowPathBaseARMVIXL : public SlowPathCodeARMVIXL { |
| 805 | protected: |
| 806 | ReadBarrierMarkSlowPathBaseARMVIXL(HInstruction* instruction, Location ref, Location entrypoint) |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 807 | : SlowPathCodeARMVIXL(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 808 | DCHECK(kEmitCompilerReadBarrier); |
| 809 | } |
| 810 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 811 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathBaseARMVIXL"; } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 812 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 813 | // Generate assembly code calling the read barrier marking runtime |
| 814 | // entry point (ReadBarrierMarkRegX). |
| 815 | void GenerateReadBarrierMarkRuntimeCall(CodeGenerator* codegen) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 816 | vixl32::Register ref_reg = RegisterFrom(ref_); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 817 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 818 | // No need to save live registers; it's taken care of by the |
| 819 | // entrypoint. Also, there is no need to update the stack mask, |
| 820 | // as this runtime call will not trigger a garbage collection. |
| 821 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 822 | DCHECK(!ref_reg.Is(sp)); |
| 823 | DCHECK(!ref_reg.Is(lr)); |
| 824 | DCHECK(!ref_reg.Is(pc)); |
| 825 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 826 | // as a temporary, it cannot be the entry point's input/output. |
| 827 | DCHECK(!ref_reg.Is(ip)); |
| 828 | DCHECK(ref_reg.IsRegister()) << ref_reg; |
| 829 | // "Compact" slow path, saving two moves. |
| 830 | // |
| 831 | // Instead of using the standard runtime calling convention (input |
| 832 | // and output in R0): |
| 833 | // |
| 834 | // R0 <- ref |
| 835 | // R0 <- ReadBarrierMark(R0) |
| 836 | // ref <- R0 |
| 837 | // |
| 838 | // we just use rX (the register containing `ref`) as input and output |
| 839 | // of a dedicated entrypoint: |
| 840 | // |
| 841 | // rX <- ReadBarrierMarkRegX(rX) |
| 842 | // |
| 843 | if (entrypoint_.IsValid()) { |
| 844 | arm_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 845 | __ Blx(RegisterFrom(entrypoint_)); |
| 846 | } else { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 847 | // Entrypoint is not already loaded, load from the thread. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 848 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 849 | Thread::ReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg.GetCode()); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 850 | // This runtime call does not require a stack map. |
| 851 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 852 | } |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 853 | } |
| 854 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 855 | // The location (register) of the marked object reference. |
| 856 | const Location ref_; |
| 857 | |
| 858 | // The location of the entrypoint if already loaded. |
| 859 | const Location entrypoint_; |
| 860 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 861 | private: |
| 862 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathBaseARMVIXL); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 863 | }; |
| 864 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 865 | // Slow path marking an object reference `ref` during a read |
| 866 | // barrier. The field `obj.field` in the object `obj` holding this |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 867 | // reference does not get updated by this slow path after marking. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 868 | // |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 869 | // This means that after the execution of this slow path, `ref` will |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 870 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 871 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 872 | // probably still be a from-space reference (unless it gets updated by |
| 873 | // another thread, or if another thread installed another object |
| 874 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 875 | // |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 876 | // Argument `entrypoint` must be a register location holding the read |
| 877 | // barrier marking runtime entry point to be invoked or an empty |
| 878 | // location; in the latter case, the read barrier marking runtime |
| 879 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 880 | class ReadBarrierMarkSlowPathARMVIXL : public ReadBarrierMarkSlowPathBaseARMVIXL { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 881 | public: |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 882 | ReadBarrierMarkSlowPathARMVIXL(HInstruction* instruction, |
| 883 | Location ref, |
| 884 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 885 | : ReadBarrierMarkSlowPathBaseARMVIXL(instruction, ref, entrypoint) { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 886 | DCHECK(kEmitCompilerReadBarrier); |
| 887 | } |
| 888 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 889 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARMVIXL"; } |
| 890 | |
| 891 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 892 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 893 | DCHECK(locations->CanCall()); |
| 894 | DCHECK(ref_.IsRegister()) << ref_; |
| 895 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
| 896 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 897 | << "Unexpected instruction in read barrier marking slow path: " |
| 898 | << instruction_->DebugName(); |
| 899 | |
| 900 | __ Bind(GetEntryLabel()); |
| 901 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 902 | __ B(GetExitLabel()); |
| 903 | } |
| 904 | |
| 905 | private: |
| 906 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARMVIXL); |
| 907 | }; |
| 908 | |
| 909 | // Slow path loading `obj`'s lock word, loading a reference from |
| 910 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 911 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 912 | // read barrier). The field `obj.field` in the object `obj` holding |
| 913 | // this reference does not get updated by this slow path after marking |
| 914 | // (see LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL |
| 915 | // below for that). |
| 916 | // |
| 917 | // This means that after the execution of this slow path, `ref` will |
| 918 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 919 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 920 | // probably still be a from-space reference (unless it gets updated by |
| 921 | // another thread, or if another thread installed another object |
| 922 | // reference (different from `ref`) in `obj.field`). |
| 923 | // |
| 924 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 925 | // barrier marking runtime entry point to be invoked or an empty |
| 926 | // location; in the latter case, the read barrier marking runtime |
| 927 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 928 | class LoadReferenceWithBakerReadBarrierSlowPathARMVIXL : public ReadBarrierMarkSlowPathBaseARMVIXL { |
| 929 | public: |
| 930 | LoadReferenceWithBakerReadBarrierSlowPathARMVIXL(HInstruction* instruction, |
| 931 | Location ref, |
| 932 | vixl32::Register obj, |
| 933 | uint32_t offset, |
| 934 | Location index, |
| 935 | ScaleFactor scale_factor, |
| 936 | bool needs_null_check, |
| 937 | vixl32::Register temp, |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 938 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 939 | : ReadBarrierMarkSlowPathBaseARMVIXL(instruction, ref, entrypoint), |
| 940 | obj_(obj), |
| 941 | offset_(offset), |
| 942 | index_(index), |
| 943 | scale_factor_(scale_factor), |
| 944 | needs_null_check_(needs_null_check), |
| 945 | temp_(temp) { |
| 946 | DCHECK(kEmitCompilerReadBarrier); |
| 947 | DCHECK(kUseBakerReadBarrier); |
| 948 | } |
| 949 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 950 | const char* GetDescription() const OVERRIDE { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 951 | return "LoadReferenceWithBakerReadBarrierSlowPathARMVIXL"; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 955 | LocationSummary* locations = instruction_->GetLocations(); |
| 956 | vixl32::Register ref_reg = RegisterFrom(ref_); |
| 957 | DCHECK(locations->CanCall()); |
| 958 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg.GetCode())) << ref_reg; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 959 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 960 | instruction_->IsStaticFieldGet() || |
| 961 | instruction_->IsArrayGet() || |
| 962 | instruction_->IsArraySet() || |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 963 | instruction_->IsInstanceOf() || |
| 964 | instruction_->IsCheckCast() || |
| 965 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 966 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 967 | << "Unexpected instruction in read barrier marking slow path: " |
| 968 | << instruction_->DebugName(); |
| 969 | // The read barrier instrumentation of object ArrayGet |
| 970 | // instructions does not support the HIntermediateAddress |
| 971 | // instruction. |
| 972 | DCHECK(!(instruction_->IsArrayGet() && |
| 973 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 974 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 975 | // Temporary register `temp_`, used to store the lock word, must |
| 976 | // not be IP, as we may use it to emit the reference load (in the |
| 977 | // call to GenerateRawReferenceLoad below), and we need the lock |
| 978 | // word to still be in `temp_` after the reference load. |
| 979 | DCHECK(!temp_.Is(ip)); |
| 980 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 981 | __ Bind(GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 982 | |
| 983 | // When using MaybeGenerateReadBarrierSlow, the read barrier call is |
| 984 | // inserted after the original load. However, in fast path based |
| 985 | // Baker's read barriers, we need to perform the load of |
| 986 | // mirror::Object::monitor_ *before* the original reference load. |
| 987 | // This load-load ordering is required by the read barrier. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 988 | // The slow path (for Baker's algorithm) should look like: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 989 | // |
| 990 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 991 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 992 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 993 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 994 | // if (is_gray) { |
| 995 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 996 | // } |
| 997 | // |
| 998 | // Note: the original implementation in ReadBarrier::Barrier is |
| 999 | // slightly more complex as it performs additional checks that we do |
| 1000 | // not do here for performance reasons. |
| 1001 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1002 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1003 | |
| 1004 | // /* int32_t */ monitor = obj->monitor_ |
| 1005 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 1006 | arm_codegen->GetAssembler()->LoadFromOffset(kLoadWord, temp_, obj_, monitor_offset); |
| 1007 | if (needs_null_check_) { |
| 1008 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1009 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1010 | // /* LockWord */ lock_word = LockWord(monitor) |
| 1011 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 1012 | "art::LockWord and int32_t have different sizes."); |
| 1013 | |
| 1014 | // Introduce a dependency on the lock_word including the rb_state, |
| 1015 | // which shall prevent load-load reordering without using |
| 1016 | // a memory barrier (which would be more expensive). |
| 1017 | // `obj` is unchanged by this operation, but its value now depends |
| 1018 | // on `temp`. |
| 1019 | __ Add(obj_, obj_, Operand(temp_, ShiftType::LSR, 32)); |
| 1020 | |
| 1021 | // The actual reference load. |
| 1022 | // A possible implicit null check has already been handled above. |
| 1023 | arm_codegen->GenerateRawReferenceLoad( |
| 1024 | instruction_, ref_, obj_, offset_, index_, scale_factor_, /* needs_null_check */ false); |
| 1025 | |
| 1026 | // Mark the object `ref` when `obj` is gray. |
| 1027 | // |
| 1028 | // if (rb_state == ReadBarrier::GrayState()) |
| 1029 | // ref = ReadBarrier::Mark(ref); |
| 1030 | // |
| 1031 | // Given the numeric representation, it's enough to check the low bit of the |
| 1032 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 1033 | // which can be a 16-bit instruction unlike the TST immediate. |
| 1034 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 1035 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 1036 | __ Lsrs(temp_, temp_, LockWord::kReadBarrierStateShift + 1); |
| 1037 | __ B(cc, GetExitLabel()); // Carry flag is the last bit shifted out by LSRS. |
| 1038 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 1039 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1040 | __ B(GetExitLabel()); |
| 1041 | } |
| 1042 | |
| 1043 | private: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1044 | // The register containing the object holding the marked object reference field. |
| 1045 | vixl32::Register obj_; |
| 1046 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1047 | uint32_t offset_; |
| 1048 | Location index_; |
| 1049 | ScaleFactor scale_factor_; |
| 1050 | // Is a null check required? |
| 1051 | bool needs_null_check_; |
| 1052 | // A temporary register used to hold the lock word of `obj_`. |
| 1053 | vixl32::Register temp_; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1054 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1055 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierSlowPathARMVIXL); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1056 | }; |
| 1057 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1058 | // Slow path loading `obj`'s lock word, loading a reference from |
| 1059 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 1060 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 1061 | // read barrier). If needed, this slow path also atomically updates |
| 1062 | // the field `obj.field` in the object `obj` holding this reference |
| 1063 | // after marking (contrary to |
| 1064 | // LoadReferenceWithBakerReadBarrierSlowPathARMVIXL above, which never |
| 1065 | // tries to update `obj.field`). |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1066 | // |
| 1067 | // This means that after the execution of this slow path, both `ref` |
| 1068 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 1069 | // hold the same to-space reference (unless another thread installed |
| 1070 | // another object reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 1071 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1072 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 1073 | // barrier marking runtime entry point to be invoked or an empty |
| 1074 | // location; in the latter case, the read barrier marking runtime |
| 1075 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1076 | class LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL |
| 1077 | : public ReadBarrierMarkSlowPathBaseARMVIXL { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1078 | public: |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 1079 | LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL( |
| 1080 | HInstruction* instruction, |
| 1081 | Location ref, |
| 1082 | vixl32::Register obj, |
| 1083 | uint32_t offset, |
| 1084 | Location index, |
| 1085 | ScaleFactor scale_factor, |
| 1086 | bool needs_null_check, |
| 1087 | vixl32::Register temp1, |
| 1088 | vixl32::Register temp2, |
| 1089 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1090 | : ReadBarrierMarkSlowPathBaseARMVIXL(instruction, ref, entrypoint), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1091 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1092 | offset_(offset), |
| 1093 | index_(index), |
| 1094 | scale_factor_(scale_factor), |
| 1095 | needs_null_check_(needs_null_check), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1096 | temp1_(temp1), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1097 | temp2_(temp2) { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1098 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1099 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | const char* GetDescription() const OVERRIDE { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1103 | return "LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL"; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1107 | LocationSummary* locations = instruction_->GetLocations(); |
| 1108 | vixl32::Register ref_reg = RegisterFrom(ref_); |
| 1109 | DCHECK(locations->CanCall()); |
| 1110 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg.GetCode())) << ref_reg; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1111 | DCHECK_NE(ref_.reg(), LocationFrom(temp1_).reg()); |
| 1112 | |
| 1113 | // 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] | 1114 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 1115 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 1116 | << instruction_->DebugName(); |
| 1117 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1118 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1119 | DCHECK_EQ(offset_, 0u); |
| 1120 | DCHECK_EQ(scale_factor_, ScaleFactor::TIMES_1); |
| 1121 | Location field_offset = index_; |
| 1122 | DCHECK(field_offset.IsRegisterPair()) << field_offset; |
| 1123 | |
| 1124 | // Temporary register `temp1_`, used to store the lock word, must |
| 1125 | // not be IP, as we may use it to emit the reference load (in the |
| 1126 | // call to GenerateRawReferenceLoad below), and we need the lock |
| 1127 | // word to still be in `temp1_` after the reference load. |
| 1128 | DCHECK(!temp1_.Is(ip)); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1129 | |
| 1130 | __ Bind(GetEntryLabel()); |
| 1131 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 1132 | // The implementation is similar to LoadReferenceWithBakerReadBarrierSlowPathARMVIXL's: |
| 1133 | // |
| 1134 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 1135 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 1136 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 1137 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 1138 | // if (is_gray) { |
| 1139 | // old_ref = ref; |
| 1140 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 1141 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 1142 | // } |
| 1143 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1144 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 1145 | |
| 1146 | // /* int32_t */ monitor = obj->monitor_ |
| 1147 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 1148 | arm_codegen->GetAssembler()->LoadFromOffset(kLoadWord, temp1_, obj_, monitor_offset); |
| 1149 | if (needs_null_check_) { |
| 1150 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| 1151 | } |
| 1152 | // /* LockWord */ lock_word = LockWord(monitor) |
| 1153 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 1154 | "art::LockWord and int32_t have different sizes."); |
| 1155 | |
| 1156 | // Introduce a dependency on the lock_word including the rb_state, |
| 1157 | // which shall prevent load-load reordering without using |
| 1158 | // a memory barrier (which would be more expensive). |
| 1159 | // `obj` is unchanged by this operation, but its value now depends |
| 1160 | // on `temp`. |
| 1161 | __ Add(obj_, obj_, Operand(temp1_, ShiftType::LSR, 32)); |
| 1162 | |
| 1163 | // The actual reference load. |
| 1164 | // A possible implicit null check has already been handled above. |
| 1165 | arm_codegen->GenerateRawReferenceLoad( |
| 1166 | instruction_, ref_, obj_, offset_, index_, scale_factor_, /* needs_null_check */ false); |
| 1167 | |
| 1168 | // Mark the object `ref` when `obj` is gray. |
| 1169 | // |
| 1170 | // if (rb_state == ReadBarrier::GrayState()) |
| 1171 | // ref = ReadBarrier::Mark(ref); |
| 1172 | // |
| 1173 | // Given the numeric representation, it's enough to check the low bit of the |
| 1174 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 1175 | // which can be a 16-bit instruction unlike the TST immediate. |
| 1176 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 1177 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 1178 | __ Lsrs(temp1_, temp1_, LockWord::kReadBarrierStateShift + 1); |
| 1179 | __ B(cc, GetExitLabel()); // Carry flag is the last bit shifted out by LSRS. |
| 1180 | |
| 1181 | // Save the old value of the reference before marking it. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1182 | // Note that we cannot use IP to save the old reference, as IP is |
| 1183 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 1184 | // need the old reference after the call to that entry point. |
| 1185 | DCHECK(!temp1_.Is(ip)); |
| 1186 | __ Mov(temp1_, ref_reg); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 1187 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1188 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1189 | |
| 1190 | // If the new reference is different from the old reference, |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1191 | // update the field in the holder (`*(obj_ + field_offset)`). |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1192 | // |
| 1193 | // Note that this field could also hold a different object, if |
| 1194 | // another thread had concurrently changed it. In that case, the |
| 1195 | // LDREX/SUBS/ITNE sequence of instructions in the compare-and-set |
| 1196 | // (CAS) operation below would abort the CAS, leaving the field |
| 1197 | // as-is. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1198 | __ Cmp(temp1_, ref_reg); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1199 | __ B(eq, GetExitLabel()); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1200 | |
| 1201 | // Update the the holder's field atomically. This may fail if |
| 1202 | // mutator updates before us, but it's OK. This is achieved |
| 1203 | // using a strong compare-and-set (CAS) operation with relaxed |
| 1204 | // memory synchronization ordering, where the expected value is |
| 1205 | // the old reference and the desired value is the new reference. |
| 1206 | |
| 1207 | UseScratchRegisterScope temps(arm_codegen->GetVIXLAssembler()); |
| 1208 | // Convenience aliases. |
| 1209 | vixl32::Register base = obj_; |
| 1210 | // The UnsafeCASObject intrinsic uses a register pair as field |
| 1211 | // offset ("long offset"), of which only the low part contains |
| 1212 | // data. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1213 | vixl32::Register offset = LowRegisterFrom(field_offset); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1214 | vixl32::Register expected = temp1_; |
| 1215 | vixl32::Register value = ref_reg; |
| 1216 | vixl32::Register tmp_ptr = temps.Acquire(); // Pointer to actual memory. |
| 1217 | vixl32::Register tmp = temp2_; // Value in memory. |
| 1218 | |
| 1219 | __ Add(tmp_ptr, base, offset); |
| 1220 | |
| 1221 | if (kPoisonHeapReferences) { |
| 1222 | arm_codegen->GetAssembler()->PoisonHeapReference(expected); |
| 1223 | if (value.Is(expected)) { |
| 1224 | // Do not poison `value`, as it is the same register as |
| 1225 | // `expected`, which has just been poisoned. |
| 1226 | } else { |
| 1227 | arm_codegen->GetAssembler()->PoisonHeapReference(value); |
| 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | // do { |
| 1232 | // tmp = [r_ptr] - expected; |
| 1233 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 1234 | |
| 1235 | vixl32::Label loop_head, exit_loop; |
| 1236 | __ Bind(&loop_head); |
| 1237 | |
| 1238 | __ Ldrex(tmp, MemOperand(tmp_ptr)); |
| 1239 | |
| 1240 | __ Subs(tmp, tmp, expected); |
| 1241 | |
| 1242 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 1243 | ExactAssemblyScope aas(arm_codegen->GetVIXLAssembler(), |
| 1244 | 2 * kMaxInstructionSizeInBytes, |
| 1245 | CodeBufferCheckScope::kMaximumSize); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1246 | |
| 1247 | __ it(ne); |
| 1248 | __ clrex(ne); |
| 1249 | } |
| 1250 | |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 1251 | __ B(ne, &exit_loop, /* far_target */ false); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1252 | |
| 1253 | __ Strex(tmp, value, MemOperand(tmp_ptr)); |
| 1254 | __ Cmp(tmp, 1); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 1255 | __ B(eq, &loop_head, /* far_target */ false); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1256 | |
| 1257 | __ Bind(&exit_loop); |
| 1258 | |
| 1259 | if (kPoisonHeapReferences) { |
| 1260 | arm_codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 1261 | if (value.Is(expected)) { |
| 1262 | // Do not unpoison `value`, as it is the same register as |
| 1263 | // `expected`, which has just been unpoisoned. |
| 1264 | } else { |
| 1265 | arm_codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 1266 | } |
| 1267 | } |
| 1268 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1269 | __ B(GetExitLabel()); |
| 1270 | } |
| 1271 | |
| 1272 | private: |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1273 | // The register containing the object holding the marked object reference field. |
| 1274 | const vixl32::Register obj_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1275 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1276 | uint32_t offset_; |
| 1277 | Location index_; |
| 1278 | ScaleFactor scale_factor_; |
| 1279 | // Is a null check required? |
| 1280 | bool needs_null_check_; |
| 1281 | // A temporary register used to hold the lock word of `obj_`; and |
| 1282 | // also to hold the original reference value, when the reference is |
| 1283 | // marked. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1284 | const vixl32::Register temp1_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1285 | // A temporary register used in the implementation of the CAS, to |
| 1286 | // update the object's reference field. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1287 | const vixl32::Register temp2_; |
| 1288 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1289 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1290 | }; |
| 1291 | |
| 1292 | // Slow path generating a read barrier for a heap reference. |
| 1293 | class ReadBarrierForHeapReferenceSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 1294 | public: |
| 1295 | ReadBarrierForHeapReferenceSlowPathARMVIXL(HInstruction* instruction, |
| 1296 | Location out, |
| 1297 | Location ref, |
| 1298 | Location obj, |
| 1299 | uint32_t offset, |
| 1300 | Location index) |
| 1301 | : SlowPathCodeARMVIXL(instruction), |
| 1302 | out_(out), |
| 1303 | ref_(ref), |
| 1304 | obj_(obj), |
| 1305 | offset_(offset), |
| 1306 | index_(index) { |
| 1307 | DCHECK(kEmitCompilerReadBarrier); |
| 1308 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 1309 | // has been overwritten by (or after) the heap object reference load |
| 1310 | // to be instrumented, e.g.: |
| 1311 | // |
| 1312 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
| 1313 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| 1314 | // |
| 1315 | // In that case, we have lost the information about the original |
| 1316 | // object, and the emitted read barrier cannot work properly. |
| 1317 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 1318 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 1319 | } |
| 1320 | |
| 1321 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1322 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 1323 | LocationSummary* locations = instruction_->GetLocations(); |
| 1324 | vixl32::Register reg_out = RegisterFrom(out_); |
| 1325 | DCHECK(locations->CanCall()); |
| 1326 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.GetCode())); |
| 1327 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 1328 | instruction_->IsStaticFieldGet() || |
| 1329 | instruction_->IsArrayGet() || |
| 1330 | instruction_->IsInstanceOf() || |
| 1331 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 1332 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1333 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 1334 | << instruction_->DebugName(); |
| 1335 | // The read barrier instrumentation of object ArrayGet |
| 1336 | // instructions does not support the HIntermediateAddress |
| 1337 | // instruction. |
| 1338 | DCHECK(!(instruction_->IsArrayGet() && |
| 1339 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 1340 | |
| 1341 | __ Bind(GetEntryLabel()); |
| 1342 | SaveLiveRegisters(codegen, locations); |
| 1343 | |
| 1344 | // We may have to change the index's value, but as `index_` is a |
| 1345 | // constant member (like other "inputs" of this slow path), |
| 1346 | // introduce a copy of it, `index`. |
| 1347 | Location index = index_; |
| 1348 | if (index_.IsValid()) { |
| 1349 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 1350 | if (instruction_->IsArrayGet()) { |
| 1351 | // Compute the actual memory offset and store it in `index`. |
| 1352 | vixl32::Register index_reg = RegisterFrom(index_); |
| 1353 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg.GetCode())); |
| 1354 | if (codegen->IsCoreCalleeSaveRegister(index_reg.GetCode())) { |
| 1355 | // We are about to change the value of `index_reg` (see the |
Roland Levillain | 9983e30 | 2017-07-14 14:34:22 +0100 | [diff] [blame] | 1356 | // calls to art::arm::ArmVIXLMacroAssembler::Lsl and |
| 1357 | // art::arm::ArmVIXLMacroAssembler::Add below), but it has |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1358 | // not been saved by the previous call to |
| 1359 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1360 | // callee-save register -- |
| 1361 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1362 | // callee-save registers, as it has been designed with the |
| 1363 | // assumption that callee-save registers are supposed to be |
| 1364 | // handled by the called function. So, as a callee-save |
| 1365 | // register, `index_reg` _would_ eventually be saved onto |
| 1366 | // the stack, but it would be too late: we would have |
| 1367 | // changed its value earlier. Therefore, we manually save |
| 1368 | // it here into another freely available register, |
| 1369 | // `free_reg`, chosen of course among the caller-save |
| 1370 | // registers (as a callee-save `free_reg` register would |
| 1371 | // exhibit the same problem). |
| 1372 | // |
| 1373 | // Note we could have requested a temporary register from |
| 1374 | // the register allocator instead; but we prefer not to, as |
| 1375 | // this is a slow path, and we know we can find a |
| 1376 | // caller-save register that is available. |
| 1377 | vixl32::Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1378 | __ Mov(free_reg, index_reg); |
| 1379 | index_reg = free_reg; |
| 1380 | index = LocationFrom(index_reg); |
| 1381 | } else { |
| 1382 | // The initial register stored in `index_` has already been |
| 1383 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1384 | // (as it is not a callee-save register), so we can freely |
| 1385 | // use it. |
| 1386 | } |
| 1387 | // Shifting the index value contained in `index_reg` by the scale |
| 1388 | // factor (2) cannot overflow in practice, as the runtime is |
| 1389 | // unable to allocate object arrays with a size larger than |
| 1390 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 1391 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 1392 | static_assert( |
| 1393 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1394 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1395 | __ Add(index_reg, index_reg, offset_); |
| 1396 | } else { |
| 1397 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1398 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1399 | // (as in the case of ArrayGet), as it is actually an offset |
| 1400 | // to an object field within an object. |
| 1401 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| 1402 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1403 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1404 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1405 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 1406 | DCHECK_EQ(offset_, 0U); |
| 1407 | DCHECK(index_.IsRegisterPair()); |
| 1408 | // UnsafeGet's offset location is a register pair, the low |
| 1409 | // part contains the correct offset. |
| 1410 | index = index_.ToLow(); |
| 1411 | } |
| 1412 | } |
| 1413 | |
| 1414 | // We're moving two or three locations to locations that could |
| 1415 | // overlap, so we need a parallel move resolver. |
| 1416 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1417 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1418 | parallel_move.AddMove(ref_, |
| 1419 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1420 | DataType::Type::kReference, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1421 | nullptr); |
| 1422 | parallel_move.AddMove(obj_, |
| 1423 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1424 | DataType::Type::kReference, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1425 | nullptr); |
| 1426 | if (index.IsValid()) { |
| 1427 | parallel_move.AddMove(index, |
| 1428 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1429 | DataType::Type::kInt32, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1430 | nullptr); |
| 1431 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1432 | } else { |
| 1433 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1434 | __ Mov(calling_convention.GetRegisterAt(2), offset_); |
| 1435 | } |
| 1436 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
| 1437 | CheckEntrypointTypes< |
| 1438 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1439 | arm_codegen->Move32(out_, LocationFrom(r0)); |
| 1440 | |
| 1441 | RestoreLiveRegisters(codegen, locations); |
| 1442 | __ B(GetExitLabel()); |
| 1443 | } |
| 1444 | |
| 1445 | const char* GetDescription() const OVERRIDE { |
| 1446 | return "ReadBarrierForHeapReferenceSlowPathARMVIXL"; |
| 1447 | } |
| 1448 | |
| 1449 | private: |
| 1450 | vixl32::Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 1451 | uint32_t ref = RegisterFrom(ref_).GetCode(); |
| 1452 | uint32_t obj = RegisterFrom(obj_).GetCode(); |
| 1453 | for (uint32_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1454 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1455 | return vixl32::Register(i); |
| 1456 | } |
| 1457 | } |
| 1458 | // We shall never fail to find a free caller-save register, as |
| 1459 | // there are more than two core caller-save registers on ARM |
| 1460 | // (meaning it is possible to find one which is different from |
| 1461 | // `ref` and `obj`). |
| 1462 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1463 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 1464 | UNREACHABLE(); |
| 1465 | } |
| 1466 | |
| 1467 | const Location out_; |
| 1468 | const Location ref_; |
| 1469 | const Location obj_; |
| 1470 | const uint32_t offset_; |
| 1471 | // An additional location containing an index to an array. |
| 1472 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1473 | // UnsafeGetObjectVolatile intrinsics. |
| 1474 | const Location index_; |
| 1475 | |
| 1476 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARMVIXL); |
| 1477 | }; |
| 1478 | |
| 1479 | // Slow path generating a read barrier for a GC root. |
| 1480 | class ReadBarrierForRootSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 1481 | public: |
| 1482 | ReadBarrierForRootSlowPathARMVIXL(HInstruction* instruction, Location out, Location root) |
| 1483 | : SlowPathCodeARMVIXL(instruction), out_(out), root_(root) { |
| 1484 | DCHECK(kEmitCompilerReadBarrier); |
| 1485 | } |
| 1486 | |
| 1487 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1488 | LocationSummary* locations = instruction_->GetLocations(); |
| 1489 | vixl32::Register reg_out = RegisterFrom(out_); |
| 1490 | DCHECK(locations->CanCall()); |
| 1491 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.GetCode())); |
| 1492 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1493 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1494 | << instruction_->DebugName(); |
| 1495 | |
| 1496 | __ Bind(GetEntryLabel()); |
| 1497 | SaveLiveRegisters(codegen, locations); |
| 1498 | |
| 1499 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 1500 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 1501 | arm_codegen->Move32(LocationFrom(calling_convention.GetRegisterAt(0)), root_); |
| 1502 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| 1503 | instruction_, |
| 1504 | instruction_->GetDexPc(), |
| 1505 | this); |
| 1506 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1507 | arm_codegen->Move32(out_, LocationFrom(r0)); |
| 1508 | |
| 1509 | RestoreLiveRegisters(codegen, locations); |
| 1510 | __ B(GetExitLabel()); |
| 1511 | } |
| 1512 | |
| 1513 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARMVIXL"; } |
| 1514 | |
| 1515 | private: |
| 1516 | const Location out_; |
| 1517 | const Location root_; |
| 1518 | |
| 1519 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARMVIXL); |
| 1520 | }; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 1521 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1522 | inline vixl32::Condition ARMCondition(IfCondition cond) { |
| 1523 | switch (cond) { |
| 1524 | case kCondEQ: return eq; |
| 1525 | case kCondNE: return ne; |
| 1526 | case kCondLT: return lt; |
| 1527 | case kCondLE: return le; |
| 1528 | case kCondGT: return gt; |
| 1529 | case kCondGE: return ge; |
| 1530 | case kCondB: return lo; |
| 1531 | case kCondBE: return ls; |
| 1532 | case kCondA: return hi; |
| 1533 | case kCondAE: return hs; |
| 1534 | } |
| 1535 | LOG(FATAL) << "Unreachable"; |
| 1536 | UNREACHABLE(); |
| 1537 | } |
| 1538 | |
| 1539 | // Maps signed condition to unsigned condition. |
| 1540 | inline vixl32::Condition ARMUnsignedCondition(IfCondition cond) { |
| 1541 | switch (cond) { |
| 1542 | case kCondEQ: return eq; |
| 1543 | case kCondNE: return ne; |
| 1544 | // Signed to unsigned. |
| 1545 | case kCondLT: return lo; |
| 1546 | case kCondLE: return ls; |
| 1547 | case kCondGT: return hi; |
| 1548 | case kCondGE: return hs; |
| 1549 | // Unsigned remain unchanged. |
| 1550 | case kCondB: return lo; |
| 1551 | case kCondBE: return ls; |
| 1552 | case kCondA: return hi; |
| 1553 | case kCondAE: return hs; |
| 1554 | } |
| 1555 | LOG(FATAL) << "Unreachable"; |
| 1556 | UNREACHABLE(); |
| 1557 | } |
| 1558 | |
| 1559 | inline vixl32::Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 1560 | // The ARM condition codes can express all the necessary branches, see the |
| 1561 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 1562 | // There is no dex instruction or HIR that would need the missing conditions |
| 1563 | // "equal or unordered" or "not equal". |
| 1564 | switch (cond) { |
| 1565 | case kCondEQ: return eq; |
| 1566 | case kCondNE: return ne /* unordered */; |
| 1567 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 1568 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 1569 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 1570 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 1571 | default: |
| 1572 | LOG(FATAL) << "UNREACHABLE"; |
| 1573 | UNREACHABLE(); |
| 1574 | } |
| 1575 | } |
| 1576 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1577 | inline ShiftType ShiftFromOpKind(HDataProcWithShifterOp::OpKind op_kind) { |
| 1578 | switch (op_kind) { |
| 1579 | case HDataProcWithShifterOp::kASR: return ShiftType::ASR; |
| 1580 | case HDataProcWithShifterOp::kLSL: return ShiftType::LSL; |
| 1581 | case HDataProcWithShifterOp::kLSR: return ShiftType::LSR; |
| 1582 | default: |
| 1583 | LOG(FATAL) << "Unexpected op kind " << op_kind; |
| 1584 | UNREACHABLE(); |
| 1585 | } |
| 1586 | } |
| 1587 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1588 | void CodeGeneratorARMVIXL::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 1589 | stream << vixl32::Register(reg); |
| 1590 | } |
| 1591 | |
| 1592 | void CodeGeneratorARMVIXL::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| 1593 | stream << vixl32::SRegister(reg); |
| 1594 | } |
| 1595 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1596 | static uint32_t ComputeSRegisterListMask(const SRegisterList& regs) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1597 | uint32_t mask = 0; |
| 1598 | for (uint32_t i = regs.GetFirstSRegister().GetCode(); |
| 1599 | i <= regs.GetLastSRegister().GetCode(); |
| 1600 | ++i) { |
| 1601 | mask |= (1 << i); |
| 1602 | } |
| 1603 | return mask; |
| 1604 | } |
| 1605 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1606 | // Saves the register in the stack. Returns the size taken on stack. |
| 1607 | size_t CodeGeneratorARMVIXL::SaveCoreRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1608 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1609 | TODO_VIXL32(FATAL); |
| 1610 | return 0; |
| 1611 | } |
| 1612 | |
| 1613 | // Restores the register from the stack. Returns the size taken on stack. |
| 1614 | size_t CodeGeneratorARMVIXL::RestoreCoreRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1615 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1616 | TODO_VIXL32(FATAL); |
| 1617 | return 0; |
| 1618 | } |
| 1619 | |
| 1620 | size_t CodeGeneratorARMVIXL::SaveFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1621 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1622 | TODO_VIXL32(FATAL); |
| 1623 | return 0; |
| 1624 | } |
| 1625 | |
| 1626 | size_t CodeGeneratorARMVIXL::RestoreFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1627 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1628 | TODO_VIXL32(FATAL); |
| 1629 | return 0; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 1630 | } |
| 1631 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1632 | static void GenerateDataProcInstruction(HInstruction::InstructionKind kind, |
| 1633 | vixl32::Register out, |
| 1634 | vixl32::Register first, |
| 1635 | const Operand& second, |
| 1636 | CodeGeneratorARMVIXL* codegen) { |
| 1637 | if (second.IsImmediate() && second.GetImmediate() == 0) { |
| 1638 | const Operand in = kind == HInstruction::kAnd |
| 1639 | ? Operand(0) |
| 1640 | : Operand(first); |
| 1641 | |
| 1642 | __ Mov(out, in); |
| 1643 | } else { |
| 1644 | switch (kind) { |
| 1645 | case HInstruction::kAdd: |
| 1646 | __ Add(out, first, second); |
| 1647 | break; |
| 1648 | case HInstruction::kAnd: |
| 1649 | __ And(out, first, second); |
| 1650 | break; |
| 1651 | case HInstruction::kOr: |
| 1652 | __ Orr(out, first, second); |
| 1653 | break; |
| 1654 | case HInstruction::kSub: |
| 1655 | __ Sub(out, first, second); |
| 1656 | break; |
| 1657 | case HInstruction::kXor: |
| 1658 | __ Eor(out, first, second); |
| 1659 | break; |
| 1660 | default: |
| 1661 | LOG(FATAL) << "Unexpected instruction kind: " << kind; |
| 1662 | UNREACHABLE(); |
| 1663 | } |
| 1664 | } |
| 1665 | } |
| 1666 | |
| 1667 | static void GenerateDataProc(HInstruction::InstructionKind kind, |
| 1668 | const Location& out, |
| 1669 | const Location& first, |
| 1670 | const Operand& second_lo, |
| 1671 | const Operand& second_hi, |
| 1672 | CodeGeneratorARMVIXL* codegen) { |
| 1673 | const vixl32::Register first_hi = HighRegisterFrom(first); |
| 1674 | const vixl32::Register first_lo = LowRegisterFrom(first); |
| 1675 | const vixl32::Register out_hi = HighRegisterFrom(out); |
| 1676 | const vixl32::Register out_lo = LowRegisterFrom(out); |
| 1677 | |
| 1678 | if (kind == HInstruction::kAdd) { |
| 1679 | __ Adds(out_lo, first_lo, second_lo); |
| 1680 | __ Adc(out_hi, first_hi, second_hi); |
| 1681 | } else if (kind == HInstruction::kSub) { |
| 1682 | __ Subs(out_lo, first_lo, second_lo); |
| 1683 | __ Sbc(out_hi, first_hi, second_hi); |
| 1684 | } else { |
| 1685 | GenerateDataProcInstruction(kind, out_lo, first_lo, second_lo, codegen); |
| 1686 | GenerateDataProcInstruction(kind, out_hi, first_hi, second_hi, codegen); |
| 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | static Operand GetShifterOperand(vixl32::Register rm, ShiftType shift, uint32_t shift_imm) { |
| 1691 | return shift_imm == 0 ? Operand(rm) : Operand(rm, shift, shift_imm); |
| 1692 | } |
| 1693 | |
| 1694 | static void GenerateLongDataProc(HDataProcWithShifterOp* instruction, |
| 1695 | CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1696 | DCHECK_EQ(instruction->GetType(), DataType::Type::kInt64); |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1697 | DCHECK(HDataProcWithShifterOp::IsShiftOp(instruction->GetOpKind())); |
| 1698 | |
| 1699 | const LocationSummary* const locations = instruction->GetLocations(); |
| 1700 | const uint32_t shift_value = instruction->GetShiftAmount(); |
| 1701 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 1702 | const Location first = locations->InAt(0); |
| 1703 | const Location second = locations->InAt(1); |
| 1704 | const Location out = locations->Out(); |
| 1705 | const vixl32::Register first_hi = HighRegisterFrom(first); |
| 1706 | const vixl32::Register first_lo = LowRegisterFrom(first); |
| 1707 | const vixl32::Register out_hi = HighRegisterFrom(out); |
| 1708 | const vixl32::Register out_lo = LowRegisterFrom(out); |
| 1709 | const vixl32::Register second_hi = HighRegisterFrom(second); |
| 1710 | const vixl32::Register second_lo = LowRegisterFrom(second); |
| 1711 | const ShiftType shift = ShiftFromOpKind(instruction->GetOpKind()); |
| 1712 | |
| 1713 | if (shift_value >= 32) { |
| 1714 | if (shift == ShiftType::LSL) { |
| 1715 | GenerateDataProcInstruction(kind, |
| 1716 | out_hi, |
| 1717 | first_hi, |
| 1718 | Operand(second_lo, ShiftType::LSL, shift_value - 32), |
| 1719 | codegen); |
| 1720 | GenerateDataProcInstruction(kind, out_lo, first_lo, 0, codegen); |
| 1721 | } else if (shift == ShiftType::ASR) { |
| 1722 | GenerateDataProc(kind, |
| 1723 | out, |
| 1724 | first, |
| 1725 | GetShifterOperand(second_hi, ShiftType::ASR, shift_value - 32), |
| 1726 | Operand(second_hi, ShiftType::ASR, 31), |
| 1727 | codegen); |
| 1728 | } else { |
| 1729 | DCHECK_EQ(shift, ShiftType::LSR); |
| 1730 | GenerateDataProc(kind, |
| 1731 | out, |
| 1732 | first, |
| 1733 | GetShifterOperand(second_hi, ShiftType::LSR, shift_value - 32), |
| 1734 | 0, |
| 1735 | codegen); |
| 1736 | } |
| 1737 | } else { |
| 1738 | DCHECK_GT(shift_value, 1U); |
| 1739 | DCHECK_LT(shift_value, 32U); |
| 1740 | |
| 1741 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1742 | |
| 1743 | if (shift == ShiftType::LSL) { |
| 1744 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1745 | // Location::kOutputOverlap; not applicable to other cases. |
| 1746 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1747 | GenerateDataProcInstruction(kind, |
| 1748 | out_hi, |
| 1749 | first_hi, |
| 1750 | Operand(second_hi, ShiftType::LSL, shift_value), |
| 1751 | codegen); |
| 1752 | GenerateDataProcInstruction(kind, |
| 1753 | out_hi, |
| 1754 | out_hi, |
| 1755 | Operand(second_lo, ShiftType::LSR, 32 - shift_value), |
| 1756 | codegen); |
| 1757 | GenerateDataProcInstruction(kind, |
| 1758 | out_lo, |
| 1759 | first_lo, |
| 1760 | Operand(second_lo, ShiftType::LSL, shift_value), |
| 1761 | codegen); |
| 1762 | } else { |
| 1763 | const vixl32::Register temp = temps.Acquire(); |
| 1764 | |
| 1765 | __ Lsl(temp, second_hi, shift_value); |
| 1766 | __ Orr(temp, temp, Operand(second_lo, ShiftType::LSR, 32 - shift_value)); |
| 1767 | GenerateDataProc(kind, |
| 1768 | out, |
| 1769 | first, |
| 1770 | Operand(second_lo, ShiftType::LSL, shift_value), |
| 1771 | temp, |
| 1772 | codegen); |
| 1773 | } |
| 1774 | } else { |
| 1775 | DCHECK(shift == ShiftType::ASR || shift == ShiftType::LSR); |
| 1776 | |
| 1777 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1778 | // Location::kOutputOverlap; not applicable to other cases. |
| 1779 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1780 | GenerateDataProcInstruction(kind, |
| 1781 | out_lo, |
| 1782 | first_lo, |
| 1783 | Operand(second_lo, ShiftType::LSR, shift_value), |
| 1784 | codegen); |
| 1785 | GenerateDataProcInstruction(kind, |
| 1786 | out_lo, |
| 1787 | out_lo, |
| 1788 | Operand(second_hi, ShiftType::LSL, 32 - shift_value), |
| 1789 | codegen); |
| 1790 | GenerateDataProcInstruction(kind, |
| 1791 | out_hi, |
| 1792 | first_hi, |
| 1793 | Operand(second_hi, shift, shift_value), |
| 1794 | codegen); |
| 1795 | } else { |
| 1796 | const vixl32::Register temp = temps.Acquire(); |
| 1797 | |
| 1798 | __ Lsr(temp, second_lo, shift_value); |
| 1799 | __ Orr(temp, temp, Operand(second_hi, ShiftType::LSL, 32 - shift_value)); |
| 1800 | GenerateDataProc(kind, |
| 1801 | out, |
| 1802 | first, |
| 1803 | temp, |
| 1804 | Operand(second_hi, shift, shift_value), |
| 1805 | codegen); |
| 1806 | } |
| 1807 | } |
| 1808 | } |
| 1809 | } |
| 1810 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1811 | static void GenerateVcmp(HInstruction* instruction, CodeGeneratorARMVIXL* codegen) { |
| 1812 | const Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1813 | if (rhs_loc.IsConstant()) { |
| 1814 | // 0.0 is the only immediate that can be encoded directly in |
| 1815 | // a VCMP instruction. |
| 1816 | // |
| 1817 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1818 | // specify that in a floating-point comparison, positive zero |
| 1819 | // and negative zero are considered equal, so we can use the |
| 1820 | // literal 0.0 for both cases here. |
| 1821 | // |
| 1822 | // Note however that some methods (Float.equal, Float.compare, |
| 1823 | // Float.compareTo, Double.equal, Double.compare, |
| 1824 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1825 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1826 | // -0.0. So if we ever translate calls to these methods into a |
| 1827 | // HCompare instruction, we must handle the -0.0 case with |
| 1828 | // care here. |
| 1829 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1830 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1831 | const DataType::Type type = instruction->InputAt(0)->GetType(); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1832 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1833 | if (type == DataType::Type::kFloat32) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1834 | __ Vcmp(F32, InputSRegisterAt(instruction, 0), 0.0); |
| 1835 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1836 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1837 | __ Vcmp(F64, InputDRegisterAt(instruction, 0), 0.0); |
| 1838 | } |
| 1839 | } else { |
| 1840 | __ Vcmp(InputVRegisterAt(instruction, 0), InputVRegisterAt(instruction, 1)); |
| 1841 | } |
| 1842 | } |
| 1843 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1844 | static int64_t AdjustConstantForCondition(int64_t value, |
| 1845 | IfCondition* condition, |
| 1846 | IfCondition* opposite) { |
| 1847 | if (value == 1) { |
| 1848 | if (*condition == kCondB) { |
| 1849 | value = 0; |
| 1850 | *condition = kCondEQ; |
| 1851 | *opposite = kCondNE; |
| 1852 | } else if (*condition == kCondAE) { |
| 1853 | value = 0; |
| 1854 | *condition = kCondNE; |
| 1855 | *opposite = kCondEQ; |
| 1856 | } |
| 1857 | } else if (value == -1) { |
| 1858 | if (*condition == kCondGT) { |
| 1859 | value = 0; |
| 1860 | *condition = kCondGE; |
| 1861 | *opposite = kCondLT; |
| 1862 | } else if (*condition == kCondLE) { |
| 1863 | value = 0; |
| 1864 | *condition = kCondLT; |
| 1865 | *opposite = kCondGE; |
| 1866 | } |
| 1867 | } |
| 1868 | |
| 1869 | return value; |
| 1870 | } |
| 1871 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1872 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateLongTestConstant( |
| 1873 | HCondition* condition, |
| 1874 | bool invert, |
| 1875 | CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1876 | DCHECK_EQ(condition->GetLeft()->GetType(), DataType::Type::kInt64); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1877 | |
| 1878 | const LocationSummary* const locations = condition->GetLocations(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1879 | IfCondition cond = condition->GetCondition(); |
| 1880 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1881 | |
| 1882 | if (invert) { |
| 1883 | std::swap(cond, opposite); |
| 1884 | } |
| 1885 | |
| 1886 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1887 | const Location left = locations->InAt(0); |
| 1888 | const Location right = locations->InAt(1); |
| 1889 | |
| 1890 | DCHECK(right.IsConstant()); |
| 1891 | |
| 1892 | const vixl32::Register left_high = HighRegisterFrom(left); |
| 1893 | const vixl32::Register left_low = LowRegisterFrom(left); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1894 | int64_t value = AdjustConstantForCondition(Int64ConstantFrom(right), &cond, &opposite); |
| 1895 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1896 | |
| 1897 | // Comparisons against 0 are common enough to deserve special attention. |
| 1898 | if (value == 0) { |
| 1899 | switch (cond) { |
| 1900 | case kCondNE: |
| 1901 | // x > 0 iff x != 0 when the comparison is unsigned. |
| 1902 | case kCondA: |
| 1903 | ret = std::make_pair(ne, eq); |
| 1904 | FALLTHROUGH_INTENDED; |
| 1905 | case kCondEQ: |
| 1906 | // x <= 0 iff x == 0 when the comparison is unsigned. |
| 1907 | case kCondBE: |
| 1908 | __ Orrs(temps.Acquire(), left_low, left_high); |
| 1909 | return ret; |
| 1910 | case kCondLT: |
| 1911 | case kCondGE: |
| 1912 | __ Cmp(left_high, 0); |
| 1913 | return std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
| 1914 | // Trivially true or false. |
| 1915 | case kCondB: |
| 1916 | ret = std::make_pair(ne, eq); |
| 1917 | FALLTHROUGH_INTENDED; |
| 1918 | case kCondAE: |
| 1919 | __ Cmp(left_low, left_low); |
| 1920 | return ret; |
| 1921 | default: |
| 1922 | break; |
| 1923 | } |
| 1924 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1925 | |
| 1926 | switch (cond) { |
| 1927 | case kCondEQ: |
| 1928 | case kCondNE: |
| 1929 | case kCondB: |
| 1930 | case kCondBE: |
| 1931 | case kCondA: |
| 1932 | case kCondAE: { |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1933 | const uint32_t value_low = Low32Bits(value); |
| 1934 | Operand operand_low(value_low); |
| 1935 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1936 | __ Cmp(left_high, High32Bits(value)); |
| 1937 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1938 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1939 | // we must ensure that the operands corresponding to the least significant |
| 1940 | // halves of the inputs fit into a 16-bit CMP encoding. |
| 1941 | if (!left_low.IsLow() || !IsUint<8>(value_low)) { |
| 1942 | operand_low = Operand(temps.Acquire()); |
| 1943 | __ Mov(LeaveFlags, operand_low.GetBaseRegister(), value_low); |
| 1944 | } |
| 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); |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1952 | __ cmp(eq, left_low, operand_low); |
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 | // Trivially true or false. |
| 1959 | if (value == std::numeric_limits<int64_t>::max()) { |
| 1960 | __ Cmp(left_low, left_low); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1961 | 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] | 1962 | break; |
| 1963 | } |
| 1964 | |
| 1965 | if (cond == kCondLE) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1966 | DCHECK_EQ(opposite, kCondGT); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1967 | cond = kCondLT; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1968 | opposite = kCondGE; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1969 | } else { |
| 1970 | DCHECK_EQ(cond, kCondGT); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1971 | DCHECK_EQ(opposite, kCondLE); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1972 | cond = kCondGE; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1973 | opposite = kCondLT; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1974 | } |
| 1975 | |
| 1976 | value++; |
| 1977 | FALLTHROUGH_INTENDED; |
| 1978 | case kCondGE: |
| 1979 | case kCondLT: { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1980 | __ Cmp(left_low, Low32Bits(value)); |
| 1981 | __ Sbcs(temps.Acquire(), left_high, High32Bits(value)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1982 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1983 | break; |
| 1984 | } |
| 1985 | default: |
| 1986 | LOG(FATAL) << "Unreachable"; |
| 1987 | UNREACHABLE(); |
| 1988 | } |
| 1989 | |
| 1990 | return ret; |
| 1991 | } |
| 1992 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1993 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateLongTest( |
| 1994 | HCondition* condition, |
| 1995 | bool invert, |
| 1996 | CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1997 | DCHECK_EQ(condition->GetLeft()->GetType(), DataType::Type::kInt64); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1998 | |
| 1999 | const LocationSummary* const locations = condition->GetLocations(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2000 | IfCondition cond = condition->GetCondition(); |
| 2001 | IfCondition opposite = condition->GetOppositeCondition(); |
| 2002 | |
| 2003 | if (invert) { |
| 2004 | std::swap(cond, opposite); |
| 2005 | } |
| 2006 | |
| 2007 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2008 | Location left = locations->InAt(0); |
| 2009 | Location right = locations->InAt(1); |
| 2010 | |
| 2011 | DCHECK(right.IsRegisterPair()); |
| 2012 | |
| 2013 | switch (cond) { |
| 2014 | case kCondEQ: |
| 2015 | case kCondNE: |
| 2016 | case kCondB: |
| 2017 | case kCondBE: |
| 2018 | case kCondA: |
| 2019 | case kCondAE: { |
| 2020 | __ Cmp(HighRegisterFrom(left), HighRegisterFrom(right)); |
| 2021 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2022 | // We use the scope because of the IT block that follows. |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2023 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 2024 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 2025 | CodeBufferCheckScope::kExactSize); |
| 2026 | |
| 2027 | __ it(eq); |
| 2028 | __ cmp(eq, LowRegisterFrom(left), LowRegisterFrom(right)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2029 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2030 | break; |
| 2031 | } |
| 2032 | case kCondLE: |
| 2033 | case kCondGT: |
| 2034 | if (cond == kCondLE) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2035 | DCHECK_EQ(opposite, kCondGT); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2036 | cond = kCondGE; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2037 | opposite = kCondLT; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2038 | } else { |
| 2039 | DCHECK_EQ(cond, kCondGT); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2040 | DCHECK_EQ(opposite, kCondLE); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2041 | cond = kCondLT; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2042 | opposite = kCondGE; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2043 | } |
| 2044 | |
| 2045 | std::swap(left, right); |
| 2046 | FALLTHROUGH_INTENDED; |
| 2047 | case kCondGE: |
| 2048 | case kCondLT: { |
| 2049 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 2050 | |
| 2051 | __ Cmp(LowRegisterFrom(left), LowRegisterFrom(right)); |
| 2052 | __ Sbcs(temps.Acquire(), HighRegisterFrom(left), HighRegisterFrom(right)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2053 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2054 | break; |
| 2055 | } |
| 2056 | default: |
| 2057 | LOG(FATAL) << "Unreachable"; |
| 2058 | UNREACHABLE(); |
| 2059 | } |
| 2060 | |
| 2061 | return ret; |
| 2062 | } |
| 2063 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2064 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateTest(HCondition* condition, |
| 2065 | bool invert, |
| 2066 | CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2067 | const DataType::Type type = condition->GetLeft()->GetType(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2068 | IfCondition cond = condition->GetCondition(); |
| 2069 | IfCondition opposite = condition->GetOppositeCondition(); |
| 2070 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2071 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2072 | if (invert) { |
| 2073 | std::swap(cond, opposite); |
| 2074 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2075 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2076 | if (type == DataType::Type::kInt64) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2077 | ret = condition->GetLocations()->InAt(1).IsConstant() |
| 2078 | ? GenerateLongTestConstant(condition, invert, codegen) |
| 2079 | : GenerateLongTest(condition, invert, codegen); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2080 | } else if (DataType::IsFloatingPointType(type)) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2081 | GenerateVcmp(condition, codegen); |
| 2082 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 2083 | ret = std::make_pair(ARMFPCondition(cond, condition->IsGtBias()), |
| 2084 | ARMFPCondition(opposite, condition->IsGtBias())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2085 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2086 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2087 | __ Cmp(InputRegisterAt(condition, 0), InputOperandAt(condition, 1)); |
| 2088 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2089 | } |
| 2090 | |
| 2091 | return ret; |
| 2092 | } |
| 2093 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2094 | static void GenerateConditionGeneric(HCondition* cond, CodeGeneratorARMVIXL* codegen) { |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2095 | const vixl32::Register out = OutputRegister(cond); |
| 2096 | const auto condition = GenerateTest(cond, false, codegen); |
| 2097 | |
| 2098 | __ Mov(LeaveFlags, out, 0); |
| 2099 | |
| 2100 | if (out.IsLow()) { |
| 2101 | // We use the scope because of the IT block that follows. |
| 2102 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 2103 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 2104 | CodeBufferCheckScope::kExactSize); |
| 2105 | |
| 2106 | __ it(condition.first); |
| 2107 | __ mov(condition.first, out, 1); |
| 2108 | } else { |
| 2109 | vixl32::Label done_label; |
| 2110 | vixl32::Label* const final_label = codegen->GetFinalLabel(cond, &done_label); |
| 2111 | |
| 2112 | __ B(condition.second, final_label, /* far_target */ false); |
| 2113 | __ Mov(out, 1); |
| 2114 | |
| 2115 | if (done_label.IsReferenced()) { |
| 2116 | __ Bind(&done_label); |
| 2117 | } |
| 2118 | } |
| 2119 | } |
| 2120 | |
| 2121 | static void GenerateEqualLong(HCondition* cond, CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2122 | DCHECK_EQ(cond->GetLeft()->GetType(), DataType::Type::kInt64); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2123 | |
| 2124 | const LocationSummary* const locations = cond->GetLocations(); |
| 2125 | IfCondition condition = cond->GetCondition(); |
| 2126 | const vixl32::Register out = OutputRegister(cond); |
| 2127 | const Location left = locations->InAt(0); |
| 2128 | const Location right = locations->InAt(1); |
| 2129 | vixl32::Register left_high = HighRegisterFrom(left); |
| 2130 | vixl32::Register left_low = LowRegisterFrom(left); |
| 2131 | vixl32::Register temp; |
| 2132 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 2133 | |
| 2134 | if (right.IsConstant()) { |
| 2135 | IfCondition opposite = cond->GetOppositeCondition(); |
| 2136 | const int64_t value = AdjustConstantForCondition(Int64ConstantFrom(right), |
| 2137 | &condition, |
| 2138 | &opposite); |
| 2139 | Operand right_high = High32Bits(value); |
| 2140 | Operand right_low = Low32Bits(value); |
| 2141 | |
| 2142 | // The output uses Location::kNoOutputOverlap. |
| 2143 | if (out.Is(left_high)) { |
| 2144 | std::swap(left_low, left_high); |
| 2145 | std::swap(right_low, right_high); |
| 2146 | } |
| 2147 | |
| 2148 | __ Sub(out, left_low, right_low); |
| 2149 | temp = temps.Acquire(); |
| 2150 | __ Sub(temp, left_high, right_high); |
| 2151 | } else { |
| 2152 | DCHECK(right.IsRegisterPair()); |
| 2153 | temp = temps.Acquire(); |
| 2154 | __ Sub(temp, left_high, HighRegisterFrom(right)); |
| 2155 | __ Sub(out, left_low, LowRegisterFrom(right)); |
| 2156 | } |
| 2157 | |
| 2158 | // Need to check after calling AdjustConstantForCondition(). |
| 2159 | DCHECK(condition == kCondEQ || condition == kCondNE) << condition; |
| 2160 | |
| 2161 | if (condition == kCondNE && out.IsLow()) { |
| 2162 | __ Orrs(out, out, temp); |
| 2163 | |
| 2164 | // We use the scope because of the IT block that follows. |
| 2165 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 2166 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 2167 | CodeBufferCheckScope::kExactSize); |
| 2168 | |
| 2169 | __ it(ne); |
| 2170 | __ mov(ne, out, 1); |
| 2171 | } else { |
| 2172 | __ Orr(out, out, temp); |
| 2173 | codegen->GenerateConditionWithZero(condition, out, out, temp); |
| 2174 | } |
| 2175 | } |
| 2176 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2177 | static void GenerateConditionLong(HCondition* cond, CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2178 | DCHECK_EQ(cond->GetLeft()->GetType(), DataType::Type::kInt64); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2179 | |
| 2180 | const LocationSummary* const locations = cond->GetLocations(); |
| 2181 | IfCondition condition = cond->GetCondition(); |
| 2182 | const vixl32::Register out = OutputRegister(cond); |
| 2183 | const Location left = locations->InAt(0); |
| 2184 | const Location right = locations->InAt(1); |
| 2185 | |
| 2186 | if (right.IsConstant()) { |
| 2187 | IfCondition opposite = cond->GetOppositeCondition(); |
| 2188 | |
| 2189 | // Comparisons against 0 are common enough to deserve special attention. |
| 2190 | if (AdjustConstantForCondition(Int64ConstantFrom(right), &condition, &opposite) == 0) { |
| 2191 | switch (condition) { |
| 2192 | case kCondNE: |
| 2193 | case kCondA: |
| 2194 | if (out.IsLow()) { |
| 2195 | // We only care if both input registers are 0 or not. |
| 2196 | __ Orrs(out, LowRegisterFrom(left), HighRegisterFrom(left)); |
| 2197 | |
| 2198 | // We use the scope because of the IT block that follows. |
| 2199 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 2200 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 2201 | CodeBufferCheckScope::kExactSize); |
| 2202 | |
| 2203 | __ it(ne); |
| 2204 | __ mov(ne, out, 1); |
| 2205 | return; |
| 2206 | } |
| 2207 | |
| 2208 | FALLTHROUGH_INTENDED; |
| 2209 | case kCondEQ: |
| 2210 | case kCondBE: |
| 2211 | // We only care if both input registers are 0 or not. |
| 2212 | __ Orr(out, LowRegisterFrom(left), HighRegisterFrom(left)); |
| 2213 | codegen->GenerateConditionWithZero(condition, out, out); |
| 2214 | return; |
| 2215 | case kCondLT: |
| 2216 | case kCondGE: |
| 2217 | // We only care about the sign bit. |
| 2218 | FALLTHROUGH_INTENDED; |
| 2219 | case kCondAE: |
| 2220 | case kCondB: |
| 2221 | codegen->GenerateConditionWithZero(condition, out, HighRegisterFrom(left)); |
| 2222 | return; |
| 2223 | case kCondLE: |
| 2224 | case kCondGT: |
| 2225 | default: |
| 2226 | break; |
| 2227 | } |
| 2228 | } |
| 2229 | } |
| 2230 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2231 | // If `out` is a low register, then the GenerateConditionGeneric() |
| 2232 | // function generates a shorter code sequence that is still branchless. |
| 2233 | if ((condition == kCondEQ || condition == kCondNE) && !out.IsLow()) { |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2234 | GenerateEqualLong(cond, codegen); |
| 2235 | return; |
| 2236 | } |
| 2237 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2238 | GenerateConditionGeneric(cond, codegen); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2239 | } |
| 2240 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 2241 | static void GenerateConditionIntegralOrNonPrimitive(HCondition* cond, |
| 2242 | CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2243 | const DataType::Type type = cond->GetLeft()->GetType(); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2244 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2245 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2246 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2247 | if (type == DataType::Type::kInt64) { |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2248 | GenerateConditionLong(cond, codegen); |
| 2249 | return; |
| 2250 | } |
| 2251 | |
| 2252 | IfCondition condition = cond->GetCondition(); |
| 2253 | vixl32::Register in = InputRegisterAt(cond, 0); |
| 2254 | const vixl32::Register out = OutputRegister(cond); |
| 2255 | const Location right = cond->GetLocations()->InAt(1); |
| 2256 | int64_t value; |
| 2257 | |
| 2258 | if (right.IsConstant()) { |
| 2259 | IfCondition opposite = cond->GetOppositeCondition(); |
| 2260 | |
| 2261 | value = AdjustConstantForCondition(Int64ConstantFrom(right), &condition, &opposite); |
| 2262 | |
| 2263 | // Comparisons against 0 are common enough to deserve special attention. |
| 2264 | if (value == 0) { |
| 2265 | switch (condition) { |
| 2266 | case kCondNE: |
| 2267 | case kCondA: |
| 2268 | if (out.IsLow() && out.Is(in)) { |
| 2269 | __ Cmp(out, 0); |
| 2270 | |
| 2271 | // We use the scope because of the IT block that follows. |
| 2272 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 2273 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 2274 | CodeBufferCheckScope::kExactSize); |
| 2275 | |
| 2276 | __ it(ne); |
| 2277 | __ mov(ne, out, 1); |
| 2278 | return; |
| 2279 | } |
| 2280 | |
| 2281 | FALLTHROUGH_INTENDED; |
| 2282 | case kCondEQ: |
| 2283 | case kCondBE: |
| 2284 | case kCondLT: |
| 2285 | case kCondGE: |
| 2286 | case kCondAE: |
| 2287 | case kCondB: |
| 2288 | codegen->GenerateConditionWithZero(condition, out, in); |
| 2289 | return; |
| 2290 | case kCondLE: |
| 2291 | case kCondGT: |
| 2292 | default: |
| 2293 | break; |
| 2294 | } |
| 2295 | } |
| 2296 | } |
| 2297 | |
| 2298 | if (condition == kCondEQ || condition == kCondNE) { |
| 2299 | Operand operand(0); |
| 2300 | |
| 2301 | if (right.IsConstant()) { |
| 2302 | operand = Operand::From(value); |
| 2303 | } else if (out.Is(RegisterFrom(right))) { |
| 2304 | // Avoid 32-bit instructions if possible. |
| 2305 | operand = InputOperandAt(cond, 0); |
| 2306 | in = RegisterFrom(right); |
| 2307 | } else { |
| 2308 | operand = InputOperandAt(cond, 1); |
| 2309 | } |
| 2310 | |
| 2311 | if (condition == kCondNE && out.IsLow()) { |
| 2312 | __ Subs(out, in, operand); |
| 2313 | |
| 2314 | // We use the scope because of the IT block that follows. |
| 2315 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 2316 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 2317 | CodeBufferCheckScope::kExactSize); |
| 2318 | |
| 2319 | __ it(ne); |
| 2320 | __ mov(ne, out, 1); |
| 2321 | } else { |
| 2322 | __ Sub(out, in, operand); |
| 2323 | codegen->GenerateConditionWithZero(condition, out, out); |
| 2324 | } |
| 2325 | |
| 2326 | return; |
| 2327 | } |
| 2328 | |
| 2329 | GenerateConditionGeneric(cond, codegen); |
| 2330 | } |
| 2331 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2332 | static bool CanEncodeConstantAs8BitImmediate(HConstant* constant) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2333 | const DataType::Type type = constant->GetType(); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2334 | bool ret = false; |
| 2335 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2336 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2337 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2338 | if (type == DataType::Type::kInt64) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2339 | const uint64_t value = Uint64ConstantFrom(constant); |
| 2340 | |
| 2341 | ret = IsUint<8>(Low32Bits(value)) && IsUint<8>(High32Bits(value)); |
| 2342 | } else { |
| 2343 | ret = IsUint<8>(Int32ConstantFrom(constant)); |
| 2344 | } |
| 2345 | |
| 2346 | return ret; |
| 2347 | } |
| 2348 | |
| 2349 | static Location Arm8BitEncodableConstantOrRegister(HInstruction* constant) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2350 | DCHECK(!DataType::IsFloatingPointType(constant->GetType())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2351 | |
| 2352 | if (constant->IsConstant() && CanEncodeConstantAs8BitImmediate(constant->AsConstant())) { |
| 2353 | return Location::ConstantLocation(constant->AsConstant()); |
| 2354 | } |
| 2355 | |
| 2356 | return Location::RequiresRegister(); |
| 2357 | } |
| 2358 | |
| 2359 | static bool CanGenerateConditionalMove(const Location& out, const Location& src) { |
| 2360 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 2361 | // we check that we are not dealing with floating-point output (there is no |
| 2362 | // 16-bit VMOV encoding). |
| 2363 | if (!out.IsRegister() && !out.IsRegisterPair()) { |
| 2364 | return false; |
| 2365 | } |
| 2366 | |
| 2367 | // For constants, we also check that the output is in one or two low registers, |
| 2368 | // and that the constants fit in an 8-bit unsigned integer, so that a 16-bit |
| 2369 | // MOV encoding can be used. |
| 2370 | if (src.IsConstant()) { |
| 2371 | if (!CanEncodeConstantAs8BitImmediate(src.GetConstant())) { |
| 2372 | return false; |
| 2373 | } |
| 2374 | |
| 2375 | if (out.IsRegister()) { |
| 2376 | if (!RegisterFrom(out).IsLow()) { |
| 2377 | return false; |
| 2378 | } |
| 2379 | } else { |
| 2380 | DCHECK(out.IsRegisterPair()); |
| 2381 | |
| 2382 | if (!HighRegisterFrom(out).IsLow()) { |
| 2383 | return false; |
| 2384 | } |
| 2385 | } |
| 2386 | } |
| 2387 | |
| 2388 | return true; |
| 2389 | } |
| 2390 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2391 | #undef __ |
| 2392 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2393 | vixl32::Label* CodeGeneratorARMVIXL::GetFinalLabel(HInstruction* instruction, |
| 2394 | vixl32::Label* final_label) { |
| 2395 | DCHECK(!instruction->IsControlFlow() && !instruction->IsSuspendCheck()); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 2396 | DCHECK(!instruction->IsInvoke() || !instruction->GetLocations()->CanCall()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2397 | |
| 2398 | const HBasicBlock* const block = instruction->GetBlock(); |
| 2399 | const HLoopInformation* const info = block->GetLoopInformation(); |
| 2400 | HInstruction* const next = instruction->GetNext(); |
| 2401 | |
| 2402 | // Avoid a branch to a branch. |
| 2403 | if (next->IsGoto() && (info == nullptr || |
| 2404 | !info->IsBackEdge(*block) || |
| 2405 | !info->HasSuspendCheck())) { |
| 2406 | final_label = GetLabelOf(next->AsGoto()->GetSuccessor()); |
| 2407 | } |
| 2408 | |
| 2409 | return final_label; |
| 2410 | } |
| 2411 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2412 | CodeGeneratorARMVIXL::CodeGeneratorARMVIXL(HGraph* graph, |
| 2413 | const ArmInstructionSetFeatures& isa_features, |
| 2414 | const CompilerOptions& compiler_options, |
| 2415 | OptimizingCompilerStats* stats) |
| 2416 | : CodeGenerator(graph, |
| 2417 | kNumberOfCoreRegisters, |
| 2418 | kNumberOfSRegisters, |
| 2419 | kNumberOfRegisterPairs, |
| 2420 | kCoreCalleeSaves.GetList(), |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2421 | ComputeSRegisterListMask(kFpuCalleeSaves), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2422 | compiler_options, |
| 2423 | stats), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2424 | block_labels_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 2425 | jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2426 | location_builder_(graph, this), |
| 2427 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2428 | move_resolver_(graph->GetAllocator(), this), |
| 2429 | assembler_(graph->GetAllocator()), |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2430 | isa_features_(isa_features), |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 2431 | uint32_literals_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2432 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 2433 | pc_relative_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 2434 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 2435 | pc_relative_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 2436 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 2437 | pc_relative_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 2438 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 2439 | baker_read_barrier_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 2440 | jit_string_patches_(StringReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2441 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 2442 | jit_class_patches_(TypeReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2443 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2444 | // Always save the LR register to mimic Quick. |
| 2445 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 2446 | // Give D30 and D31 as scratch register to VIXL. The register allocator only works on |
| 2447 | // S0-S31, which alias to D0-D15. |
| 2448 | GetVIXLAssembler()->GetScratchVRegisterList()->Combine(d31); |
| 2449 | GetVIXLAssembler()->GetScratchVRegisterList()->Combine(d30); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2450 | } |
| 2451 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2452 | void JumpTableARMVIXL::EmitTable(CodeGeneratorARMVIXL* codegen) { |
| 2453 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| 2454 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| 2455 | |
| 2456 | // 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] | 2457 | // underlying code buffer and we have generated a jump table of the right size, using |
| 2458 | // codegen->GetVIXLAssembler()->GetBuffer().Align(); |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 2459 | ExactAssemblyScope aas(codegen->GetVIXLAssembler(), |
| 2460 | num_entries * sizeof(int32_t), |
| 2461 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2462 | // TODO(VIXL): Check that using lower case bind is fine here. |
| 2463 | codegen->GetVIXLAssembler()->bind(&table_start_); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2464 | for (uint32_t i = 0; i < num_entries; i++) { |
| 2465 | codegen->GetVIXLAssembler()->place(bb_addresses_[i].get()); |
| 2466 | } |
| 2467 | } |
| 2468 | |
| 2469 | void JumpTableARMVIXL::FixTable(CodeGeneratorARMVIXL* codegen) { |
| 2470 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| 2471 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| 2472 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2473 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 2474 | for (uint32_t i = 0; i < num_entries; i++) { |
| 2475 | vixl32::Label* target_label = codegen->GetLabelOf(successors[i]); |
| 2476 | DCHECK(target_label->IsBound()); |
| 2477 | int32_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
| 2478 | // When doing BX to address we need to have lower bit set to 1 in T32. |
| 2479 | if (codegen->GetVIXLAssembler()->IsUsingT32()) { |
| 2480 | jump_offset++; |
| 2481 | } |
| 2482 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 2483 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2484 | |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 2485 | bb_addresses_[i].get()->UpdateValue(jump_offset, codegen->GetVIXLAssembler()->GetBuffer()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2486 | } |
| 2487 | } |
| 2488 | |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2489 | void CodeGeneratorARMVIXL::FixJumpTables() { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2490 | for (auto&& jump_table : jump_tables_) { |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2491 | jump_table->FixTable(this); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2492 | } |
| 2493 | } |
| 2494 | |
Andreas Gampe | ca620d7 | 2016-11-08 08:09:33 -0800 | [diff] [blame] | 2495 | #define __ reinterpret_cast<ArmVIXLAssembler*>(GetAssembler())->GetVIXLAssembler()-> // NOLINT |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2496 | |
| 2497 | void CodeGeneratorARMVIXL::Finalize(CodeAllocator* allocator) { |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2498 | FixJumpTables(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2499 | GetAssembler()->FinalizeCode(); |
| 2500 | CodeGenerator::Finalize(allocator); |
| 2501 | } |
| 2502 | |
| 2503 | void CodeGeneratorARMVIXL::SetupBlockedRegisters() const { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2504 | // Stack register, LR and PC are always reserved. |
| 2505 | blocked_core_registers_[SP] = true; |
| 2506 | blocked_core_registers_[LR] = true; |
| 2507 | blocked_core_registers_[PC] = true; |
| 2508 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 2509 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2510 | // Reserve marking register. |
| 2511 | blocked_core_registers_[MR] = true; |
| 2512 | } |
| 2513 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2514 | // Reserve thread register. |
| 2515 | blocked_core_registers_[TR] = true; |
| 2516 | |
| 2517 | // Reserve temp register. |
| 2518 | blocked_core_registers_[IP] = true; |
| 2519 | |
| 2520 | if (GetGraph()->IsDebuggable()) { |
| 2521 | // Stubs do not save callee-save floating point registers. If the graph |
| 2522 | // is debuggable, we need to deal with these registers differently. For |
| 2523 | // now, just block them. |
| 2524 | for (uint32_t i = kFpuCalleeSaves.GetFirstSRegister().GetCode(); |
| 2525 | i <= kFpuCalleeSaves.GetLastSRegister().GetCode(); |
| 2526 | ++i) { |
| 2527 | blocked_fpu_registers_[i] = true; |
| 2528 | } |
| 2529 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2530 | } |
| 2531 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2532 | InstructionCodeGeneratorARMVIXL::InstructionCodeGeneratorARMVIXL(HGraph* graph, |
| 2533 | CodeGeneratorARMVIXL* codegen) |
| 2534 | : InstructionCodeGenerator(graph, codegen), |
| 2535 | assembler_(codegen->GetAssembler()), |
| 2536 | codegen_(codegen) {} |
| 2537 | |
| 2538 | void CodeGeneratorARMVIXL::ComputeSpillMask() { |
| 2539 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 2540 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
| 2541 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 2542 | // restore another arbitrary register. |
| 2543 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister.GetCode()); |
| 2544 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 2545 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 2546 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 2547 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 2548 | // but in the range. |
| 2549 | if (fpu_spill_mask_ != 0) { |
| 2550 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 2551 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 2552 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 2553 | fpu_spill_mask_ |= (1 << i); |
| 2554 | } |
| 2555 | } |
| 2556 | } |
| 2557 | |
| 2558 | void CodeGeneratorARMVIXL::GenerateFrameEntry() { |
| 2559 | bool skip_overflow_check = |
| 2560 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
| 2561 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
| 2562 | __ Bind(&frame_entry_label_); |
| 2563 | |
| 2564 | if (HasEmptyFrame()) { |
| 2565 | return; |
| 2566 | } |
| 2567 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2568 | if (!skip_overflow_check) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2569 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2570 | vixl32::Register temp = temps.Acquire(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 2571 | __ Sub(temp, sp, Operand::From(GetStackOverflowReservedBytes(InstructionSet::kArm))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2572 | // The load must immediately precede RecordPcInfo. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 2573 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2574 | vixl32::kMaxInstructionSizeInBytes, |
| 2575 | CodeBufferCheckScope::kMaximumSize); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2576 | __ ldr(temp, MemOperand(temp)); |
| 2577 | RecordPcInfo(nullptr, 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2578 | } |
| 2579 | |
| 2580 | __ Push(RegisterList(core_spill_mask_)); |
| 2581 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 2582 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(kMethodRegister), |
| 2583 | 0, |
| 2584 | core_spill_mask_, |
| 2585 | kArmWordSize); |
| 2586 | if (fpu_spill_mask_ != 0) { |
| 2587 | uint32_t first = LeastSignificantBit(fpu_spill_mask_); |
| 2588 | |
| 2589 | // Check that list is contiguous. |
| 2590 | DCHECK_EQ(fpu_spill_mask_ >> CTZ(fpu_spill_mask_), ~0u >> (32 - POPCOUNT(fpu_spill_mask_))); |
| 2591 | |
| 2592 | __ Vpush(SRegisterList(vixl32::SRegister(first), POPCOUNT(fpu_spill_mask_))); |
| 2593 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2594 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(s0), 0, fpu_spill_mask_, kArmWordSize); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2595 | } |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 2596 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2597 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 2598 | __ Sub(sp, sp, adjust); |
| 2599 | GetAssembler()->cfi().AdjustCFAOffset(adjust); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 2600 | |
| 2601 | // Save the current method if we need it. Note that we do not |
| 2602 | // do this in HCurrentMethod, as the instruction might have been removed |
| 2603 | // in the SSA graph. |
| 2604 | if (RequiresCurrentMethod()) { |
| 2605 | GetAssembler()->StoreToOffset(kStoreWord, kMethodRegister, sp, 0); |
| 2606 | } |
Nicolas Geoffray | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 2607 | |
| 2608 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 2609 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2610 | vixl32::Register temp = temps.Acquire(); |
| 2611 | // Initialize should_deoptimize flag to 0. |
| 2612 | __ Mov(temp, 0); |
| 2613 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, GetStackOffsetOfShouldDeoptimizeFlag()); |
| 2614 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 2615 | |
| 2616 | MaybeGenerateMarkingRegisterCheck(/* code */ 1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | void CodeGeneratorARMVIXL::GenerateFrameExit() { |
| 2620 | if (HasEmptyFrame()) { |
| 2621 | __ Bx(lr); |
| 2622 | return; |
| 2623 | } |
| 2624 | GetAssembler()->cfi().RememberState(); |
| 2625 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 2626 | __ Add(sp, sp, adjust); |
| 2627 | GetAssembler()->cfi().AdjustCFAOffset(-adjust); |
| 2628 | if (fpu_spill_mask_ != 0) { |
| 2629 | uint32_t first = LeastSignificantBit(fpu_spill_mask_); |
| 2630 | |
| 2631 | // Check that list is contiguous. |
| 2632 | DCHECK_EQ(fpu_spill_mask_ >> CTZ(fpu_spill_mask_), ~0u >> (32 - POPCOUNT(fpu_spill_mask_))); |
| 2633 | |
| 2634 | __ Vpop(SRegisterList(vixl32::SRegister(first), POPCOUNT(fpu_spill_mask_))); |
| 2635 | GetAssembler()->cfi().AdjustCFAOffset( |
| 2636 | -static_cast<int>(kArmWordSize) * POPCOUNT(fpu_spill_mask_)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2637 | GetAssembler()->cfi().RestoreMany(DWARFReg(vixl32::SRegister(0)), fpu_spill_mask_); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2638 | } |
| 2639 | // Pop LR into PC to return. |
| 2640 | DCHECK_NE(core_spill_mask_ & (1 << kLrCode), 0U); |
| 2641 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << kLrCode))) | 1 << kPcCode; |
| 2642 | __ Pop(RegisterList(pop_mask)); |
| 2643 | GetAssembler()->cfi().RestoreState(); |
| 2644 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
| 2645 | } |
| 2646 | |
| 2647 | void CodeGeneratorARMVIXL::Bind(HBasicBlock* block) { |
| 2648 | __ Bind(GetLabelOf(block)); |
| 2649 | } |
| 2650 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2651 | Location InvokeDexCallingConventionVisitorARMVIXL::GetNextLocation(DataType::Type type) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2652 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2653 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2654 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2655 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2656 | case DataType::Type::kInt8: |
| 2657 | case DataType::Type::kUint16: |
| 2658 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2659 | case DataType::Type::kInt32: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2660 | uint32_t index = gp_index_++; |
| 2661 | uint32_t stack_index = stack_index_++; |
| 2662 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2663 | return LocationFrom(calling_convention.GetRegisterAt(index)); |
| 2664 | } else { |
| 2665 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2666 | } |
| 2667 | } |
| 2668 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2669 | case DataType::Type::kInt64: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2670 | uint32_t index = gp_index_; |
| 2671 | uint32_t stack_index = stack_index_; |
| 2672 | gp_index_ += 2; |
| 2673 | stack_index_ += 2; |
| 2674 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2675 | if (calling_convention.GetRegisterAt(index).Is(r1)) { |
| 2676 | // Skip R1, and use R2_R3 instead. |
| 2677 | gp_index_++; |
| 2678 | index++; |
| 2679 | } |
| 2680 | } |
| 2681 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2682 | DCHECK_EQ(calling_convention.GetRegisterAt(index).GetCode() + 1, |
| 2683 | calling_convention.GetRegisterAt(index + 1).GetCode()); |
| 2684 | |
| 2685 | return LocationFrom(calling_convention.GetRegisterAt(index), |
| 2686 | calling_convention.GetRegisterAt(index + 1)); |
| 2687 | } else { |
| 2688 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2689 | } |
| 2690 | } |
| 2691 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2692 | case DataType::Type::kFloat32: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2693 | uint32_t stack_index = stack_index_++; |
| 2694 | if (float_index_ % 2 == 0) { |
| 2695 | float_index_ = std::max(double_index_, float_index_); |
| 2696 | } |
| 2697 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 2698 | return LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 2699 | } else { |
| 2700 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2701 | } |
| 2702 | } |
| 2703 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2704 | case DataType::Type::kFloat64: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2705 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 2706 | uint32_t stack_index = stack_index_; |
| 2707 | stack_index_ += 2; |
| 2708 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 2709 | uint32_t index = double_index_; |
| 2710 | double_index_ += 2; |
| 2711 | Location result = LocationFrom( |
| 2712 | calling_convention.GetFpuRegisterAt(index), |
| 2713 | calling_convention.GetFpuRegisterAt(index + 1)); |
| 2714 | DCHECK(ExpectedPairLayout(result)); |
| 2715 | return result; |
| 2716 | } else { |
| 2717 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2718 | } |
| 2719 | } |
| 2720 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2721 | case DataType::Type::kVoid: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2722 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2723 | break; |
| 2724 | } |
| 2725 | return Location::NoLocation(); |
| 2726 | } |
| 2727 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2728 | Location InvokeDexCallingConventionVisitorARMVIXL::GetReturnLocation(DataType::Type type) const { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2729 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2730 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2731 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2732 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2733 | case DataType::Type::kInt8: |
| 2734 | case DataType::Type::kUint16: |
| 2735 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2736 | case DataType::Type::kInt32: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2737 | return LocationFrom(r0); |
| 2738 | } |
| 2739 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2740 | case DataType::Type::kFloat32: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2741 | return LocationFrom(s0); |
| 2742 | } |
| 2743 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2744 | case DataType::Type::kInt64: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2745 | return LocationFrom(r0, r1); |
| 2746 | } |
| 2747 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2748 | case DataType::Type::kFloat64: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2749 | return LocationFrom(s0, s1); |
| 2750 | } |
| 2751 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2752 | case DataType::Type::kVoid: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2753 | return Location::NoLocation(); |
| 2754 | } |
| 2755 | |
| 2756 | UNREACHABLE(); |
| 2757 | } |
| 2758 | |
| 2759 | Location InvokeDexCallingConventionVisitorARMVIXL::GetMethodLocation() const { |
| 2760 | return LocationFrom(kMethodRegister); |
| 2761 | } |
| 2762 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2763 | void CodeGeneratorARMVIXL::Move32(Location destination, Location source) { |
| 2764 | if (source.Equals(destination)) { |
| 2765 | return; |
| 2766 | } |
| 2767 | if (destination.IsRegister()) { |
| 2768 | if (source.IsRegister()) { |
| 2769 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 2770 | } else if (source.IsFpuRegister()) { |
| 2771 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
| 2772 | } else { |
| 2773 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 2774 | RegisterFrom(destination), |
| 2775 | sp, |
| 2776 | source.GetStackIndex()); |
| 2777 | } |
| 2778 | } else if (destination.IsFpuRegister()) { |
| 2779 | if (source.IsRegister()) { |
| 2780 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
| 2781 | } else if (source.IsFpuRegister()) { |
| 2782 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 2783 | } else { |
| 2784 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 2785 | } |
| 2786 | } else { |
| 2787 | DCHECK(destination.IsStackSlot()) << destination; |
| 2788 | if (source.IsRegister()) { |
| 2789 | GetAssembler()->StoreToOffset(kStoreWord, |
| 2790 | RegisterFrom(source), |
| 2791 | sp, |
| 2792 | destination.GetStackIndex()); |
| 2793 | } else if (source.IsFpuRegister()) { |
| 2794 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 2795 | } else { |
| 2796 | DCHECK(source.IsStackSlot()) << source; |
| 2797 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2798 | vixl32::Register temp = temps.Acquire(); |
| 2799 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 2800 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 2801 | } |
| 2802 | } |
| 2803 | } |
| 2804 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2805 | void CodeGeneratorARMVIXL::MoveConstant(Location location, int32_t value) { |
| 2806 | DCHECK(location.IsRegister()); |
| 2807 | __ Mov(RegisterFrom(location), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2808 | } |
| 2809 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2810 | void CodeGeneratorARMVIXL::MoveLocation(Location dst, Location src, DataType::Type dst_type) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2811 | // TODO(VIXL): Maybe refactor to have the 'move' implementation here and use it in |
| 2812 | // `ParallelMoveResolverARMVIXL::EmitMove`, as is done in the `arm64` backend. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2813 | HParallelMove move(GetGraph()->GetAllocator()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2814 | move.AddMove(src, dst, dst_type, nullptr); |
| 2815 | GetMoveResolver()->EmitNativeCode(&move); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2816 | } |
| 2817 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2818 | void CodeGeneratorARMVIXL::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 2819 | if (location.IsRegister()) { |
| 2820 | locations->AddTemp(location); |
| 2821 | } else if (location.IsRegisterPair()) { |
| 2822 | locations->AddTemp(LocationFrom(LowRegisterFrom(location))); |
| 2823 | locations->AddTemp(LocationFrom(HighRegisterFrom(location))); |
| 2824 | } else { |
| 2825 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 2826 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2827 | } |
| 2828 | |
| 2829 | void CodeGeneratorARMVIXL::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2830 | HInstruction* instruction, |
| 2831 | uint32_t dex_pc, |
| 2832 | SlowPathCode* slow_path) { |
| 2833 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2834 | __ Ldr(lr, MemOperand(tr, GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value())); |
| 2835 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 2836 | // 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] | 2837 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2838 | vixl32::k16BitT32InstructionSizeInBytes, |
| 2839 | CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2840 | __ blx(lr); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2841 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2842 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2843 | } |
| 2844 | } |
| 2845 | |
| 2846 | void CodeGeneratorARMVIXL::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2847 | HInstruction* instruction, |
| 2848 | SlowPathCode* slow_path) { |
| 2849 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2850 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2851 | __ Blx(lr); |
| 2852 | } |
| 2853 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2854 | void InstructionCodeGeneratorARMVIXL::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| 2855 | DCHECK(!successor->IsExitBlock()); |
| 2856 | HBasicBlock* block = got->GetBlock(); |
| 2857 | HInstruction* previous = got->GetPrevious(); |
| 2858 | HLoopInformation* info = block->GetLoopInformation(); |
| 2859 | |
| 2860 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2861 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2862 | return; |
| 2863 | } |
| 2864 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2865 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 2866 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 2); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2867 | } |
| 2868 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 2869 | __ B(codegen_->GetLabelOf(successor)); |
| 2870 | } |
| 2871 | } |
| 2872 | |
| 2873 | void LocationsBuilderARMVIXL::VisitGoto(HGoto* got) { |
| 2874 | got->SetLocations(nullptr); |
| 2875 | } |
| 2876 | |
| 2877 | void InstructionCodeGeneratorARMVIXL::VisitGoto(HGoto* got) { |
| 2878 | HandleGoto(got, got->GetSuccessor()); |
| 2879 | } |
| 2880 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2881 | void LocationsBuilderARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2882 | try_boundary->SetLocations(nullptr); |
| 2883 | } |
| 2884 | |
| 2885 | void InstructionCodeGeneratorARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2886 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2887 | if (!successor->IsExitBlock()) { |
| 2888 | HandleGoto(try_boundary, successor); |
| 2889 | } |
| 2890 | } |
| 2891 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2892 | void LocationsBuilderARMVIXL::VisitExit(HExit* exit) { |
| 2893 | exit->SetLocations(nullptr); |
| 2894 | } |
| 2895 | |
| 2896 | void InstructionCodeGeneratorARMVIXL::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 2897 | } |
| 2898 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2899 | void InstructionCodeGeneratorARMVIXL::GenerateCompareTestAndBranch(HCondition* condition, |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2900 | vixl32::Label* true_target, |
| 2901 | vixl32::Label* false_target, |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2902 | bool is_far_target) { |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2903 | if (true_target == false_target) { |
| 2904 | DCHECK(true_target != nullptr); |
| 2905 | __ B(true_target); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2906 | return; |
| 2907 | } |
| 2908 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2909 | vixl32::Label* non_fallthrough_target; |
| 2910 | bool invert; |
| 2911 | bool emit_both_branches; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2912 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2913 | if (true_target == nullptr) { |
| 2914 | // The true target is fallthrough. |
| 2915 | DCHECK(false_target != nullptr); |
| 2916 | non_fallthrough_target = false_target; |
| 2917 | invert = true; |
| 2918 | emit_both_branches = false; |
| 2919 | } else { |
| 2920 | non_fallthrough_target = true_target; |
| 2921 | invert = false; |
| 2922 | // Either the false target is fallthrough, or there is no fallthrough |
| 2923 | // and both branches must be emitted. |
| 2924 | emit_both_branches = (false_target != nullptr); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2925 | } |
| 2926 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2927 | const auto cond = GenerateTest(condition, invert, codegen_); |
| 2928 | |
| 2929 | __ B(cond.first, non_fallthrough_target, is_far_target); |
| 2930 | |
| 2931 | if (emit_both_branches) { |
| 2932 | // No target falls through, we need to branch. |
| 2933 | __ B(false_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2934 | } |
| 2935 | } |
| 2936 | |
| 2937 | void InstructionCodeGeneratorARMVIXL::GenerateTestAndBranch(HInstruction* instruction, |
| 2938 | size_t condition_input_index, |
| 2939 | vixl32::Label* true_target, |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2940 | vixl32::Label* false_target, |
| 2941 | bool far_target) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2942 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 2943 | |
| 2944 | if (true_target == nullptr && false_target == nullptr) { |
| 2945 | // Nothing to do. The code always falls through. |
| 2946 | return; |
| 2947 | } else if (cond->IsIntConstant()) { |
| 2948 | // Constant condition, statically compared against "true" (integer value 1). |
| 2949 | if (cond->AsIntConstant()->IsTrue()) { |
| 2950 | if (true_target != nullptr) { |
| 2951 | __ B(true_target); |
| 2952 | } |
| 2953 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 2954 | DCHECK(cond->AsIntConstant()->IsFalse()) << Int32ConstantFrom(cond); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2955 | if (false_target != nullptr) { |
| 2956 | __ B(false_target); |
| 2957 | } |
| 2958 | } |
| 2959 | return; |
| 2960 | } |
| 2961 | |
| 2962 | // The following code generates these patterns: |
| 2963 | // (1) true_target == nullptr && false_target != nullptr |
| 2964 | // - opposite condition true => branch to false_target |
| 2965 | // (2) true_target != nullptr && false_target == nullptr |
| 2966 | // - condition true => branch to true_target |
| 2967 | // (3) true_target != nullptr && false_target != nullptr |
| 2968 | // - condition true => branch to true_target |
| 2969 | // - branch to false_target |
| 2970 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 2971 | // Condition has been materialized, compare the output to 0. |
| 2972 | if (kIsDebugBuild) { |
| 2973 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 2974 | DCHECK(cond_val.IsRegister()); |
| 2975 | } |
| 2976 | if (true_target == nullptr) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2977 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, condition_input_index), |
| 2978 | false_target, |
| 2979 | far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2980 | } else { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2981 | __ CompareAndBranchIfNonZero(InputRegisterAt(instruction, condition_input_index), |
| 2982 | true_target, |
| 2983 | far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2984 | } |
| 2985 | } else { |
| 2986 | // Condition has not been materialized. Use its inputs as the comparison and |
| 2987 | // its condition as the branch condition. |
| 2988 | HCondition* condition = cond->AsCondition(); |
| 2989 | |
| 2990 | // If this is a long or FP comparison that has been folded into |
| 2991 | // the HCondition, generate the comparison directly. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2992 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 2993 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2994 | GenerateCompareTestAndBranch(condition, true_target, false_target, far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2995 | return; |
| 2996 | } |
| 2997 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2998 | vixl32::Label* non_fallthrough_target; |
| 2999 | vixl32::Condition arm_cond = vixl32::Condition::None(); |
| 3000 | const vixl32::Register left = InputRegisterAt(cond, 0); |
| 3001 | const Operand right = InputOperandAt(cond, 1); |
| 3002 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3003 | if (true_target == nullptr) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3004 | arm_cond = ARMCondition(condition->GetOppositeCondition()); |
| 3005 | non_fallthrough_target = false_target; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3006 | } else { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3007 | arm_cond = ARMCondition(condition->GetCondition()); |
| 3008 | non_fallthrough_target = true_target; |
| 3009 | } |
| 3010 | |
| 3011 | if (right.IsImmediate() && right.GetImmediate() == 0 && (arm_cond.Is(ne) || arm_cond.Is(eq))) { |
| 3012 | if (arm_cond.Is(eq)) { |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 3013 | __ CompareAndBranchIfZero(left, non_fallthrough_target, far_target); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3014 | } else { |
| 3015 | DCHECK(arm_cond.Is(ne)); |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 3016 | __ CompareAndBranchIfNonZero(left, non_fallthrough_target, far_target); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3017 | } |
| 3018 | } else { |
| 3019 | __ Cmp(left, right); |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 3020 | __ B(arm_cond, non_fallthrough_target, far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3021 | } |
| 3022 | } |
| 3023 | |
| 3024 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3025 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3026 | if (true_target != nullptr && false_target != nullptr) { |
| 3027 | __ B(false_target); |
| 3028 | } |
| 3029 | } |
| 3030 | |
| 3031 | void LocationsBuilderARMVIXL::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3032 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3033 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| 3034 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3035 | } |
| 3036 | } |
| 3037 | |
| 3038 | void InstructionCodeGeneratorARMVIXL::VisitIf(HIf* if_instr) { |
| 3039 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3040 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3041 | vixl32::Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 3042 | nullptr : codegen_->GetLabelOf(true_successor); |
| 3043 | vixl32::Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 3044 | nullptr : codegen_->GetLabelOf(false_successor); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3045 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
| 3046 | } |
| 3047 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3048 | void LocationsBuilderARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3049 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3050 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3051 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3052 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3053 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 3054 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3055 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| 3056 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3057 | } |
| 3058 | } |
| 3059 | |
| 3060 | void InstructionCodeGeneratorARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 3061 | SlowPathCodeARMVIXL* slow_path = |
| 3062 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARMVIXL>(deoptimize); |
| 3063 | GenerateTestAndBranch(deoptimize, |
| 3064 | /* condition_input_index */ 0, |
| 3065 | slow_path->GetEntryLabel(), |
| 3066 | /* false_target */ nullptr); |
| 3067 | } |
| 3068 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3069 | void LocationsBuilderARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3070 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3071 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3072 | locations->SetOut(Location::RequiresRegister()); |
| 3073 | } |
| 3074 | |
| 3075 | void InstructionCodeGeneratorARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3076 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3077 | OutputRegister(flag), |
| 3078 | sp, |
| 3079 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 3080 | } |
| 3081 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3082 | void LocationsBuilderARMVIXL::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3083 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3084 | const bool is_floating_point = DataType::IsFloatingPointType(select->GetType()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3085 | |
| 3086 | if (is_floating_point) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3087 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3088 | locations->SetInAt(1, Location::FpuRegisterOrConstant(select->GetTrueValue())); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3089 | } else { |
| 3090 | locations->SetInAt(0, Location::RequiresRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3091 | locations->SetInAt(1, Arm8BitEncodableConstantOrRegister(select->GetTrueValue())); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3092 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3093 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3094 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3095 | locations->SetInAt(2, Location::RegisterOrConstant(select->GetCondition())); |
| 3096 | // The code generator handles overlap with the values, but not with the condition. |
| 3097 | locations->SetOut(Location::SameAsFirstInput()); |
| 3098 | } else if (is_floating_point) { |
| 3099 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3100 | } else { |
| 3101 | if (!locations->InAt(1).IsConstant()) { |
| 3102 | locations->SetInAt(0, Arm8BitEncodableConstantOrRegister(select->GetFalseValue())); |
| 3103 | } |
| 3104 | |
| 3105 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3106 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3107 | } |
| 3108 | |
| 3109 | void InstructionCodeGeneratorARMVIXL::VisitSelect(HSelect* select) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3110 | HInstruction* const condition = select->GetCondition(); |
| 3111 | const LocationSummary* const locations = select->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3112 | const DataType::Type type = select->GetType(); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3113 | const Location first = locations->InAt(0); |
| 3114 | const Location out = locations->Out(); |
| 3115 | const Location second = locations->InAt(1); |
| 3116 | Location src; |
| 3117 | |
| 3118 | if (condition->IsIntConstant()) { |
| 3119 | if (condition->AsIntConstant()->IsFalse()) { |
| 3120 | src = first; |
| 3121 | } else { |
| 3122 | src = second; |
| 3123 | } |
| 3124 | |
| 3125 | codegen_->MoveLocation(out, src, type); |
| 3126 | return; |
| 3127 | } |
| 3128 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3129 | if (!DataType::IsFloatingPointType(type)) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3130 | bool invert = false; |
| 3131 | |
| 3132 | if (out.Equals(second)) { |
| 3133 | src = first; |
| 3134 | invert = true; |
| 3135 | } else if (out.Equals(first)) { |
| 3136 | src = second; |
| 3137 | } else if (second.IsConstant()) { |
| 3138 | DCHECK(CanEncodeConstantAs8BitImmediate(second.GetConstant())); |
| 3139 | src = second; |
| 3140 | } else if (first.IsConstant()) { |
| 3141 | DCHECK(CanEncodeConstantAs8BitImmediate(first.GetConstant())); |
| 3142 | src = first; |
| 3143 | invert = true; |
| 3144 | } else { |
| 3145 | src = second; |
| 3146 | } |
| 3147 | |
| 3148 | if (CanGenerateConditionalMove(out, src)) { |
| 3149 | if (!out.Equals(first) && !out.Equals(second)) { |
| 3150 | codegen_->MoveLocation(out, src.Equals(first) ? second : first, type); |
| 3151 | } |
| 3152 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3153 | std::pair<vixl32::Condition, vixl32::Condition> cond(eq, ne); |
| 3154 | |
| 3155 | if (IsBooleanValueOrMaterializedCondition(condition)) { |
| 3156 | __ Cmp(InputRegisterAt(select, 2), 0); |
| 3157 | cond = invert ? std::make_pair(eq, ne) : std::make_pair(ne, eq); |
| 3158 | } else { |
| 3159 | cond = GenerateTest(condition->AsCondition(), invert, codegen_); |
| 3160 | } |
| 3161 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3162 | const size_t instr_count = out.IsRegisterPair() ? 4 : 2; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3163 | // We use the scope because of the IT block that follows. |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3164 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 3165 | instr_count * vixl32::k16BitT32InstructionSizeInBytes, |
| 3166 | CodeBufferCheckScope::kExactSize); |
| 3167 | |
| 3168 | if (out.IsRegister()) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3169 | __ it(cond.first); |
| 3170 | __ mov(cond.first, RegisterFrom(out), OperandFrom(src, type)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3171 | } else { |
| 3172 | DCHECK(out.IsRegisterPair()); |
| 3173 | |
| 3174 | Operand operand_high(0); |
| 3175 | Operand operand_low(0); |
| 3176 | |
| 3177 | if (src.IsConstant()) { |
| 3178 | const int64_t value = Int64ConstantFrom(src); |
| 3179 | |
| 3180 | operand_high = High32Bits(value); |
| 3181 | operand_low = Low32Bits(value); |
| 3182 | } else { |
| 3183 | DCHECK(src.IsRegisterPair()); |
| 3184 | operand_high = HighRegisterFrom(src); |
| 3185 | operand_low = LowRegisterFrom(src); |
| 3186 | } |
| 3187 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3188 | __ it(cond.first); |
| 3189 | __ mov(cond.first, LowRegisterFrom(out), operand_low); |
| 3190 | __ it(cond.first); |
| 3191 | __ mov(cond.first, HighRegisterFrom(out), operand_high); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3192 | } |
| 3193 | |
| 3194 | return; |
| 3195 | } |
| 3196 | } |
| 3197 | |
| 3198 | vixl32::Label* false_target = nullptr; |
| 3199 | vixl32::Label* true_target = nullptr; |
| 3200 | vixl32::Label select_end; |
| 3201 | vixl32::Label* const target = codegen_->GetFinalLabel(select, &select_end); |
| 3202 | |
| 3203 | if (out.Equals(second)) { |
| 3204 | true_target = target; |
| 3205 | src = first; |
| 3206 | } else { |
| 3207 | false_target = target; |
| 3208 | src = second; |
| 3209 | |
| 3210 | if (!out.Equals(first)) { |
| 3211 | codegen_->MoveLocation(out, first, type); |
| 3212 | } |
| 3213 | } |
| 3214 | |
| 3215 | GenerateTestAndBranch(select, 2, true_target, false_target, /* far_target */ false); |
| 3216 | codegen_->MoveLocation(out, src, type); |
| 3217 | |
| 3218 | if (select_end.IsReferenced()) { |
| 3219 | __ Bind(&select_end); |
| 3220 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3221 | } |
| 3222 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 3223 | void LocationsBuilderARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3224 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 3225 | } |
| 3226 | |
| 3227 | void InstructionCodeGeneratorARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3228 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| 3229 | } |
| 3230 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3231 | void CodeGeneratorARMVIXL::GenerateNop() { |
| 3232 | __ Nop(); |
| 3233 | } |
| 3234 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3235 | // `temp` is an extra temporary register that is used for some conditions; |
| 3236 | // callers may not specify it, in which case the method will use a scratch |
| 3237 | // register instead. |
| 3238 | void CodeGeneratorARMVIXL::GenerateConditionWithZero(IfCondition condition, |
| 3239 | vixl32::Register out, |
| 3240 | vixl32::Register in, |
| 3241 | vixl32::Register temp) { |
| 3242 | switch (condition) { |
| 3243 | case kCondEQ: |
| 3244 | // x <= 0 iff x == 0 when the comparison is unsigned. |
| 3245 | case kCondBE: |
| 3246 | if (!temp.IsValid() || (out.IsLow() && !out.Is(in))) { |
| 3247 | temp = out; |
| 3248 | } |
| 3249 | |
| 3250 | // Avoid 32-bit instructions if possible; note that `in` and `temp` must be |
| 3251 | // different as well. |
| 3252 | if (in.IsLow() && temp.IsLow() && !in.Is(temp)) { |
| 3253 | // temp = - in; only 0 sets the carry flag. |
| 3254 | __ Rsbs(temp, in, 0); |
| 3255 | |
| 3256 | if (out.Is(in)) { |
| 3257 | std::swap(in, temp); |
| 3258 | } |
| 3259 | |
| 3260 | // out = - in + in + carry = carry |
| 3261 | __ Adc(out, temp, in); |
| 3262 | } else { |
| 3263 | // If `in` is 0, then it has 32 leading zeros, and less than that otherwise. |
| 3264 | __ Clz(out, in); |
| 3265 | // Any number less than 32 logically shifted right by 5 bits results in 0; |
| 3266 | // the same operation on 32 yields 1. |
| 3267 | __ Lsr(out, out, 5); |
| 3268 | } |
| 3269 | |
| 3270 | break; |
| 3271 | case kCondNE: |
| 3272 | // x > 0 iff x != 0 when the comparison is unsigned. |
| 3273 | case kCondA: { |
| 3274 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3275 | |
| 3276 | if (out.Is(in)) { |
| 3277 | if (!temp.IsValid() || in.Is(temp)) { |
| 3278 | temp = temps.Acquire(); |
| 3279 | } |
| 3280 | } else if (!temp.IsValid() || !temp.IsLow()) { |
| 3281 | temp = out; |
| 3282 | } |
| 3283 | |
| 3284 | // temp = in - 1; only 0 does not set the carry flag. |
| 3285 | __ Subs(temp, in, 1); |
| 3286 | // out = in + ~temp + carry = in + (-(in - 1) - 1) + carry = in - in + 1 - 1 + carry = carry |
| 3287 | __ Sbc(out, in, temp); |
| 3288 | break; |
| 3289 | } |
| 3290 | case kCondGE: |
| 3291 | __ Mvn(out, in); |
| 3292 | in = out; |
| 3293 | FALLTHROUGH_INTENDED; |
| 3294 | case kCondLT: |
| 3295 | // We only care about the sign bit. |
| 3296 | __ Lsr(out, in, 31); |
| 3297 | break; |
| 3298 | case kCondAE: |
| 3299 | // Trivially true. |
| 3300 | __ Mov(out, 1); |
| 3301 | break; |
| 3302 | case kCondB: |
| 3303 | // Trivially false. |
| 3304 | __ Mov(out, 0); |
| 3305 | break; |
| 3306 | default: |
| 3307 | LOG(FATAL) << "Unexpected condition " << condition; |
| 3308 | UNREACHABLE(); |
| 3309 | } |
| 3310 | } |
| 3311 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3312 | void LocationsBuilderARMVIXL::HandleCondition(HCondition* cond) { |
| 3313 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3314 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3315 | // Handle the long/FP comparisons made in instruction simplification. |
| 3316 | switch (cond->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3317 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3318 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3319 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 3320 | if (!cond->IsEmittedAtUseSite()) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3321 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3322 | } |
| 3323 | break; |
| 3324 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3325 | case DataType::Type::kFloat32: |
| 3326 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3327 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 3328 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3329 | if (!cond->IsEmittedAtUseSite()) { |
| 3330 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3331 | } |
| 3332 | break; |
| 3333 | |
| 3334 | default: |
| 3335 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3336 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 3337 | if (!cond->IsEmittedAtUseSite()) { |
| 3338 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3339 | } |
| 3340 | } |
| 3341 | } |
| 3342 | |
| 3343 | void InstructionCodeGeneratorARMVIXL::HandleCondition(HCondition* cond) { |
| 3344 | if (cond->IsEmittedAtUseSite()) { |
| 3345 | return; |
| 3346 | } |
| 3347 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3348 | const DataType::Type type = cond->GetLeft()->GetType(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3349 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3350 | if (DataType::IsFloatingPointType(type)) { |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3351 | GenerateConditionGeneric(cond, codegen_); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3352 | return; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3353 | } |
| 3354 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3355 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3356 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3357 | const IfCondition condition = cond->GetCondition(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3358 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3359 | // A condition with only one boolean input, or two boolean inputs without being equality or |
| 3360 | // inequality results from transformations done by the instruction simplifier, and is handled |
| 3361 | // as a regular condition with integral inputs. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3362 | if (type == DataType::Type::kBool && |
| 3363 | cond->GetRight()->GetType() == DataType::Type::kBool && |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3364 | (condition == kCondEQ || condition == kCondNE)) { |
| 3365 | vixl32::Register left = InputRegisterAt(cond, 0); |
| 3366 | const vixl32::Register out = OutputRegister(cond); |
| 3367 | const Location right_loc = cond->GetLocations()->InAt(1); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3368 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3369 | // The constant case is handled by the instruction simplifier. |
| 3370 | DCHECK(!right_loc.IsConstant()); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3371 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3372 | vixl32::Register right = RegisterFrom(right_loc); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3373 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3374 | // Avoid 32-bit instructions if possible. |
| 3375 | if (out.Is(right)) { |
| 3376 | std::swap(left, right); |
| 3377 | } |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3378 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3379 | __ Eor(out, left, right); |
| 3380 | |
| 3381 | if (condition == kCondEQ) { |
| 3382 | __ Eor(out, out, 1); |
| 3383 | } |
| 3384 | |
| 3385 | return; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3386 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 3387 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3388 | GenerateConditionIntegralOrNonPrimitive(cond, codegen_); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3389 | } |
| 3390 | |
| 3391 | void LocationsBuilderARMVIXL::VisitEqual(HEqual* comp) { |
| 3392 | HandleCondition(comp); |
| 3393 | } |
| 3394 | |
| 3395 | void InstructionCodeGeneratorARMVIXL::VisitEqual(HEqual* comp) { |
| 3396 | HandleCondition(comp); |
| 3397 | } |
| 3398 | |
| 3399 | void LocationsBuilderARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 3400 | HandleCondition(comp); |
| 3401 | } |
| 3402 | |
| 3403 | void InstructionCodeGeneratorARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 3404 | HandleCondition(comp); |
| 3405 | } |
| 3406 | |
| 3407 | void LocationsBuilderARMVIXL::VisitLessThan(HLessThan* comp) { |
| 3408 | HandleCondition(comp); |
| 3409 | } |
| 3410 | |
| 3411 | void InstructionCodeGeneratorARMVIXL::VisitLessThan(HLessThan* comp) { |
| 3412 | HandleCondition(comp); |
| 3413 | } |
| 3414 | |
| 3415 | void LocationsBuilderARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 3416 | HandleCondition(comp); |
| 3417 | } |
| 3418 | |
| 3419 | void InstructionCodeGeneratorARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 3420 | HandleCondition(comp); |
| 3421 | } |
| 3422 | |
| 3423 | void LocationsBuilderARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 3424 | HandleCondition(comp); |
| 3425 | } |
| 3426 | |
| 3427 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 3428 | HandleCondition(comp); |
| 3429 | } |
| 3430 | |
| 3431 | void LocationsBuilderARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 3432 | HandleCondition(comp); |
| 3433 | } |
| 3434 | |
| 3435 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 3436 | HandleCondition(comp); |
| 3437 | } |
| 3438 | |
| 3439 | void LocationsBuilderARMVIXL::VisitBelow(HBelow* comp) { |
| 3440 | HandleCondition(comp); |
| 3441 | } |
| 3442 | |
| 3443 | void InstructionCodeGeneratorARMVIXL::VisitBelow(HBelow* comp) { |
| 3444 | HandleCondition(comp); |
| 3445 | } |
| 3446 | |
| 3447 | void LocationsBuilderARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 3448 | HandleCondition(comp); |
| 3449 | } |
| 3450 | |
| 3451 | void InstructionCodeGeneratorARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 3452 | HandleCondition(comp); |
| 3453 | } |
| 3454 | |
| 3455 | void LocationsBuilderARMVIXL::VisitAbove(HAbove* comp) { |
| 3456 | HandleCondition(comp); |
| 3457 | } |
| 3458 | |
| 3459 | void InstructionCodeGeneratorARMVIXL::VisitAbove(HAbove* comp) { |
| 3460 | HandleCondition(comp); |
| 3461 | } |
| 3462 | |
| 3463 | void LocationsBuilderARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 3464 | HandleCondition(comp); |
| 3465 | } |
| 3466 | |
| 3467 | void InstructionCodeGeneratorARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 3468 | HandleCondition(comp); |
| 3469 | } |
| 3470 | |
| 3471 | void LocationsBuilderARMVIXL::VisitIntConstant(HIntConstant* constant) { |
| 3472 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3473 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3474 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3475 | } |
| 3476 | |
| 3477 | void InstructionCodeGeneratorARMVIXL::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 3478 | // Will be generated at use site. |
| 3479 | } |
| 3480 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3481 | void LocationsBuilderARMVIXL::VisitNullConstant(HNullConstant* constant) { |
| 3482 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3483 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3484 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3485 | } |
| 3486 | |
| 3487 | void InstructionCodeGeneratorARMVIXL::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 3488 | // Will be generated at use site. |
| 3489 | } |
| 3490 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3491 | void LocationsBuilderARMVIXL::VisitLongConstant(HLongConstant* constant) { |
| 3492 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3493 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3494 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3495 | } |
| 3496 | |
| 3497 | void InstructionCodeGeneratorARMVIXL::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 3498 | // Will be generated at use site. |
| 3499 | } |
| 3500 | |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3501 | void LocationsBuilderARMVIXL::VisitFloatConstant(HFloatConstant* constant) { |
| 3502 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3503 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3504 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3505 | } |
| 3506 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3507 | void InstructionCodeGeneratorARMVIXL::VisitFloatConstant( |
| 3508 | HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3509 | // Will be generated at use site. |
| 3510 | } |
| 3511 | |
| 3512 | void LocationsBuilderARMVIXL::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3513 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3514 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3515 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3516 | } |
| 3517 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3518 | void InstructionCodeGeneratorARMVIXL::VisitDoubleConstant( |
| 3519 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3520 | // Will be generated at use site. |
| 3521 | } |
| 3522 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 3523 | void LocationsBuilderARMVIXL::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 3524 | constructor_fence->SetLocations(nullptr); |
| 3525 | } |
| 3526 | |
| 3527 | void InstructionCodeGeneratorARMVIXL::VisitConstructorFence( |
| 3528 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 3529 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 3530 | } |
| 3531 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3532 | void LocationsBuilderARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3533 | memory_barrier->SetLocations(nullptr); |
| 3534 | } |
| 3535 | |
| 3536 | void InstructionCodeGeneratorARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3537 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 3538 | } |
| 3539 | |
| 3540 | void LocationsBuilderARMVIXL::VisitReturnVoid(HReturnVoid* ret) { |
| 3541 | ret->SetLocations(nullptr); |
| 3542 | } |
| 3543 | |
| 3544 | void InstructionCodeGeneratorARMVIXL::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 3545 | codegen_->GenerateFrameExit(); |
| 3546 | } |
| 3547 | |
| 3548 | void LocationsBuilderARMVIXL::VisitReturn(HReturn* ret) { |
| 3549 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3550 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3551 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
| 3552 | } |
| 3553 | |
| 3554 | void InstructionCodeGeneratorARMVIXL::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 3555 | codegen_->GenerateFrameExit(); |
| 3556 | } |
| 3557 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3558 | void LocationsBuilderARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3559 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3560 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3561 | // the method_idx. |
| 3562 | HandleInvoke(invoke); |
| 3563 | } |
| 3564 | |
| 3565 | void InstructionCodeGeneratorARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3566 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3567 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 3); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3568 | } |
| 3569 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3570 | void LocationsBuilderARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3571 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3572 | // art::PrepareForRegisterAllocation. |
| 3573 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 3574 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3575 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3576 | if (intrinsic.TryDispatch(invoke)) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3577 | return; |
| 3578 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3579 | |
| 3580 | HandleInvoke(invoke); |
| 3581 | } |
| 3582 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3583 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARMVIXL* codegen) { |
| 3584 | if (invoke->GetLocations()->Intrinsified()) { |
| 3585 | IntrinsicCodeGeneratorARMVIXL intrinsic(codegen); |
| 3586 | intrinsic.Dispatch(invoke); |
| 3587 | return true; |
| 3588 | } |
| 3589 | return false; |
| 3590 | } |
| 3591 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3592 | void InstructionCodeGeneratorARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3593 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3594 | // art::PrepareForRegisterAllocation. |
| 3595 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 3596 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3597 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3598 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 4); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3599 | return; |
| 3600 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3601 | |
| 3602 | LocationSummary* locations = invoke->GetLocations(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3603 | codegen_->GenerateStaticOrDirectCall( |
| 3604 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3605 | |
| 3606 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 5); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3607 | } |
| 3608 | |
| 3609 | void LocationsBuilderARMVIXL::HandleInvoke(HInvoke* invoke) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3610 | InvokeDexCallingConventionVisitorARMVIXL calling_convention_visitor; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3611 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 3612 | } |
| 3613 | |
| 3614 | void LocationsBuilderARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3615 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3616 | if (intrinsic.TryDispatch(invoke)) { |
| 3617 | return; |
| 3618 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3619 | |
| 3620 | HandleInvoke(invoke); |
| 3621 | } |
| 3622 | |
| 3623 | void InstructionCodeGeneratorARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3624 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3625 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 6); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3626 | return; |
| 3627 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3628 | |
| 3629 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3630 | DCHECK(!codegen_->IsLeafMethod()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3631 | |
| 3632 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 7); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3633 | } |
| 3634 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3635 | void LocationsBuilderARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3636 | HandleInvoke(invoke); |
| 3637 | // Add the hidden argument. |
| 3638 | invoke->GetLocations()->AddTemp(LocationFrom(r12)); |
| 3639 | } |
| 3640 | |
| 3641 | void InstructionCodeGeneratorARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3642 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 3643 | LocationSummary* locations = invoke->GetLocations(); |
| 3644 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 3645 | vixl32::Register hidden_reg = RegisterFrom(locations->GetTemp(1)); |
| 3646 | Location receiver = locations->InAt(0); |
| 3647 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3648 | |
| 3649 | DCHECK(!receiver.IsStackSlot()); |
| 3650 | |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3651 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
| 3652 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 3653 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 3654 | vixl32::kMaxInstructionSizeInBytes, |
| 3655 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3656 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 3657 | __ ldr(temp, MemOperand(RegisterFrom(receiver), class_offset)); |
| 3658 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 3659 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3660 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3661 | // emit a read barrier for the previous class reference load. |
| 3662 | // However this is not required in practice, as this is an |
| 3663 | // intermediate/temporary reference and because the current |
| 3664 | // concurrent copying collector keeps the from-space memory |
| 3665 | // intact/accessible until the end of the marking phase (the |
| 3666 | // concurrent copying collector may not in the future). |
| 3667 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 3668 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3669 | temp, |
| 3670 | temp, |
| 3671 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 3672 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 3673 | invoke->GetImtIndex(), kArmPointerSize)); |
| 3674 | // temp = temp->GetImtEntryAt(method_offset); |
| 3675 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 3676 | uint32_t entry_point = |
| 3677 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
| 3678 | // LR = temp->GetEntryPoint(); |
| 3679 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
| 3680 | |
| 3681 | // Set the hidden (in r12) argument. It is done here, right before a BLX to prevent other |
| 3682 | // instruction from clobbering it as they might use r12 as a scratch register. |
| 3683 | DCHECK(hidden_reg.Is(r12)); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3684 | |
| 3685 | { |
| 3686 | // The VIXL macro assembler may clobber any of the scratch registers that are available to it, |
| 3687 | // so it checks if the application is using them (by passing them to the macro assembler |
| 3688 | // methods). The following application of UseScratchRegisterScope corrects VIXL's notion of |
| 3689 | // what is available, and is the opposite of the standard usage: Instead of requesting a |
| 3690 | // temporary location, it imposes an external constraint (i.e. a specific register is reserved |
| 3691 | // for the hidden argument). Note that this works even if VIXL needs a scratch register itself |
| 3692 | // (to materialize the constant), since the destination register becomes available for such use |
| 3693 | // internally for the duration of the macro instruction. |
| 3694 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3695 | temps.Exclude(hidden_reg); |
| 3696 | __ Mov(hidden_reg, invoke->GetDexMethodIndex()); |
| 3697 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3698 | { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3699 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 3700 | // 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] | 3701 | ExactAssemblyScope aas(GetVIXLAssembler(), |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3702 | vixl32::k16BitT32InstructionSizeInBytes, |
| 3703 | CodeBufferCheckScope::kExactSize); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3704 | // LR(); |
| 3705 | __ blx(lr); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3706 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3707 | DCHECK(!codegen_->IsLeafMethod()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3708 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3709 | |
| 3710 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 8); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3711 | } |
| 3712 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3713 | void LocationsBuilderARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3714 | HandleInvoke(invoke); |
| 3715 | } |
| 3716 | |
| 3717 | void InstructionCodeGeneratorARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3718 | codegen_->GenerateInvokePolymorphicCall(invoke); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3719 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 9); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3720 | } |
| 3721 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3722 | void LocationsBuilderARMVIXL::VisitNeg(HNeg* neg) { |
| 3723 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3724 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3725 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3726 | case DataType::Type::kInt32: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3727 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3728 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3729 | break; |
| 3730 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3731 | case DataType::Type::kInt64: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3732 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3733 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3734 | break; |
| 3735 | } |
| 3736 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3737 | case DataType::Type::kFloat32: |
| 3738 | case DataType::Type::kFloat64: |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3739 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3740 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3741 | break; |
| 3742 | |
| 3743 | default: |
| 3744 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3745 | } |
| 3746 | } |
| 3747 | |
| 3748 | void InstructionCodeGeneratorARMVIXL::VisitNeg(HNeg* neg) { |
| 3749 | LocationSummary* locations = neg->GetLocations(); |
| 3750 | Location out = locations->Out(); |
| 3751 | Location in = locations->InAt(0); |
| 3752 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3753 | case DataType::Type::kInt32: |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3754 | __ Rsb(OutputRegister(neg), InputRegisterAt(neg, 0), 0); |
| 3755 | break; |
| 3756 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3757 | case DataType::Type::kInt64: |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3758 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 3759 | __ Rsbs(LowRegisterFrom(out), LowRegisterFrom(in), 0); |
| 3760 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 3761 | // instruction here, as it does not exist in the Thumb-2 |
| 3762 | // instruction set. We use the following approach |
| 3763 | // using SBC and SUB instead. |
| 3764 | // |
| 3765 | // out.hi = -C |
| 3766 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(out)); |
| 3767 | // out.hi = out.hi - in.hi |
| 3768 | __ Sub(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(in)); |
| 3769 | break; |
| 3770 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3771 | case DataType::Type::kFloat32: |
| 3772 | case DataType::Type::kFloat64: |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 3773 | __ Vneg(OutputVRegister(neg), InputVRegister(neg)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3774 | break; |
| 3775 | |
| 3776 | default: |
| 3777 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3778 | } |
| 3779 | } |
| 3780 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3781 | void LocationsBuilderARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3782 | DataType::Type result_type = conversion->GetResultType(); |
| 3783 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3784 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 3785 | << input_type << " -> " << result_type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3786 | |
| 3787 | // The float-to-long, double-to-long and long-to-float type conversions |
| 3788 | // rely on a call to the runtime. |
| 3789 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3790 | (((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) |
| 3791 | && result_type == DataType::Type::kInt64) |
| 3792 | || (input_type == DataType::Type::kInt64 && result_type == DataType::Type::kFloat32)) |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3793 | ? LocationSummary::kCallOnMainOnly |
| 3794 | : LocationSummary::kNoCall; |
| 3795 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3796 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3797 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3798 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3799 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3800 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3801 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3802 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3803 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 3804 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3805 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3806 | break; |
| 3807 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3808 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3809 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3810 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3811 | locations->SetInAt(0, Location::Any()); |
| 3812 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3813 | break; |
| 3814 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3815 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3816 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3817 | locations->SetOut(Location::RequiresRegister()); |
| 3818 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3819 | break; |
| 3820 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3821 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3822 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3823 | locations->SetOut(Location::RequiresRegister()); |
| 3824 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3825 | break; |
| 3826 | |
| 3827 | default: |
| 3828 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3829 | << " to " << result_type; |
| 3830 | } |
| 3831 | break; |
| 3832 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3833 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3834 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3835 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3836 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3837 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3838 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3839 | case DataType::Type::kInt16: |
| 3840 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3841 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3842 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3843 | break; |
| 3844 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3845 | case DataType::Type::kFloat32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3846 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3847 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 3848 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3849 | break; |
| 3850 | } |
| 3851 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3852 | case DataType::Type::kFloat64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3853 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3854 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0), |
| 3855 | calling_convention.GetFpuRegisterAt(1))); |
| 3856 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3857 | break; |
| 3858 | } |
| 3859 | |
| 3860 | default: |
| 3861 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3862 | << " to " << result_type; |
| 3863 | } |
| 3864 | break; |
| 3865 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3866 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3867 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3868 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3869 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3870 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3871 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3872 | case DataType::Type::kInt16: |
| 3873 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3874 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3875 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3876 | break; |
| 3877 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3878 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3879 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3880 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0), |
| 3881 | calling_convention.GetRegisterAt(1))); |
| 3882 | locations->SetOut(LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3883 | break; |
| 3884 | } |
| 3885 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3886 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3887 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3888 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3889 | break; |
| 3890 | |
| 3891 | default: |
| 3892 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3893 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame^] | 3894 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3895 | break; |
| 3896 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3897 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3898 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3899 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3900 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3901 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3902 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3903 | case DataType::Type::kInt16: |
| 3904 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3905 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3906 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3907 | break; |
| 3908 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3909 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3910 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3911 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3912 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3913 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3914 | break; |
| 3915 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3916 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3917 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3918 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3919 | break; |
| 3920 | |
| 3921 | default: |
| 3922 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3923 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame^] | 3924 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3925 | break; |
| 3926 | |
| 3927 | default: |
| 3928 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3929 | << " to " << result_type; |
| 3930 | } |
| 3931 | } |
| 3932 | |
| 3933 | void InstructionCodeGeneratorARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
| 3934 | LocationSummary* locations = conversion->GetLocations(); |
| 3935 | Location out = locations->Out(); |
| 3936 | Location in = locations->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3937 | DataType::Type result_type = conversion->GetResultType(); |
| 3938 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3939 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 3940 | << input_type << " -> " << result_type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3941 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3942 | case DataType::Type::kUint8: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3943 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3944 | case DataType::Type::kInt8: |
| 3945 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3946 | case DataType::Type::kInt16: |
| 3947 | case DataType::Type::kInt32: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3948 | __ Ubfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 8); |
| 3949 | break; |
| 3950 | case DataType::Type::kInt64: |
| 3951 | __ Ubfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 8); |
| 3952 | break; |
| 3953 | |
| 3954 | default: |
| 3955 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3956 | << " to " << result_type; |
| 3957 | } |
| 3958 | break; |
| 3959 | |
| 3960 | case DataType::Type::kInt8: |
| 3961 | switch (input_type) { |
| 3962 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3963 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3964 | case DataType::Type::kInt16: |
| 3965 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3966 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 8); |
| 3967 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3968 | case DataType::Type::kInt64: |
| 3969 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 8); |
| 3970 | break; |
| 3971 | |
| 3972 | default: |
| 3973 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3974 | << " to " << result_type; |
| 3975 | } |
| 3976 | break; |
| 3977 | |
| 3978 | case DataType::Type::kUint16: |
| 3979 | switch (input_type) { |
| 3980 | case DataType::Type::kInt8: |
| 3981 | case DataType::Type::kInt16: |
| 3982 | case DataType::Type::kInt32: |
| 3983 | __ Ubfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 3984 | break; |
| 3985 | case DataType::Type::kInt64: |
| 3986 | __ Ubfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
| 3987 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3988 | |
| 3989 | default: |
| 3990 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3991 | << " to " << result_type; |
| 3992 | } |
| 3993 | break; |
| 3994 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3995 | case DataType::Type::kInt16: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3996 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3997 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3998 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3999 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 4000 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4001 | case DataType::Type::kInt64: |
| 4002 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
| 4003 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4004 | |
| 4005 | default: |
| 4006 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4007 | << " to " << result_type; |
| 4008 | } |
| 4009 | break; |
| 4010 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4011 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4012 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4013 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4014 | DCHECK(out.IsRegister()); |
| 4015 | if (in.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4016 | __ Mov(OutputRegister(conversion), LowRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4017 | } else if (in.IsDoubleStackSlot()) { |
| 4018 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 4019 | OutputRegister(conversion), |
| 4020 | sp, |
| 4021 | in.GetStackIndex()); |
| 4022 | } else { |
| 4023 | DCHECK(in.IsConstant()); |
| 4024 | DCHECK(in.GetConstant()->IsLongConstant()); |
Vladimir Marko | ba1a48e | 2017-04-13 11:50:14 +0100 | [diff] [blame] | 4025 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 4026 | __ Mov(OutputRegister(conversion), static_cast<int32_t>(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4027 | } |
| 4028 | break; |
| 4029 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4030 | case DataType::Type::kFloat32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4031 | vixl32::SRegister temp = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4032 | __ Vcvt(S32, F32, temp, InputSRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4033 | __ Vmov(OutputRegister(conversion), temp); |
| 4034 | break; |
| 4035 | } |
| 4036 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4037 | case DataType::Type::kFloat64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4038 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4039 | __ Vcvt(S32, F64, temp_s, DRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4040 | __ Vmov(OutputRegister(conversion), temp_s); |
| 4041 | break; |
| 4042 | } |
| 4043 | |
| 4044 | default: |
| 4045 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4046 | << " to " << result_type; |
| 4047 | } |
| 4048 | break; |
| 4049 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4050 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4051 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4052 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4053 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4054 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4055 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4056 | case DataType::Type::kInt16: |
| 4057 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4058 | DCHECK(out.IsRegisterPair()); |
| 4059 | DCHECK(in.IsRegister()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4060 | __ Mov(LowRegisterFrom(out), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4061 | // Sign extension. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4062 | __ Asr(HighRegisterFrom(out), LowRegisterFrom(out), 31); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4063 | break; |
| 4064 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4065 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4066 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
| 4067 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 4068 | break; |
| 4069 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4070 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4071 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
| 4072 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 4073 | break; |
| 4074 | |
| 4075 | default: |
| 4076 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4077 | << " to " << result_type; |
| 4078 | } |
| 4079 | break; |
| 4080 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4081 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4082 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4083 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4084 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4085 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4086 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4087 | case DataType::Type::kInt16: |
| 4088 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4089 | __ Vmov(OutputSRegister(conversion), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4090 | __ Vcvt(F32, S32, OutputSRegister(conversion), OutputSRegister(conversion)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4091 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4092 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4093 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4094 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
| 4095 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 4096 | break; |
| 4097 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4098 | case DataType::Type::kFloat64: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4099 | __ Vcvt(F32, F64, OutputSRegister(conversion), DRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4100 | break; |
| 4101 | |
| 4102 | default: |
| 4103 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4104 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame^] | 4105 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4106 | break; |
| 4107 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4108 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4109 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4110 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4111 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4112 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4113 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4114 | case DataType::Type::kInt16: |
| 4115 | case DataType::Type::kInt32: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4116 | __ Vmov(LowSRegisterFrom(out), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4117 | __ Vcvt(F64, S32, DRegisterFrom(out), LowSRegisterFrom(out)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4118 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4119 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4120 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4121 | vixl32::Register low = LowRegisterFrom(in); |
| 4122 | vixl32::Register high = HighRegisterFrom(in); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4123 | vixl32::SRegister out_s = LowSRegisterFrom(out); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4124 | vixl32::DRegister out_d = DRegisterFrom(out); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4125 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4126 | vixl32::DRegister temp_d = DRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4127 | vixl32::DRegister constant_d = DRegisterFrom(locations->GetTemp(1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4128 | |
| 4129 | // temp_d = int-to-double(high) |
| 4130 | __ Vmov(temp_s, high); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4131 | __ Vcvt(F64, S32, temp_d, temp_s); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4132 | // constant_d = k2Pow32EncodingForDouble |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4133 | __ Vmov(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4134 | // out_d = unsigned-to-double(low) |
| 4135 | __ Vmov(out_s, low); |
| 4136 | __ Vcvt(F64, U32, out_d, out_s); |
| 4137 | // out_d += temp_d * constant_d |
| 4138 | __ Vmla(F64, out_d, temp_d, constant_d); |
| 4139 | break; |
| 4140 | } |
| 4141 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4142 | case DataType::Type::kFloat32: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4143 | __ Vcvt(F64, F32, DRegisterFrom(out), InputSRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4144 | break; |
| 4145 | |
| 4146 | default: |
| 4147 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4148 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame^] | 4149 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4150 | break; |
| 4151 | |
| 4152 | default: |
| 4153 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4154 | << " to " << result_type; |
| 4155 | } |
| 4156 | } |
| 4157 | |
| 4158 | void LocationsBuilderARMVIXL::VisitAdd(HAdd* add) { |
| 4159 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4160 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4161 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4162 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4163 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4164 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 4165 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4166 | break; |
| 4167 | } |
| 4168 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4169 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4170 | locations->SetInAt(0, Location::RequiresRegister()); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4171 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4172 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4173 | break; |
| 4174 | } |
| 4175 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4176 | case DataType::Type::kFloat32: |
| 4177 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4178 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4179 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4180 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4181 | break; |
| 4182 | } |
| 4183 | |
| 4184 | default: |
| 4185 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 4186 | } |
| 4187 | } |
| 4188 | |
| 4189 | void InstructionCodeGeneratorARMVIXL::VisitAdd(HAdd* add) { |
| 4190 | LocationSummary* locations = add->GetLocations(); |
| 4191 | Location out = locations->Out(); |
| 4192 | Location first = locations->InAt(0); |
| 4193 | Location second = locations->InAt(1); |
| 4194 | |
| 4195 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4196 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4197 | __ Add(OutputRegister(add), InputRegisterAt(add, 0), InputOperandAt(add, 1)); |
| 4198 | } |
| 4199 | break; |
| 4200 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4201 | case DataType::Type::kInt64: { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4202 | if (second.IsConstant()) { |
| 4203 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 4204 | GenerateAddLongConst(out, first, value); |
| 4205 | } else { |
| 4206 | DCHECK(second.IsRegisterPair()); |
| 4207 | __ Adds(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 4208 | __ Adc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 4209 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4210 | break; |
| 4211 | } |
| 4212 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4213 | case DataType::Type::kFloat32: |
| 4214 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4215 | __ Vadd(OutputVRegister(add), InputVRegisterAt(add, 0), InputVRegisterAt(add, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4216 | break; |
| 4217 | |
| 4218 | default: |
| 4219 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 4220 | } |
| 4221 | } |
| 4222 | |
| 4223 | void LocationsBuilderARMVIXL::VisitSub(HSub* sub) { |
| 4224 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4225 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4226 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4227 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4228 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4229 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
| 4230 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4231 | break; |
| 4232 | } |
| 4233 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4234 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4235 | locations->SetInAt(0, Location::RequiresRegister()); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4236 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4237 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4238 | break; |
| 4239 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4240 | case DataType::Type::kFloat32: |
| 4241 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4242 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4243 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4244 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4245 | break; |
| 4246 | } |
| 4247 | default: |
| 4248 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 4249 | } |
| 4250 | } |
| 4251 | |
| 4252 | void InstructionCodeGeneratorARMVIXL::VisitSub(HSub* sub) { |
| 4253 | LocationSummary* locations = sub->GetLocations(); |
| 4254 | Location out = locations->Out(); |
| 4255 | Location first = locations->InAt(0); |
| 4256 | Location second = locations->InAt(1); |
| 4257 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4258 | case DataType::Type::kInt32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4259 | __ Sub(OutputRegister(sub), InputRegisterAt(sub, 0), InputOperandAt(sub, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4260 | break; |
| 4261 | } |
| 4262 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4263 | case DataType::Type::kInt64: { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4264 | if (second.IsConstant()) { |
| 4265 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 4266 | GenerateAddLongConst(out, first, -value); |
| 4267 | } else { |
| 4268 | DCHECK(second.IsRegisterPair()); |
| 4269 | __ Subs(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 4270 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 4271 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4272 | break; |
| 4273 | } |
| 4274 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4275 | case DataType::Type::kFloat32: |
| 4276 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4277 | __ Vsub(OutputVRegister(sub), InputVRegisterAt(sub, 0), InputVRegisterAt(sub, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4278 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4279 | |
| 4280 | default: |
| 4281 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 4282 | } |
| 4283 | } |
| 4284 | |
| 4285 | void LocationsBuilderARMVIXL::VisitMul(HMul* mul) { |
| 4286 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4287 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4288 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4289 | case DataType::Type::kInt32: |
| 4290 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4291 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4292 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4293 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4294 | break; |
| 4295 | } |
| 4296 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4297 | case DataType::Type::kFloat32: |
| 4298 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4299 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4300 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4301 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4302 | break; |
| 4303 | } |
| 4304 | |
| 4305 | default: |
| 4306 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4307 | } |
| 4308 | } |
| 4309 | |
| 4310 | void InstructionCodeGeneratorARMVIXL::VisitMul(HMul* mul) { |
| 4311 | LocationSummary* locations = mul->GetLocations(); |
| 4312 | Location out = locations->Out(); |
| 4313 | Location first = locations->InAt(0); |
| 4314 | Location second = locations->InAt(1); |
| 4315 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4316 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4317 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 4318 | break; |
| 4319 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4320 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4321 | vixl32::Register out_hi = HighRegisterFrom(out); |
| 4322 | vixl32::Register out_lo = LowRegisterFrom(out); |
| 4323 | vixl32::Register in1_hi = HighRegisterFrom(first); |
| 4324 | vixl32::Register in1_lo = LowRegisterFrom(first); |
| 4325 | vixl32::Register in2_hi = HighRegisterFrom(second); |
| 4326 | vixl32::Register in2_lo = LowRegisterFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4327 | |
| 4328 | // Extra checks to protect caused by the existence of R1_R2. |
| 4329 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 4330 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4331 | DCHECK(!out_hi.Is(in1_lo)); |
| 4332 | DCHECK(!out_hi.Is(in2_lo)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4333 | |
| 4334 | // input: in1 - 64 bits, in2 - 64 bits |
| 4335 | // output: out |
| 4336 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 4337 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 4338 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 4339 | |
| 4340 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4341 | vixl32::Register temp = temps.Acquire(); |
| 4342 | // temp <- in1.lo * in2.hi |
| 4343 | __ Mul(temp, in1_lo, in2_hi); |
| 4344 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 4345 | __ Mla(out_hi, in1_hi, in2_lo, temp); |
| 4346 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 4347 | __ Umull(out_lo, temp, in1_lo, in2_lo); |
| 4348 | // 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] | 4349 | __ Add(out_hi, out_hi, temp); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4350 | break; |
| 4351 | } |
| 4352 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4353 | case DataType::Type::kFloat32: |
| 4354 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4355 | __ Vmul(OutputVRegister(mul), InputVRegisterAt(mul, 0), InputVRegisterAt(mul, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4356 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4357 | |
| 4358 | default: |
| 4359 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4360 | } |
| 4361 | } |
| 4362 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4363 | void InstructionCodeGeneratorARMVIXL::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 4364 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4365 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4366 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4367 | Location second = instruction->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4368 | DCHECK(second.IsConstant()); |
| 4369 | |
| 4370 | vixl32::Register out = OutputRegister(instruction); |
| 4371 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4372 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4373 | DCHECK(imm == 1 || imm == -1); |
| 4374 | |
| 4375 | if (instruction->IsRem()) { |
| 4376 | __ Mov(out, 0); |
| 4377 | } else { |
| 4378 | if (imm == 1) { |
| 4379 | __ Mov(out, dividend); |
| 4380 | } else { |
| 4381 | __ Rsb(out, dividend, 0); |
| 4382 | } |
| 4383 | } |
| 4384 | } |
| 4385 | |
| 4386 | void InstructionCodeGeneratorARMVIXL::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 4387 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4388 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4389 | |
| 4390 | LocationSummary* locations = instruction->GetLocations(); |
| 4391 | Location second = locations->InAt(1); |
| 4392 | DCHECK(second.IsConstant()); |
| 4393 | |
| 4394 | vixl32::Register out = OutputRegister(instruction); |
| 4395 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4396 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4397 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4398 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 4399 | int ctz_imm = CTZ(abs_imm); |
| 4400 | |
| 4401 | if (ctz_imm == 1) { |
| 4402 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 4403 | } else { |
| 4404 | __ Asr(temp, dividend, 31); |
| 4405 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 4406 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4407 | __ Add(out, temp, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4408 | |
| 4409 | if (instruction->IsDiv()) { |
| 4410 | __ Asr(out, out, ctz_imm); |
| 4411 | if (imm < 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4412 | __ Rsb(out, out, 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4413 | } |
| 4414 | } else { |
| 4415 | __ Ubfx(out, out, 0, ctz_imm); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4416 | __ Sub(out, out, temp); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4417 | } |
| 4418 | } |
| 4419 | |
| 4420 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 4421 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4422 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4423 | |
| 4424 | LocationSummary* locations = instruction->GetLocations(); |
| 4425 | Location second = locations->InAt(1); |
| 4426 | DCHECK(second.IsConstant()); |
| 4427 | |
| 4428 | vixl32::Register out = OutputRegister(instruction); |
| 4429 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4430 | vixl32::Register temp1 = RegisterFrom(locations->GetTemp(0)); |
| 4431 | vixl32::Register temp2 = RegisterFrom(locations->GetTemp(1)); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4432 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4433 | |
| 4434 | int64_t magic; |
| 4435 | int shift; |
| 4436 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 4437 | |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4438 | // TODO(VIXL): Change the static cast to Operand::From() after VIXL is fixed. |
| 4439 | __ Mov(temp1, static_cast<int32_t>(magic)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4440 | __ Smull(temp2, temp1, dividend, temp1); |
| 4441 | |
| 4442 | if (imm > 0 && magic < 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4443 | __ Add(temp1, temp1, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4444 | } else if (imm < 0 && magic > 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4445 | __ Sub(temp1, temp1, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4446 | } |
| 4447 | |
| 4448 | if (shift != 0) { |
| 4449 | __ Asr(temp1, temp1, shift); |
| 4450 | } |
| 4451 | |
| 4452 | if (instruction->IsDiv()) { |
| 4453 | __ Sub(out, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 4454 | } else { |
| 4455 | __ Sub(temp1, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 4456 | // TODO: Strength reduction for mls. |
| 4457 | __ Mov(temp2, imm); |
| 4458 | __ Mls(out, temp1, temp2, dividend); |
| 4459 | } |
| 4460 | } |
| 4461 | |
| 4462 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemConstantIntegral( |
| 4463 | HBinaryOperation* instruction) { |
| 4464 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4465 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4466 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4467 | Location second = instruction->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4468 | DCHECK(second.IsConstant()); |
| 4469 | |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4470 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4471 | if (imm == 0) { |
| 4472 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4473 | } else if (imm == 1 || imm == -1) { |
| 4474 | DivRemOneOrMinusOne(instruction); |
| 4475 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 4476 | DivRemByPowerOfTwo(instruction); |
| 4477 | } else { |
| 4478 | DCHECK(imm <= -2 || imm >= 2); |
| 4479 | GenerateDivRemWithAnyConstant(instruction); |
| 4480 | } |
| 4481 | } |
| 4482 | |
| 4483 | void LocationsBuilderARMVIXL::VisitDiv(HDiv* div) { |
| 4484 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4485 | if (div->GetResultType() == DataType::Type::kInt64) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4486 | // pLdiv runtime call. |
| 4487 | call_kind = LocationSummary::kCallOnMainOnly; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4488 | } else if (div->GetResultType() == DataType::Type::kInt32 && div->InputAt(1)->IsConstant()) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4489 | // sdiv will be replaced by other instruction sequence. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4490 | } else if (div->GetResultType() == DataType::Type::kInt32 && |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4491 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4492 | // pIdivmod runtime call. |
| 4493 | call_kind = LocationSummary::kCallOnMainOnly; |
| 4494 | } |
| 4495 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4496 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4497 | |
| 4498 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4499 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4500 | if (div->InputAt(1)->IsConstant()) { |
| 4501 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4502 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
| 4503 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4504 | int32_t value = Int32ConstantFrom(div->InputAt(1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4505 | if (value == 1 || value == 0 || value == -1) { |
| 4506 | // No temp register required. |
| 4507 | } else { |
| 4508 | locations->AddTemp(Location::RequiresRegister()); |
| 4509 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
| 4510 | locations->AddTemp(Location::RequiresRegister()); |
| 4511 | } |
| 4512 | } |
| 4513 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4514 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4515 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4516 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4517 | } else { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4518 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4519 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4520 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4521 | // 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] | 4522 | // we only need the former. |
| 4523 | locations->SetOut(LocationFrom(r0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4524 | } |
| 4525 | break; |
| 4526 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4527 | case DataType::Type::kInt64: { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4528 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4529 | locations->SetInAt(0, LocationFrom( |
| 4530 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4531 | locations->SetInAt(1, LocationFrom( |
| 4532 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4533 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4534 | break; |
| 4535 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4536 | case DataType::Type::kFloat32: |
| 4537 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4538 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4539 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4540 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4541 | break; |
| 4542 | } |
| 4543 | |
| 4544 | default: |
| 4545 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4546 | } |
| 4547 | } |
| 4548 | |
| 4549 | void InstructionCodeGeneratorARMVIXL::VisitDiv(HDiv* div) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4550 | Location lhs = div->GetLocations()->InAt(0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4551 | Location rhs = div->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4552 | |
| 4553 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4554 | case DataType::Type::kInt32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4555 | if (rhs.IsConstant()) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4556 | GenerateDivRemConstantIntegral(div); |
| 4557 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4558 | __ Sdiv(OutputRegister(div), InputRegisterAt(div, 0), InputRegisterAt(div, 1)); |
| 4559 | } else { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4560 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4561 | DCHECK(calling_convention.GetRegisterAt(0).Is(RegisterFrom(lhs))); |
| 4562 | DCHECK(calling_convention.GetRegisterAt(1).Is(RegisterFrom(rhs))); |
| 4563 | DCHECK(r0.Is(OutputRegister(div))); |
| 4564 | |
| 4565 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
| 4566 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4567 | } |
| 4568 | break; |
| 4569 | } |
| 4570 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4571 | case DataType::Type::kInt64: { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4572 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4573 | DCHECK(calling_convention.GetRegisterAt(0).Is(LowRegisterFrom(lhs))); |
| 4574 | DCHECK(calling_convention.GetRegisterAt(1).Is(HighRegisterFrom(lhs))); |
| 4575 | DCHECK(calling_convention.GetRegisterAt(2).Is(LowRegisterFrom(rhs))); |
| 4576 | DCHECK(calling_convention.GetRegisterAt(3).Is(HighRegisterFrom(rhs))); |
| 4577 | DCHECK(LowRegisterFrom(div->GetLocations()->Out()).Is(r0)); |
| 4578 | DCHECK(HighRegisterFrom(div->GetLocations()->Out()).Is(r1)); |
| 4579 | |
| 4580 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
| 4581 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4582 | break; |
| 4583 | } |
| 4584 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4585 | case DataType::Type::kFloat32: |
| 4586 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4587 | __ Vdiv(OutputVRegister(div), InputVRegisterAt(div, 0), InputVRegisterAt(div, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4588 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4589 | |
| 4590 | default: |
| 4591 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4592 | } |
| 4593 | } |
| 4594 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4595 | void LocationsBuilderARMVIXL::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4596 | DataType::Type type = rem->GetResultType(); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4597 | |
| 4598 | // Most remainders are implemented in the runtime. |
| 4599 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4600 | if (rem->GetResultType() == DataType::Type::kInt32 && rem->InputAt(1)->IsConstant()) { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4601 | // sdiv will be replaced by other instruction sequence. |
| 4602 | call_kind = LocationSummary::kNoCall; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4603 | } else if ((rem->GetResultType() == DataType::Type::kInt32) |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4604 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4605 | // Have hardware divide instruction for int, do it with three instructions. |
| 4606 | call_kind = LocationSummary::kNoCall; |
| 4607 | } |
| 4608 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4609 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4610 | |
| 4611 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4612 | case DataType::Type::kInt32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4613 | if (rem->InputAt(1)->IsConstant()) { |
| 4614 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4615 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
| 4616 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4617 | int32_t value = Int32ConstantFrom(rem->InputAt(1)); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4618 | if (value == 1 || value == 0 || value == -1) { |
| 4619 | // No temp register required. |
| 4620 | } else { |
| 4621 | locations->AddTemp(Location::RequiresRegister()); |
| 4622 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
| 4623 | locations->AddTemp(Location::RequiresRegister()); |
| 4624 | } |
| 4625 | } |
| 4626 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4627 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4628 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4629 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4630 | locations->AddTemp(Location::RequiresRegister()); |
| 4631 | } else { |
| 4632 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4633 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4634 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4635 | // 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] | 4636 | // we only need the latter. |
| 4637 | locations->SetOut(LocationFrom(r1)); |
| 4638 | } |
| 4639 | break; |
| 4640 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4641 | case DataType::Type::kInt64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4642 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4643 | locations->SetInAt(0, LocationFrom( |
| 4644 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4645 | locations->SetInAt(1, LocationFrom( |
| 4646 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4647 | // The runtime helper puts the output in R2,R3. |
| 4648 | locations->SetOut(LocationFrom(r2, r3)); |
| 4649 | break; |
| 4650 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4651 | case DataType::Type::kFloat32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4652 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4653 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 4654 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 4655 | locations->SetOut(LocationFrom(s0)); |
| 4656 | break; |
| 4657 | } |
| 4658 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4659 | case DataType::Type::kFloat64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4660 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4661 | locations->SetInAt(0, LocationFrom( |
| 4662 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 4663 | locations->SetInAt(1, LocationFrom( |
| 4664 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 4665 | locations->SetOut(LocationFrom(s0, s1)); |
| 4666 | break; |
| 4667 | } |
| 4668 | |
| 4669 | default: |
| 4670 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4671 | } |
| 4672 | } |
| 4673 | |
| 4674 | void InstructionCodeGeneratorARMVIXL::VisitRem(HRem* rem) { |
| 4675 | LocationSummary* locations = rem->GetLocations(); |
| 4676 | Location second = locations->InAt(1); |
| 4677 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4678 | DataType::Type type = rem->GetResultType(); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4679 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4680 | case DataType::Type::kInt32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4681 | vixl32::Register reg1 = InputRegisterAt(rem, 0); |
| 4682 | vixl32::Register out_reg = OutputRegister(rem); |
| 4683 | if (second.IsConstant()) { |
| 4684 | GenerateDivRemConstantIntegral(rem); |
| 4685 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4686 | vixl32::Register reg2 = RegisterFrom(second); |
| 4687 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 4688 | |
| 4689 | // temp = reg1 / reg2 (integer division) |
| 4690 | // dest = reg1 - temp * reg2 |
| 4691 | __ Sdiv(temp, reg1, reg2); |
| 4692 | __ Mls(out_reg, temp, reg2, reg1); |
| 4693 | } else { |
| 4694 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4695 | DCHECK(reg1.Is(calling_convention.GetRegisterAt(0))); |
| 4696 | DCHECK(RegisterFrom(second).Is(calling_convention.GetRegisterAt(1))); |
| 4697 | DCHECK(out_reg.Is(r1)); |
| 4698 | |
| 4699 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
| 4700 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
| 4701 | } |
| 4702 | break; |
| 4703 | } |
| 4704 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4705 | case DataType::Type::kInt64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4706 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
| 4707 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 4708 | break; |
| 4709 | } |
| 4710 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4711 | case DataType::Type::kFloat32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4712 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
| 4713 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 4714 | break; |
| 4715 | } |
| 4716 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4717 | case DataType::Type::kFloat64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4718 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
| 4719 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 4720 | break; |
| 4721 | } |
| 4722 | |
| 4723 | default: |
| 4724 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4725 | } |
| 4726 | } |
| 4727 | |
| 4728 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4729 | void LocationsBuilderARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 4730 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4731 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4732 | } |
| 4733 | |
| 4734 | void InstructionCodeGeneratorARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 4735 | DivZeroCheckSlowPathARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4736 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathARMVIXL(instruction); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4737 | codegen_->AddSlowPath(slow_path); |
| 4738 | |
| 4739 | LocationSummary* locations = instruction->GetLocations(); |
| 4740 | Location value = locations->InAt(0); |
| 4741 | |
| 4742 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4743 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4744 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4745 | case DataType::Type::kInt8: |
| 4746 | case DataType::Type::kUint16: |
| 4747 | case DataType::Type::kInt16: |
| 4748 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4749 | if (value.IsRegister()) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 4750 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4751 | } else { |
| 4752 | DCHECK(value.IsConstant()) << value; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4753 | if (Int32ConstantFrom(value) == 0) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4754 | __ B(slow_path->GetEntryLabel()); |
| 4755 | } |
| 4756 | } |
| 4757 | break; |
| 4758 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4759 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4760 | if (value.IsRegisterPair()) { |
| 4761 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4762 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4763 | __ Orrs(temp, LowRegisterFrom(value), HighRegisterFrom(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4764 | __ B(eq, slow_path->GetEntryLabel()); |
| 4765 | } else { |
| 4766 | DCHECK(value.IsConstant()) << value; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4767 | if (Int64ConstantFrom(value) == 0) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4768 | __ B(slow_path->GetEntryLabel()); |
| 4769 | } |
| 4770 | } |
| 4771 | break; |
| 4772 | } |
| 4773 | default: |
| 4774 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4775 | } |
| 4776 | } |
| 4777 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4778 | void InstructionCodeGeneratorARMVIXL::HandleIntegerRotate(HRor* ror) { |
| 4779 | LocationSummary* locations = ror->GetLocations(); |
| 4780 | vixl32::Register in = InputRegisterAt(ror, 0); |
| 4781 | Location rhs = locations->InAt(1); |
| 4782 | vixl32::Register out = OutputRegister(ror); |
| 4783 | |
| 4784 | if (rhs.IsConstant()) { |
| 4785 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 4786 | // so map all rotations to a +ve. equivalent in that range. |
| 4787 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 4788 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 4789 | if (rot) { |
| 4790 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 4791 | // (e.g. left by 2 bits == right by 30.) |
| 4792 | __ Ror(out, in, rot); |
| 4793 | } else if (!out.Is(in)) { |
| 4794 | __ Mov(out, in); |
| 4795 | } |
| 4796 | } else { |
| 4797 | __ Ror(out, in, RegisterFrom(rhs)); |
| 4798 | } |
| 4799 | } |
| 4800 | |
| 4801 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 4802 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 4803 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 4804 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 4805 | void InstructionCodeGeneratorARMVIXL::HandleLongRotate(HRor* ror) { |
| 4806 | LocationSummary* locations = ror->GetLocations(); |
| 4807 | vixl32::Register in_reg_lo = LowRegisterFrom(locations->InAt(0)); |
| 4808 | vixl32::Register in_reg_hi = HighRegisterFrom(locations->InAt(0)); |
| 4809 | Location rhs = locations->InAt(1); |
| 4810 | vixl32::Register out_reg_lo = LowRegisterFrom(locations->Out()); |
| 4811 | vixl32::Register out_reg_hi = HighRegisterFrom(locations->Out()); |
| 4812 | |
| 4813 | if (rhs.IsConstant()) { |
| 4814 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 4815 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
| 4816 | rot &= kMaxLongShiftDistance; |
| 4817 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 4818 | // logic below to a simple pair of binary orr. |
| 4819 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 4820 | if (rot >= kArmBitsPerWord) { |
| 4821 | rot -= kArmBitsPerWord; |
| 4822 | std::swap(in_reg_hi, in_reg_lo); |
| 4823 | } |
| 4824 | // Rotate, or mov to out for zero or word size rotations. |
| 4825 | if (rot != 0u) { |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4826 | __ Lsr(out_reg_hi, in_reg_hi, Operand::From(rot)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4827 | __ 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] | 4828 | __ Lsr(out_reg_lo, in_reg_lo, Operand::From(rot)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4829 | __ Orr(out_reg_lo, out_reg_lo, Operand(in_reg_hi, ShiftType::LSL, kArmBitsPerWord - rot)); |
| 4830 | } else { |
| 4831 | __ Mov(out_reg_lo, in_reg_lo); |
| 4832 | __ Mov(out_reg_hi, in_reg_hi); |
| 4833 | } |
| 4834 | } else { |
| 4835 | vixl32::Register shift_right = RegisterFrom(locations->GetTemp(0)); |
| 4836 | vixl32::Register shift_left = RegisterFrom(locations->GetTemp(1)); |
| 4837 | vixl32::Label end; |
| 4838 | vixl32::Label shift_by_32_plus_shift_right; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4839 | vixl32::Label* final_label = codegen_->GetFinalLabel(ror, &end); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4840 | |
| 4841 | __ And(shift_right, RegisterFrom(rhs), 0x1F); |
| 4842 | __ Lsrs(shift_left, RegisterFrom(rhs), 6); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 4843 | __ Rsb(LeaveFlags, shift_left, shift_right, Operand::From(kArmBitsPerWord)); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 4844 | __ B(cc, &shift_by_32_plus_shift_right, /* far_target */ false); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4845 | |
| 4846 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 4847 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 4848 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 4849 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4850 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 4851 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4852 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 4853 | __ Add(out_reg_lo, out_reg_lo, shift_left); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4854 | __ B(final_label); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4855 | |
| 4856 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 4857 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 4858 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 4859 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 4860 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4861 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 4862 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4863 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 4864 | __ Add(out_reg_lo, out_reg_lo, shift_right); |
| 4865 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4866 | if (end.IsReferenced()) { |
| 4867 | __ Bind(&end); |
| 4868 | } |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4869 | } |
| 4870 | } |
| 4871 | |
| 4872 | void LocationsBuilderARMVIXL::VisitRor(HRor* ror) { |
| 4873 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4874 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4875 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4876 | case DataType::Type::kInt32: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4877 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4878 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 4879 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4880 | break; |
| 4881 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4882 | case DataType::Type::kInt64: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4883 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4884 | if (ror->InputAt(1)->IsConstant()) { |
| 4885 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 4886 | } else { |
| 4887 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4888 | locations->AddTemp(Location::RequiresRegister()); |
| 4889 | locations->AddTemp(Location::RequiresRegister()); |
| 4890 | } |
| 4891 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4892 | break; |
| 4893 | } |
| 4894 | default: |
| 4895 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4896 | } |
| 4897 | } |
| 4898 | |
| 4899 | void InstructionCodeGeneratorARMVIXL::VisitRor(HRor* ror) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4900 | DataType::Type type = ror->GetResultType(); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4901 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4902 | case DataType::Type::kInt32: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4903 | HandleIntegerRotate(ror); |
| 4904 | break; |
| 4905 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4906 | case DataType::Type::kInt64: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4907 | HandleLongRotate(ror); |
| 4908 | break; |
| 4909 | } |
| 4910 | default: |
| 4911 | LOG(FATAL) << "Unexpected operation type " << type; |
| 4912 | UNREACHABLE(); |
| 4913 | } |
| 4914 | } |
| 4915 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4916 | void LocationsBuilderARMVIXL::HandleShift(HBinaryOperation* op) { |
| 4917 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4918 | |
| 4919 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4920 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4921 | |
| 4922 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4923 | case DataType::Type::kInt32: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4924 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4925 | if (op->InputAt(1)->IsConstant()) { |
| 4926 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 4927 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4928 | } else { |
| 4929 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4930 | // Make the output overlap, as it will be used to hold the masked |
| 4931 | // second input. |
| 4932 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4933 | } |
| 4934 | break; |
| 4935 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4936 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4937 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4938 | if (op->InputAt(1)->IsConstant()) { |
| 4939 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 4940 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 4941 | // don't clash with high registers which the register allocator currently guarantees. |
| 4942 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4943 | } else { |
| 4944 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4945 | locations->AddTemp(Location::RequiresRegister()); |
| 4946 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4947 | } |
| 4948 | break; |
| 4949 | } |
| 4950 | default: |
| 4951 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 4952 | } |
| 4953 | } |
| 4954 | |
| 4955 | void InstructionCodeGeneratorARMVIXL::HandleShift(HBinaryOperation* op) { |
| 4956 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4957 | |
| 4958 | LocationSummary* locations = op->GetLocations(); |
| 4959 | Location out = locations->Out(); |
| 4960 | Location first = locations->InAt(0); |
| 4961 | Location second = locations->InAt(1); |
| 4962 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4963 | DataType::Type type = op->GetResultType(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4964 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4965 | case DataType::Type::kInt32: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4966 | vixl32::Register out_reg = OutputRegister(op); |
| 4967 | vixl32::Register first_reg = InputRegisterAt(op, 0); |
| 4968 | if (second.IsRegister()) { |
| 4969 | vixl32::Register second_reg = RegisterFrom(second); |
| 4970 | // ARM doesn't mask the shift count so we need to do it ourselves. |
| 4971 | __ And(out_reg, second_reg, kMaxIntShiftDistance); |
| 4972 | if (op->IsShl()) { |
| 4973 | __ Lsl(out_reg, first_reg, out_reg); |
| 4974 | } else if (op->IsShr()) { |
| 4975 | __ Asr(out_reg, first_reg, out_reg); |
| 4976 | } else { |
| 4977 | __ Lsr(out_reg, first_reg, out_reg); |
| 4978 | } |
| 4979 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4980 | int32_t cst = Int32ConstantFrom(second); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4981 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
| 4982 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
| 4983 | __ Mov(out_reg, first_reg); |
| 4984 | } else if (op->IsShl()) { |
| 4985 | __ Lsl(out_reg, first_reg, shift_value); |
| 4986 | } else if (op->IsShr()) { |
| 4987 | __ Asr(out_reg, first_reg, shift_value); |
| 4988 | } else { |
| 4989 | __ Lsr(out_reg, first_reg, shift_value); |
| 4990 | } |
| 4991 | } |
| 4992 | break; |
| 4993 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4994 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4995 | vixl32::Register o_h = HighRegisterFrom(out); |
| 4996 | vixl32::Register o_l = LowRegisterFrom(out); |
| 4997 | |
| 4998 | vixl32::Register high = HighRegisterFrom(first); |
| 4999 | vixl32::Register low = LowRegisterFrom(first); |
| 5000 | |
| 5001 | if (second.IsRegister()) { |
| 5002 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5003 | |
| 5004 | vixl32::Register second_reg = RegisterFrom(second); |
| 5005 | |
| 5006 | if (op->IsShl()) { |
| 5007 | __ And(o_l, second_reg, kMaxLongShiftDistance); |
| 5008 | // Shift the high part |
| 5009 | __ Lsl(o_h, high, o_l); |
| 5010 | // Shift the low part and `or` what overflew on the high part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5011 | __ Rsb(temp, o_l, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5012 | __ Lsr(temp, low, temp); |
| 5013 | __ Orr(o_h, o_h, temp); |
| 5014 | // If the shift is > 32 bits, override the high part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5015 | __ Subs(temp, o_l, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5016 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5017 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5018 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5019 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5020 | __ it(pl); |
| 5021 | __ lsl(pl, o_h, low, temp); |
| 5022 | } |
| 5023 | // Shift the low part |
| 5024 | __ Lsl(o_l, low, o_l); |
| 5025 | } else if (op->IsShr()) { |
| 5026 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 5027 | // Shift the low part |
| 5028 | __ Lsr(o_l, low, o_h); |
| 5029 | // Shift the high part and `or` what underflew on the low part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5030 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5031 | __ Lsl(temp, high, temp); |
| 5032 | __ Orr(o_l, o_l, temp); |
| 5033 | // If the shift is > 32 bits, override the low part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5034 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5035 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5036 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5037 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5038 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5039 | __ it(pl); |
| 5040 | __ asr(pl, o_l, high, temp); |
| 5041 | } |
| 5042 | // Shift the high part |
| 5043 | __ Asr(o_h, high, o_h); |
| 5044 | } else { |
| 5045 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 5046 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 5047 | __ Lsr(o_l, low, o_h); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5048 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5049 | __ Lsl(temp, high, temp); |
| 5050 | __ Orr(o_l, o_l, temp); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5051 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5052 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5053 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5054 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5055 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5056 | __ it(pl); |
| 5057 | __ lsr(pl, o_l, high, temp); |
| 5058 | } |
| 5059 | __ Lsr(o_h, high, o_h); |
| 5060 | } |
| 5061 | } else { |
| 5062 | // Register allocator doesn't create partial overlap. |
| 5063 | DCHECK(!o_l.Is(high)); |
| 5064 | DCHECK(!o_h.Is(low)); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5065 | int32_t cst = Int32ConstantFrom(second); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5066 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
| 5067 | if (shift_value > 32) { |
| 5068 | if (op->IsShl()) { |
| 5069 | __ Lsl(o_h, low, shift_value - 32); |
| 5070 | __ Mov(o_l, 0); |
| 5071 | } else if (op->IsShr()) { |
| 5072 | __ Asr(o_l, high, shift_value - 32); |
| 5073 | __ Asr(o_h, high, 31); |
| 5074 | } else { |
| 5075 | __ Lsr(o_l, high, shift_value - 32); |
| 5076 | __ Mov(o_h, 0); |
| 5077 | } |
| 5078 | } else if (shift_value == 32) { |
| 5079 | if (op->IsShl()) { |
| 5080 | __ Mov(o_h, low); |
| 5081 | __ Mov(o_l, 0); |
| 5082 | } else if (op->IsShr()) { |
| 5083 | __ Mov(o_l, high); |
| 5084 | __ Asr(o_h, high, 31); |
| 5085 | } else { |
| 5086 | __ Mov(o_l, high); |
| 5087 | __ Mov(o_h, 0); |
| 5088 | } |
| 5089 | } else if (shift_value == 1) { |
| 5090 | if (op->IsShl()) { |
| 5091 | __ Lsls(o_l, low, 1); |
| 5092 | __ Adc(o_h, high, high); |
| 5093 | } else if (op->IsShr()) { |
| 5094 | __ Asrs(o_h, high, 1); |
| 5095 | __ Rrx(o_l, low); |
| 5096 | } else { |
| 5097 | __ Lsrs(o_h, high, 1); |
| 5098 | __ Rrx(o_l, low); |
| 5099 | } |
| 5100 | } else { |
| 5101 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
| 5102 | if (op->IsShl()) { |
| 5103 | __ Lsl(o_h, high, shift_value); |
| 5104 | __ Orr(o_h, o_h, Operand(low, ShiftType::LSR, 32 - shift_value)); |
| 5105 | __ Lsl(o_l, low, shift_value); |
| 5106 | } else if (op->IsShr()) { |
| 5107 | __ Lsr(o_l, low, shift_value); |
| 5108 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 5109 | __ Asr(o_h, high, shift_value); |
| 5110 | } else { |
| 5111 | __ Lsr(o_l, low, shift_value); |
| 5112 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 5113 | __ Lsr(o_h, high, shift_value); |
| 5114 | } |
| 5115 | } |
| 5116 | } |
| 5117 | break; |
| 5118 | } |
| 5119 | default: |
| 5120 | LOG(FATAL) << "Unexpected operation type " << type; |
| 5121 | UNREACHABLE(); |
| 5122 | } |
| 5123 | } |
| 5124 | |
| 5125 | void LocationsBuilderARMVIXL::VisitShl(HShl* shl) { |
| 5126 | HandleShift(shl); |
| 5127 | } |
| 5128 | |
| 5129 | void InstructionCodeGeneratorARMVIXL::VisitShl(HShl* shl) { |
| 5130 | HandleShift(shl); |
| 5131 | } |
| 5132 | |
| 5133 | void LocationsBuilderARMVIXL::VisitShr(HShr* shr) { |
| 5134 | HandleShift(shr); |
| 5135 | } |
| 5136 | |
| 5137 | void InstructionCodeGeneratorARMVIXL::VisitShr(HShr* shr) { |
| 5138 | HandleShift(shr); |
| 5139 | } |
| 5140 | |
| 5141 | void LocationsBuilderARMVIXL::VisitUShr(HUShr* ushr) { |
| 5142 | HandleShift(ushr); |
| 5143 | } |
| 5144 | |
| 5145 | void InstructionCodeGeneratorARMVIXL::VisitUShr(HUShr* ushr) { |
| 5146 | HandleShift(ushr); |
| 5147 | } |
| 5148 | |
| 5149 | void LocationsBuilderARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5150 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5151 | instruction, LocationSummary::kCallOnMainOnly); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5152 | if (instruction->IsStringAlloc()) { |
| 5153 | locations->AddTemp(LocationFrom(kMethodRegister)); |
| 5154 | } else { |
| 5155 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 5156 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5157 | } |
| 5158 | locations->SetOut(LocationFrom(r0)); |
| 5159 | } |
| 5160 | |
| 5161 | void InstructionCodeGeneratorARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
| 5162 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5163 | // of poisoning the reference. |
| 5164 | if (instruction->IsStringAlloc()) { |
| 5165 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 5166 | vixl32::Register temp = RegisterFrom(instruction->GetLocations()->GetTemp(0)); |
| 5167 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
| 5168 | GetAssembler()->LoadFromOffset(kLoadWord, temp, tr, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 5169 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, code_offset.Int32Value()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5170 | // 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] | 5171 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5172 | vixl32::k16BitT32InstructionSizeInBytes, |
| 5173 | CodeBufferCheckScope::kExactSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5174 | __ blx(lr); |
| 5175 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5176 | } else { |
| 5177 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 5178 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5179 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 5180 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 10); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5181 | } |
| 5182 | |
| 5183 | void LocationsBuilderARMVIXL::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5184 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5185 | instruction, LocationSummary::kCallOnMainOnly); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5186 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5187 | locations->SetOut(LocationFrom(r0)); |
Nicolas Geoffray | 8c7c4f1 | 2017-01-26 10:13:11 +0000 | [diff] [blame] | 5188 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5189 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5190 | } |
| 5191 | |
| 5192 | void InstructionCodeGeneratorARMVIXL::VisitNewArray(HNewArray* instruction) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5193 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5194 | // of poisoning the reference. |
Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 5195 | QuickEntrypointEnum entrypoint = |
| 5196 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 5197 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5198 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 5199 | DCHECK(!codegen_->IsLeafMethod()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 5200 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 11); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5201 | } |
| 5202 | |
| 5203 | void LocationsBuilderARMVIXL::VisitParameterValue(HParameterValue* instruction) { |
| 5204 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5205 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5206 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5207 | if (location.IsStackSlot()) { |
| 5208 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5209 | } else if (location.IsDoubleStackSlot()) { |
| 5210 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5211 | } |
| 5212 | locations->SetOut(location); |
| 5213 | } |
| 5214 | |
| 5215 | void InstructionCodeGeneratorARMVIXL::VisitParameterValue( |
| 5216 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 5217 | // Nothing to do, the parameter is already at its location. |
| 5218 | } |
| 5219 | |
| 5220 | void LocationsBuilderARMVIXL::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5221 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5222 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5223 | locations->SetOut(LocationFrom(kMethodRegister)); |
| 5224 | } |
| 5225 | |
| 5226 | void InstructionCodeGeneratorARMVIXL::VisitCurrentMethod( |
| 5227 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5228 | // Nothing to do, the method is already at its location. |
| 5229 | } |
| 5230 | |
| 5231 | void LocationsBuilderARMVIXL::VisitNot(HNot* not_) { |
| 5232 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5233 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5234 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5235 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5236 | } |
| 5237 | |
| 5238 | void InstructionCodeGeneratorARMVIXL::VisitNot(HNot* not_) { |
| 5239 | LocationSummary* locations = not_->GetLocations(); |
| 5240 | Location out = locations->Out(); |
| 5241 | Location in = locations->InAt(0); |
| 5242 | switch (not_->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5243 | case DataType::Type::kInt32: |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5244 | __ Mvn(OutputRegister(not_), InputRegisterAt(not_, 0)); |
| 5245 | break; |
| 5246 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5247 | case DataType::Type::kInt64: |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5248 | __ Mvn(LowRegisterFrom(out), LowRegisterFrom(in)); |
| 5249 | __ Mvn(HighRegisterFrom(out), HighRegisterFrom(in)); |
| 5250 | break; |
| 5251 | |
| 5252 | default: |
| 5253 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 5254 | } |
| 5255 | } |
| 5256 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5257 | void LocationsBuilderARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5258 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5259 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5260 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5261 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5262 | } |
| 5263 | |
| 5264 | void InstructionCodeGeneratorARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5265 | __ Eor(OutputRegister(bool_not), InputRegister(bool_not), 1); |
| 5266 | } |
| 5267 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5268 | void LocationsBuilderARMVIXL::VisitCompare(HCompare* compare) { |
| 5269 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5270 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5271 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5272 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5273 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5274 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5275 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5276 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5277 | case DataType::Type::kInt32: |
| 5278 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5279 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5280 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5281 | // Output overlaps because it is written before doing the low comparison. |
| 5282 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5283 | break; |
| 5284 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5285 | case DataType::Type::kFloat32: |
| 5286 | case DataType::Type::kFloat64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5287 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5288 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
| 5289 | locations->SetOut(Location::RequiresRegister()); |
| 5290 | break; |
| 5291 | } |
| 5292 | default: |
| 5293 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 5294 | } |
| 5295 | } |
| 5296 | |
| 5297 | void InstructionCodeGeneratorARMVIXL::VisitCompare(HCompare* compare) { |
| 5298 | LocationSummary* locations = compare->GetLocations(); |
| 5299 | vixl32::Register out = OutputRegister(compare); |
| 5300 | Location left = locations->InAt(0); |
| 5301 | Location right = locations->InAt(1); |
| 5302 | |
| 5303 | vixl32::Label less, greater, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5304 | vixl32::Label* final_label = codegen_->GetFinalLabel(compare, &done); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5305 | DataType::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 5306 | vixl32::Condition less_cond = vixl32::Condition::None(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5307 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5308 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5309 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5310 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5311 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5312 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5313 | case DataType::Type::kInt32: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5314 | // Emit move to `out` before the `Cmp`, as `Mov` might affect the status flags. |
| 5315 | __ Mov(out, 0); |
| 5316 | __ Cmp(RegisterFrom(left), RegisterFrom(right)); // Signed compare. |
| 5317 | less_cond = lt; |
| 5318 | break; |
| 5319 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5320 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5321 | __ Cmp(HighRegisterFrom(left), HighRegisterFrom(right)); // Signed compare. |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 5322 | __ B(lt, &less, /* far_target */ false); |
| 5323 | __ B(gt, &greater, /* far_target */ false); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5324 | // Emit move to `out` before the last `Cmp`, as `Mov` might affect the status flags. |
| 5325 | __ Mov(out, 0); |
| 5326 | __ Cmp(LowRegisterFrom(left), LowRegisterFrom(right)); // Unsigned compare. |
| 5327 | less_cond = lo; |
| 5328 | break; |
| 5329 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5330 | case DataType::Type::kFloat32: |
| 5331 | case DataType::Type::kFloat64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5332 | __ Mov(out, 0); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 5333 | GenerateVcmp(compare, codegen_); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5334 | // To branch on the FP compare result we transfer FPSCR to APSR (encoded as PC in VMRS). |
| 5335 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 5336 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
| 5337 | break; |
| 5338 | } |
| 5339 | default: |
| 5340 | LOG(FATAL) << "Unexpected compare type " << type; |
| 5341 | UNREACHABLE(); |
| 5342 | } |
| 5343 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5344 | __ B(eq, final_label, /* far_target */ false); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 5345 | __ B(less_cond, &less, /* far_target */ false); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5346 | |
| 5347 | __ Bind(&greater); |
| 5348 | __ Mov(out, 1); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5349 | __ B(final_label); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5350 | |
| 5351 | __ Bind(&less); |
| 5352 | __ Mov(out, -1); |
| 5353 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5354 | if (done.IsReferenced()) { |
| 5355 | __ Bind(&done); |
| 5356 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5357 | } |
| 5358 | |
| 5359 | void LocationsBuilderARMVIXL::VisitPhi(HPhi* instruction) { |
| 5360 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5361 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5362 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| 5363 | locations->SetInAt(i, Location::Any()); |
| 5364 | } |
| 5365 | locations->SetOut(Location::Any()); |
| 5366 | } |
| 5367 | |
| 5368 | void InstructionCodeGeneratorARMVIXL::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 5369 | LOG(FATAL) << "Unreachable"; |
| 5370 | } |
| 5371 | |
| 5372 | void CodeGeneratorARMVIXL::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 5373 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 5374 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
| 5375 | switch (kind) { |
| 5376 | case MemBarrierKind::kAnyStore: |
| 5377 | case MemBarrierKind::kLoadAny: |
| 5378 | case MemBarrierKind::kAnyAny: { |
| 5379 | flavor = DmbOptions::ISH; |
| 5380 | break; |
| 5381 | } |
| 5382 | case MemBarrierKind::kStoreStore: { |
| 5383 | flavor = DmbOptions::ISHST; |
| 5384 | break; |
| 5385 | } |
| 5386 | default: |
| 5387 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 5388 | } |
| 5389 | __ Dmb(flavor); |
| 5390 | } |
| 5391 | |
| 5392 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicLoad(vixl32::Register addr, |
| 5393 | uint32_t offset, |
| 5394 | vixl32::Register out_lo, |
| 5395 | vixl32::Register out_hi) { |
| 5396 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5397 | if (offset != 0) { |
| 5398 | vixl32::Register temp = temps.Acquire(); |
| 5399 | __ Add(temp, addr, offset); |
| 5400 | addr = temp; |
| 5401 | } |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5402 | __ Ldrexd(out_lo, out_hi, MemOperand(addr)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5403 | } |
| 5404 | |
| 5405 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicStore(vixl32::Register addr, |
| 5406 | uint32_t offset, |
| 5407 | vixl32::Register value_lo, |
| 5408 | vixl32::Register value_hi, |
| 5409 | vixl32::Register temp1, |
| 5410 | vixl32::Register temp2, |
| 5411 | HInstruction* instruction) { |
| 5412 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5413 | vixl32::Label fail; |
| 5414 | if (offset != 0) { |
| 5415 | vixl32::Register temp = temps.Acquire(); |
| 5416 | __ Add(temp, addr, offset); |
| 5417 | addr = temp; |
| 5418 | } |
| 5419 | __ Bind(&fail); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5420 | { |
| 5421 | // Ensure the pc position is recorded immediately after the `ldrexd` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5422 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5423 | vixl32::kMaxInstructionSizeInBytes, |
| 5424 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5425 | // We need a load followed by store. (The address used in a STREX instruction must |
| 5426 | // be the same as the address in the most recently executed LDREX instruction.) |
| 5427 | __ ldrexd(temp1, temp2, MemOperand(addr)); |
| 5428 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5429 | } |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5430 | __ Strexd(temp1, value_lo, value_hi, MemOperand(addr)); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5431 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5432 | } |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5433 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5434 | void LocationsBuilderARMVIXL::HandleFieldSet( |
| 5435 | HInstruction* instruction, const FieldInfo& field_info) { |
| 5436 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5437 | |
| 5438 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5439 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5440 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5441 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5442 | DataType::Type field_type = field_info.GetFieldType(); |
| 5443 | if (DataType::IsFloatingPointType(field_type)) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5444 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5445 | } else { |
| 5446 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5447 | } |
| 5448 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5449 | 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] | 5450 | bool generate_volatile = field_info.IsVolatile() |
| 5451 | && is_wide |
| 5452 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5453 | bool needs_write_barrier = |
| 5454 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 5455 | // Temporary registers for the write barrier. |
| 5456 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
| 5457 | if (needs_write_barrier) { |
| 5458 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
| 5459 | locations->AddTemp(Location::RequiresRegister()); |
| 5460 | } else if (generate_volatile) { |
| 5461 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 5462 | // - registers need to be consecutive |
| 5463 | // - the first register should be even but not R14. |
| 5464 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5465 | // revisit this if we ever enable ARM encoding. |
| 5466 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5467 | |
| 5468 | locations->AddTemp(Location::RequiresRegister()); |
| 5469 | locations->AddTemp(Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5470 | if (field_type == DataType::Type::kFloat64) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5471 | // For doubles we need two more registers to copy the value. |
| 5472 | locations->AddTemp(LocationFrom(r2)); |
| 5473 | locations->AddTemp(LocationFrom(r3)); |
| 5474 | } |
| 5475 | } |
| 5476 | } |
| 5477 | |
| 5478 | void InstructionCodeGeneratorARMVIXL::HandleFieldSet(HInstruction* instruction, |
| 5479 | const FieldInfo& field_info, |
| 5480 | bool value_can_be_null) { |
| 5481 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5482 | |
| 5483 | LocationSummary* locations = instruction->GetLocations(); |
| 5484 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 5485 | Location value = locations->InAt(1); |
| 5486 | |
| 5487 | bool is_volatile = field_info.IsVolatile(); |
| 5488 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5489 | DataType::Type field_type = field_info.GetFieldType(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5490 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5491 | bool needs_write_barrier = |
| 5492 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 5493 | |
| 5494 | if (is_volatile) { |
| 5495 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 5496 | } |
| 5497 | |
| 5498 | switch (field_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5499 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5500 | case DataType::Type::kUint8: |
| 5501 | case DataType::Type::kInt8: |
| 5502 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5503 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5504 | case DataType::Type::kInt32: { |
| 5505 | StoreOperandType operand_type = GetStoreOperandType(field_type); |
| 5506 | GetAssembler()->StoreToOffset(operand_type, RegisterFrom(value), base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5507 | break; |
| 5508 | } |
| 5509 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5510 | case DataType::Type::kReference: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5511 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5512 | // Note that in the case where `value` is a null reference, |
| 5513 | // we do not enter this block, as a null reference does not |
| 5514 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5515 | DCHECK_EQ(field_type, DataType::Type::kReference); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5516 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5517 | __ Mov(temp, RegisterFrom(value)); |
| 5518 | GetAssembler()->PoisonHeapReference(temp); |
| 5519 | GetAssembler()->StoreToOffset(kStoreWord, temp, base, offset); |
| 5520 | } else { |
| 5521 | GetAssembler()->StoreToOffset(kStoreWord, RegisterFrom(value), base, offset); |
| 5522 | } |
| 5523 | break; |
| 5524 | } |
| 5525 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5526 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5527 | if (is_volatile && !atomic_ldrd_strd) { |
| 5528 | GenerateWideAtomicStore(base, |
| 5529 | offset, |
| 5530 | LowRegisterFrom(value), |
| 5531 | HighRegisterFrom(value), |
| 5532 | RegisterFrom(locations->GetTemp(0)), |
| 5533 | RegisterFrom(locations->GetTemp(1)), |
| 5534 | instruction); |
| 5535 | } else { |
| 5536 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), base, offset); |
| 5537 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5538 | } |
| 5539 | break; |
| 5540 | } |
| 5541 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5542 | case DataType::Type::kFloat32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5543 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), base, offset); |
| 5544 | break; |
| 5545 | } |
| 5546 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5547 | case DataType::Type::kFloat64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5548 | vixl32::DRegister value_reg = DRegisterFrom(value); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5549 | if (is_volatile && !atomic_ldrd_strd) { |
| 5550 | vixl32::Register value_reg_lo = RegisterFrom(locations->GetTemp(0)); |
| 5551 | vixl32::Register value_reg_hi = RegisterFrom(locations->GetTemp(1)); |
| 5552 | |
| 5553 | __ Vmov(value_reg_lo, value_reg_hi, value_reg); |
| 5554 | |
| 5555 | GenerateWideAtomicStore(base, |
| 5556 | offset, |
| 5557 | value_reg_lo, |
| 5558 | value_reg_hi, |
| 5559 | RegisterFrom(locations->GetTemp(2)), |
| 5560 | RegisterFrom(locations->GetTemp(3)), |
| 5561 | instruction); |
| 5562 | } else { |
| 5563 | GetAssembler()->StoreDToOffset(value_reg, base, offset); |
| 5564 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5565 | } |
| 5566 | break; |
| 5567 | } |
| 5568 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5569 | case DataType::Type::kVoid: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5570 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5571 | UNREACHABLE(); |
| 5572 | } |
| 5573 | |
| 5574 | // Longs and doubles are handled in the switch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5575 | if (field_type != DataType::Type::kInt64 && field_type != DataType::Type::kFloat64) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5576 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, we |
| 5577 | // should use a scope and the assembler to emit the store instruction to guarantee that we |
| 5578 | // record the pc at the correct position. But the `Assembler` does not automatically handle |
| 5579 | // unencodable offsets. Practically, everything is fine because the helper and VIXL, at the time |
| 5580 | // of writing, do generate the store instruction last. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5581 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5582 | } |
| 5583 | |
| 5584 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5585 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5586 | vixl32::Register card = RegisterFrom(locations->GetTemp(1)); |
| 5587 | codegen_->MarkGCCard(temp, card, base, RegisterFrom(value), value_can_be_null); |
| 5588 | } |
| 5589 | |
| 5590 | if (is_volatile) { |
| 5591 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 5592 | } |
| 5593 | } |
| 5594 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5595 | void LocationsBuilderARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 5596 | const FieldInfo& field_info) { |
| 5597 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 5598 | |
| 5599 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5600 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == DataType::Type::kReference); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5601 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5602 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5603 | object_field_get_with_read_barrier |
| 5604 | ? LocationSummary::kCallOnSlowPath |
| 5605 | : LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5606 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5607 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 5608 | } |
| 5609 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5610 | |
| 5611 | bool volatile_for_double = field_info.IsVolatile() |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5612 | && (field_info.GetFieldType() == DataType::Type::kFloat64) |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5613 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5614 | // The output overlaps in case of volatile long: we don't want the |
| 5615 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 5616 | // object's location. Likewise, in the case of an object field get |
| 5617 | // with read barriers enabled, we do not want the load to overwrite |
| 5618 | // 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] | 5619 | bool overlap = |
| 5620 | (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) || |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5621 | object_field_get_with_read_barrier; |
| 5622 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5623 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5624 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5625 | } else { |
| 5626 | locations->SetOut(Location::RequiresRegister(), |
| 5627 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 5628 | } |
| 5629 | if (volatile_for_double) { |
| 5630 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 5631 | // - registers need to be consecutive |
| 5632 | // - the first register should be even but not R14. |
| 5633 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5634 | // revisit this if we ever enable ARM encoding. |
| 5635 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5636 | locations->AddTemp(Location::RequiresRegister()); |
| 5637 | locations->AddTemp(Location::RequiresRegister()); |
| 5638 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5639 | // We need a temporary register for the read barrier marking slow |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 5640 | // path in CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 5641 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 5642 | !Runtime::Current()->UseJitCompilation()) { |
| 5643 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 5644 | // loads we need a temporary only if the offset is too big. |
| 5645 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 5646 | locations->AddTemp(Location::RequiresRegister()); |
| 5647 | } |
| 5648 | // And we always need the reserved entrypoint register. |
| 5649 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 5650 | } else { |
| 5651 | locations->AddTemp(Location::RequiresRegister()); |
| 5652 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5653 | } |
| 5654 | } |
| 5655 | |
| 5656 | Location LocationsBuilderARMVIXL::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5657 | DCHECK(DataType::IsFloatingPointType(input->GetType())) << input->GetType(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5658 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 5659 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 5660 | return Location::ConstantLocation(input->AsConstant()); |
| 5661 | } else { |
| 5662 | return Location::RequiresFpuRegister(); |
| 5663 | } |
| 5664 | } |
| 5665 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5666 | Location LocationsBuilderARMVIXL::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 5667 | Opcode opcode) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5668 | DCHECK(!DataType::IsFloatingPointType(constant->GetType())); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5669 | if (constant->IsConstant() && |
| 5670 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 5671 | return Location::ConstantLocation(constant->AsConstant()); |
| 5672 | } |
| 5673 | return Location::RequiresRegister(); |
| 5674 | } |
| 5675 | |
| 5676 | bool LocationsBuilderARMVIXL::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 5677 | Opcode opcode) { |
| 5678 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5679 | if (DataType::Is64BitType(input_cst->GetType())) { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5680 | Opcode high_opcode = opcode; |
| 5681 | SetCc low_set_cc = kCcDontCare; |
| 5682 | switch (opcode) { |
| 5683 | case SUB: |
| 5684 | // Flip the operation to an ADD. |
| 5685 | value = -value; |
| 5686 | opcode = ADD; |
| 5687 | FALLTHROUGH_INTENDED; |
| 5688 | case ADD: |
| 5689 | if (Low32Bits(value) == 0u) { |
| 5690 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 5691 | } |
| 5692 | high_opcode = ADC; |
| 5693 | low_set_cc = kCcSet; |
| 5694 | break; |
| 5695 | default: |
| 5696 | break; |
| 5697 | } |
| 5698 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 5699 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
| 5700 | } else { |
| 5701 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 5702 | } |
| 5703 | } |
| 5704 | |
| 5705 | // TODO(VIXL): Replace art::arm::SetCc` with `vixl32::FlagsUpdate after flags set optimization |
| 5706 | // enabled. |
| 5707 | bool LocationsBuilderARMVIXL::CanEncodeConstantAsImmediate(uint32_t value, |
| 5708 | Opcode opcode, |
| 5709 | SetCc set_cc) { |
| 5710 | ArmVIXLAssembler* assembler = codegen_->GetAssembler(); |
| 5711 | if (assembler->ShifterOperandCanHold(opcode, value, set_cc)) { |
| 5712 | return true; |
| 5713 | } |
| 5714 | Opcode neg_opcode = kNoOperand; |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5715 | uint32_t neg_value = 0; |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5716 | switch (opcode) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5717 | case AND: neg_opcode = BIC; neg_value = ~value; break; |
| 5718 | case ORR: neg_opcode = ORN; neg_value = ~value; break; |
| 5719 | case ADD: neg_opcode = SUB; neg_value = -value; break; |
| 5720 | case ADC: neg_opcode = SBC; neg_value = ~value; break; |
| 5721 | case SUB: neg_opcode = ADD; neg_value = -value; break; |
| 5722 | case SBC: neg_opcode = ADC; neg_value = ~value; break; |
| 5723 | case MOV: neg_opcode = MVN; neg_value = ~value; break; |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5724 | default: |
| 5725 | return false; |
| 5726 | } |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5727 | |
| 5728 | if (assembler->ShifterOperandCanHold(neg_opcode, neg_value, set_cc)) { |
| 5729 | return true; |
| 5730 | } |
| 5731 | |
| 5732 | return opcode == AND && IsPowerOfTwo(value + 1); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5733 | } |
| 5734 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5735 | void InstructionCodeGeneratorARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 5736 | const FieldInfo& field_info) { |
| 5737 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 5738 | |
| 5739 | LocationSummary* locations = instruction->GetLocations(); |
| 5740 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 5741 | Location out = locations->Out(); |
| 5742 | bool is_volatile = field_info.IsVolatile(); |
| 5743 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5744 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 5745 | DataType::Type load_type = instruction->GetType(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5746 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5747 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5748 | switch (load_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5749 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5750 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5751 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5752 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5753 | case DataType::Type::kInt16: |
| 5754 | case DataType::Type::kInt32: { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5755 | LoadOperandType operand_type = GetLoadOperandType(load_type); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5756 | GetAssembler()->LoadFromOffset(operand_type, RegisterFrom(out), base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5757 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5758 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5759 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5760 | case DataType::Type::kReference: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5761 | // /* HeapReference<Object> */ out = *(base + offset) |
| 5762 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5763 | Location temp_loc = locations->GetTemp(0); |
| 5764 | // Note that a potential implicit null check is handled in this |
| 5765 | // CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier call. |
| 5766 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 5767 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 5768 | if (is_volatile) { |
| 5769 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5770 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5771 | } else { |
| 5772 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(out), base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5773 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5774 | if (is_volatile) { |
| 5775 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5776 | } |
| 5777 | // If read barriers are enabled, emit read barriers other than |
| 5778 | // Baker's using a slow path (and also unpoison the loaded |
| 5779 | // reference, if heap poisoning is enabled). |
| 5780 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, locations->InAt(0), offset); |
| 5781 | } |
| 5782 | break; |
| 5783 | } |
| 5784 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5785 | case DataType::Type::kInt64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5786 | if (is_volatile && !atomic_ldrd_strd) { |
| 5787 | GenerateWideAtomicLoad(base, offset, LowRegisterFrom(out), HighRegisterFrom(out)); |
| 5788 | } else { |
| 5789 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out), base, offset); |
| 5790 | } |
| 5791 | break; |
| 5792 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5793 | case DataType::Type::kFloat32: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5794 | GetAssembler()->LoadSFromOffset(SRegisterFrom(out), base, offset); |
| 5795 | break; |
| 5796 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5797 | case DataType::Type::kFloat64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5798 | vixl32::DRegister out_dreg = DRegisterFrom(out); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5799 | if (is_volatile && !atomic_ldrd_strd) { |
| 5800 | vixl32::Register lo = RegisterFrom(locations->GetTemp(0)); |
| 5801 | vixl32::Register hi = RegisterFrom(locations->GetTemp(1)); |
| 5802 | GenerateWideAtomicLoad(base, offset, lo, hi); |
| 5803 | // TODO(VIXL): Do we need to be immediately after the ldrexd instruction? If so we need a |
| 5804 | // scope. |
| 5805 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5806 | __ Vmov(out_dreg, lo, hi); |
| 5807 | } else { |
| 5808 | GetAssembler()->LoadDFromOffset(out_dreg, base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5809 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5810 | } |
| 5811 | break; |
| 5812 | } |
| 5813 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5814 | case DataType::Type::kVoid: |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5815 | LOG(FATAL) << "Unreachable type " << load_type; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5816 | UNREACHABLE(); |
| 5817 | } |
| 5818 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5819 | if (load_type == DataType::Type::kReference || load_type == DataType::Type::kFloat64) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5820 | // Potential implicit null checks, in the case of reference or |
| 5821 | // double fields, are handled in the previous switch statement. |
| 5822 | } else { |
| 5823 | // 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] | 5824 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, we |
| 5825 | // should use a scope and the assembler to emit the load instruction to guarantee that we |
| 5826 | // record the pc at the correct position. But the `Assembler` does not automatically handle |
| 5827 | // unencodable offsets. Practically, everything is fine because the helper and VIXL, at the time |
| 5828 | // of writing, do generate the store instruction last. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5829 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5830 | } |
| 5831 | |
| 5832 | if (is_volatile) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5833 | if (load_type == DataType::Type::kReference) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5834 | // Memory barriers, in the case of references, are also handled |
| 5835 | // in the previous switch statement. |
| 5836 | } else { |
| 5837 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5838 | } |
| 5839 | } |
| 5840 | } |
| 5841 | |
| 5842 | void LocationsBuilderARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5843 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5844 | } |
| 5845 | |
| 5846 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5847 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 5848 | } |
| 5849 | |
| 5850 | void LocationsBuilderARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5851 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5852 | } |
| 5853 | |
| 5854 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5855 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5856 | } |
| 5857 | |
| 5858 | void LocationsBuilderARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5859 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5860 | } |
| 5861 | |
| 5862 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5863 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5864 | } |
| 5865 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5866 | void LocationsBuilderARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5867 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5868 | } |
| 5869 | |
| 5870 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5871 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 5872 | } |
| 5873 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 5874 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 5875 | HUnresolvedInstanceFieldGet* instruction) { |
| 5876 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5877 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5878 | instruction, instruction->GetFieldType(), calling_convention); |
| 5879 | } |
| 5880 | |
| 5881 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 5882 | HUnresolvedInstanceFieldGet* instruction) { |
| 5883 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5884 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5885 | instruction->GetFieldType(), |
| 5886 | instruction->GetFieldIndex(), |
| 5887 | instruction->GetDexPc(), |
| 5888 | calling_convention); |
| 5889 | } |
| 5890 | |
| 5891 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 5892 | HUnresolvedInstanceFieldSet* instruction) { |
| 5893 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5894 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5895 | instruction, instruction->GetFieldType(), calling_convention); |
| 5896 | } |
| 5897 | |
| 5898 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 5899 | HUnresolvedInstanceFieldSet* instruction) { |
| 5900 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5901 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5902 | instruction->GetFieldType(), |
| 5903 | instruction->GetFieldIndex(), |
| 5904 | instruction->GetDexPc(), |
| 5905 | calling_convention); |
| 5906 | } |
| 5907 | |
| 5908 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldGet( |
| 5909 | HUnresolvedStaticFieldGet* instruction) { |
| 5910 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5911 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5912 | instruction, instruction->GetFieldType(), calling_convention); |
| 5913 | } |
| 5914 | |
| 5915 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldGet( |
| 5916 | HUnresolvedStaticFieldGet* instruction) { |
| 5917 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5918 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5919 | instruction->GetFieldType(), |
| 5920 | instruction->GetFieldIndex(), |
| 5921 | instruction->GetDexPc(), |
| 5922 | calling_convention); |
| 5923 | } |
| 5924 | |
| 5925 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldSet( |
| 5926 | HUnresolvedStaticFieldSet* instruction) { |
| 5927 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5928 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5929 | instruction, instruction->GetFieldType(), calling_convention); |
| 5930 | } |
| 5931 | |
| 5932 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldSet( |
| 5933 | HUnresolvedStaticFieldSet* instruction) { |
| 5934 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5935 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5936 | instruction->GetFieldType(), |
| 5937 | instruction->GetFieldIndex(), |
| 5938 | instruction->GetDexPc(), |
| 5939 | calling_convention); |
| 5940 | } |
| 5941 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5942 | void LocationsBuilderARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 5943 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5944 | locations->SetInAt(0, Location::RequiresRegister()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5945 | } |
| 5946 | |
| 5947 | void CodeGeneratorARMVIXL::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5948 | if (CanMoveNullCheckToUser(instruction)) { |
| 5949 | return; |
| 5950 | } |
| 5951 | |
| 5952 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5953 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5954 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5955 | vixl32::kMaxInstructionSizeInBytes, |
| 5956 | CodeBufferCheckScope::kMaximumSize); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5957 | __ ldr(temps.Acquire(), MemOperand(InputRegisterAt(instruction, 0))); |
| 5958 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5959 | } |
| 5960 | |
| 5961 | void CodeGeneratorARMVIXL::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| 5962 | NullCheckSlowPathARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5963 | new (GetScopedAllocator()) NullCheckSlowPathARMVIXL(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5964 | AddSlowPath(slow_path); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5965 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5966 | } |
| 5967 | |
| 5968 | void InstructionCodeGeneratorARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
| 5969 | codegen_->GenerateNullCheck(instruction); |
| 5970 | } |
| 5971 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5972 | void CodeGeneratorARMVIXL::LoadFromShiftedRegOffset(DataType::Type type, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5973 | Location out_loc, |
| 5974 | vixl32::Register base, |
| 5975 | vixl32::Register reg_index, |
| 5976 | vixl32::Condition cond) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5977 | uint32_t shift_count = DataType::SizeShift(type); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5978 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 5979 | |
| 5980 | switch (type) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5981 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5982 | case DataType::Type::kUint8: |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5983 | __ Ldrb(cond, RegisterFrom(out_loc), mem_address); |
| 5984 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5985 | case DataType::Type::kInt8: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5986 | __ Ldrsb(cond, RegisterFrom(out_loc), mem_address); |
| 5987 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5988 | case DataType::Type::kUint16: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5989 | __ Ldrh(cond, RegisterFrom(out_loc), mem_address); |
| 5990 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5991 | case DataType::Type::kInt16: |
| 5992 | __ Ldrsh(cond, RegisterFrom(out_loc), mem_address); |
| 5993 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5994 | case DataType::Type::kReference: |
| 5995 | case DataType::Type::kInt32: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5996 | __ Ldr(cond, RegisterFrom(out_loc), mem_address); |
| 5997 | break; |
| 5998 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5999 | case DataType::Type::kInt64: |
| 6000 | case DataType::Type::kFloat32: |
| 6001 | case DataType::Type::kFloat64: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6002 | default: |
| 6003 | LOG(FATAL) << "Unreachable type " << type; |
| 6004 | UNREACHABLE(); |
| 6005 | } |
| 6006 | } |
| 6007 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6008 | void CodeGeneratorARMVIXL::StoreToShiftedRegOffset(DataType::Type type, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6009 | Location loc, |
| 6010 | vixl32::Register base, |
| 6011 | vixl32::Register reg_index, |
| 6012 | vixl32::Condition cond) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6013 | uint32_t shift_count = DataType::SizeShift(type); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6014 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 6015 | |
| 6016 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6017 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6018 | case DataType::Type::kUint8: |
| 6019 | case DataType::Type::kInt8: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6020 | __ Strb(cond, RegisterFrom(loc), mem_address); |
| 6021 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6022 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6023 | case DataType::Type::kInt16: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6024 | __ Strh(cond, RegisterFrom(loc), mem_address); |
| 6025 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6026 | case DataType::Type::kReference: |
| 6027 | case DataType::Type::kInt32: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6028 | __ Str(cond, RegisterFrom(loc), mem_address); |
| 6029 | break; |
| 6030 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6031 | case DataType::Type::kInt64: |
| 6032 | case DataType::Type::kFloat32: |
| 6033 | case DataType::Type::kFloat64: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6034 | default: |
| 6035 | LOG(FATAL) << "Unreachable type " << type; |
| 6036 | UNREACHABLE(); |
| 6037 | } |
| 6038 | } |
| 6039 | |
| 6040 | void LocationsBuilderARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
| 6041 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6042 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6043 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6044 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 6045 | object_array_get_with_read_barrier |
| 6046 | ? LocationSummary::kCallOnSlowPath |
| 6047 | : LocationSummary::kNoCall); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6048 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6049 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6050 | } |
| 6051 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6052 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6053 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6054 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6055 | } else { |
| 6056 | // The output overlaps in the case of an object array get with |
| 6057 | // read barriers enabled: we do not want the move to overwrite the |
| 6058 | // array's location, as we need it to emit the read barrier. |
| 6059 | locations->SetOut( |
| 6060 | Location::RequiresRegister(), |
| 6061 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 6062 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6063 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 6064 | // We need a temporary register for the read barrier marking slow |
| 6065 | // path in CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier. |
| 6066 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 6067 | !Runtime::Current()->UseJitCompilation() && |
| 6068 | instruction->GetIndex()->IsConstant()) { |
| 6069 | // Array loads with constant index are treated as field loads. |
| 6070 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 6071 | // constant index loads we need a temporary only if the offset is too big. |
| 6072 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 6073 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6074 | offset += index << DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6075 | if (offset >= kReferenceLoadMinFarOffset) { |
| 6076 | locations->AddTemp(Location::RequiresRegister()); |
| 6077 | } |
| 6078 | // And we always need the reserved entrypoint register. |
| 6079 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 6080 | } else if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 6081 | !Runtime::Current()->UseJitCompilation() && |
| 6082 | !instruction->GetIndex()->IsConstant()) { |
| 6083 | // We need a non-scratch temporary for the array data pointer. |
| 6084 | locations->AddTemp(Location::RequiresRegister()); |
| 6085 | // And we always need the reserved entrypoint register. |
| 6086 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 6087 | } else { |
| 6088 | locations->AddTemp(Location::RequiresRegister()); |
| 6089 | } |
| 6090 | } else if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 6091 | // Also need a temporary for String compression feature. |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6092 | locations->AddTemp(Location::RequiresRegister()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6093 | } |
| 6094 | } |
| 6095 | |
| 6096 | void InstructionCodeGeneratorARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6097 | LocationSummary* locations = instruction->GetLocations(); |
| 6098 | Location obj_loc = locations->InAt(0); |
| 6099 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 6100 | Location index = locations->InAt(1); |
| 6101 | Location out_loc = locations->Out(); |
| 6102 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6103 | DataType::Type type = instruction->GetType(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6104 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 6105 | instruction->IsStringCharAt(); |
| 6106 | HInstruction* array_instr = instruction->GetArray(); |
| 6107 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6108 | |
| 6109 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6110 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6111 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6112 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6113 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6114 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6115 | case DataType::Type::kInt32: { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6116 | vixl32::Register length; |
| 6117 | if (maybe_compressed_char_at) { |
| 6118 | length = RegisterFrom(locations->GetTemp(0)); |
| 6119 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 6120 | GetAssembler()->LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 6121 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6122 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6123 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6124 | int32_t const_index = Int32ConstantFrom(index); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6125 | if (maybe_compressed_char_at) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6126 | vixl32::Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6127 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6128 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 6129 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6130 | "Expecting 0=compressed, 1=uncompressed"); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 6131 | __ B(cs, &uncompressed_load, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6132 | GetAssembler()->LoadFromOffset(kLoadUnsignedByte, |
| 6133 | RegisterFrom(out_loc), |
| 6134 | obj, |
| 6135 | data_offset + const_index); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6136 | __ B(final_label); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6137 | __ Bind(&uncompressed_load); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6138 | GetAssembler()->LoadFromOffset(GetLoadOperandType(DataType::Type::kUint16), |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6139 | RegisterFrom(out_loc), |
| 6140 | obj, |
| 6141 | data_offset + (const_index << 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6142 | if (done.IsReferenced()) { |
| 6143 | __ Bind(&done); |
| 6144 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6145 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6146 | uint32_t full_offset = data_offset + (const_index << DataType::SizeShift(type)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6147 | |
| 6148 | LoadOperandType load_type = GetLoadOperandType(type); |
| 6149 | GetAssembler()->LoadFromOffset(load_type, RegisterFrom(out_loc), obj, full_offset); |
| 6150 | } |
| 6151 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6152 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6153 | vixl32::Register temp = temps.Acquire(); |
| 6154 | |
| 6155 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6156 | // We do not need to compute the intermediate address from the array: the |
| 6157 | // input instruction has done it already. See the comment in |
| 6158 | // `TryExtractArrayAccessAddress()`. |
| 6159 | if (kIsDebugBuild) { |
| 6160 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6161 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6162 | } |
| 6163 | temp = obj; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6164 | } else { |
| 6165 | __ Add(temp, obj, data_offset); |
| 6166 | } |
| 6167 | if (maybe_compressed_char_at) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6168 | vixl32::Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6169 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6170 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 6171 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6172 | "Expecting 0=compressed, 1=uncompressed"); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 6173 | __ B(cs, &uncompressed_load, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6174 | __ Ldrb(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 0)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6175 | __ B(final_label); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6176 | __ Bind(&uncompressed_load); |
| 6177 | __ Ldrh(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6178 | if (done.IsReferenced()) { |
| 6179 | __ Bind(&done); |
| 6180 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6181 | } else { |
| 6182 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
| 6183 | } |
| 6184 | } |
| 6185 | break; |
| 6186 | } |
| 6187 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6188 | case DataType::Type::kReference: { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6189 | // The read barrier instrumentation of object ArrayGet |
| 6190 | // instructions does not support the HIntermediateAddress |
| 6191 | // instruction. |
| 6192 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 6193 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6194 | static_assert( |
| 6195 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6196 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 6197 | // /* HeapReference<Object> */ out = |
| 6198 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6199 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6200 | Location temp = locations->GetTemp(0); |
| 6201 | // Note that a potential implicit null check is handled in this |
| 6202 | // CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6203 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 6204 | if (index.IsConstant()) { |
| 6205 | // 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] | 6206 | data_offset += Int32ConstantFrom(index) << DataType::SizeShift(type); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6207 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6208 | out_loc, |
| 6209 | obj, |
| 6210 | data_offset, |
| 6211 | locations->GetTemp(0), |
| 6212 | /* needs_null_check */ false); |
| 6213 | } else { |
| 6214 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 6215 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ false); |
| 6216 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6217 | } else { |
| 6218 | vixl32::Register out = OutputRegister(instruction); |
| 6219 | if (index.IsConstant()) { |
| 6220 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6221 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6222 | GetAssembler()->LoadFromOffset(kLoadWord, out, obj, offset); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6223 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, |
| 6224 | // we should use a scope and the assembler to emit the load instruction to guarantee that |
| 6225 | // we record the pc at the correct position. But the `Assembler` does not automatically |
| 6226 | // handle unencodable offsets. Practically, everything is fine because the helper and |
| 6227 | // VIXL, at the time of writing, do generate the store instruction last. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6228 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6229 | // If read barriers are enabled, emit read barriers other than |
| 6230 | // Baker's using a slow path (and also unpoison the loaded |
| 6231 | // reference, if heap poisoning is enabled). |
| 6232 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 6233 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6234 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6235 | vixl32::Register temp = temps.Acquire(); |
| 6236 | |
| 6237 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6238 | // We do not need to compute the intermediate address from the array: the |
| 6239 | // input instruction has done it already. See the comment in |
| 6240 | // `TryExtractArrayAccessAddress()`. |
| 6241 | if (kIsDebugBuild) { |
| 6242 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6243 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6244 | } |
| 6245 | temp = obj; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6246 | } else { |
| 6247 | __ Add(temp, obj, data_offset); |
| 6248 | } |
| 6249 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6250 | temps.Close(); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6251 | // TODO(VIXL): Use a scope to ensure that we record the pc position immediately after the |
| 6252 | // load instruction. Practically, everything is fine because the helper and VIXL, at the |
| 6253 | // time of writing, do generate the store instruction last. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6254 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6255 | // If read barriers are enabled, emit read barriers other than |
| 6256 | // Baker's using a slow path (and also unpoison the loaded |
| 6257 | // reference, if heap poisoning is enabled). |
| 6258 | codegen_->MaybeGenerateReadBarrierSlow( |
| 6259 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 6260 | } |
| 6261 | } |
| 6262 | break; |
| 6263 | } |
| 6264 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6265 | case DataType::Type::kInt64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6266 | if (index.IsConstant()) { |
| 6267 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6268 | (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6269 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), obj, offset); |
| 6270 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6271 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6272 | vixl32::Register temp = temps.Acquire(); |
| 6273 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6274 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), temp, data_offset); |
| 6275 | } |
| 6276 | break; |
| 6277 | } |
| 6278 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6279 | case DataType::Type::kFloat32: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6280 | vixl32::SRegister out = SRegisterFrom(out_loc); |
| 6281 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6282 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6283 | GetAssembler()->LoadSFromOffset(out, obj, offset); |
| 6284 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6285 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6286 | vixl32::Register temp = temps.Acquire(); |
| 6287 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 6288 | GetAssembler()->LoadSFromOffset(out, temp, data_offset); |
| 6289 | } |
| 6290 | break; |
| 6291 | } |
| 6292 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6293 | case DataType::Type::kFloat64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6294 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6295 | size_t offset = (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6296 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), obj, offset); |
| 6297 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6298 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6299 | vixl32::Register temp = temps.Acquire(); |
| 6300 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6301 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), temp, data_offset); |
| 6302 | } |
| 6303 | break; |
| 6304 | } |
| 6305 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6306 | case DataType::Type::kVoid: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6307 | LOG(FATAL) << "Unreachable type " << type; |
| 6308 | UNREACHABLE(); |
| 6309 | } |
| 6310 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6311 | if (type == DataType::Type::kReference) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6312 | // Potential implicit null checks, in the case of reference |
| 6313 | // arrays, are handled in the previous switch statement. |
| 6314 | } else if (!maybe_compressed_char_at) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6315 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after |
| 6316 | // the preceding load instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6317 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6318 | } |
| 6319 | } |
| 6320 | |
| 6321 | void LocationsBuilderARMVIXL::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6322 | DataType::Type value_type = instruction->GetComponentType(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6323 | |
| 6324 | bool needs_write_barrier = |
| 6325 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 6326 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 6327 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6328 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6329 | instruction, |
| 6330 | may_need_runtime_call_for_type_check ? |
| 6331 | LocationSummary::kCallOnSlowPath : |
| 6332 | LocationSummary::kNoCall); |
| 6333 | |
| 6334 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6335 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6336 | if (DataType::IsFloatingPointType(value_type)) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6337 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 6338 | } else { |
| 6339 | locations->SetInAt(2, Location::RequiresRegister()); |
| 6340 | } |
| 6341 | if (needs_write_barrier) { |
| 6342 | // Temporary registers for the write barrier. |
| 6343 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 6344 | locations->AddTemp(Location::RequiresRegister()); |
| 6345 | } |
| 6346 | } |
| 6347 | |
| 6348 | void InstructionCodeGeneratorARMVIXL::VisitArraySet(HArraySet* instruction) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6349 | LocationSummary* locations = instruction->GetLocations(); |
| 6350 | vixl32::Register array = InputRegisterAt(instruction, 0); |
| 6351 | Location index = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6352 | DataType::Type value_type = instruction->GetComponentType(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6353 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 6354 | bool needs_write_barrier = |
| 6355 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 6356 | uint32_t data_offset = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6357 | mirror::Array::DataOffset(DataType::Size(value_type)).Uint32Value(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6358 | Location value_loc = locations->InAt(2); |
| 6359 | HInstruction* array_instr = instruction->GetArray(); |
| 6360 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6361 | |
| 6362 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6363 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6364 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6365 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6366 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6367 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6368 | case DataType::Type::kInt32: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6369 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6370 | int32_t const_index = Int32ConstantFrom(index); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6371 | uint32_t full_offset = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6372 | data_offset + (const_index << DataType::SizeShift(value_type)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6373 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 6374 | GetAssembler()->StoreToOffset(store_type, RegisterFrom(value_loc), array, full_offset); |
| 6375 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6376 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6377 | vixl32::Register temp = temps.Acquire(); |
| 6378 | |
| 6379 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6380 | // We do not need to compute the intermediate address from the array: the |
| 6381 | // input instruction has done it already. See the comment in |
| 6382 | // `TryExtractArrayAccessAddress()`. |
| 6383 | if (kIsDebugBuild) { |
| 6384 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6385 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6386 | } |
| 6387 | temp = array; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6388 | } else { |
| 6389 | __ Add(temp, array, data_offset); |
| 6390 | } |
| 6391 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 6392 | } |
| 6393 | break; |
| 6394 | } |
| 6395 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6396 | case DataType::Type::kReference: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6397 | vixl32::Register value = RegisterFrom(value_loc); |
| 6398 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 6399 | // See the comment in instruction_simplifier_shared.cc. |
| 6400 | DCHECK(!has_intermediate_address); |
| 6401 | |
| 6402 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 6403 | // Just setting null. |
| 6404 | if (index.IsConstant()) { |
| 6405 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6406 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6407 | GetAssembler()->StoreToOffset(kStoreWord, value, array, offset); |
| 6408 | } else { |
| 6409 | DCHECK(index.IsRegister()) << index; |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6410 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6411 | vixl32::Register temp = temps.Acquire(); |
| 6412 | __ Add(temp, array, data_offset); |
| 6413 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 6414 | } |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6415 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after the preceding |
| 6416 | // store instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6417 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6418 | DCHECK(!needs_write_barrier); |
| 6419 | DCHECK(!may_need_runtime_call_for_type_check); |
| 6420 | break; |
| 6421 | } |
| 6422 | |
| 6423 | DCHECK(needs_write_barrier); |
| 6424 | Location temp1_loc = locations->GetTemp(0); |
| 6425 | vixl32::Register temp1 = RegisterFrom(temp1_loc); |
| 6426 | Location temp2_loc = locations->GetTemp(1); |
| 6427 | vixl32::Register temp2 = RegisterFrom(temp2_loc); |
| 6428 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6429 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6430 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6431 | vixl32::Label done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6432 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6433 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 6434 | |
| 6435 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6436 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathARMVIXL(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6437 | codegen_->AddSlowPath(slow_path); |
| 6438 | if (instruction->GetValueCanBeNull()) { |
| 6439 | vixl32::Label non_zero; |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6440 | __ CompareAndBranchIfNonZero(value, &non_zero); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6441 | if (index.IsConstant()) { |
| 6442 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6443 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6444 | GetAssembler()->StoreToOffset(kStoreWord, value, array, offset); |
| 6445 | } else { |
| 6446 | DCHECK(index.IsRegister()) << index; |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6447 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6448 | vixl32::Register temp = temps.Acquire(); |
| 6449 | __ Add(temp, array, data_offset); |
| 6450 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 6451 | } |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6452 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after the preceding |
| 6453 | // store instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6454 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6455 | __ B(final_label); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6456 | __ Bind(&non_zero); |
| 6457 | } |
| 6458 | |
| 6459 | // Note that when read barriers are enabled, the type checks |
| 6460 | // are performed without read barriers. This is fine, even in |
| 6461 | // the case where a class object is in the from-space after |
| 6462 | // the flip, as a comparison involving such a type would not |
| 6463 | // produce a false positive; it may of course produce a false |
| 6464 | // negative, in which case we would take the ArraySet slow |
| 6465 | // path. |
| 6466 | |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6467 | { |
| 6468 | // Ensure we record the pc position immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6469 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6470 | vixl32::kMaxInstructionSizeInBytes, |
| 6471 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6472 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 6473 | __ ldr(temp1, MemOperand(array, class_offset)); |
| 6474 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6475 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6476 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 6477 | |
| 6478 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 6479 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 6480 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 6481 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 6482 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 6483 | // nor `temp2`, as we are comparing two poisoned references. |
| 6484 | __ Cmp(temp1, temp2); |
| 6485 | |
| 6486 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 6487 | vixl32::Label do_put; |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 6488 | __ B(eq, &do_put, /* far_target */ false); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6489 | // If heap poisoning is enabled, the `temp1` reference has |
| 6490 | // not been unpoisoned yet; unpoison it now. |
| 6491 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 6492 | |
| 6493 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 6494 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 6495 | // If heap poisoning is enabled, no need to unpoison |
| 6496 | // `temp1`, as we are comparing against null below. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6497 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6498 | __ Bind(&do_put); |
| 6499 | } else { |
| 6500 | __ B(ne, slow_path->GetEntryLabel()); |
| 6501 | } |
| 6502 | } |
| 6503 | |
| 6504 | vixl32::Register source = value; |
| 6505 | if (kPoisonHeapReferences) { |
| 6506 | // Note that in the case where `value` is a null reference, |
| 6507 | // we do not enter this block, as a null reference does not |
| 6508 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6509 | DCHECK_EQ(value_type, DataType::Type::kReference); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6510 | __ Mov(temp1, value); |
| 6511 | GetAssembler()->PoisonHeapReference(temp1); |
| 6512 | source = temp1; |
| 6513 | } |
| 6514 | |
| 6515 | if (index.IsConstant()) { |
| 6516 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6517 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6518 | GetAssembler()->StoreToOffset(kStoreWord, source, array, offset); |
| 6519 | } else { |
| 6520 | DCHECK(index.IsRegister()) << index; |
| 6521 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6522 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6523 | vixl32::Register temp = temps.Acquire(); |
| 6524 | __ Add(temp, array, data_offset); |
| 6525 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6526 | LocationFrom(source), |
| 6527 | temp, |
| 6528 | RegisterFrom(index)); |
| 6529 | } |
| 6530 | |
| 6531 | if (!may_need_runtime_call_for_type_check) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6532 | // TODO(VIXL): Ensure we record the pc position immediately after the preceding store |
| 6533 | // instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6534 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6535 | } |
| 6536 | |
| 6537 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 6538 | |
| 6539 | if (done.IsReferenced()) { |
| 6540 | __ Bind(&done); |
| 6541 | } |
| 6542 | |
| 6543 | if (slow_path != nullptr) { |
| 6544 | __ Bind(slow_path->GetExitLabel()); |
| 6545 | } |
| 6546 | |
| 6547 | break; |
| 6548 | } |
| 6549 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6550 | case DataType::Type::kInt64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6551 | Location value = locations->InAt(2); |
| 6552 | if (index.IsConstant()) { |
| 6553 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6554 | (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6555 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), array, offset); |
| 6556 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6557 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6558 | vixl32::Register temp = temps.Acquire(); |
| 6559 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6560 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), temp, data_offset); |
| 6561 | } |
| 6562 | break; |
| 6563 | } |
| 6564 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6565 | case DataType::Type::kFloat32: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6566 | Location value = locations->InAt(2); |
| 6567 | DCHECK(value.IsFpuRegister()); |
| 6568 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6569 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6570 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), array, offset); |
| 6571 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6572 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6573 | vixl32::Register temp = temps.Acquire(); |
| 6574 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 6575 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), temp, data_offset); |
| 6576 | } |
| 6577 | break; |
| 6578 | } |
| 6579 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6580 | case DataType::Type::kFloat64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6581 | Location value = locations->InAt(2); |
| 6582 | DCHECK(value.IsFpuRegisterPair()); |
| 6583 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6584 | size_t offset = (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6585 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), array, offset); |
| 6586 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6587 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6588 | vixl32::Register temp = temps.Acquire(); |
| 6589 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6590 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), temp, data_offset); |
| 6591 | } |
| 6592 | break; |
| 6593 | } |
| 6594 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6595 | case DataType::Type::kVoid: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6596 | LOG(FATAL) << "Unreachable type " << value_type; |
| 6597 | UNREACHABLE(); |
| 6598 | } |
| 6599 | |
| 6600 | // Objects are handled in the switch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6601 | if (value_type != DataType::Type::kReference) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6602 | // TODO(VIXL): Ensure we record the pc position immediately after the preceding store |
| 6603 | // instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6604 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6605 | } |
| 6606 | } |
| 6607 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6608 | void LocationsBuilderARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 6609 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6610 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6611 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6612 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6613 | } |
| 6614 | |
| 6615 | void InstructionCodeGeneratorARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 6616 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| 6617 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 6618 | vixl32::Register out = OutputRegister(instruction); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6619 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6620 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6621 | vixl32::kMaxInstructionSizeInBytes, |
| 6622 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6623 | __ ldr(out, MemOperand(obj, offset)); |
| 6624 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6625 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6626 | // Mask out compression flag from String's array length. |
| 6627 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6628 | __ Lsr(out, out, 1u); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6629 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6630 | } |
| 6631 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6632 | void LocationsBuilderARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6633 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6634 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6635 | |
| 6636 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6637 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 6638 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6639 | } |
| 6640 | |
| 6641 | void InstructionCodeGeneratorARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 6642 | vixl32::Register out = OutputRegister(instruction); |
| 6643 | vixl32::Register first = InputRegisterAt(instruction, 0); |
| 6644 | Location second = instruction->GetLocations()->InAt(1); |
| 6645 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6646 | if (second.IsRegister()) { |
| 6647 | __ Add(out, first, RegisterFrom(second)); |
| 6648 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6649 | __ Add(out, first, Int32ConstantFrom(second)); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6650 | } |
| 6651 | } |
| 6652 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 6653 | void LocationsBuilderARMVIXL::VisitIntermediateAddressIndex( |
| 6654 | HIntermediateAddressIndex* instruction) { |
| 6655 | LOG(FATAL) << "Unreachable " << instruction->GetId(); |
| 6656 | } |
| 6657 | |
| 6658 | void InstructionCodeGeneratorARMVIXL::VisitIntermediateAddressIndex( |
| 6659 | HIntermediateAddressIndex* instruction) { |
| 6660 | LOG(FATAL) << "Unreachable " << instruction->GetId(); |
| 6661 | } |
| 6662 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6663 | void LocationsBuilderARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 6664 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6665 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 6666 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 6667 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(1))); |
| 6668 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6669 | |
| 6670 | HInstruction* index = instruction->InputAt(0); |
| 6671 | HInstruction* length = instruction->InputAt(1); |
| 6672 | // If both index and length are constants we can statically check the bounds. But if at least one |
| 6673 | // of them is not encodable ArmEncodableConstantOrRegister will create |
| 6674 | // Location::RequiresRegister() which is not desired to happen. Instead we create constant |
| 6675 | // locations. |
| 6676 | bool both_const = index->IsConstant() && length->IsConstant(); |
| 6677 | locations->SetInAt(0, both_const |
| 6678 | ? Location::ConstantLocation(index->AsConstant()) |
| 6679 | : ArmEncodableConstantOrRegister(index, CMP)); |
| 6680 | locations->SetInAt(1, both_const |
| 6681 | ? Location::ConstantLocation(length->AsConstant()) |
| 6682 | : ArmEncodableConstantOrRegister(length, CMP)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6683 | } |
| 6684 | |
| 6685 | void InstructionCodeGeneratorARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6686 | LocationSummary* locations = instruction->GetLocations(); |
| 6687 | Location index_loc = locations->InAt(0); |
| 6688 | Location length_loc = locations->InAt(1); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6689 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6690 | if (length_loc.IsConstant()) { |
| 6691 | int32_t length = Int32ConstantFrom(length_loc); |
| 6692 | if (index_loc.IsConstant()) { |
| 6693 | // BCE will remove the bounds check if we are guaranteed to pass. |
| 6694 | int32_t index = Int32ConstantFrom(index_loc); |
| 6695 | if (index < 0 || index >= length) { |
| 6696 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6697 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARMVIXL(instruction); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6698 | codegen_->AddSlowPath(slow_path); |
| 6699 | __ B(slow_path->GetEntryLabel()); |
| 6700 | } else { |
| 6701 | // Some optimization after BCE may have generated this, and we should not |
| 6702 | // generate a bounds check if it is a valid range. |
| 6703 | } |
| 6704 | return; |
| 6705 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6706 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6707 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6708 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARMVIXL(instruction); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6709 | __ Cmp(RegisterFrom(index_loc), length); |
| 6710 | codegen_->AddSlowPath(slow_path); |
| 6711 | __ B(hs, slow_path->GetEntryLabel()); |
| 6712 | } else { |
| 6713 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6714 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARMVIXL(instruction); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6715 | __ Cmp(RegisterFrom(length_loc), InputOperandAt(instruction, 0)); |
| 6716 | codegen_->AddSlowPath(slow_path); |
| 6717 | __ B(ls, slow_path->GetEntryLabel()); |
| 6718 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6719 | } |
| 6720 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6721 | void CodeGeneratorARMVIXL::MarkGCCard(vixl32::Register temp, |
| 6722 | vixl32::Register card, |
| 6723 | vixl32::Register object, |
| 6724 | vixl32::Register value, |
| 6725 | bool can_be_null) { |
| 6726 | vixl32::Label is_null; |
| 6727 | if (can_be_null) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6728 | __ CompareAndBranchIfZero(value, &is_null); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6729 | } |
| 6730 | GetAssembler()->LoadFromOffset( |
| 6731 | kLoadWord, card, tr, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 6732 | __ Lsr(temp, object, Operand::From(gc::accounting::CardTable::kCardShift)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6733 | __ Strb(card, MemOperand(card, temp)); |
| 6734 | if (can_be_null) { |
| 6735 | __ Bind(&is_null); |
| 6736 | } |
| 6737 | } |
| 6738 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6739 | void LocationsBuilderARMVIXL::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 6740 | LOG(FATAL) << "Unreachable"; |
| 6741 | } |
| 6742 | |
| 6743 | void InstructionCodeGeneratorARMVIXL::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 6744 | if (instruction->GetNext()->IsSuspendCheck() && |
| 6745 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 6746 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 6747 | // The back edge will generate the suspend check. |
| 6748 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 6749 | } |
| 6750 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6751 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6752 | } |
| 6753 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6754 | void LocationsBuilderARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6755 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6756 | instruction, LocationSummary::kCallOnSlowPath); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6757 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6758 | } |
| 6759 | |
| 6760 | void InstructionCodeGeneratorARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 6761 | HBasicBlock* block = instruction->GetBlock(); |
| 6762 | if (block->GetLoopInformation() != nullptr) { |
| 6763 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6764 | // The back edge will generate the suspend check. |
| 6765 | return; |
| 6766 | } |
| 6767 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6768 | // The goto will generate the suspend check. |
| 6769 | return; |
| 6770 | } |
| 6771 | GenerateSuspendCheck(instruction, nullptr); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 6772 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 12); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6773 | } |
| 6774 | |
| 6775 | void InstructionCodeGeneratorARMVIXL::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 6776 | HBasicBlock* successor) { |
| 6777 | SuspendCheckSlowPathARMVIXL* slow_path = |
| 6778 | down_cast<SuspendCheckSlowPathARMVIXL*>(instruction->GetSlowPath()); |
| 6779 | if (slow_path == nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6780 | slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6781 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathARMVIXL(instruction, successor); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6782 | instruction->SetSlowPath(slow_path); |
| 6783 | codegen_->AddSlowPath(slow_path); |
| 6784 | if (successor != nullptr) { |
| 6785 | DCHECK(successor->IsLoopHeader()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6786 | } |
| 6787 | } else { |
| 6788 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 6789 | } |
| 6790 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6791 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6792 | vixl32::Register temp = temps.Acquire(); |
| 6793 | GetAssembler()->LoadFromOffset( |
| 6794 | kLoadUnsignedHalfword, temp, tr, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
| 6795 | if (successor == nullptr) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6796 | __ CompareAndBranchIfNonZero(temp, slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6797 | __ Bind(slow_path->GetReturnLabel()); |
| 6798 | } else { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6799 | __ CompareAndBranchIfZero(temp, codegen_->GetLabelOf(successor)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6800 | __ B(slow_path->GetEntryLabel()); |
| 6801 | } |
| 6802 | } |
| 6803 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6804 | ArmVIXLAssembler* ParallelMoveResolverARMVIXL::GetAssembler() const { |
| 6805 | return codegen_->GetAssembler(); |
| 6806 | } |
| 6807 | |
| 6808 | void ParallelMoveResolverARMVIXL::EmitMove(size_t index) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6809 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6810 | MoveOperands* move = moves_[index]; |
| 6811 | Location source = move->GetSource(); |
| 6812 | Location destination = move->GetDestination(); |
| 6813 | |
| 6814 | if (source.IsRegister()) { |
| 6815 | if (destination.IsRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6816 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6817 | } else if (destination.IsFpuRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6818 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6819 | } else { |
| 6820 | DCHECK(destination.IsStackSlot()); |
| 6821 | GetAssembler()->StoreToOffset(kStoreWord, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6822 | RegisterFrom(source), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6823 | sp, |
| 6824 | destination.GetStackIndex()); |
| 6825 | } |
| 6826 | } else if (source.IsStackSlot()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6827 | if (destination.IsRegister()) { |
| 6828 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 6829 | RegisterFrom(destination), |
| 6830 | sp, |
| 6831 | source.GetStackIndex()); |
| 6832 | } else if (destination.IsFpuRegister()) { |
| 6833 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 6834 | } else { |
| 6835 | DCHECK(destination.IsStackSlot()); |
| 6836 | vixl32::Register temp = temps.Acquire(); |
| 6837 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 6838 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6839 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6840 | } else if (source.IsFpuRegister()) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6841 | if (destination.IsRegister()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6842 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6843 | } else if (destination.IsFpuRegister()) { |
| 6844 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 6845 | } else { |
| 6846 | DCHECK(destination.IsStackSlot()); |
| 6847 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 6848 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6849 | } else if (source.IsDoubleStackSlot()) { |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6850 | if (destination.IsDoubleStackSlot()) { |
| 6851 | vixl32::DRegister temp = temps.AcquireD(); |
| 6852 | GetAssembler()->LoadDFromOffset(temp, sp, source.GetStackIndex()); |
| 6853 | GetAssembler()->StoreDToOffset(temp, sp, destination.GetStackIndex()); |
| 6854 | } else if (destination.IsRegisterPair()) { |
| 6855 | DCHECK(ExpectedPairLayout(destination)); |
| 6856 | GetAssembler()->LoadFromOffset( |
| 6857 | kLoadWordPair, LowRegisterFrom(destination), sp, source.GetStackIndex()); |
| 6858 | } else { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6859 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 6860 | GetAssembler()->LoadDFromOffset(DRegisterFrom(destination), sp, source.GetStackIndex()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6861 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6862 | } else if (source.IsRegisterPair()) { |
| 6863 | if (destination.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6864 | __ Mov(LowRegisterFrom(destination), LowRegisterFrom(source)); |
| 6865 | __ Mov(HighRegisterFrom(destination), HighRegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6866 | } else if (destination.IsFpuRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6867 | __ Vmov(DRegisterFrom(destination), LowRegisterFrom(source), HighRegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6868 | } else { |
| 6869 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6870 | DCHECK(ExpectedPairLayout(source)); |
| 6871 | GetAssembler()->StoreToOffset(kStoreWordPair, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6872 | LowRegisterFrom(source), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6873 | sp, |
| 6874 | destination.GetStackIndex()); |
| 6875 | } |
| 6876 | } else if (source.IsFpuRegisterPair()) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6877 | if (destination.IsRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6878 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), DRegisterFrom(source)); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6879 | } else if (destination.IsFpuRegisterPair()) { |
| 6880 | __ Vmov(DRegisterFrom(destination), DRegisterFrom(source)); |
| 6881 | } else { |
| 6882 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6883 | GetAssembler()->StoreDToOffset(DRegisterFrom(source), sp, destination.GetStackIndex()); |
| 6884 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6885 | } else { |
| 6886 | DCHECK(source.IsConstant()) << source; |
| 6887 | HConstant* constant = source.GetConstant(); |
| 6888 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 6889 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
| 6890 | if (destination.IsRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6891 | __ Mov(RegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6892 | } else { |
| 6893 | DCHECK(destination.IsStackSlot()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6894 | vixl32::Register temp = temps.Acquire(); |
| 6895 | __ Mov(temp, value); |
| 6896 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6897 | } |
| 6898 | } else if (constant->IsLongConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6899 | int64_t value = Int64ConstantFrom(source); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6900 | if (destination.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6901 | __ Mov(LowRegisterFrom(destination), Low32Bits(value)); |
| 6902 | __ Mov(HighRegisterFrom(destination), High32Bits(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6903 | } else { |
| 6904 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6905 | vixl32::Register temp = temps.Acquire(); |
| 6906 | __ Mov(temp, Low32Bits(value)); |
| 6907 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6908 | __ Mov(temp, High32Bits(value)); |
| 6909 | GetAssembler()->StoreToOffset(kStoreWord, |
| 6910 | temp, |
| 6911 | sp, |
| 6912 | destination.GetHighStackIndex(kArmWordSize)); |
| 6913 | } |
| 6914 | } else if (constant->IsDoubleConstant()) { |
| 6915 | double value = constant->AsDoubleConstant()->GetValue(); |
| 6916 | if (destination.IsFpuRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6917 | __ Vmov(DRegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6918 | } else { |
| 6919 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6920 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6921 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6922 | __ Mov(temp, Low32Bits(int_value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6923 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6924 | __ Mov(temp, High32Bits(int_value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6925 | GetAssembler()->StoreToOffset(kStoreWord, |
| 6926 | temp, |
| 6927 | sp, |
| 6928 | destination.GetHighStackIndex(kArmWordSize)); |
| 6929 | } |
| 6930 | } else { |
| 6931 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
| 6932 | float value = constant->AsFloatConstant()->GetValue(); |
| 6933 | if (destination.IsFpuRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6934 | __ Vmov(SRegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6935 | } else { |
| 6936 | DCHECK(destination.IsStackSlot()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6937 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6938 | __ Mov(temp, bit_cast<int32_t, float>(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6939 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6940 | } |
| 6941 | } |
| 6942 | } |
| 6943 | } |
| 6944 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6945 | void ParallelMoveResolverARMVIXL::Exchange(vixl32::Register reg, int mem) { |
| 6946 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 6947 | vixl32::Register temp = temps.Acquire(); |
| 6948 | __ Mov(temp, reg); |
| 6949 | GetAssembler()->LoadFromOffset(kLoadWord, reg, sp, mem); |
| 6950 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6951 | } |
| 6952 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6953 | void ParallelMoveResolverARMVIXL::Exchange(int mem1, int mem2) { |
| 6954 | // TODO(VIXL32): Double check the performance of this implementation. |
| 6955 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6956 | vixl32::Register temp1 = temps.Acquire(); |
| 6957 | ScratchRegisterScope ensure_scratch( |
| 6958 | this, temp1.GetCode(), r0.GetCode(), codegen_->GetNumberOfCoreRegisters()); |
| 6959 | vixl32::Register temp2(ensure_scratch.GetRegister()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6960 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6961 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 6962 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, sp, mem1 + stack_offset); |
| 6963 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, sp, mem2 + stack_offset); |
| 6964 | GetAssembler()->StoreToOffset(kStoreWord, temp1, sp, mem2 + stack_offset); |
| 6965 | GetAssembler()->StoreToOffset(kStoreWord, temp2, sp, mem1 + stack_offset); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6966 | } |
| 6967 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6968 | void ParallelMoveResolverARMVIXL::EmitSwap(size_t index) { |
| 6969 | MoveOperands* move = moves_[index]; |
| 6970 | Location source = move->GetSource(); |
| 6971 | Location destination = move->GetDestination(); |
| 6972 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 6973 | |
| 6974 | if (source.IsRegister() && destination.IsRegister()) { |
| 6975 | vixl32::Register temp = temps.Acquire(); |
| 6976 | DCHECK(!RegisterFrom(source).Is(temp)); |
| 6977 | DCHECK(!RegisterFrom(destination).Is(temp)); |
| 6978 | __ Mov(temp, RegisterFrom(destination)); |
| 6979 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 6980 | __ Mov(RegisterFrom(source), temp); |
| 6981 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| 6982 | Exchange(RegisterFrom(source), destination.GetStackIndex()); |
| 6983 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| 6984 | Exchange(RegisterFrom(destination), source.GetStackIndex()); |
| 6985 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 6986 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6987 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6988 | vixl32::Register temp = temps.Acquire(); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 6989 | __ Vmov(temp, SRegisterFrom(source)); |
| 6990 | __ Vmov(SRegisterFrom(source), SRegisterFrom(destination)); |
| 6991 | __ Vmov(SRegisterFrom(destination), temp); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6992 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
| 6993 | vixl32::DRegister temp = temps.AcquireD(); |
| 6994 | __ Vmov(temp, LowRegisterFrom(source), HighRegisterFrom(source)); |
| 6995 | __ Mov(LowRegisterFrom(source), LowRegisterFrom(destination)); |
| 6996 | __ Mov(HighRegisterFrom(source), HighRegisterFrom(destination)); |
| 6997 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), temp); |
| 6998 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
| 6999 | vixl32::Register low_reg = LowRegisterFrom(source.IsRegisterPair() ? source : destination); |
| 7000 | int mem = source.IsRegisterPair() ? destination.GetStackIndex() : source.GetStackIndex(); |
| 7001 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
| 7002 | vixl32::DRegister temp = temps.AcquireD(); |
| 7003 | __ Vmov(temp, low_reg, vixl32::Register(low_reg.GetCode() + 1)); |
| 7004 | GetAssembler()->LoadFromOffset(kLoadWordPair, low_reg, sp, mem); |
| 7005 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
| 7006 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7007 | vixl32::DRegister first = DRegisterFrom(source); |
| 7008 | vixl32::DRegister second = DRegisterFrom(destination); |
| 7009 | vixl32::DRegister temp = temps.AcquireD(); |
| 7010 | __ Vmov(temp, first); |
| 7011 | __ Vmov(first, second); |
| 7012 | __ Vmov(second, temp); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7013 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7014 | vixl32::DRegister reg = source.IsFpuRegisterPair() |
| 7015 | ? DRegisterFrom(source) |
| 7016 | : DRegisterFrom(destination); |
| 7017 | int mem = source.IsFpuRegisterPair() |
| 7018 | ? destination.GetStackIndex() |
| 7019 | : source.GetStackIndex(); |
| 7020 | vixl32::DRegister temp = temps.AcquireD(); |
| 7021 | __ Vmov(temp, reg); |
| 7022 | GetAssembler()->LoadDFromOffset(reg, sp, mem); |
| 7023 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7024 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7025 | vixl32::SRegister reg = source.IsFpuRegister() |
| 7026 | ? SRegisterFrom(source) |
| 7027 | : SRegisterFrom(destination); |
| 7028 | int mem = source.IsFpuRegister() |
| 7029 | ? destination.GetStackIndex() |
| 7030 | : source.GetStackIndex(); |
| 7031 | vixl32::Register temp = temps.Acquire(); |
| 7032 | __ Vmov(temp, reg); |
| 7033 | GetAssembler()->LoadSFromOffset(reg, sp, mem); |
| 7034 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7035 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 7036 | vixl32::DRegister temp1 = temps.AcquireD(); |
| 7037 | vixl32::DRegister temp2 = temps.AcquireD(); |
| 7038 | __ Vldr(temp1, MemOperand(sp, source.GetStackIndex())); |
| 7039 | __ Vldr(temp2, MemOperand(sp, destination.GetStackIndex())); |
| 7040 | __ Vstr(temp1, MemOperand(sp, destination.GetStackIndex())); |
| 7041 | __ Vstr(temp2, MemOperand(sp, source.GetStackIndex())); |
| 7042 | } else { |
| 7043 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
| 7044 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7045 | } |
| 7046 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7047 | void ParallelMoveResolverARMVIXL::SpillScratch(int reg) { |
| 7048 | __ Push(vixl32::Register(reg)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7049 | } |
| 7050 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7051 | void ParallelMoveResolverARMVIXL::RestoreScratch(int reg) { |
| 7052 | __ Pop(vixl32::Register(reg)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7053 | } |
| 7054 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7055 | HLoadClass::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadClassKind( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7056 | HLoadClass::LoadKind desired_class_load_kind) { |
| 7057 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7058 | case HLoadClass::LoadKind::kInvalid: |
| 7059 | LOG(FATAL) << "UNREACHABLE"; |
| 7060 | UNREACHABLE(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7061 | case HLoadClass::LoadKind::kReferrersClass: |
| 7062 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7063 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7064 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7065 | case HLoadClass::LoadKind::kBssEntry: |
| 7066 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 7067 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7068 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7069 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7070 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 7071 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7072 | case HLoadClass::LoadKind::kRuntimeCall: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7073 | break; |
| 7074 | } |
| 7075 | return desired_class_load_kind; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7076 | } |
| 7077 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7078 | void LocationsBuilderARMVIXL::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7079 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7080 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7081 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7082 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7083 | cls, |
| 7084 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7085 | LocationFrom(r0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7086 | DCHECK(calling_convention.GetRegisterAt(0).Is(r0)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7087 | return; |
| 7088 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7089 | DCHECK(!cls->NeedsAccessCheck()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7090 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7091 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 7092 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7093 | ? LocationSummary::kCallOnSlowPath |
| 7094 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7095 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7096 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7097 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7098 | } |
| 7099 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7100 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7101 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7102 | } |
| 7103 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7104 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 7105 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 7106 | // Rely on the type resolution or initialization and marking to save everything we need. |
| 7107 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 7108 | // to the custom calling convention) or by marking, so we request a different temp. |
| 7109 | locations->AddTemp(Location::RequiresRegister()); |
| 7110 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 7111 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7112 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7113 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 7114 | // that the the kPrimNot result register is the same as the first argument register. |
| 7115 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 7116 | } else { |
| 7117 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7118 | } |
| 7119 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 7120 | if (kUseBakerReadBarrier && kBakerReadBarrierLinkTimeThunksEnableForGcRoots) { |
| 7121 | if (load_kind == HLoadClass::LoadKind::kBssEntry || |
| 7122 | (load_kind == HLoadClass::LoadKind::kReferrersClass && |
| 7123 | !Runtime::Current()->UseJitCompilation())) { |
| 7124 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 7125 | } |
| 7126 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7127 | } |
| 7128 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7129 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7130 | // move. |
| 7131 | void InstructionCodeGeneratorARMVIXL::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7132 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7133 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7134 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 7135 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 13); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7136 | return; |
| 7137 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7138 | DCHECK(!cls->NeedsAccessCheck()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7139 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7140 | LocationSummary* locations = cls->GetLocations(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7141 | Location out_loc = locations->Out(); |
| 7142 | vixl32::Register out = OutputRegister(cls); |
| 7143 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7144 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 7145 | ? kWithoutReadBarrier |
| 7146 | : kCompilerReadBarrierOption; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7147 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7148 | switch (load_kind) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7149 | case HLoadClass::LoadKind::kReferrersClass: { |
| 7150 | DCHECK(!cls->CanCallRuntime()); |
| 7151 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 7152 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 7153 | vixl32::Register current_method = InputRegisterAt(cls, 0); |
| 7154 | GenerateGcRootFieldLoad(cls, |
| 7155 | out_loc, |
| 7156 | current_method, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 7157 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7158 | read_barrier_option); |
| 7159 | break; |
| 7160 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7161 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7162 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7163 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 7164 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 7165 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 7166 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 7167 | break; |
| 7168 | } |
| 7169 | case HLoadClass::LoadKind::kBootImageAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7170 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7171 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 7172 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 7173 | DCHECK_NE(address, 0u); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7174 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7175 | break; |
| 7176 | } |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7177 | case HLoadClass::LoadKind::kBootImageClassTable: { |
| 7178 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7179 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 7180 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 7181 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 7182 | __ Ldr(out, MemOperand(out, /* offset */ 0)); |
| 7183 | // Extract the reference from the slot data, i.e. clear the hash bits. |
| 7184 | int32_t masked_hash = ClassTable::TableSlot::MaskHash( |
| 7185 | ComputeModifiedUtf8Hash(cls->GetDexFile().StringByTypeIdx(cls->GetTypeIndex()))); |
| 7186 | if (masked_hash != 0) { |
| 7187 | __ Sub(out, out, Operand(masked_hash)); |
| 7188 | } |
| 7189 | break; |
| 7190 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7191 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7192 | vixl32::Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 7193 | ? RegisterFrom(locations->GetTemp(0)) |
| 7194 | : out; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7195 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7196 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7197 | codegen_->EmitMovwMovtPlaceholder(labels, temp); |
| 7198 | GenerateGcRootFieldLoad(cls, out_loc, temp, /* offset */ 0, read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7199 | generate_null_check = true; |
| 7200 | break; |
| 7201 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7202 | case HLoadClass::LoadKind::kJitTableAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7203 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 7204 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7205 | cls->GetClass())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7206 | // /* GcRoot<mirror::Class> */ out = *out |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7207 | GenerateGcRootFieldLoad(cls, out_loc, out, /* offset */ 0, read_barrier_option); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7208 | break; |
| 7209 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7210 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7211 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7212 | LOG(FATAL) << "UNREACHABLE"; |
| 7213 | UNREACHABLE(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7214 | } |
| 7215 | |
| 7216 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 7217 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7218 | LoadClassSlowPathARMVIXL* slow_path = |
| 7219 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARMVIXL( |
| 7220 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7221 | codegen_->AddSlowPath(slow_path); |
| 7222 | if (generate_null_check) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7223 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7224 | } |
| 7225 | if (cls->MustGenerateClinitCheck()) { |
| 7226 | GenerateClassInitializationCheck(slow_path, out); |
| 7227 | } else { |
| 7228 | __ Bind(slow_path->GetExitLabel()); |
| 7229 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 7230 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 14); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7231 | } |
| 7232 | } |
| 7233 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7234 | void LocationsBuilderARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 7235 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7236 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7237 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7238 | if (check->HasUses()) { |
| 7239 | locations->SetOut(Location::SameAsFirstInput()); |
| 7240 | } |
| 7241 | } |
| 7242 | |
| 7243 | void InstructionCodeGeneratorARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 7244 | // We assume the class is not null. |
| 7245 | LoadClassSlowPathARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7246 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARMVIXL(check->GetLoadClass(), |
| 7247 | check, |
| 7248 | check->GetDexPc(), |
| 7249 | /* do_clinit */ true); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7250 | codegen_->AddSlowPath(slow_path); |
| 7251 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 7252 | } |
| 7253 | |
| 7254 | void InstructionCodeGeneratorARMVIXL::GenerateClassInitializationCheck( |
| 7255 | LoadClassSlowPathARMVIXL* slow_path, vixl32::Register class_reg) { |
| 7256 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 7257 | vixl32::Register temp = temps.Acquire(); |
Igor Murashkin | 86083f7 | 2017-10-27 10:59:04 -0700 | [diff] [blame] | 7258 | GetAssembler()->LoadFromOffset(kLoadSignedByte, |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7259 | temp, |
| 7260 | class_reg, |
| 7261 | mirror::Class::StatusOffset().Int32Value()); |
| 7262 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 7263 | __ B(lt, slow_path->GetEntryLabel()); |
| 7264 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 7265 | // properly. Therefore, we do a memory fence. |
| 7266 | __ Dmb(ISH); |
| 7267 | __ Bind(slow_path->GetExitLabel()); |
| 7268 | } |
| 7269 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7270 | HLoadString::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadStringKind( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7271 | HLoadString::LoadKind desired_string_load_kind) { |
| 7272 | switch (desired_string_load_kind) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7273 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7274 | case HLoadString::LoadKind::kBootImageInternTable: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7275 | case HLoadString::LoadKind::kBssEntry: |
| 7276 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 7277 | break; |
| 7278 | case HLoadString::LoadKind::kJitTableAddress: |
| 7279 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7280 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 7281 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7282 | case HLoadString::LoadKind::kRuntimeCall: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7283 | break; |
| 7284 | } |
| 7285 | return desired_string_load_kind; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7286 | } |
| 7287 | |
| 7288 | void LocationsBuilderARMVIXL::VisitLoadString(HLoadString* load) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7289 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7290 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7291 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7292 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7293 | locations->SetOut(LocationFrom(r0)); |
| 7294 | } else { |
| 7295 | locations->SetOut(Location::RequiresRegister()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7296 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 7297 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7298 | // Rely on the pResolveString and marking to save everything we need, including temps. |
| 7299 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 7300 | // to the custom calling convention) or by marking, so we request a different temp. |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7301 | locations->AddTemp(Location::RequiresRegister()); |
| 7302 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 7303 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7304 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7305 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 7306 | // that the the kPrimNot result register is the same as the first argument register. |
| 7307 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 7308 | if (kUseBakerReadBarrier && kBakerReadBarrierLinkTimeThunksEnableForGcRoots) { |
| 7309 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 7310 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7311 | } else { |
| 7312 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7313 | } |
| 7314 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7315 | } |
| 7316 | } |
| 7317 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7318 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7319 | // move. |
| 7320 | void InstructionCodeGeneratorARMVIXL::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7321 | LocationSummary* locations = load->GetLocations(); |
| 7322 | Location out_loc = locations->Out(); |
| 7323 | vixl32::Register out = OutputRegister(load); |
| 7324 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 7325 | |
| 7326 | switch (load_kind) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7327 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 7328 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| 7329 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7330 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7331 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7332 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7333 | } |
| 7334 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7335 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 7336 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 7337 | DCHECK_NE(address, 0u); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7338 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7339 | return; |
| 7340 | } |
| 7341 | case HLoadString::LoadKind::kBootImageInternTable: { |
| 7342 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7343 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 7344 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
| 7345 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 7346 | __ Ldr(out, MemOperand(out, /* offset */ 0)); |
| 7347 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7348 | } |
| 7349 | case HLoadString::LoadKind::kBssEntry: { |
| 7350 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7351 | vixl32::Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 7352 | ? RegisterFrom(locations->GetTemp(0)) |
| 7353 | : out; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7354 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7355 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7356 | codegen_->EmitMovwMovtPlaceholder(labels, temp); |
| 7357 | GenerateGcRootFieldLoad(load, out_loc, temp, /* offset */ 0, kCompilerReadBarrierOption); |
| 7358 | LoadStringSlowPathARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7359 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathARMVIXL(load); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7360 | codegen_->AddSlowPath(slow_path); |
| 7361 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 7362 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 7363 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 15); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7364 | return; |
| 7365 | } |
| 7366 | case HLoadString::LoadKind::kJitTableAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7367 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7368 | load->GetStringIndex(), |
| 7369 | load->GetString())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7370 | // /* GcRoot<mirror::String> */ out = *out |
| 7371 | GenerateGcRootFieldLoad(load, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
| 7372 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7373 | } |
| 7374 | default: |
| 7375 | break; |
| 7376 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7377 | |
| 7378 | // 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] | 7379 | DCHECK_EQ(load->GetLoadKind(), HLoadString::LoadKind::kRuntimeCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7380 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7381 | __ Mov(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7382 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 7383 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 7384 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 16); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7385 | } |
| 7386 | |
| 7387 | static int32_t GetExceptionTlsOffset() { |
| 7388 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
| 7389 | } |
| 7390 | |
| 7391 | void LocationsBuilderARMVIXL::VisitLoadException(HLoadException* load) { |
| 7392 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7393 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7394 | locations->SetOut(Location::RequiresRegister()); |
| 7395 | } |
| 7396 | |
| 7397 | void InstructionCodeGeneratorARMVIXL::VisitLoadException(HLoadException* load) { |
| 7398 | vixl32::Register out = OutputRegister(load); |
| 7399 | GetAssembler()->LoadFromOffset(kLoadWord, out, tr, GetExceptionTlsOffset()); |
| 7400 | } |
| 7401 | |
| 7402 | |
| 7403 | void LocationsBuilderARMVIXL::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7404 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7405 | } |
| 7406 | |
| 7407 | void InstructionCodeGeneratorARMVIXL::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 7408 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 7409 | vixl32::Register temp = temps.Acquire(); |
| 7410 | __ Mov(temp, 0); |
| 7411 | GetAssembler()->StoreToOffset(kStoreWord, temp, tr, GetExceptionTlsOffset()); |
| 7412 | } |
| 7413 | |
| 7414 | void LocationsBuilderARMVIXL::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7415 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7416 | instruction, LocationSummary::kCallOnMainOnly); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7417 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7418 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7419 | } |
| 7420 | |
| 7421 | void InstructionCodeGeneratorARMVIXL::VisitThrow(HThrow* instruction) { |
| 7422 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| 7423 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 7424 | } |
| 7425 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7426 | // Temp is used for read barrier. |
| 7427 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 7428 | if (kEmitCompilerReadBarrier && |
| 7429 | (kUseBakerReadBarrier || |
| 7430 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7431 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7432 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 7433 | return 1; |
| 7434 | } |
| 7435 | return 0; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7436 | } |
| 7437 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7438 | // Interface case has 3 temps, one for holding the number of interfaces, one for the current |
| 7439 | // interface pointer, one for loading the current interface. |
| 7440 | // The other checks have one temp for loading the object's class. |
| 7441 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 7442 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7443 | return 3; |
| 7444 | } |
| 7445 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 7446 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7447 | |
| 7448 | void LocationsBuilderARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 7449 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7450 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7451 | bool baker_read_barrier_slow_path = false; |
| 7452 | switch (type_check_kind) { |
| 7453 | case TypeCheckKind::kExactCheck: |
| 7454 | case TypeCheckKind::kAbstractClassCheck: |
| 7455 | case TypeCheckKind::kClassHierarchyCheck: |
| 7456 | case TypeCheckKind::kArrayObjectCheck: |
| 7457 | call_kind = |
| 7458 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 7459 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
| 7460 | break; |
| 7461 | case TypeCheckKind::kArrayCheck: |
| 7462 | case TypeCheckKind::kUnresolvedCheck: |
| 7463 | case TypeCheckKind::kInterfaceCheck: |
| 7464 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7465 | break; |
| 7466 | } |
| 7467 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7468 | LocationSummary* locations = |
| 7469 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7470 | if (baker_read_barrier_slow_path) { |
| 7471 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 7472 | } |
| 7473 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7474 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7475 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 7476 | // Note that TypeCheckSlowPathARM uses this register too. |
| 7477 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7478 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 7479 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 7480 | codegen_->MaybeAddBakerCcEntrypointTempForFields(locations); |
| 7481 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7482 | } |
| 7483 | |
| 7484 | void InstructionCodeGeneratorARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 7485 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7486 | LocationSummary* locations = instruction->GetLocations(); |
| 7487 | Location obj_loc = locations->InAt(0); |
| 7488 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 7489 | vixl32::Register cls = InputRegisterAt(instruction, 1); |
| 7490 | Location out_loc = locations->Out(); |
| 7491 | vixl32::Register out = OutputRegister(instruction); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7492 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7493 | DCHECK_LE(num_temps, 1u); |
| 7494 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7495 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7496 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7497 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7498 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7499 | vixl32::Label done; |
| 7500 | vixl32::Label* const final_label = codegen_->GetFinalLabel(instruction, &done); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7501 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 7502 | |
| 7503 | // Return 0 if `obj` is null. |
| 7504 | // avoid null check if we know obj is not null. |
| 7505 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7506 | DCHECK(!out.Is(obj)); |
| 7507 | __ Mov(out, 0); |
| 7508 | __ CompareAndBranchIfZero(obj, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7509 | } |
| 7510 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7511 | switch (type_check_kind) { |
| 7512 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7513 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7514 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7515 | out_loc, |
| 7516 | obj_loc, |
| 7517 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7518 | maybe_temp_loc, |
| 7519 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7520 | // Classes must be equal for the instanceof to succeed. |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7521 | __ Cmp(out, cls); |
| 7522 | // We speculatively set the result to false without changing the condition |
| 7523 | // flags, which allows us to avoid some branching later. |
| 7524 | __ Mov(LeaveFlags, out, 0); |
| 7525 | |
| 7526 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7527 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7528 | // encoding can be used. |
| 7529 | if (out.IsLow()) { |
| 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 | __ it(eq); |
| 7536 | __ mov(eq, out, 1); |
| 7537 | } else { |
| 7538 | __ B(ne, final_label, /* far_target */ false); |
| 7539 | __ Mov(out, 1); |
| 7540 | } |
| 7541 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7542 | break; |
| 7543 | } |
| 7544 | |
| 7545 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7546 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7547 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7548 | out_loc, |
| 7549 | obj_loc, |
| 7550 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7551 | maybe_temp_loc, |
| 7552 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7553 | // If the class is abstract, we eagerly fetch the super class of the |
| 7554 | // object to avoid doing a comparison we know will fail. |
| 7555 | vixl32::Label loop; |
| 7556 | __ Bind(&loop); |
| 7557 | // /* HeapReference<Class> */ out = out->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7558 | GenerateReferenceLoadOneRegister(instruction, |
| 7559 | out_loc, |
| 7560 | super_offset, |
| 7561 | maybe_temp_loc, |
| 7562 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7563 | // 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] | 7564 | __ CompareAndBranchIfZero(out, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7565 | __ Cmp(out, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7566 | __ B(ne, &loop, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7567 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7568 | break; |
| 7569 | } |
| 7570 | |
| 7571 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7572 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7573 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7574 | out_loc, |
| 7575 | obj_loc, |
| 7576 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7577 | maybe_temp_loc, |
| 7578 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7579 | // Walk over the class hierarchy to find a match. |
| 7580 | vixl32::Label loop, success; |
| 7581 | __ Bind(&loop); |
| 7582 | __ Cmp(out, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7583 | __ B(eq, &success, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7584 | // /* HeapReference<Class> */ out = out->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7585 | GenerateReferenceLoadOneRegister(instruction, |
| 7586 | out_loc, |
| 7587 | super_offset, |
| 7588 | maybe_temp_loc, |
| 7589 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7590 | // This is essentially a null check, but it sets the condition flags to the |
| 7591 | // proper value for the code that follows the loop, i.e. not `eq`. |
| 7592 | __ Cmp(out, 1); |
| 7593 | __ B(hs, &loop, /* far_target */ false); |
| 7594 | |
| 7595 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7596 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7597 | // encoding can be used. |
| 7598 | if (out.IsLow()) { |
| 7599 | // If `out` is null, we use it for the result, and the condition flags |
| 7600 | // have already been set to `ne`, so the IT block that comes afterwards |
| 7601 | // (and which handles the successful case) turns into a NOP (instead of |
| 7602 | // overwriting `out`). |
| 7603 | __ Bind(&success); |
| 7604 | |
| 7605 | // We use the scope because of the IT block that follows. |
| 7606 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7607 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7608 | CodeBufferCheckScope::kExactSize); |
| 7609 | |
| 7610 | // There is only one branch to the `success` label (which is bound to this |
| 7611 | // IT block), and it has the same condition, `eq`, so in that case the MOV |
| 7612 | // is executed. |
| 7613 | __ it(eq); |
| 7614 | __ mov(eq, out, 1); |
| 7615 | } else { |
| 7616 | // If `out` is null, we use it for the result, and jump to the final label. |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7617 | __ B(final_label); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7618 | __ Bind(&success); |
| 7619 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7620 | } |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7621 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7622 | break; |
| 7623 | } |
| 7624 | |
| 7625 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7626 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7627 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7628 | out_loc, |
| 7629 | obj_loc, |
| 7630 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7631 | maybe_temp_loc, |
| 7632 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7633 | // Do an exact check. |
| 7634 | vixl32::Label exact_check; |
| 7635 | __ Cmp(out, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7636 | __ B(eq, &exact_check, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7637 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 7638 | // /* HeapReference<Class> */ out = out->component_type_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7639 | GenerateReferenceLoadOneRegister(instruction, |
| 7640 | out_loc, |
| 7641 | component_offset, |
| 7642 | maybe_temp_loc, |
| 7643 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7644 | // 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] | 7645 | __ CompareAndBranchIfZero(out, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7646 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 7647 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7648 | __ Cmp(out, 0); |
| 7649 | // We speculatively set the result to false without changing the condition |
| 7650 | // flags, which allows us to avoid some branching later. |
| 7651 | __ Mov(LeaveFlags, out, 0); |
| 7652 | |
| 7653 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7654 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7655 | // encoding can be used. |
| 7656 | if (out.IsLow()) { |
| 7657 | __ Bind(&exact_check); |
| 7658 | |
| 7659 | // We use the scope because of the IT block that follows. |
| 7660 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7661 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7662 | CodeBufferCheckScope::kExactSize); |
| 7663 | |
| 7664 | __ it(eq); |
| 7665 | __ mov(eq, out, 1); |
| 7666 | } else { |
| 7667 | __ B(ne, final_label, /* far_target */ false); |
| 7668 | __ Bind(&exact_check); |
| 7669 | __ Mov(out, 1); |
| 7670 | } |
| 7671 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7672 | break; |
| 7673 | } |
| 7674 | |
| 7675 | case TypeCheckKind::kArrayCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7676 | // No read barrier since the slow path will retry upon failure. |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7677 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7678 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7679 | out_loc, |
| 7680 | obj_loc, |
| 7681 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7682 | maybe_temp_loc, |
| 7683 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7684 | __ Cmp(out, cls); |
| 7685 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7686 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
| 7687 | instruction, /* is_fatal */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7688 | codegen_->AddSlowPath(slow_path); |
| 7689 | __ B(ne, slow_path->GetEntryLabel()); |
| 7690 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7691 | break; |
| 7692 | } |
| 7693 | |
| 7694 | case TypeCheckKind::kUnresolvedCheck: |
| 7695 | case TypeCheckKind::kInterfaceCheck: { |
| 7696 | // Note that we indeed only call on slow path, but we always go |
| 7697 | // into the slow path for the unresolved and interface check |
| 7698 | // cases. |
| 7699 | // |
| 7700 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7701 | // entry point without resorting to a type checking slow path |
| 7702 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7703 | // require to assign fixed registers for the inputs of this |
| 7704 | // HInstanceOf instruction (following the runtime calling |
| 7705 | // convention), which might be cluttered by the potential first |
| 7706 | // read barrier emission at the beginning of this method. |
| 7707 | // |
| 7708 | // TODO: Introduce a new runtime entry point taking the object |
| 7709 | // to test (instead of its class) as argument, and let it deal |
| 7710 | // with the read barrier issues. This will let us refactor this |
| 7711 | // case of the `switch` code as it was previously (with a direct |
| 7712 | // call to the runtime not using a type checking slow path). |
| 7713 | // This should also be beneficial for the other cases above. |
| 7714 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7715 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
| 7716 | instruction, /* is_fatal */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7717 | codegen_->AddSlowPath(slow_path); |
| 7718 | __ B(slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7719 | break; |
| 7720 | } |
| 7721 | } |
| 7722 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7723 | if (done.IsReferenced()) { |
| 7724 | __ Bind(&done); |
| 7725 | } |
| 7726 | |
| 7727 | if (slow_path != nullptr) { |
| 7728 | __ Bind(slow_path->GetExitLabel()); |
| 7729 | } |
| 7730 | } |
| 7731 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7732 | void LocationsBuilderARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
| 7733 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7734 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 7735 | |
| 7736 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7737 | switch (type_check_kind) { |
| 7738 | case TypeCheckKind::kExactCheck: |
| 7739 | case TypeCheckKind::kAbstractClassCheck: |
| 7740 | case TypeCheckKind::kClassHierarchyCheck: |
| 7741 | case TypeCheckKind::kArrayObjectCheck: |
| 7742 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 7743 | LocationSummary::kCallOnSlowPath : |
| 7744 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
| 7745 | break; |
| 7746 | case TypeCheckKind::kArrayCheck: |
| 7747 | case TypeCheckKind::kUnresolvedCheck: |
| 7748 | case TypeCheckKind::kInterfaceCheck: |
| 7749 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7750 | break; |
| 7751 | } |
| 7752 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7753 | LocationSummary* locations = |
| 7754 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7755 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7756 | locations->SetInAt(1, Location::RequiresRegister()); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7757 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7758 | } |
| 7759 | |
| 7760 | void InstructionCodeGeneratorARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
| 7761 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7762 | LocationSummary* locations = instruction->GetLocations(); |
| 7763 | Location obj_loc = locations->InAt(0); |
| 7764 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 7765 | vixl32::Register cls = InputRegisterAt(instruction, 1); |
| 7766 | Location temp_loc = locations->GetTemp(0); |
| 7767 | vixl32::Register temp = RegisterFrom(temp_loc); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7768 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 7769 | DCHECK_LE(num_temps, 3u); |
| 7770 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 7771 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 7772 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7773 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7774 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7775 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 7776 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 7777 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 7778 | const uint32_t object_array_data_offset = |
| 7779 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7780 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7781 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 7782 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 7783 | // read barriers is done for performance and code size reasons. |
| 7784 | bool is_type_check_slow_path_fatal = false; |
| 7785 | if (!kEmitCompilerReadBarrier) { |
| 7786 | is_type_check_slow_path_fatal = |
| 7787 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 7788 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7789 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7790 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 7791 | !instruction->CanThrowIntoCatchBlock(); |
| 7792 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7793 | SlowPathCodeARMVIXL* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7794 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
| 7795 | instruction, is_type_check_slow_path_fatal); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7796 | codegen_->AddSlowPath(type_check_slow_path); |
| 7797 | |
| 7798 | vixl32::Label done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7799 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7800 | // Avoid null check if we know obj is not null. |
| 7801 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7802 | __ CompareAndBranchIfZero(obj, final_label, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7803 | } |
| 7804 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7805 | switch (type_check_kind) { |
| 7806 | case TypeCheckKind::kExactCheck: |
| 7807 | case TypeCheckKind::kArrayCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7808 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7809 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7810 | temp_loc, |
| 7811 | obj_loc, |
| 7812 | class_offset, |
| 7813 | maybe_temp2_loc, |
| 7814 | kWithoutReadBarrier); |
| 7815 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7816 | __ Cmp(temp, cls); |
| 7817 | // Jump to slow path for throwing the exception or doing a |
| 7818 | // more involved array check. |
| 7819 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 7820 | break; |
| 7821 | } |
| 7822 | |
| 7823 | case TypeCheckKind::kAbstractClassCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7824 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7825 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7826 | temp_loc, |
| 7827 | obj_loc, |
| 7828 | class_offset, |
| 7829 | maybe_temp2_loc, |
| 7830 | kWithoutReadBarrier); |
| 7831 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7832 | // If the class is abstract, we eagerly fetch the super class of the |
| 7833 | // object to avoid doing a comparison we know will fail. |
| 7834 | vixl32::Label loop; |
| 7835 | __ Bind(&loop); |
| 7836 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7837 | GenerateReferenceLoadOneRegister(instruction, |
| 7838 | temp_loc, |
| 7839 | super_offset, |
| 7840 | maybe_temp2_loc, |
| 7841 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7842 | |
| 7843 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7844 | // exception. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7845 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7846 | |
| 7847 | // Otherwise, compare the classes. |
| 7848 | __ Cmp(temp, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7849 | __ B(ne, &loop, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7850 | break; |
| 7851 | } |
| 7852 | |
| 7853 | case TypeCheckKind::kClassHierarchyCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7854 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7855 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7856 | temp_loc, |
| 7857 | obj_loc, |
| 7858 | class_offset, |
| 7859 | maybe_temp2_loc, |
| 7860 | kWithoutReadBarrier); |
| 7861 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7862 | // Walk over the class hierarchy to find a match. |
| 7863 | vixl32::Label loop; |
| 7864 | __ Bind(&loop); |
| 7865 | __ Cmp(temp, cls); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7866 | __ B(eq, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7867 | |
| 7868 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7869 | GenerateReferenceLoadOneRegister(instruction, |
| 7870 | temp_loc, |
| 7871 | super_offset, |
| 7872 | maybe_temp2_loc, |
| 7873 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7874 | |
| 7875 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7876 | // exception. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7877 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7878 | // Otherwise, jump to the beginning of the loop. |
| 7879 | __ B(&loop); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7880 | break; |
| 7881 | } |
| 7882 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7883 | case TypeCheckKind::kArrayObjectCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7884 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7885 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7886 | temp_loc, |
| 7887 | obj_loc, |
| 7888 | class_offset, |
| 7889 | maybe_temp2_loc, |
| 7890 | kWithoutReadBarrier); |
| 7891 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7892 | // Do an exact check. |
| 7893 | __ Cmp(temp, cls); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7894 | __ B(eq, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7895 | |
| 7896 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 7897 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7898 | GenerateReferenceLoadOneRegister(instruction, |
| 7899 | temp_loc, |
| 7900 | component_offset, |
| 7901 | maybe_temp2_loc, |
| 7902 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7903 | // 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] | 7904 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7905 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 7906 | // to further check that this component type is not a primitive type. |
| 7907 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7908 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7909 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7910 | break; |
| 7911 | } |
| 7912 | |
| 7913 | case TypeCheckKind::kUnresolvedCheck: |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7914 | // 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] | 7915 | // We cannot directly call the CheckCast runtime entry point |
| 7916 | // without resorting to a type checking slow path here (i.e. by |
| 7917 | // calling InvokeRuntime directly), as it would require to |
| 7918 | // assign fixed registers for the inputs of this HInstanceOf |
| 7919 | // instruction (following the runtime calling convention), which |
| 7920 | // might be cluttered by the potential first read barrier |
| 7921 | // emission at the beginning of this method. |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7922 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7923 | __ B(type_check_slow_path->GetEntryLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7924 | break; |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7925 | |
| 7926 | case TypeCheckKind::kInterfaceCheck: { |
| 7927 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 7928 | // positives by doing this. |
| 7929 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7930 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7931 | temp_loc, |
| 7932 | obj_loc, |
| 7933 | class_offset, |
| 7934 | maybe_temp2_loc, |
| 7935 | kWithoutReadBarrier); |
| 7936 | |
| 7937 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 7938 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7939 | temp_loc, |
| 7940 | temp_loc, |
| 7941 | iftable_offset, |
| 7942 | maybe_temp2_loc, |
| 7943 | kWithoutReadBarrier); |
| 7944 | // Iftable is never null. |
| 7945 | __ Ldr(RegisterFrom(maybe_temp2_loc), MemOperand(temp, array_length_offset)); |
| 7946 | // Loop through the iftable and check if any class matches. |
| 7947 | vixl32::Label start_loop; |
| 7948 | __ Bind(&start_loop); |
| 7949 | __ CompareAndBranchIfZero(RegisterFrom(maybe_temp2_loc), |
| 7950 | type_check_slow_path->GetEntryLabel()); |
| 7951 | __ Ldr(RegisterFrom(maybe_temp3_loc), MemOperand(temp, object_array_data_offset)); |
| 7952 | GetAssembler()->MaybeUnpoisonHeapReference(RegisterFrom(maybe_temp3_loc)); |
| 7953 | // Go to next interface. |
| 7954 | __ Add(temp, temp, Operand::From(2 * kHeapReferenceSize)); |
| 7955 | __ Sub(RegisterFrom(maybe_temp2_loc), RegisterFrom(maybe_temp2_loc), 2); |
| 7956 | // Compare the classes and continue the loop if they do not match. |
| 7957 | __ Cmp(cls, RegisterFrom(maybe_temp3_loc)); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7958 | __ B(ne, &start_loop, /* far_target */ false); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7959 | break; |
| 7960 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7961 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7962 | if (done.IsReferenced()) { |
| 7963 | __ Bind(&done); |
| 7964 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7965 | |
| 7966 | __ Bind(type_check_slow_path->GetExitLabel()); |
| 7967 | } |
| 7968 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 7969 | void LocationsBuilderARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7970 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7971 | instruction, LocationSummary::kCallOnMainOnly); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 7972 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7973 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7974 | } |
| 7975 | |
| 7976 | void InstructionCodeGeneratorARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 7977 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 7978 | instruction, |
| 7979 | instruction->GetDexPc()); |
| 7980 | if (instruction->IsEnter()) { |
| 7981 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 7982 | } else { |
| 7983 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 7984 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 7985 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 17); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 7986 | } |
| 7987 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 7988 | void LocationsBuilderARMVIXL::VisitAnd(HAnd* instruction) { |
| 7989 | HandleBitwiseOperation(instruction, AND); |
| 7990 | } |
| 7991 | |
| 7992 | void LocationsBuilderARMVIXL::VisitOr(HOr* instruction) { |
| 7993 | HandleBitwiseOperation(instruction, ORR); |
| 7994 | } |
| 7995 | |
| 7996 | void LocationsBuilderARMVIXL::VisitXor(HXor* instruction) { |
| 7997 | HandleBitwiseOperation(instruction, EOR); |
| 7998 | } |
| 7999 | |
| 8000 | void LocationsBuilderARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
| 8001 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8002 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8003 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 8004 | || instruction->GetResultType() == DataType::Type::kInt64); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8005 | // Note: GVN reorders commutative operations to have the constant on the right hand side. |
| 8006 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8007 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
| 8008 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8009 | } |
| 8010 | |
| 8011 | void InstructionCodeGeneratorARMVIXL::VisitAnd(HAnd* instruction) { |
| 8012 | HandleBitwiseOperation(instruction); |
| 8013 | } |
| 8014 | |
| 8015 | void InstructionCodeGeneratorARMVIXL::VisitOr(HOr* instruction) { |
| 8016 | HandleBitwiseOperation(instruction); |
| 8017 | } |
| 8018 | |
| 8019 | void InstructionCodeGeneratorARMVIXL::VisitXor(HXor* instruction) { |
| 8020 | HandleBitwiseOperation(instruction); |
| 8021 | } |
| 8022 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8023 | void LocationsBuilderARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 8024 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8025 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8026 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 8027 | || instruction->GetResultType() == DataType::Type::kInt64); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8028 | |
| 8029 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8030 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8031 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8032 | } |
| 8033 | |
| 8034 | void InstructionCodeGeneratorARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 8035 | LocationSummary* locations = instruction->GetLocations(); |
| 8036 | Location first = locations->InAt(0); |
| 8037 | Location second = locations->InAt(1); |
| 8038 | Location out = locations->Out(); |
| 8039 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8040 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8041 | vixl32::Register first_reg = RegisterFrom(first); |
| 8042 | vixl32::Register second_reg = RegisterFrom(second); |
| 8043 | vixl32::Register out_reg = RegisterFrom(out); |
| 8044 | |
| 8045 | switch (instruction->GetOpKind()) { |
| 8046 | case HInstruction::kAnd: |
| 8047 | __ Bic(out_reg, first_reg, second_reg); |
| 8048 | break; |
| 8049 | case HInstruction::kOr: |
| 8050 | __ Orn(out_reg, first_reg, second_reg); |
| 8051 | break; |
| 8052 | // There is no EON on arm. |
| 8053 | case HInstruction::kXor: |
| 8054 | default: |
| 8055 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 8056 | UNREACHABLE(); |
| 8057 | } |
| 8058 | return; |
| 8059 | |
| 8060 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8061 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8062 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8063 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8064 | vixl32::Register second_low = LowRegisterFrom(second); |
| 8065 | vixl32::Register second_high = HighRegisterFrom(second); |
| 8066 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8067 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8068 | |
| 8069 | switch (instruction->GetOpKind()) { |
| 8070 | case HInstruction::kAnd: |
| 8071 | __ Bic(out_low, first_low, second_low); |
| 8072 | __ Bic(out_high, first_high, second_high); |
| 8073 | break; |
| 8074 | case HInstruction::kOr: |
| 8075 | __ Orn(out_low, first_low, second_low); |
| 8076 | __ Orn(out_high, first_high, second_high); |
| 8077 | break; |
| 8078 | // There is no EON on arm. |
| 8079 | case HInstruction::kXor: |
| 8080 | default: |
| 8081 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 8082 | UNREACHABLE(); |
| 8083 | } |
| 8084 | } |
| 8085 | } |
| 8086 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8087 | void LocationsBuilderARMVIXL::VisitDataProcWithShifterOp( |
| 8088 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8089 | DCHECK(instruction->GetType() == DataType::Type::kInt32 || |
| 8090 | instruction->GetType() == DataType::Type::kInt64); |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8091 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8092 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8093 | const bool overlap = instruction->GetType() == DataType::Type::kInt64 && |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8094 | HDataProcWithShifterOp::IsExtensionOp(instruction->GetOpKind()); |
| 8095 | |
| 8096 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8097 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8098 | locations->SetOut(Location::RequiresRegister(), |
| 8099 | overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 8100 | } |
| 8101 | |
| 8102 | void InstructionCodeGeneratorARMVIXL::VisitDataProcWithShifterOp( |
| 8103 | HDataProcWithShifterOp* instruction) { |
| 8104 | const LocationSummary* const locations = instruction->GetLocations(); |
| 8105 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 8106 | const HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 8107 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8108 | if (instruction->GetType() == DataType::Type::kInt32) { |
Anton Kirilov | 420ee30 | 2017-02-21 18:10:26 +0000 | [diff] [blame] | 8109 | const vixl32::Register first = InputRegisterAt(instruction, 0); |
| 8110 | const vixl32::Register output = OutputRegister(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8111 | const vixl32::Register second = instruction->InputAt(1)->GetType() == DataType::Type::kInt64 |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8112 | ? LowRegisterFrom(locations->InAt(1)) |
| 8113 | : InputRegisterAt(instruction, 1); |
| 8114 | |
Anton Kirilov | 420ee30 | 2017-02-21 18:10:26 +0000 | [diff] [blame] | 8115 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 8116 | DCHECK_EQ(kind, HInstruction::kAdd); |
| 8117 | |
| 8118 | switch (op_kind) { |
| 8119 | case HDataProcWithShifterOp::kUXTB: |
| 8120 | __ Uxtab(output, first, second); |
| 8121 | break; |
| 8122 | case HDataProcWithShifterOp::kUXTH: |
| 8123 | __ Uxtah(output, first, second); |
| 8124 | break; |
| 8125 | case HDataProcWithShifterOp::kSXTB: |
| 8126 | __ Sxtab(output, first, second); |
| 8127 | break; |
| 8128 | case HDataProcWithShifterOp::kSXTH: |
| 8129 | __ Sxtah(output, first, second); |
| 8130 | break; |
| 8131 | default: |
| 8132 | LOG(FATAL) << "Unexpected operation kind: " << op_kind; |
| 8133 | UNREACHABLE(); |
| 8134 | } |
| 8135 | } else { |
| 8136 | GenerateDataProcInstruction(kind, |
| 8137 | output, |
| 8138 | first, |
| 8139 | Operand(second, |
| 8140 | ShiftFromOpKind(op_kind), |
| 8141 | instruction->GetShiftAmount()), |
| 8142 | codegen_); |
| 8143 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8144 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8145 | DCHECK_EQ(instruction->GetType(), DataType::Type::kInt64); |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8146 | |
| 8147 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 8148 | const vixl32::Register second = InputRegisterAt(instruction, 1); |
| 8149 | |
| 8150 | DCHECK(!LowRegisterFrom(locations->Out()).Is(second)); |
| 8151 | GenerateDataProc(kind, |
| 8152 | locations->Out(), |
| 8153 | locations->InAt(0), |
| 8154 | second, |
| 8155 | Operand(second, ShiftType::ASR, 31), |
| 8156 | codegen_); |
| 8157 | } else { |
| 8158 | GenerateLongDataProc(instruction, codegen_); |
| 8159 | } |
| 8160 | } |
| 8161 | } |
| 8162 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8163 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8164 | void InstructionCodeGeneratorARMVIXL::GenerateAndConst(vixl32::Register out, |
| 8165 | vixl32::Register first, |
| 8166 | uint32_t value) { |
| 8167 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 8168 | if (value == 0xffffffffu) { |
| 8169 | if (!out.Is(first)) { |
| 8170 | __ Mov(out, first); |
| 8171 | } |
| 8172 | return; |
| 8173 | } |
| 8174 | if (value == 0u) { |
| 8175 | __ Mov(out, 0); |
| 8176 | return; |
| 8177 | } |
| 8178 | if (GetAssembler()->ShifterOperandCanHold(AND, value)) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 8179 | __ And(out, first, value); |
| 8180 | } else if (GetAssembler()->ShifterOperandCanHold(BIC, ~value)) { |
| 8181 | __ Bic(out, first, ~value); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8182 | } else { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 8183 | DCHECK(IsPowerOfTwo(value + 1)); |
| 8184 | __ Ubfx(out, first, 0, WhichPowerOf2(value + 1)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8185 | } |
| 8186 | } |
| 8187 | |
| 8188 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8189 | void InstructionCodeGeneratorARMVIXL::GenerateOrrConst(vixl32::Register out, |
| 8190 | vixl32::Register first, |
| 8191 | uint32_t value) { |
| 8192 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 8193 | if (value == 0u) { |
| 8194 | if (!out.Is(first)) { |
| 8195 | __ Mov(out, first); |
| 8196 | } |
| 8197 | return; |
| 8198 | } |
| 8199 | if (value == 0xffffffffu) { |
| 8200 | __ Mvn(out, 0); |
| 8201 | return; |
| 8202 | } |
| 8203 | if (GetAssembler()->ShifterOperandCanHold(ORR, value)) { |
| 8204 | __ Orr(out, first, value); |
| 8205 | } else { |
| 8206 | DCHECK(GetAssembler()->ShifterOperandCanHold(ORN, ~value)); |
| 8207 | __ Orn(out, first, ~value); |
| 8208 | } |
| 8209 | } |
| 8210 | |
| 8211 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8212 | void InstructionCodeGeneratorARMVIXL::GenerateEorConst(vixl32::Register out, |
| 8213 | vixl32::Register first, |
| 8214 | uint32_t value) { |
| 8215 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 8216 | if (value == 0u) { |
| 8217 | if (!out.Is(first)) { |
| 8218 | __ Mov(out, first); |
| 8219 | } |
| 8220 | return; |
| 8221 | } |
| 8222 | __ Eor(out, first, value); |
| 8223 | } |
| 8224 | |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8225 | void InstructionCodeGeneratorARMVIXL::GenerateAddLongConst(Location out, |
| 8226 | Location first, |
| 8227 | uint64_t value) { |
| 8228 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8229 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8230 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8231 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8232 | uint32_t value_low = Low32Bits(value); |
| 8233 | uint32_t value_high = High32Bits(value); |
| 8234 | if (value_low == 0u) { |
| 8235 | if (!out_low.Is(first_low)) { |
| 8236 | __ Mov(out_low, first_low); |
| 8237 | } |
| 8238 | __ Add(out_high, first_high, value_high); |
| 8239 | return; |
| 8240 | } |
| 8241 | __ Adds(out_low, first_low, value_low); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 8242 | if (GetAssembler()->ShifterOperandCanHold(ADC, value_high, kCcDontCare)) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8243 | __ Adc(out_high, first_high, value_high); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 8244 | } else if (GetAssembler()->ShifterOperandCanHold(SBC, ~value_high, kCcDontCare)) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8245 | __ Sbc(out_high, first_high, ~value_high); |
| 8246 | } else { |
| 8247 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 8248 | UNREACHABLE(); |
| 8249 | } |
| 8250 | } |
| 8251 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8252 | void InstructionCodeGeneratorARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 8253 | LocationSummary* locations = instruction->GetLocations(); |
| 8254 | Location first = locations->InAt(0); |
| 8255 | Location second = locations->InAt(1); |
| 8256 | Location out = locations->Out(); |
| 8257 | |
| 8258 | if (second.IsConstant()) { |
| 8259 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 8260 | uint32_t value_low = Low32Bits(value); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8261 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8262 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 8263 | vixl32::Register out_reg = OutputRegister(instruction); |
| 8264 | if (instruction->IsAnd()) { |
| 8265 | GenerateAndConst(out_reg, first_reg, value_low); |
| 8266 | } else if (instruction->IsOr()) { |
| 8267 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 8268 | } else { |
| 8269 | DCHECK(instruction->IsXor()); |
| 8270 | GenerateEorConst(out_reg, first_reg, value_low); |
| 8271 | } |
| 8272 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8273 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8274 | uint32_t value_high = High32Bits(value); |
| 8275 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8276 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8277 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8278 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8279 | if (instruction->IsAnd()) { |
| 8280 | GenerateAndConst(out_low, first_low, value_low); |
| 8281 | GenerateAndConst(out_high, first_high, value_high); |
| 8282 | } else if (instruction->IsOr()) { |
| 8283 | GenerateOrrConst(out_low, first_low, value_low); |
| 8284 | GenerateOrrConst(out_high, first_high, value_high); |
| 8285 | } else { |
| 8286 | DCHECK(instruction->IsXor()); |
| 8287 | GenerateEorConst(out_low, first_low, value_low); |
| 8288 | GenerateEorConst(out_high, first_high, value_high); |
| 8289 | } |
| 8290 | } |
| 8291 | return; |
| 8292 | } |
| 8293 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8294 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8295 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 8296 | vixl32::Register second_reg = InputRegisterAt(instruction, 1); |
| 8297 | vixl32::Register out_reg = OutputRegister(instruction); |
| 8298 | if (instruction->IsAnd()) { |
| 8299 | __ And(out_reg, first_reg, second_reg); |
| 8300 | } else if (instruction->IsOr()) { |
| 8301 | __ Orr(out_reg, first_reg, second_reg); |
| 8302 | } else { |
| 8303 | DCHECK(instruction->IsXor()); |
| 8304 | __ Eor(out_reg, first_reg, second_reg); |
| 8305 | } |
| 8306 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8307 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8308 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8309 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8310 | vixl32::Register second_low = LowRegisterFrom(second); |
| 8311 | vixl32::Register second_high = HighRegisterFrom(second); |
| 8312 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8313 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8314 | if (instruction->IsAnd()) { |
| 8315 | __ And(out_low, first_low, second_low); |
| 8316 | __ And(out_high, first_high, second_high); |
| 8317 | } else if (instruction->IsOr()) { |
| 8318 | __ Orr(out_low, first_low, second_low); |
| 8319 | __ Orr(out_high, first_high, second_high); |
| 8320 | } else { |
| 8321 | DCHECK(instruction->IsXor()); |
| 8322 | __ Eor(out_low, first_low, second_low); |
| 8323 | __ Eor(out_high, first_high, second_high); |
| 8324 | } |
| 8325 | } |
| 8326 | } |
| 8327 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8328 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadOneRegister( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8329 | HInstruction* instruction, |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8330 | Location out, |
| 8331 | uint32_t offset, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8332 | Location maybe_temp, |
| 8333 | ReadBarrierOption read_barrier_option) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8334 | vixl32::Register out_reg = RegisterFrom(out); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8335 | if (read_barrier_option == kWithReadBarrier) { |
| 8336 | CHECK(kEmitCompilerReadBarrier); |
| 8337 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 8338 | if (kUseBakerReadBarrier) { |
| 8339 | // Load with fast path based Baker's read barrier. |
| 8340 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8341 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 8342 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
| 8343 | } else { |
| 8344 | // Load with slow path based read barrier. |
| 8345 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 8346 | // in the following move operation, as we will need it for the |
| 8347 | // read barrier below. |
| 8348 | __ Mov(RegisterFrom(maybe_temp), out_reg); |
| 8349 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8350 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 8351 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 8352 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8353 | } else { |
| 8354 | // Plain load with no read barrier. |
| 8355 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8356 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 8357 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 8358 | } |
| 8359 | } |
| 8360 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8361 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadTwoRegisters( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8362 | HInstruction* instruction, |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8363 | Location out, |
| 8364 | Location obj, |
| 8365 | uint32_t offset, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8366 | Location maybe_temp, |
| 8367 | ReadBarrierOption read_barrier_option) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8368 | vixl32::Register out_reg = RegisterFrom(out); |
| 8369 | vixl32::Register obj_reg = RegisterFrom(obj); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8370 | if (read_barrier_option == kWithReadBarrier) { |
| 8371 | CHECK(kEmitCompilerReadBarrier); |
| 8372 | if (kUseBakerReadBarrier) { |
| 8373 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 8374 | // Load with fast path based Baker's read barrier. |
| 8375 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8376 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 8377 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
| 8378 | } else { |
| 8379 | // Load with slow path based read barrier. |
| 8380 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8381 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8382 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 8383 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8384 | } else { |
| 8385 | // Plain load with no read barrier. |
| 8386 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8387 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8388 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 8389 | } |
| 8390 | } |
| 8391 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8392 | void InstructionCodeGeneratorARMVIXL::GenerateGcRootFieldLoad( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8393 | HInstruction* instruction, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8394 | Location root, |
| 8395 | vixl32::Register obj, |
| 8396 | uint32_t offset, |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8397 | ReadBarrierOption read_barrier_option) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8398 | vixl32::Register root_reg = RegisterFrom(root); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8399 | if (read_barrier_option == kWithReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8400 | DCHECK(kEmitCompilerReadBarrier); |
| 8401 | if (kUseBakerReadBarrier) { |
| 8402 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8403 | // Baker's read barrier are used. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8404 | if (kBakerReadBarrierLinkTimeThunksEnableForGcRoots && |
| 8405 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8406 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 8407 | // the Marking Register) to decide whether we need to enter |
| 8408 | // the slow path to mark the GC root. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8409 | // |
| 8410 | // We use link-time generated thunks for the slow path. That thunk |
| 8411 | // checks the reference and jumps to the entrypoint if needed. |
| 8412 | // |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8413 | // lr = &return_address; |
| 8414 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8415 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8416 | // goto gc_root_thunk<root_reg>(lr) |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8417 | // } |
| 8418 | // return_address: |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8419 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8420 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8421 | ExcludeIPAndBakerCcEntrypointRegister(&temps, instruction); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8422 | bool narrow = CanEmitNarrowLdr(root_reg, obj, offset); |
| 8423 | uint32_t custom_data = linker::Thumb2RelativePatcher::EncodeBakerReadBarrierGcRootData( |
| 8424 | root_reg.GetCode(), narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8425 | vixl32::Label* bne_label = codegen_->NewBakerReadBarrierPatch(custom_data); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8426 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8427 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), 4 * vixl32::kMaxInstructionSizeInBytes); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8428 | vixl32::Label return_address; |
| 8429 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8430 | __ cmp(mr, Operand(0)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8431 | // Currently the offset is always within range. If that changes, |
| 8432 | // we shall have to split the load the same way as for fields. |
| 8433 | DCHECK_LT(offset, kReferenceLoadMinFarOffset); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8434 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8435 | __ ldr(EncodingSize(narrow ? Narrow : Wide), root_reg, MemOperand(obj, offset)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8436 | EmitPlaceholderBne(codegen_, bne_label); |
| 8437 | __ Bind(&return_address); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8438 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8439 | narrow ? BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_OFFSET |
| 8440 | : BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8441 | } else { |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8442 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 8443 | // the Marking Register) to decide whether we need to enter |
| 8444 | // the slow path to mark the GC root. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8445 | // |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8446 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8447 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8448 | // // Slow path. |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8449 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8450 | // root = entrypoint(root); // root = ReadBarrier::Mark(root); // Entry point call. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8451 | // } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8452 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8453 | // Slow path marking the GC root `root`. The entrypoint will |
| 8454 | // be loaded by the slow path code. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8455 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8456 | new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathARMVIXL(instruction, root); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8457 | codegen_->AddSlowPath(slow_path); |
| 8458 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8459 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8460 | GetAssembler()->LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8461 | static_assert( |
| 8462 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 8463 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 8464 | "have different sizes."); |
| 8465 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 8466 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 8467 | "have different sizes."); |
| 8468 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8469 | __ CompareAndBranchIfNonZero(mr, slow_path->GetEntryLabel()); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8470 | __ Bind(slow_path->GetExitLabel()); |
| 8471 | } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8472 | } else { |
| 8473 | // GC root loaded through a slow path for read barriers other |
| 8474 | // than Baker's. |
| 8475 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 8476 | __ Add(root_reg, obj, offset); |
| 8477 | // /* mirror::Object* */ root = root->Read() |
| 8478 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 8479 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8480 | } else { |
| 8481 | // Plain GC root load with no read barrier. |
| 8482 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8483 | GetAssembler()->LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8484 | // Note that GC roots are not affected by heap poisoning, thus we |
| 8485 | // do not have to unpoison `root_reg` here. |
| 8486 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8487 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 18); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8488 | } |
| 8489 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8490 | void CodeGeneratorARMVIXL::MaybeAddBakerCcEntrypointTempForFields(LocationSummary* locations) { |
| 8491 | DCHECK(kEmitCompilerReadBarrier); |
| 8492 | DCHECK(kUseBakerReadBarrier); |
| 8493 | if (kBakerReadBarrierLinkTimeThunksEnableForFields) { |
| 8494 | if (!Runtime::Current()->UseJitCompilation()) { |
| 8495 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 8496 | } |
| 8497 | } |
| 8498 | } |
| 8499 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8500 | void CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8501 | Location ref, |
| 8502 | vixl32::Register obj, |
| 8503 | uint32_t offset, |
| 8504 | Location temp, |
| 8505 | bool needs_null_check) { |
| 8506 | DCHECK(kEmitCompilerReadBarrier); |
| 8507 | DCHECK(kUseBakerReadBarrier); |
| 8508 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8509 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 8510 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8511 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 8512 | // Marking Register) to decide whether we need to enter the slow |
| 8513 | // path to mark the reference. Then, in the slow path, check the |
| 8514 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 8515 | // decide whether to mark `ref` or not. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8516 | // |
| 8517 | // We use link-time generated thunks for the slow path. That thunk checks |
| 8518 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 8519 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 8520 | // |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8521 | // lr = &gray_return_address; |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8522 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8523 | // goto field_thunk<holder_reg, base_reg>(lr) |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8524 | // } |
| 8525 | // not_gray_return_address: |
| 8526 | // // Original reference load. If the offset is too large to fit |
| 8527 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8528 | // HeapReference<mirror::Object> reference = *(obj+offset); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8529 | // gray_return_address: |
| 8530 | |
| 8531 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8532 | vixl32::Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8533 | bool narrow = CanEmitNarrowLdr(ref_reg, obj, offset); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8534 | vixl32::Register base = obj; |
| 8535 | if (offset >= kReferenceLoadMinFarOffset) { |
| 8536 | base = RegisterFrom(temp); |
| 8537 | DCHECK(!base.Is(kBakerCcEntrypointRegister)); |
| 8538 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 8539 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 8540 | offset &= (kReferenceLoadMinFarOffset - 1u); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8541 | // Use narrow LDR only for small offsets. Generating narrow encoding LDR for the large |
| 8542 | // offsets with `(offset & (kReferenceLoadMinFarOffset - 1u)) < 32u` would most likely |
| 8543 | // increase the overall code size when taking the generated thunks into account. |
| 8544 | DCHECK(!narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8545 | } |
| 8546 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8547 | ExcludeIPAndBakerCcEntrypointRegister(&temps, instruction); |
| 8548 | uint32_t custom_data = linker::Thumb2RelativePatcher::EncodeBakerReadBarrierFieldData( |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8549 | base.GetCode(), obj.GetCode(), narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8550 | vixl32::Label* bne_label = NewBakerReadBarrierPatch(custom_data); |
| 8551 | |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8552 | { |
| 8553 | vixl::EmissionCheckScope guard( |
| 8554 | GetVIXLAssembler(), |
| 8555 | (kPoisonHeapReferences ? 5u : 4u) * vixl32::kMaxInstructionSizeInBytes); |
| 8556 | vixl32::Label return_address; |
| 8557 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8558 | __ cmp(mr, Operand(0)); |
| 8559 | EmitPlaceholderBne(this, bne_label); |
| 8560 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8561 | __ ldr(EncodingSize(narrow ? Narrow : Wide), ref_reg, MemOperand(base, offset)); |
| 8562 | if (needs_null_check) { |
| 8563 | MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8564 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8565 | // Note: We need a specific width for the unpoisoning NEG. |
| 8566 | if (kPoisonHeapReferences) { |
| 8567 | if (narrow) { |
| 8568 | // The only 16-bit encoding is T1 which sets flags outside IT block (i.e. RSBS, not RSB). |
| 8569 | __ rsbs(EncodingSize(Narrow), ref_reg, ref_reg, Operand(0)); |
| 8570 | } else { |
| 8571 | __ rsb(EncodingSize(Wide), ref_reg, ref_reg, Operand(0)); |
| 8572 | } |
| 8573 | } |
| 8574 | __ Bind(&return_address); |
| 8575 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8576 | narrow ? BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_OFFSET |
| 8577 | : BAKER_MARK_INTROSPECTION_FIELD_LDR_WIDE_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8578 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8579 | MaybeGenerateMarkingRegisterCheck(/* code */ 19, /* temp_loc */ LocationFrom(ip)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8580 | return; |
| 8581 | } |
| 8582 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8583 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 8584 | Location no_index = Location::NoLocation(); |
| 8585 | ScaleFactor no_scale_factor = TIMES_1; |
| 8586 | GenerateReferenceLoadWithBakerReadBarrier( |
| 8587 | 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] | 8588 | } |
| 8589 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8590 | void CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8591 | Location ref, |
| 8592 | vixl32::Register obj, |
| 8593 | uint32_t data_offset, |
| 8594 | Location index, |
| 8595 | Location temp, |
| 8596 | bool needs_null_check) { |
| 8597 | DCHECK(kEmitCompilerReadBarrier); |
| 8598 | DCHECK(kUseBakerReadBarrier); |
| 8599 | |
| 8600 | static_assert( |
| 8601 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 8602 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8603 | ScaleFactor scale_factor = TIMES_4; |
| 8604 | |
| 8605 | if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 8606 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8607 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 8608 | // Marking Register) to decide whether we need to enter the slow |
| 8609 | // path to mark the reference. Then, in the slow path, check the |
| 8610 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 8611 | // decide whether to mark `ref` or not. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8612 | // |
| 8613 | // We use link-time generated thunks for the slow path. That thunk checks |
| 8614 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 8615 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 8616 | // |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8617 | // lr = &gray_return_address; |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8618 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8619 | // goto array_thunk<base_reg>(lr) |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8620 | // } |
| 8621 | // not_gray_return_address: |
| 8622 | // // Original reference load. If the offset is too large to fit |
| 8623 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8624 | // HeapReference<mirror::Object> reference = data[index]; |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8625 | // gray_return_address: |
| 8626 | |
| 8627 | DCHECK(index.IsValid()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8628 | vixl32::Register index_reg = RegisterFrom(index, DataType::Type::kInt32); |
| 8629 | vixl32::Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
| 8630 | vixl32::Register data_reg = RegisterFrom(temp, DataType::Type::kInt32); // Raw pointer. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8631 | DCHECK(!data_reg.Is(kBakerCcEntrypointRegister)); |
| 8632 | |
| 8633 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8634 | ExcludeIPAndBakerCcEntrypointRegister(&temps, instruction); |
| 8635 | uint32_t custom_data = |
| 8636 | linker::Thumb2RelativePatcher::EncodeBakerReadBarrierArrayData(data_reg.GetCode()); |
| 8637 | vixl32::Label* bne_label = NewBakerReadBarrierPatch(custom_data); |
| 8638 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8639 | __ Add(data_reg, obj, Operand(data_offset)); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8640 | { |
| 8641 | vixl::EmissionCheckScope guard( |
| 8642 | GetVIXLAssembler(), |
| 8643 | (kPoisonHeapReferences ? 5u : 4u) * vixl32::kMaxInstructionSizeInBytes); |
| 8644 | vixl32::Label return_address; |
| 8645 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8646 | __ cmp(mr, Operand(0)); |
| 8647 | EmitPlaceholderBne(this, bne_label); |
| 8648 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8649 | __ ldr(ref_reg, MemOperand(data_reg, index_reg, vixl32::LSL, scale_factor)); |
| 8650 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 8651 | // Note: We need a Wide NEG for the unpoisoning. |
| 8652 | if (kPoisonHeapReferences) { |
| 8653 | __ rsb(EncodingSize(Wide), ref_reg, ref_reg, Operand(0)); |
| 8654 | } |
| 8655 | __ Bind(&return_address); |
| 8656 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8657 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8658 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8659 | MaybeGenerateMarkingRegisterCheck(/* code */ 20, /* temp_loc */ LocationFrom(ip)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8660 | return; |
| 8661 | } |
| 8662 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8663 | // /* HeapReference<Object> */ ref = |
| 8664 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8665 | GenerateReferenceLoadWithBakerReadBarrier( |
| 8666 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | 6070e88 | 2016-11-03 17:51:58 +0000 | [diff] [blame] | 8667 | } |
| 8668 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8669 | void CodeGeneratorARMVIXL::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8670 | Location ref, |
| 8671 | vixl32::Register obj, |
| 8672 | uint32_t offset, |
| 8673 | Location index, |
| 8674 | ScaleFactor scale_factor, |
| 8675 | Location temp, |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8676 | bool needs_null_check) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8677 | DCHECK(kEmitCompilerReadBarrier); |
| 8678 | DCHECK(kUseBakerReadBarrier); |
| 8679 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8680 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 8681 | // Marking Register) to decide whether we need to enter the slow |
| 8682 | // path to mark the reference. Then, in the slow path, check the |
| 8683 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 8684 | // decide whether to mark `ref` or not. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8685 | // |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8686 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8687 | // // Slow path. |
| 8688 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8689 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 8690 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 8691 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 8692 | // if (is_gray) { |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8693 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8694 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8695 | // } |
| 8696 | // } else { |
| 8697 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 8698 | // } |
| 8699 | |
| 8700 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 8701 | |
| 8702 | // Slow path marking the object `ref` when the GC is marking. The |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8703 | // entrypoint will be loaded by the slow path code. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8704 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8705 | new (GetScopedAllocator()) LoadReferenceWithBakerReadBarrierSlowPathARMVIXL( |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8706 | instruction, ref, obj, offset, index, scale_factor, needs_null_check, temp_reg); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8707 | AddSlowPath(slow_path); |
| 8708 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8709 | __ CompareAndBranchIfNonZero(mr, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8710 | // Fast path: the GC is not marking: just load the reference. |
| 8711 | GenerateRawReferenceLoad(instruction, ref, obj, offset, index, scale_factor, needs_null_check); |
| 8712 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8713 | MaybeGenerateMarkingRegisterCheck(/* code */ 21); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8714 | } |
| 8715 | |
| 8716 | void CodeGeneratorARMVIXL::UpdateReferenceFieldWithBakerReadBarrier(HInstruction* instruction, |
| 8717 | Location ref, |
| 8718 | vixl32::Register obj, |
| 8719 | Location field_offset, |
| 8720 | Location temp, |
| 8721 | bool needs_null_check, |
| 8722 | vixl32::Register temp2) { |
| 8723 | DCHECK(kEmitCompilerReadBarrier); |
| 8724 | DCHECK(kUseBakerReadBarrier); |
| 8725 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8726 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 8727 | // Marking Register) to decide whether we need to enter the slow |
| 8728 | // path to update the reference field within `obj`. Then, in the |
| 8729 | // slow path, check the gray bit in the lock word of the reference's |
| 8730 | // holder (`obj`) to decide whether to mark `ref` and update the |
| 8731 | // field or not. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8732 | // |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8733 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8734 | // // Slow path. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8735 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8736 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8737 | // HeapReference<mirror::Object> ref = *(obj + field_offset); // Reference load. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8738 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 8739 | // if (is_gray) { |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8740 | // old_ref = ref; |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8741 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8742 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8743 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8744 | // } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8745 | // } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8746 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8747 | vixl32::Register temp_reg = RegisterFrom(temp); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8748 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8749 | // Slow path updating the object reference at address `obj + field_offset` |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8750 | // 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] | 8751 | SlowPathCodeARMVIXL* slow_path = |
| 8752 | new (GetScopedAllocator()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL( |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8753 | instruction, |
| 8754 | ref, |
| 8755 | obj, |
| 8756 | /* offset */ 0u, |
| 8757 | /* index */ field_offset, |
| 8758 | /* scale_factor */ ScaleFactor::TIMES_1, |
| 8759 | needs_null_check, |
| 8760 | temp_reg, |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8761 | temp2); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8762 | AddSlowPath(slow_path); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8763 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8764 | __ CompareAndBranchIfNonZero(mr, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8765 | // Fast path: the GC is not marking: nothing to do (the field is |
| 8766 | // up-to-date, and we don't need to load the reference). |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8767 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8768 | MaybeGenerateMarkingRegisterCheck(/* code */ 22); |
Roland Levillain | 844e653 | 2016-11-03 16:09:47 +0000 | [diff] [blame] | 8769 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8770 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8771 | void CodeGeneratorARMVIXL::GenerateRawReferenceLoad(HInstruction* instruction, |
| 8772 | Location ref, |
| 8773 | vixl::aarch32::Register obj, |
| 8774 | uint32_t offset, |
| 8775 | Location index, |
| 8776 | ScaleFactor scale_factor, |
| 8777 | bool needs_null_check) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8778 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8779 | vixl32::Register ref_reg = RegisterFrom(ref, type); |
| 8780 | |
| 8781 | // If needed, vixl::EmissionCheckScope guards are used to ensure |
| 8782 | // that no pools are emitted between the load (macro) instruction |
| 8783 | // and MaybeRecordImplicitNullCheck. |
| 8784 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8785 | if (index.IsValid()) { |
| 8786 | // Load types involving an "index": ArrayGet, |
| 8787 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 8788 | // intrinsics. |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8789 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8790 | if (index.IsConstant()) { |
| 8791 | size_t computed_offset = |
| 8792 | (Int32ConstantFrom(index) << scale_factor) + offset; |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8793 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8794 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8795 | if (needs_null_check) { |
| 8796 | MaybeRecordImplicitNullCheck(instruction); |
| 8797 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8798 | } else { |
| 8799 | // Handle the special case of the |
| 8800 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 8801 | // intrinsics, which use a register pair as index ("long |
| 8802 | // offset"), of which only the low part contains data. |
| 8803 | vixl32::Register index_reg = index.IsRegisterPair() |
| 8804 | ? LowRegisterFrom(index) |
| 8805 | : RegisterFrom(index); |
| 8806 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8807 | vixl32::Register temp = temps.Acquire(); |
| 8808 | __ Add(temp, obj, Operand(index_reg, ShiftType::LSL, scale_factor)); |
| 8809 | { |
| 8810 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 8811 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, temp, offset); |
| 8812 | if (needs_null_check) { |
| 8813 | MaybeRecordImplicitNullCheck(instruction); |
| 8814 | } |
| 8815 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8816 | } |
| 8817 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8818 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
| 8819 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8820 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8821 | if (needs_null_check) { |
| 8822 | MaybeRecordImplicitNullCheck(instruction); |
| 8823 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8824 | } |
| 8825 | |
Roland Levillain | 844e653 | 2016-11-03 16:09:47 +0000 | [diff] [blame] | 8826 | // Object* ref = ref_addr->AsMirrorPtr() |
| 8827 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | 844e653 | 2016-11-03 16:09:47 +0000 | [diff] [blame] | 8828 | } |
| 8829 | |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8830 | void CodeGeneratorARMVIXL::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 8831 | // The following condition is a compile-time one, so it does not have a run-time cost. |
| 8832 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && kIsDebugBuild) { |
| 8833 | // The following condition is a run-time one; it is executed after the |
| 8834 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 8835 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 8836 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8837 | vixl32::Register temp = temp_loc.IsValid() ? RegisterFrom(temp_loc) : temps.Acquire(); |
| 8838 | GetAssembler()->GenerateMarkingRegisterCheck(temp, |
| 8839 | kMarkingRegisterCheckBreakCodeBaseCode + code); |
| 8840 | } |
| 8841 | } |
| 8842 | } |
| 8843 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8844 | void CodeGeneratorARMVIXL::GenerateReadBarrierSlow(HInstruction* instruction, |
| 8845 | Location out, |
| 8846 | Location ref, |
| 8847 | Location obj, |
| 8848 | uint32_t offset, |
| 8849 | Location index) { |
| 8850 | DCHECK(kEmitCompilerReadBarrier); |
| 8851 | |
| 8852 | // Insert a slow path based read barrier *after* the reference load. |
| 8853 | // |
| 8854 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 8855 | // reference will be carried out by the runtime within the slow |
| 8856 | // path. |
| 8857 | // |
| 8858 | // Note that `ref` currently does not get unpoisoned (when heap |
| 8859 | // poisoning is enabled), which is alright as the `ref` argument is |
| 8860 | // not used by the artReadBarrierSlow entry point. |
| 8861 | // |
| 8862 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8863 | SlowPathCodeARMVIXL* slow_path = new (GetScopedAllocator()) |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8864 | ReadBarrierForHeapReferenceSlowPathARMVIXL(instruction, out, ref, obj, offset, index); |
| 8865 | AddSlowPath(slow_path); |
| 8866 | |
| 8867 | __ B(slow_path->GetEntryLabel()); |
| 8868 | __ Bind(slow_path->GetExitLabel()); |
| 8869 | } |
| 8870 | |
| 8871 | void CodeGeneratorARMVIXL::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8872 | Location out, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8873 | Location ref, |
| 8874 | Location obj, |
| 8875 | uint32_t offset, |
| 8876 | Location index) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8877 | if (kEmitCompilerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8878 | // Baker's read barriers shall be handled by the fast path |
Roland Levillain | 9983e30 | 2017-07-14 14:34:22 +0100 | [diff] [blame] | 8879 | // (CodeGeneratorARMVIXL::GenerateReferenceLoadWithBakerReadBarrier). |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8880 | DCHECK(!kUseBakerReadBarrier); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8881 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 8882 | // by the runtime within the slow path. |
| 8883 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8884 | } else if (kPoisonHeapReferences) { |
| 8885 | GetAssembler()->UnpoisonHeapReference(RegisterFrom(out)); |
| 8886 | } |
| 8887 | } |
| 8888 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8889 | void CodeGeneratorARMVIXL::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 8890 | Location out, |
| 8891 | Location root) { |
| 8892 | DCHECK(kEmitCompilerReadBarrier); |
| 8893 | |
| 8894 | // Insert a slow path based read barrier *after* the GC root load. |
| 8895 | // |
| 8896 | // Note that GC roots are not affected by heap poisoning, so we do |
| 8897 | // not need to do anything special for this here. |
| 8898 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8899 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathARMVIXL(instruction, out, root); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8900 | AddSlowPath(slow_path); |
| 8901 | |
| 8902 | __ B(slow_path->GetEntryLabel()); |
| 8903 | __ Bind(slow_path->GetExitLabel()); |
| 8904 | } |
| 8905 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8906 | // Check if the desired_dispatch_info is supported. If it is, return it, |
| 8907 | // otherwise return a fall-back info that should be used instead. |
| 8908 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARMVIXL::GetSupportedInvokeStaticOrDirectDispatch( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8909 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 8910 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e807ff7 | 2017-01-23 09:03:12 +0000 | [diff] [blame] | 8911 | return desired_dispatch_info; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8912 | } |
| 8913 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8914 | vixl32::Register CodeGeneratorARMVIXL::GetInvokeStaticOrDirectExtraParameter( |
| 8915 | HInvokeStaticOrDirect* invoke, vixl32::Register temp) { |
| 8916 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 8917 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 8918 | if (!invoke->GetLocations()->Intrinsified()) { |
| 8919 | return RegisterFrom(location); |
| 8920 | } |
| 8921 | // For intrinsics we allow any location, so it may be on the stack. |
| 8922 | if (!location.IsRegister()) { |
| 8923 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, location.GetStackIndex()); |
| 8924 | return temp; |
| 8925 | } |
| 8926 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 8927 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 8928 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 8929 | // simple and more robust approach rather that trying to determine if that's the case. |
| 8930 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Scott Wakeling | d5cd497 | 2017-02-03 11:38:35 +0000 | [diff] [blame] | 8931 | if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(RegisterFrom(location).GetCode())) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8932 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(RegisterFrom(location).GetCode()); |
| 8933 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, stack_offset); |
| 8934 | return temp; |
| 8935 | } |
| 8936 | return RegisterFrom(location); |
| 8937 | } |
| 8938 | |
Vladimir Marko | d254f5c | 2017-06-02 15:18:36 +0000 | [diff] [blame] | 8939 | void CodeGeneratorARMVIXL::GenerateStaticOrDirectCall( |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8940 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8941 | 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] | 8942 | switch (invoke->GetMethodLoadKind()) { |
| 8943 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 8944 | uint32_t offset = |
| 8945 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 8946 | // temp = thread->string_init_entrypoint |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8947 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp), tr, offset); |
| 8948 | break; |
| 8949 | } |
| 8950 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 8951 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 8952 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 8953 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 8954 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 8955 | PcRelativePatchInfo* labels = NewPcRelativeMethodPatch(invoke->GetTargetMethod()); |
| 8956 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 8957 | EmitMovwMovtPlaceholder(labels, temp_reg); |
| 8958 | break; |
| 8959 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8960 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 8961 | __ Mov(RegisterFrom(temp), Operand::From(invoke->GetMethodAddress())); |
| 8962 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 8963 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
| 8964 | PcRelativePatchInfo* labels = NewMethodBssEntryPatch( |
| 8965 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex())); |
| 8966 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 8967 | EmitMovwMovtPlaceholder(labels, temp_reg); |
| 8968 | GetAssembler()->LoadFromOffset(kLoadWord, temp_reg, temp_reg, /* offset*/ 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8969 | break; |
| 8970 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8971 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 8972 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 8973 | return; // No code pointer retrieval; the runtime performs the call directly. |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8974 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8975 | } |
| 8976 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8977 | switch (invoke->GetCodePtrLocation()) { |
| 8978 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8979 | { |
| 8980 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 8981 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 8982 | vixl32::k32BitT32InstructionSizeInBytes, |
| 8983 | CodeBufferCheckScope::kMaximumSize); |
| 8984 | __ bl(GetFrameEntryLabel()); |
| 8985 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 8986 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8987 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8988 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 8989 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 8990 | GetAssembler()->LoadFromOffset( |
| 8991 | kLoadWord, |
| 8992 | lr, |
| 8993 | RegisterFrom(callee_method), |
| 8994 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8995 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8996 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8997 | // 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] | 8998 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 8999 | vixl32::k16BitT32InstructionSizeInBytes, |
| 9000 | CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9001 | // LR() |
| 9002 | __ blx(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9003 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9004 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9005 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9006 | } |
| 9007 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9008 | DCHECK(!IsLeafMethod()); |
| 9009 | } |
| 9010 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9011 | void CodeGeneratorARMVIXL::GenerateVirtualCall( |
| 9012 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9013 | vixl32::Register temp = RegisterFrom(temp_location); |
| 9014 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 9015 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
| 9016 | |
| 9017 | // Use the calling convention instead of the location of the receiver, as |
| 9018 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 9019 | // slow path, the arguments have been moved to the right place, so here we are |
| 9020 | // guaranteed that the receiver is the first register of the calling convention. |
| 9021 | InvokeDexCallingConventionARMVIXL calling_convention; |
| 9022 | vixl32::Register receiver = calling_convention.GetRegisterAt(0); |
| 9023 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9024 | { |
| 9025 | // Make sure the pc is recorded immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 9026 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9027 | vixl32::kMaxInstructionSizeInBytes, |
| 9028 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9029 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 9030 | __ ldr(temp, MemOperand(receiver, class_offset)); |
| 9031 | MaybeRecordImplicitNullCheck(invoke); |
| 9032 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9033 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 9034 | // emit a read barrier for the previous class reference load. |
| 9035 | // However this is not required in practice, as this is an |
| 9036 | // intermediate/temporary reference and because the current |
| 9037 | // concurrent copying collector keeps the from-space memory |
| 9038 | // intact/accessible until the end of the marking phase (the |
| 9039 | // concurrent copying collector may not in the future). |
| 9040 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 9041 | |
| 9042 | // temp = temp->GetMethodAt(method_offset); |
| 9043 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 9044 | kArmPointerSize).Int32Value(); |
| 9045 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 9046 | // LR = temp->GetEntryPoint(); |
| 9047 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9048 | { |
| 9049 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 9050 | // blx in T32 has only 16bit encoding that's why a stricter check for the scope is used. |
| 9051 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9052 | vixl32::k16BitT32InstructionSizeInBytes, |
| 9053 | CodeBufferCheckScope::kExactSize); |
| 9054 | // LR(); |
| 9055 | __ blx(lr); |
| 9056 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 9057 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9058 | } |
| 9059 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9060 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeMethodPatch( |
| 9061 | MethodReference target_method) { |
| 9062 | return NewPcRelativePatch(*target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 9063 | target_method.index, |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9064 | &pc_relative_method_patches_); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9065 | } |
| 9066 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9067 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewMethodBssEntryPatch( |
| 9068 | MethodReference target_method) { |
| 9069 | return NewPcRelativePatch(*target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 9070 | target_method.index, |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9071 | &method_bss_entry_patches_); |
| 9072 | } |
| 9073 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9074 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeTypePatch( |
| 9075 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 9076 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
| 9077 | } |
| 9078 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9079 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewTypeBssEntryPatch( |
| 9080 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 9081 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 9082 | } |
| 9083 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9084 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeStringPatch( |
| 9085 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 9086 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
| 9087 | } |
| 9088 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 9089 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewStringBssEntryPatch( |
| 9090 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 9091 | return NewPcRelativePatch(dex_file, string_index.index_, &string_bss_entry_patches_); |
| 9092 | } |
| 9093 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9094 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativePatch( |
| 9095 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 9096 | patches->emplace_back(dex_file, offset_or_index); |
| 9097 | return &patches->back(); |
| 9098 | } |
| 9099 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9100 | vixl::aarch32::Label* CodeGeneratorARMVIXL::NewBakerReadBarrierPatch(uint32_t custom_data) { |
| 9101 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 9102 | return &baker_read_barrier_patches_.back().label; |
| 9103 | } |
| 9104 | |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9105 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateBootImageAddressLiteral(uint32_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 9106 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9107 | } |
| 9108 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 9109 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitStringLiteral( |
| 9110 | const DexFile& dex_file, |
| 9111 | dex::StringIndex string_index, |
| 9112 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9113 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9114 | return jit_string_patches_.GetOrCreate( |
| 9115 | StringReference(&dex_file, string_index), |
| 9116 | [this]() { |
| 9117 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 9118 | }); |
| 9119 | } |
| 9120 | |
| 9121 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 9122 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 9123 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9124 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9125 | return jit_class_patches_.GetOrCreate( |
| 9126 | TypeReference(&dex_file, type_index), |
| 9127 | [this]() { |
| 9128 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 9129 | }); |
| 9130 | } |
| 9131 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9132 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9133 | inline void CodeGeneratorARMVIXL::EmitPcRelativeLinkerPatches( |
| 9134 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9135 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9136 | for (const PcRelativePatchInfo& info : infos) { |
| 9137 | const DexFile& dex_file = info.target_dex_file; |
| 9138 | size_t offset_or_index = info.offset_or_index; |
| 9139 | DCHECK(info.add_pc_label.IsBound()); |
| 9140 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.GetLocation()); |
| 9141 | // Add MOVW patch. |
| 9142 | DCHECK(info.movw_label.IsBound()); |
| 9143 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.GetLocation()); |
| 9144 | linker_patches->push_back(Factory(movw_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 9145 | // Add MOVT patch. |
| 9146 | DCHECK(info.movt_label.IsBound()); |
| 9147 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.GetLocation()); |
| 9148 | linker_patches->push_back(Factory(movt_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 9149 | } |
| 9150 | } |
| 9151 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9152 | void CodeGeneratorARMVIXL::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9153 | DCHECK(linker_patches->empty()); |
| 9154 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9155 | /* MOVW+MOVT for each entry */ 2u * pc_relative_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9156 | /* MOVW+MOVT for each entry */ 2u * method_bss_entry_patches_.size() + |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9157 | /* MOVW+MOVT for each entry */ 2u * pc_relative_type_patches_.size() + |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9158 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9159 | /* MOVW+MOVT for each entry */ 2u * pc_relative_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 9160 | /* MOVW+MOVT for each entry */ 2u * string_bss_entry_patches_.size() + |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9161 | baker_read_barrier_patches_.size(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9162 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9163 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9164 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 9165 | pc_relative_method_patches_, linker_patches); |
| 9166 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 9167 | pc_relative_type_patches_, linker_patches); |
| 9168 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| 9169 | pc_relative_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9170 | } else { |
| 9171 | DCHECK(pc_relative_method_patches_.empty()); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9172 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeClassTablePatch>( |
| 9173 | pc_relative_type_patches_, linker_patches); |
| 9174 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringInternTablePatch>( |
| 9175 | pc_relative_string_patches_, linker_patches); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9176 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9177 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 9178 | method_bss_entry_patches_, linker_patches); |
| 9179 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 9180 | type_bss_entry_patches_, linker_patches); |
| 9181 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 9182 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9183 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9184 | linker_patches->push_back(linker::LinkerPatch::BakerReadBarrierBranchPatch( |
| 9185 | info.label.GetLocation(), info.custom_data)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9186 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9187 | DCHECK_EQ(size, linker_patches->size()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9188 | } |
| 9189 | |
| 9190 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateUint32Literal( |
| 9191 | uint32_t value, |
| 9192 | Uint32ToLiteralMap* map) { |
| 9193 | return map->GetOrCreate( |
| 9194 | value, |
| 9195 | [this, value]() { |
| 9196 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ value); |
| 9197 | }); |
| 9198 | } |
| 9199 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 9200 | void LocationsBuilderARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 9201 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9202 | new (GetGraph()->GetAllocator()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 9203 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 9204 | Location::RequiresRegister()); |
| 9205 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 9206 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 9207 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 9208 | } |
| 9209 | |
| 9210 | void InstructionCodeGeneratorARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 9211 | vixl32::Register res = OutputRegister(instr); |
| 9212 | vixl32::Register accumulator = |
| 9213 | InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 9214 | vixl32::Register mul_left = |
| 9215 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 9216 | vixl32::Register mul_right = |
| 9217 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
| 9218 | |
| 9219 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 9220 | __ Mla(res, mul_left, mul_right, accumulator); |
| 9221 | } else { |
| 9222 | __ Mls(res, mul_left, mul_right, accumulator); |
| 9223 | } |
| 9224 | } |
| 9225 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9226 | void LocationsBuilderARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9227 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9228 | LOG(FATAL) << "Unreachable"; |
| 9229 | } |
| 9230 | |
| 9231 | void InstructionCodeGeneratorARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9232 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9233 | LOG(FATAL) << "Unreachable"; |
| 9234 | } |
| 9235 | |
| 9236 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 9237 | void LocationsBuilderARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9238 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9239 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9240 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9241 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
| 9242 | codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 9243 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 9244 | if (switch_instr->GetStartValue() != 0) { |
| 9245 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 9246 | } |
| 9247 | } |
| 9248 | } |
| 9249 | |
| 9250 | // TODO(VIXL): Investigate and reach the parity with old arm codegen. |
| 9251 | void InstructionCodeGeneratorARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9252 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 9253 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9254 | LocationSummary* locations = switch_instr->GetLocations(); |
| 9255 | vixl32::Register value_reg = InputRegisterAt(switch_instr, 0); |
| 9256 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 9257 | |
| 9258 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
| 9259 | !codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 9260 | // Create a series of compare/jumps. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9261 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9262 | vixl32::Register temp_reg = temps.Acquire(); |
| 9263 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 9264 | // the immediate, because IP is used as the destination register. For the other |
| 9265 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 9266 | // and they can be encoded in the instruction without making use of IP register. |
| 9267 | __ Adds(temp_reg, value_reg, -lower_bound); |
| 9268 | |
| 9269 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 9270 | // Jump to successors[0] if value == lower_bound. |
| 9271 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 9272 | int32_t last_index = 0; |
| 9273 | for (; num_entries - last_index > 2; last_index += 2) { |
| 9274 | __ Adds(temp_reg, temp_reg, -2); |
| 9275 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 9276 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9277 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 9278 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 9279 | } |
| 9280 | if (num_entries - last_index == 2) { |
| 9281 | // The last missing case_value. |
| 9282 | __ Cmp(temp_reg, 1); |
| 9283 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9284 | } |
| 9285 | |
| 9286 | // And the default for any other value. |
| 9287 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 9288 | __ B(codegen_->GetLabelOf(default_block)); |
| 9289 | } |
| 9290 | } else { |
| 9291 | // Create a table lookup. |
| 9292 | vixl32::Register table_base = RegisterFrom(locations->GetTemp(0)); |
| 9293 | |
| 9294 | JumpTableARMVIXL* jump_table = codegen_->CreateJumpTable(switch_instr); |
| 9295 | |
| 9296 | // Remove the bias. |
| 9297 | vixl32::Register key_reg; |
| 9298 | if (lower_bound != 0) { |
| 9299 | key_reg = RegisterFrom(locations->GetTemp(1)); |
| 9300 | __ Sub(key_reg, value_reg, lower_bound); |
| 9301 | } else { |
| 9302 | key_reg = value_reg; |
| 9303 | } |
| 9304 | |
| 9305 | // Check whether the value is in the table, jump to default block if not. |
| 9306 | __ Cmp(key_reg, num_entries - 1); |
| 9307 | __ B(hi, codegen_->GetLabelOf(default_block)); |
| 9308 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9309 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9310 | vixl32::Register jump_offset = temps.Acquire(); |
| 9311 | |
| 9312 | // Load jump offset from the table. |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9313 | { |
| 9314 | const size_t jump_size = switch_instr->GetNumEntries() * sizeof(int32_t); |
| 9315 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9316 | (vixl32::kMaxInstructionSizeInBytes * 4) + jump_size, |
| 9317 | CodeBufferCheckScope::kMaximumSize); |
| 9318 | __ adr(table_base, jump_table->GetTableStartLabel()); |
| 9319 | __ ldr(jump_offset, MemOperand(table_base, key_reg, vixl32::LSL, 2)); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9320 | |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9321 | // Jump to target block by branching to table_base(pc related) + offset. |
| 9322 | vixl32::Register target_address = table_base; |
| 9323 | __ add(target_address, table_base, jump_offset); |
| 9324 | __ bx(target_address); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 9325 | |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9326 | jump_table->EmitTable(codegen_); |
| 9327 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9328 | } |
| 9329 | } |
| 9330 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9331 | // Copy the result of a call into the given target. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9332 | void CodeGeneratorARMVIXL::MoveFromReturnRegister(Location trg, DataType::Type type) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9333 | if (!trg.IsValid()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9334 | DCHECK_EQ(type, DataType::Type::kVoid); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9335 | return; |
| 9336 | } |
| 9337 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9338 | DCHECK_NE(type, DataType::Type::kVoid); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9339 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9340 | Location return_loc = InvokeDexCallingConventionVisitorARMVIXL().GetReturnLocation(type); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9341 | if (return_loc.Equals(trg)) { |
| 9342 | return; |
| 9343 | } |
| 9344 | |
| 9345 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 9346 | // with the last branch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9347 | if (type == DataType::Type::kInt64) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9348 | TODO_VIXL32(FATAL); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9349 | } else if (type == DataType::Type::kFloat64) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9350 | TODO_VIXL32(FATAL); |
| 9351 | } else { |
| 9352 | // Let the parallel move resolver take care of all of this. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9353 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9354 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 9355 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 9356 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9357 | } |
| 9358 | |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9359 | void LocationsBuilderARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 9360 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9361 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9362 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9363 | locations->SetOut(Location::RequiresRegister()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9364 | } |
| 9365 | |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9366 | void InstructionCodeGeneratorARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 9367 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| 9368 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 9369 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
| 9370 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9371 | OutputRegister(instruction), |
| 9372 | InputRegisterAt(instruction, 0), |
| 9373 | method_offset); |
| 9374 | } else { |
| 9375 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 9376 | instruction->GetIndex(), kArmPointerSize)); |
| 9377 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9378 | OutputRegister(instruction), |
| 9379 | InputRegisterAt(instruction, 0), |
| 9380 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 9381 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9382 | OutputRegister(instruction), |
| 9383 | OutputRegister(instruction), |
| 9384 | method_offset); |
| 9385 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9386 | } |
| 9387 | |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9388 | static void PatchJitRootUse(uint8_t* code, |
| 9389 | const uint8_t* roots_data, |
| 9390 | VIXLUInt32Literal* literal, |
| 9391 | uint64_t index_in_table) { |
| 9392 | DCHECK(literal->IsBound()); |
| 9393 | uint32_t literal_offset = literal->GetLocation(); |
| 9394 | uintptr_t address = |
| 9395 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 9396 | uint8_t* data = code + literal_offset; |
| 9397 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 9398 | } |
| 9399 | |
| 9400 | void CodeGeneratorARMVIXL::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 9401 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9402 | const StringReference& string_reference = entry.first; |
| 9403 | VIXLUInt32Literal* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9404 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9405 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9406 | } |
| 9407 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9408 | const TypeReference& type_reference = entry.first; |
| 9409 | VIXLUInt32Literal* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9410 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9411 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9412 | } |
| 9413 | } |
| 9414 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9415 | void CodeGeneratorARMVIXL::EmitMovwMovtPlaceholder( |
| 9416 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels, |
| 9417 | vixl32::Register out) { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 9418 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9419 | 3 * vixl32::kMaxInstructionSizeInBytes, |
| 9420 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9421 | // TODO(VIXL): Think about using mov instead of movw. |
| 9422 | __ bind(&labels->movw_label); |
| 9423 | __ movw(out, /* placeholder */ 0u); |
| 9424 | __ bind(&labels->movt_label); |
| 9425 | __ movt(out, /* placeholder */ 0u); |
| 9426 | __ bind(&labels->add_pc_label); |
| 9427 | __ add(out, out, pc); |
| 9428 | } |
| 9429 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9430 | #undef __ |
| 9431 | #undef QUICK_ENTRY_POINT |
| 9432 | #undef TODO_VIXL32 |
| 9433 | |
| 9434 | } // namespace arm |
| 9435 | } // namespace art |