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; |
| 766 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 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; |
| 1417 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 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), |
| 2424 | block_labels_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2425 | jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2426 | location_builder_(graph, this), |
| 2427 | instruction_visitor_(graph, this), |
| 2428 | move_resolver_(graph->GetArena(), this), |
| 2429 | assembler_(graph->GetArena()), |
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>(), |
| 2432 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 2433 | pc_relative_method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 2434 | method_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 2435 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 2436 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 2437 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 2438 | string_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 2439 | baker_read_barrier_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 2440 | jit_string_patches_(StringReferenceValueComparator(), |
| 2441 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 2442 | jit_class_patches_(TypeReferenceValueComparator(), |
| 2443 | graph->GetArena()->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(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 2571 | __ Sub(temp, sp, Operand::From(GetStackOverflowReservedBytes(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. |
| 2813 | HParallelMove move(GetGraph()->GetArena()); |
| 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()) { |
| 2861 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 2862 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2863 | return; |
| 2864 | } |
| 2865 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2866 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 2867 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 2); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2868 | } |
| 2869 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 2870 | __ B(codegen_->GetLabelOf(successor)); |
| 2871 | } |
| 2872 | } |
| 2873 | |
| 2874 | void LocationsBuilderARMVIXL::VisitGoto(HGoto* got) { |
| 2875 | got->SetLocations(nullptr); |
| 2876 | } |
| 2877 | |
| 2878 | void InstructionCodeGeneratorARMVIXL::VisitGoto(HGoto* got) { |
| 2879 | HandleGoto(got, got->GetSuccessor()); |
| 2880 | } |
| 2881 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2882 | void LocationsBuilderARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2883 | try_boundary->SetLocations(nullptr); |
| 2884 | } |
| 2885 | |
| 2886 | void InstructionCodeGeneratorARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2887 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2888 | if (!successor->IsExitBlock()) { |
| 2889 | HandleGoto(try_boundary, successor); |
| 2890 | } |
| 2891 | } |
| 2892 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2893 | void LocationsBuilderARMVIXL::VisitExit(HExit* exit) { |
| 2894 | exit->SetLocations(nullptr); |
| 2895 | } |
| 2896 | |
| 2897 | void InstructionCodeGeneratorARMVIXL::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 2898 | } |
| 2899 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2900 | void InstructionCodeGeneratorARMVIXL::GenerateCompareTestAndBranch(HCondition* condition, |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2901 | vixl32::Label* true_target, |
| 2902 | vixl32::Label* false_target, |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2903 | bool is_far_target) { |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2904 | if (true_target == false_target) { |
| 2905 | DCHECK(true_target != nullptr); |
| 2906 | __ B(true_target); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2907 | return; |
| 2908 | } |
| 2909 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2910 | vixl32::Label* non_fallthrough_target; |
| 2911 | bool invert; |
| 2912 | bool emit_both_branches; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2913 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2914 | if (true_target == nullptr) { |
| 2915 | // The true target is fallthrough. |
| 2916 | DCHECK(false_target != nullptr); |
| 2917 | non_fallthrough_target = false_target; |
| 2918 | invert = true; |
| 2919 | emit_both_branches = false; |
| 2920 | } else { |
| 2921 | non_fallthrough_target = true_target; |
| 2922 | invert = false; |
| 2923 | // Either the false target is fallthrough, or there is no fallthrough |
| 2924 | // and both branches must be emitted. |
| 2925 | emit_both_branches = (false_target != nullptr); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2926 | } |
| 2927 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2928 | const auto cond = GenerateTest(condition, invert, codegen_); |
| 2929 | |
| 2930 | __ B(cond.first, non_fallthrough_target, is_far_target); |
| 2931 | |
| 2932 | if (emit_both_branches) { |
| 2933 | // No target falls through, we need to branch. |
| 2934 | __ B(false_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2935 | } |
| 2936 | } |
| 2937 | |
| 2938 | void InstructionCodeGeneratorARMVIXL::GenerateTestAndBranch(HInstruction* instruction, |
| 2939 | size_t condition_input_index, |
| 2940 | vixl32::Label* true_target, |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2941 | vixl32::Label* false_target, |
| 2942 | bool far_target) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2943 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 2944 | |
| 2945 | if (true_target == nullptr && false_target == nullptr) { |
| 2946 | // Nothing to do. The code always falls through. |
| 2947 | return; |
| 2948 | } else if (cond->IsIntConstant()) { |
| 2949 | // Constant condition, statically compared against "true" (integer value 1). |
| 2950 | if (cond->AsIntConstant()->IsTrue()) { |
| 2951 | if (true_target != nullptr) { |
| 2952 | __ B(true_target); |
| 2953 | } |
| 2954 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 2955 | DCHECK(cond->AsIntConstant()->IsFalse()) << Int32ConstantFrom(cond); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2956 | if (false_target != nullptr) { |
| 2957 | __ B(false_target); |
| 2958 | } |
| 2959 | } |
| 2960 | return; |
| 2961 | } |
| 2962 | |
| 2963 | // The following code generates these patterns: |
| 2964 | // (1) true_target == nullptr && false_target != nullptr |
| 2965 | // - opposite condition true => branch to false_target |
| 2966 | // (2) true_target != nullptr && false_target == nullptr |
| 2967 | // - condition true => branch to true_target |
| 2968 | // (3) true_target != nullptr && false_target != nullptr |
| 2969 | // - condition true => branch to true_target |
| 2970 | // - branch to false_target |
| 2971 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 2972 | // Condition has been materialized, compare the output to 0. |
| 2973 | if (kIsDebugBuild) { |
| 2974 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 2975 | DCHECK(cond_val.IsRegister()); |
| 2976 | } |
| 2977 | if (true_target == nullptr) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2978 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, condition_input_index), |
| 2979 | false_target, |
| 2980 | far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2981 | } else { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2982 | __ CompareAndBranchIfNonZero(InputRegisterAt(instruction, condition_input_index), |
| 2983 | true_target, |
| 2984 | far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2985 | } |
| 2986 | } else { |
| 2987 | // Condition has not been materialized. Use its inputs as the comparison and |
| 2988 | // its condition as the branch condition. |
| 2989 | HCondition* condition = cond->AsCondition(); |
| 2990 | |
| 2991 | // If this is a long or FP comparison that has been folded into |
| 2992 | // the HCondition, generate the comparison directly. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2993 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 2994 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2995 | GenerateCompareTestAndBranch(condition, true_target, false_target, far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2996 | return; |
| 2997 | } |
| 2998 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2999 | vixl32::Label* non_fallthrough_target; |
| 3000 | vixl32::Condition arm_cond = vixl32::Condition::None(); |
| 3001 | const vixl32::Register left = InputRegisterAt(cond, 0); |
| 3002 | const Operand right = InputOperandAt(cond, 1); |
| 3003 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3004 | if (true_target == nullptr) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3005 | arm_cond = ARMCondition(condition->GetOppositeCondition()); |
| 3006 | non_fallthrough_target = false_target; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3007 | } else { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3008 | arm_cond = ARMCondition(condition->GetCondition()); |
| 3009 | non_fallthrough_target = true_target; |
| 3010 | } |
| 3011 | |
| 3012 | if (right.IsImmediate() && right.GetImmediate() == 0 && (arm_cond.Is(ne) || arm_cond.Is(eq))) { |
| 3013 | if (arm_cond.Is(eq)) { |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 3014 | __ CompareAndBranchIfZero(left, non_fallthrough_target, far_target); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3015 | } else { |
| 3016 | DCHECK(arm_cond.Is(ne)); |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 3017 | __ CompareAndBranchIfNonZero(left, non_fallthrough_target, far_target); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3018 | } |
| 3019 | } else { |
| 3020 | __ Cmp(left, right); |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 3021 | __ B(arm_cond, non_fallthrough_target, far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3022 | } |
| 3023 | } |
| 3024 | |
| 3025 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3026 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3027 | if (true_target != nullptr && false_target != nullptr) { |
| 3028 | __ B(false_target); |
| 3029 | } |
| 3030 | } |
| 3031 | |
| 3032 | void LocationsBuilderARMVIXL::VisitIf(HIf* if_instr) { |
| 3033 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 3034 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| 3035 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3036 | } |
| 3037 | } |
| 3038 | |
| 3039 | void InstructionCodeGeneratorARMVIXL::VisitIf(HIf* if_instr) { |
| 3040 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3041 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3042 | vixl32::Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 3043 | nullptr : codegen_->GetLabelOf(true_successor); |
| 3044 | vixl32::Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 3045 | nullptr : codegen_->GetLabelOf(false_successor); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3046 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
| 3047 | } |
| 3048 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3049 | void LocationsBuilderARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 3050 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3051 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3052 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3053 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3054 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 3055 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3056 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| 3057 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3058 | } |
| 3059 | } |
| 3060 | |
| 3061 | void InstructionCodeGeneratorARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 3062 | SlowPathCodeARMVIXL* slow_path = |
| 3063 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARMVIXL>(deoptimize); |
| 3064 | GenerateTestAndBranch(deoptimize, |
| 3065 | /* condition_input_index */ 0, |
| 3066 | slow_path->GetEntryLabel(), |
| 3067 | /* false_target */ nullptr); |
| 3068 | } |
| 3069 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3070 | void LocationsBuilderARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3071 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3072 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3073 | locations->SetOut(Location::RequiresRegister()); |
| 3074 | } |
| 3075 | |
| 3076 | void InstructionCodeGeneratorARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3077 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3078 | OutputRegister(flag), |
| 3079 | sp, |
| 3080 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 3081 | } |
| 3082 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3083 | void LocationsBuilderARMVIXL::VisitSelect(HSelect* select) { |
| 3084 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3085 | const bool is_floating_point = DataType::IsFloatingPointType(select->GetType()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3086 | |
| 3087 | if (is_floating_point) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3088 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3089 | locations->SetInAt(1, Location::FpuRegisterOrConstant(select->GetTrueValue())); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3090 | } else { |
| 3091 | locations->SetInAt(0, Location::RequiresRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3092 | locations->SetInAt(1, Arm8BitEncodableConstantOrRegister(select->GetTrueValue())); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3093 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3094 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3095 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3096 | locations->SetInAt(2, Location::RegisterOrConstant(select->GetCondition())); |
| 3097 | // The code generator handles overlap with the values, but not with the condition. |
| 3098 | locations->SetOut(Location::SameAsFirstInput()); |
| 3099 | } else if (is_floating_point) { |
| 3100 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3101 | } else { |
| 3102 | if (!locations->InAt(1).IsConstant()) { |
| 3103 | locations->SetInAt(0, Arm8BitEncodableConstantOrRegister(select->GetFalseValue())); |
| 3104 | } |
| 3105 | |
| 3106 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3107 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3108 | } |
| 3109 | |
| 3110 | void InstructionCodeGeneratorARMVIXL::VisitSelect(HSelect* select) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3111 | HInstruction* const condition = select->GetCondition(); |
| 3112 | const LocationSummary* const locations = select->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3113 | const DataType::Type type = select->GetType(); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3114 | const Location first = locations->InAt(0); |
| 3115 | const Location out = locations->Out(); |
| 3116 | const Location second = locations->InAt(1); |
| 3117 | Location src; |
| 3118 | |
| 3119 | if (condition->IsIntConstant()) { |
| 3120 | if (condition->AsIntConstant()->IsFalse()) { |
| 3121 | src = first; |
| 3122 | } else { |
| 3123 | src = second; |
| 3124 | } |
| 3125 | |
| 3126 | codegen_->MoveLocation(out, src, type); |
| 3127 | return; |
| 3128 | } |
| 3129 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3130 | if (!DataType::IsFloatingPointType(type)) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3131 | bool invert = false; |
| 3132 | |
| 3133 | if (out.Equals(second)) { |
| 3134 | src = first; |
| 3135 | invert = true; |
| 3136 | } else if (out.Equals(first)) { |
| 3137 | src = second; |
| 3138 | } else if (second.IsConstant()) { |
| 3139 | DCHECK(CanEncodeConstantAs8BitImmediate(second.GetConstant())); |
| 3140 | src = second; |
| 3141 | } else if (first.IsConstant()) { |
| 3142 | DCHECK(CanEncodeConstantAs8BitImmediate(first.GetConstant())); |
| 3143 | src = first; |
| 3144 | invert = true; |
| 3145 | } else { |
| 3146 | src = second; |
| 3147 | } |
| 3148 | |
| 3149 | if (CanGenerateConditionalMove(out, src)) { |
| 3150 | if (!out.Equals(first) && !out.Equals(second)) { |
| 3151 | codegen_->MoveLocation(out, src.Equals(first) ? second : first, type); |
| 3152 | } |
| 3153 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3154 | std::pair<vixl32::Condition, vixl32::Condition> cond(eq, ne); |
| 3155 | |
| 3156 | if (IsBooleanValueOrMaterializedCondition(condition)) { |
| 3157 | __ Cmp(InputRegisterAt(select, 2), 0); |
| 3158 | cond = invert ? std::make_pair(eq, ne) : std::make_pair(ne, eq); |
| 3159 | } else { |
| 3160 | cond = GenerateTest(condition->AsCondition(), invert, codegen_); |
| 3161 | } |
| 3162 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3163 | const size_t instr_count = out.IsRegisterPair() ? 4 : 2; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3164 | // We use the scope because of the IT block that follows. |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3165 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 3166 | instr_count * vixl32::k16BitT32InstructionSizeInBytes, |
| 3167 | CodeBufferCheckScope::kExactSize); |
| 3168 | |
| 3169 | if (out.IsRegister()) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3170 | __ it(cond.first); |
| 3171 | __ mov(cond.first, RegisterFrom(out), OperandFrom(src, type)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3172 | } else { |
| 3173 | DCHECK(out.IsRegisterPair()); |
| 3174 | |
| 3175 | Operand operand_high(0); |
| 3176 | Operand operand_low(0); |
| 3177 | |
| 3178 | if (src.IsConstant()) { |
| 3179 | const int64_t value = Int64ConstantFrom(src); |
| 3180 | |
| 3181 | operand_high = High32Bits(value); |
| 3182 | operand_low = Low32Bits(value); |
| 3183 | } else { |
| 3184 | DCHECK(src.IsRegisterPair()); |
| 3185 | operand_high = HighRegisterFrom(src); |
| 3186 | operand_low = LowRegisterFrom(src); |
| 3187 | } |
| 3188 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3189 | __ it(cond.first); |
| 3190 | __ mov(cond.first, LowRegisterFrom(out), operand_low); |
| 3191 | __ it(cond.first); |
| 3192 | __ mov(cond.first, HighRegisterFrom(out), operand_high); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3193 | } |
| 3194 | |
| 3195 | return; |
| 3196 | } |
| 3197 | } |
| 3198 | |
| 3199 | vixl32::Label* false_target = nullptr; |
| 3200 | vixl32::Label* true_target = nullptr; |
| 3201 | vixl32::Label select_end; |
| 3202 | vixl32::Label* const target = codegen_->GetFinalLabel(select, &select_end); |
| 3203 | |
| 3204 | if (out.Equals(second)) { |
| 3205 | true_target = target; |
| 3206 | src = first; |
| 3207 | } else { |
| 3208 | false_target = target; |
| 3209 | src = second; |
| 3210 | |
| 3211 | if (!out.Equals(first)) { |
| 3212 | codegen_->MoveLocation(out, first, type); |
| 3213 | } |
| 3214 | } |
| 3215 | |
| 3216 | GenerateTestAndBranch(select, 2, true_target, false_target, /* far_target */ false); |
| 3217 | codegen_->MoveLocation(out, src, type); |
| 3218 | |
| 3219 | if (select_end.IsReferenced()) { |
| 3220 | __ Bind(&select_end); |
| 3221 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3222 | } |
| 3223 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 3224 | void LocationsBuilderARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 3225 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 3226 | } |
| 3227 | |
| 3228 | void InstructionCodeGeneratorARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3229 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| 3230 | } |
| 3231 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3232 | void CodeGeneratorARMVIXL::GenerateNop() { |
| 3233 | __ Nop(); |
| 3234 | } |
| 3235 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3236 | // `temp` is an extra temporary register that is used for some conditions; |
| 3237 | // callers may not specify it, in which case the method will use a scratch |
| 3238 | // register instead. |
| 3239 | void CodeGeneratorARMVIXL::GenerateConditionWithZero(IfCondition condition, |
| 3240 | vixl32::Register out, |
| 3241 | vixl32::Register in, |
| 3242 | vixl32::Register temp) { |
| 3243 | switch (condition) { |
| 3244 | case kCondEQ: |
| 3245 | // x <= 0 iff x == 0 when the comparison is unsigned. |
| 3246 | case kCondBE: |
| 3247 | if (!temp.IsValid() || (out.IsLow() && !out.Is(in))) { |
| 3248 | temp = out; |
| 3249 | } |
| 3250 | |
| 3251 | // Avoid 32-bit instructions if possible; note that `in` and `temp` must be |
| 3252 | // different as well. |
| 3253 | if (in.IsLow() && temp.IsLow() && !in.Is(temp)) { |
| 3254 | // temp = - in; only 0 sets the carry flag. |
| 3255 | __ Rsbs(temp, in, 0); |
| 3256 | |
| 3257 | if (out.Is(in)) { |
| 3258 | std::swap(in, temp); |
| 3259 | } |
| 3260 | |
| 3261 | // out = - in + in + carry = carry |
| 3262 | __ Adc(out, temp, in); |
| 3263 | } else { |
| 3264 | // If `in` is 0, then it has 32 leading zeros, and less than that otherwise. |
| 3265 | __ Clz(out, in); |
| 3266 | // Any number less than 32 logically shifted right by 5 bits results in 0; |
| 3267 | // the same operation on 32 yields 1. |
| 3268 | __ Lsr(out, out, 5); |
| 3269 | } |
| 3270 | |
| 3271 | break; |
| 3272 | case kCondNE: |
| 3273 | // x > 0 iff x != 0 when the comparison is unsigned. |
| 3274 | case kCondA: { |
| 3275 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3276 | |
| 3277 | if (out.Is(in)) { |
| 3278 | if (!temp.IsValid() || in.Is(temp)) { |
| 3279 | temp = temps.Acquire(); |
| 3280 | } |
| 3281 | } else if (!temp.IsValid() || !temp.IsLow()) { |
| 3282 | temp = out; |
| 3283 | } |
| 3284 | |
| 3285 | // temp = in - 1; only 0 does not set the carry flag. |
| 3286 | __ Subs(temp, in, 1); |
| 3287 | // out = in + ~temp + carry = in + (-(in - 1) - 1) + carry = in - in + 1 - 1 + carry = carry |
| 3288 | __ Sbc(out, in, temp); |
| 3289 | break; |
| 3290 | } |
| 3291 | case kCondGE: |
| 3292 | __ Mvn(out, in); |
| 3293 | in = out; |
| 3294 | FALLTHROUGH_INTENDED; |
| 3295 | case kCondLT: |
| 3296 | // We only care about the sign bit. |
| 3297 | __ Lsr(out, in, 31); |
| 3298 | break; |
| 3299 | case kCondAE: |
| 3300 | // Trivially true. |
| 3301 | __ Mov(out, 1); |
| 3302 | break; |
| 3303 | case kCondB: |
| 3304 | // Trivially false. |
| 3305 | __ Mov(out, 0); |
| 3306 | break; |
| 3307 | default: |
| 3308 | LOG(FATAL) << "Unexpected condition " << condition; |
| 3309 | UNREACHABLE(); |
| 3310 | } |
| 3311 | } |
| 3312 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3313 | void LocationsBuilderARMVIXL::HandleCondition(HCondition* cond) { |
| 3314 | LocationSummary* locations = |
| 3315 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
| 3316 | // Handle the long/FP comparisons made in instruction simplification. |
| 3317 | switch (cond->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3318 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3319 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3320 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 3321 | if (!cond->IsEmittedAtUseSite()) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3322 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3323 | } |
| 3324 | break; |
| 3325 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3326 | case DataType::Type::kFloat32: |
| 3327 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3328 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 3329 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3330 | if (!cond->IsEmittedAtUseSite()) { |
| 3331 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3332 | } |
| 3333 | break; |
| 3334 | |
| 3335 | default: |
| 3336 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3337 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 3338 | if (!cond->IsEmittedAtUseSite()) { |
| 3339 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3340 | } |
| 3341 | } |
| 3342 | } |
| 3343 | |
| 3344 | void InstructionCodeGeneratorARMVIXL::HandleCondition(HCondition* cond) { |
| 3345 | if (cond->IsEmittedAtUseSite()) { |
| 3346 | return; |
| 3347 | } |
| 3348 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3349 | const DataType::Type type = cond->GetLeft()->GetType(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3350 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3351 | if (DataType::IsFloatingPointType(type)) { |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3352 | GenerateConditionGeneric(cond, codegen_); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3353 | return; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3354 | } |
| 3355 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3356 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3357 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3358 | const IfCondition condition = cond->GetCondition(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3359 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3360 | // A condition with only one boolean input, or two boolean inputs without being equality or |
| 3361 | // inequality results from transformations done by the instruction simplifier, and is handled |
| 3362 | // as a regular condition with integral inputs. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3363 | if (type == DataType::Type::kBool && |
| 3364 | cond->GetRight()->GetType() == DataType::Type::kBool && |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3365 | (condition == kCondEQ || condition == kCondNE)) { |
| 3366 | vixl32::Register left = InputRegisterAt(cond, 0); |
| 3367 | const vixl32::Register out = OutputRegister(cond); |
| 3368 | const Location right_loc = cond->GetLocations()->InAt(1); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3369 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3370 | // The constant case is handled by the instruction simplifier. |
| 3371 | DCHECK(!right_loc.IsConstant()); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3372 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3373 | vixl32::Register right = RegisterFrom(right_loc); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3374 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3375 | // Avoid 32-bit instructions if possible. |
| 3376 | if (out.Is(right)) { |
| 3377 | std::swap(left, right); |
| 3378 | } |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3379 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3380 | __ Eor(out, left, right); |
| 3381 | |
| 3382 | if (condition == kCondEQ) { |
| 3383 | __ Eor(out, out, 1); |
| 3384 | } |
| 3385 | |
| 3386 | return; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3387 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 3388 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3389 | GenerateConditionIntegralOrNonPrimitive(cond, codegen_); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3390 | } |
| 3391 | |
| 3392 | void LocationsBuilderARMVIXL::VisitEqual(HEqual* comp) { |
| 3393 | HandleCondition(comp); |
| 3394 | } |
| 3395 | |
| 3396 | void InstructionCodeGeneratorARMVIXL::VisitEqual(HEqual* comp) { |
| 3397 | HandleCondition(comp); |
| 3398 | } |
| 3399 | |
| 3400 | void LocationsBuilderARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 3401 | HandleCondition(comp); |
| 3402 | } |
| 3403 | |
| 3404 | void InstructionCodeGeneratorARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 3405 | HandleCondition(comp); |
| 3406 | } |
| 3407 | |
| 3408 | void LocationsBuilderARMVIXL::VisitLessThan(HLessThan* comp) { |
| 3409 | HandleCondition(comp); |
| 3410 | } |
| 3411 | |
| 3412 | void InstructionCodeGeneratorARMVIXL::VisitLessThan(HLessThan* comp) { |
| 3413 | HandleCondition(comp); |
| 3414 | } |
| 3415 | |
| 3416 | void LocationsBuilderARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 3417 | HandleCondition(comp); |
| 3418 | } |
| 3419 | |
| 3420 | void InstructionCodeGeneratorARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 3421 | HandleCondition(comp); |
| 3422 | } |
| 3423 | |
| 3424 | void LocationsBuilderARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 3425 | HandleCondition(comp); |
| 3426 | } |
| 3427 | |
| 3428 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 3429 | HandleCondition(comp); |
| 3430 | } |
| 3431 | |
| 3432 | void LocationsBuilderARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 3433 | HandleCondition(comp); |
| 3434 | } |
| 3435 | |
| 3436 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 3437 | HandleCondition(comp); |
| 3438 | } |
| 3439 | |
| 3440 | void LocationsBuilderARMVIXL::VisitBelow(HBelow* comp) { |
| 3441 | HandleCondition(comp); |
| 3442 | } |
| 3443 | |
| 3444 | void InstructionCodeGeneratorARMVIXL::VisitBelow(HBelow* comp) { |
| 3445 | HandleCondition(comp); |
| 3446 | } |
| 3447 | |
| 3448 | void LocationsBuilderARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 3449 | HandleCondition(comp); |
| 3450 | } |
| 3451 | |
| 3452 | void InstructionCodeGeneratorARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 3453 | HandleCondition(comp); |
| 3454 | } |
| 3455 | |
| 3456 | void LocationsBuilderARMVIXL::VisitAbove(HAbove* comp) { |
| 3457 | HandleCondition(comp); |
| 3458 | } |
| 3459 | |
| 3460 | void InstructionCodeGeneratorARMVIXL::VisitAbove(HAbove* comp) { |
| 3461 | HandleCondition(comp); |
| 3462 | } |
| 3463 | |
| 3464 | void LocationsBuilderARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 3465 | HandleCondition(comp); |
| 3466 | } |
| 3467 | |
| 3468 | void InstructionCodeGeneratorARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 3469 | HandleCondition(comp); |
| 3470 | } |
| 3471 | |
| 3472 | void LocationsBuilderARMVIXL::VisitIntConstant(HIntConstant* constant) { |
| 3473 | LocationSummary* locations = |
| 3474 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3475 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3476 | } |
| 3477 | |
| 3478 | void InstructionCodeGeneratorARMVIXL::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 3479 | // Will be generated at use site. |
| 3480 | } |
| 3481 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3482 | void LocationsBuilderARMVIXL::VisitNullConstant(HNullConstant* constant) { |
| 3483 | LocationSummary* locations = |
| 3484 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3485 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3486 | } |
| 3487 | |
| 3488 | void InstructionCodeGeneratorARMVIXL::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 3489 | // Will be generated at use site. |
| 3490 | } |
| 3491 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3492 | void LocationsBuilderARMVIXL::VisitLongConstant(HLongConstant* constant) { |
| 3493 | LocationSummary* locations = |
| 3494 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3495 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3496 | } |
| 3497 | |
| 3498 | void InstructionCodeGeneratorARMVIXL::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 3499 | // Will be generated at use site. |
| 3500 | } |
| 3501 | |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3502 | void LocationsBuilderARMVIXL::VisitFloatConstant(HFloatConstant* constant) { |
| 3503 | LocationSummary* locations = |
| 3504 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3505 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3506 | } |
| 3507 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3508 | void InstructionCodeGeneratorARMVIXL::VisitFloatConstant( |
| 3509 | HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3510 | // Will be generated at use site. |
| 3511 | } |
| 3512 | |
| 3513 | void LocationsBuilderARMVIXL::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3514 | LocationSummary* locations = |
| 3515 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3516 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3517 | } |
| 3518 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3519 | void InstructionCodeGeneratorARMVIXL::VisitDoubleConstant( |
| 3520 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3521 | // Will be generated at use site. |
| 3522 | } |
| 3523 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 3524 | void LocationsBuilderARMVIXL::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 3525 | constructor_fence->SetLocations(nullptr); |
| 3526 | } |
| 3527 | |
| 3528 | void InstructionCodeGeneratorARMVIXL::VisitConstructorFence( |
| 3529 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 3530 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 3531 | } |
| 3532 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3533 | void LocationsBuilderARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3534 | memory_barrier->SetLocations(nullptr); |
| 3535 | } |
| 3536 | |
| 3537 | void InstructionCodeGeneratorARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3538 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 3539 | } |
| 3540 | |
| 3541 | void LocationsBuilderARMVIXL::VisitReturnVoid(HReturnVoid* ret) { |
| 3542 | ret->SetLocations(nullptr); |
| 3543 | } |
| 3544 | |
| 3545 | void InstructionCodeGeneratorARMVIXL::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 3546 | codegen_->GenerateFrameExit(); |
| 3547 | } |
| 3548 | |
| 3549 | void LocationsBuilderARMVIXL::VisitReturn(HReturn* ret) { |
| 3550 | LocationSummary* locations = |
| 3551 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
| 3552 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
| 3553 | } |
| 3554 | |
| 3555 | void InstructionCodeGeneratorARMVIXL::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 3556 | codegen_->GenerateFrameExit(); |
| 3557 | } |
| 3558 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3559 | void LocationsBuilderARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3560 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3561 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3562 | // the method_idx. |
| 3563 | HandleInvoke(invoke); |
| 3564 | } |
| 3565 | |
| 3566 | void InstructionCodeGeneratorARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3567 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3568 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 3); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3569 | } |
| 3570 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3571 | void LocationsBuilderARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3572 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3573 | // art::PrepareForRegisterAllocation. |
| 3574 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 3575 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3576 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3577 | if (intrinsic.TryDispatch(invoke)) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3578 | return; |
| 3579 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3580 | |
| 3581 | HandleInvoke(invoke); |
| 3582 | } |
| 3583 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3584 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARMVIXL* codegen) { |
| 3585 | if (invoke->GetLocations()->Intrinsified()) { |
| 3586 | IntrinsicCodeGeneratorARMVIXL intrinsic(codegen); |
| 3587 | intrinsic.Dispatch(invoke); |
| 3588 | return true; |
| 3589 | } |
| 3590 | return false; |
| 3591 | } |
| 3592 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3593 | void InstructionCodeGeneratorARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3594 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3595 | // art::PrepareForRegisterAllocation. |
| 3596 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 3597 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3598 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3599 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 4); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3600 | return; |
| 3601 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3602 | |
| 3603 | LocationSummary* locations = invoke->GetLocations(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3604 | codegen_->GenerateStaticOrDirectCall( |
| 3605 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3606 | |
| 3607 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 5); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3608 | } |
| 3609 | |
| 3610 | void LocationsBuilderARMVIXL::HandleInvoke(HInvoke* invoke) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3611 | InvokeDexCallingConventionVisitorARMVIXL calling_convention_visitor; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3612 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 3613 | } |
| 3614 | |
| 3615 | void LocationsBuilderARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3616 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3617 | if (intrinsic.TryDispatch(invoke)) { |
| 3618 | return; |
| 3619 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3620 | |
| 3621 | HandleInvoke(invoke); |
| 3622 | } |
| 3623 | |
| 3624 | void InstructionCodeGeneratorARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3625 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3626 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 6); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3627 | return; |
| 3628 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3629 | |
| 3630 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3631 | DCHECK(!codegen_->IsLeafMethod()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3632 | |
| 3633 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 7); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3634 | } |
| 3635 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3636 | void LocationsBuilderARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3637 | HandleInvoke(invoke); |
| 3638 | // Add the hidden argument. |
| 3639 | invoke->GetLocations()->AddTemp(LocationFrom(r12)); |
| 3640 | } |
| 3641 | |
| 3642 | void InstructionCodeGeneratorARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3643 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 3644 | LocationSummary* locations = invoke->GetLocations(); |
| 3645 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 3646 | vixl32::Register hidden_reg = RegisterFrom(locations->GetTemp(1)); |
| 3647 | Location receiver = locations->InAt(0); |
| 3648 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3649 | |
| 3650 | DCHECK(!receiver.IsStackSlot()); |
| 3651 | |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3652 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
| 3653 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 3654 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 3655 | vixl32::kMaxInstructionSizeInBytes, |
| 3656 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3657 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 3658 | __ ldr(temp, MemOperand(RegisterFrom(receiver), class_offset)); |
| 3659 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 3660 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3661 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3662 | // emit a read barrier for the previous class reference load. |
| 3663 | // However this is not required in practice, as this is an |
| 3664 | // intermediate/temporary reference and because the current |
| 3665 | // concurrent copying collector keeps the from-space memory |
| 3666 | // intact/accessible until the end of the marking phase (the |
| 3667 | // concurrent copying collector may not in the future). |
| 3668 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 3669 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3670 | temp, |
| 3671 | temp, |
| 3672 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 3673 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 3674 | invoke->GetImtIndex(), kArmPointerSize)); |
| 3675 | // temp = temp->GetImtEntryAt(method_offset); |
| 3676 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 3677 | uint32_t entry_point = |
| 3678 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
| 3679 | // LR = temp->GetEntryPoint(); |
| 3680 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
| 3681 | |
| 3682 | // Set the hidden (in r12) argument. It is done here, right before a BLX to prevent other |
| 3683 | // instruction from clobbering it as they might use r12 as a scratch register. |
| 3684 | DCHECK(hidden_reg.Is(r12)); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3685 | |
| 3686 | { |
| 3687 | // The VIXL macro assembler may clobber any of the scratch registers that are available to it, |
| 3688 | // so it checks if the application is using them (by passing them to the macro assembler |
| 3689 | // methods). The following application of UseScratchRegisterScope corrects VIXL's notion of |
| 3690 | // what is available, and is the opposite of the standard usage: Instead of requesting a |
| 3691 | // temporary location, it imposes an external constraint (i.e. a specific register is reserved |
| 3692 | // for the hidden argument). Note that this works even if VIXL needs a scratch register itself |
| 3693 | // (to materialize the constant), since the destination register becomes available for such use |
| 3694 | // internally for the duration of the macro instruction. |
| 3695 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3696 | temps.Exclude(hidden_reg); |
| 3697 | __ Mov(hidden_reg, invoke->GetDexMethodIndex()); |
| 3698 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3699 | { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3700 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 3701 | // 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] | 3702 | ExactAssemblyScope aas(GetVIXLAssembler(), |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3703 | vixl32::k16BitT32InstructionSizeInBytes, |
| 3704 | CodeBufferCheckScope::kExactSize); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3705 | // LR(); |
| 3706 | __ blx(lr); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3707 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3708 | DCHECK(!codegen_->IsLeafMethod()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3709 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3710 | |
| 3711 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 8); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3712 | } |
| 3713 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3714 | void LocationsBuilderARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3715 | HandleInvoke(invoke); |
| 3716 | } |
| 3717 | |
| 3718 | void InstructionCodeGeneratorARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3719 | codegen_->GenerateInvokePolymorphicCall(invoke); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3720 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 9); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3721 | } |
| 3722 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3723 | void LocationsBuilderARMVIXL::VisitNeg(HNeg* neg) { |
| 3724 | LocationSummary* locations = |
| 3725 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 3726 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3727 | case DataType::Type::kInt32: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3728 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3729 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3730 | break; |
| 3731 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3732 | case DataType::Type::kInt64: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3733 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3734 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3735 | break; |
| 3736 | } |
| 3737 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3738 | case DataType::Type::kFloat32: |
| 3739 | case DataType::Type::kFloat64: |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3740 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3741 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3742 | break; |
| 3743 | |
| 3744 | default: |
| 3745 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3746 | } |
| 3747 | } |
| 3748 | |
| 3749 | void InstructionCodeGeneratorARMVIXL::VisitNeg(HNeg* neg) { |
| 3750 | LocationSummary* locations = neg->GetLocations(); |
| 3751 | Location out = locations->Out(); |
| 3752 | Location in = locations->InAt(0); |
| 3753 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3754 | case DataType::Type::kInt32: |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3755 | __ Rsb(OutputRegister(neg), InputRegisterAt(neg, 0), 0); |
| 3756 | break; |
| 3757 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3758 | case DataType::Type::kInt64: |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3759 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 3760 | __ Rsbs(LowRegisterFrom(out), LowRegisterFrom(in), 0); |
| 3761 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 3762 | // instruction here, as it does not exist in the Thumb-2 |
| 3763 | // instruction set. We use the following approach |
| 3764 | // using SBC and SUB instead. |
| 3765 | // |
| 3766 | // out.hi = -C |
| 3767 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(out)); |
| 3768 | // out.hi = out.hi - in.hi |
| 3769 | __ Sub(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(in)); |
| 3770 | break; |
| 3771 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3772 | case DataType::Type::kFloat32: |
| 3773 | case DataType::Type::kFloat64: |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 3774 | __ Vneg(OutputVRegister(neg), InputVRegister(neg)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3775 | break; |
| 3776 | |
| 3777 | default: |
| 3778 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3779 | } |
| 3780 | } |
| 3781 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3782 | void LocationsBuilderARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3783 | DataType::Type result_type = conversion->GetResultType(); |
| 3784 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 3785 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 3786 | << input_type << " -> " << result_type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3787 | |
| 3788 | // The float-to-long, double-to-long and long-to-float type conversions |
| 3789 | // rely on a call to the runtime. |
| 3790 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3791 | (((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) |
| 3792 | && result_type == DataType::Type::kInt64) |
| 3793 | || (input_type == DataType::Type::kInt64 && result_type == DataType::Type::kFloat32)) |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3794 | ? LocationSummary::kCallOnMainOnly |
| 3795 | : LocationSummary::kNoCall; |
| 3796 | LocationSummary* locations = |
| 3797 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 3798 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3799 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 3800 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3801 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 3802 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3803 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 3804 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 3805 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3806 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3807 | break; |
| 3808 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3809 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3810 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3811 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3812 | locations->SetInAt(0, Location::Any()); |
| 3813 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3814 | break; |
| 3815 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3816 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3817 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3818 | locations->SetOut(Location::RequiresRegister()); |
| 3819 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3820 | break; |
| 3821 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3822 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3823 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3824 | locations->SetOut(Location::RequiresRegister()); |
| 3825 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3826 | break; |
| 3827 | |
| 3828 | default: |
| 3829 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3830 | << " to " << result_type; |
| 3831 | } |
| 3832 | break; |
| 3833 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3834 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3835 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3836 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 3837 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3838 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 3839 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3840 | case DataType::Type::kInt16: |
| 3841 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3842 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3843 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3844 | break; |
| 3845 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3846 | case DataType::Type::kFloat32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3847 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3848 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 3849 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3850 | break; |
| 3851 | } |
| 3852 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3853 | case DataType::Type::kFloat64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3854 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3855 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0), |
| 3856 | calling_convention.GetFpuRegisterAt(1))); |
| 3857 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3858 | break; |
| 3859 | } |
| 3860 | |
| 3861 | default: |
| 3862 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3863 | << " to " << result_type; |
| 3864 | } |
| 3865 | break; |
| 3866 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3867 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3868 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3869 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 3870 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3871 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 3872 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3873 | case DataType::Type::kInt16: |
| 3874 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3875 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3876 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3877 | break; |
| 3878 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3879 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3880 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3881 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0), |
| 3882 | calling_convention.GetRegisterAt(1))); |
| 3883 | locations->SetOut(LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3884 | break; |
| 3885 | } |
| 3886 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3887 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3888 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3889 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3890 | break; |
| 3891 | |
| 3892 | default: |
| 3893 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3894 | << " to " << result_type; |
| 3895 | }; |
| 3896 | break; |
| 3897 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3898 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3899 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3900 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 3901 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3902 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 3903 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3904 | case DataType::Type::kInt16: |
| 3905 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3906 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3907 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3908 | break; |
| 3909 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3910 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3911 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3912 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3913 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3914 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3915 | break; |
| 3916 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3917 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3918 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3919 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3920 | break; |
| 3921 | |
| 3922 | default: |
| 3923 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3924 | << " to " << result_type; |
| 3925 | }; |
| 3926 | break; |
| 3927 | |
| 3928 | default: |
| 3929 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3930 | << " to " << result_type; |
| 3931 | } |
| 3932 | } |
| 3933 | |
| 3934 | void InstructionCodeGeneratorARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
| 3935 | LocationSummary* locations = conversion->GetLocations(); |
| 3936 | Location out = locations->Out(); |
| 3937 | Location in = locations->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3938 | DataType::Type result_type = conversion->GetResultType(); |
| 3939 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 3940 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 3941 | << input_type << " -> " << result_type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3942 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 3943 | case DataType::Type::kUint8: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3944 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 3945 | case DataType::Type::kInt8: |
| 3946 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3947 | case DataType::Type::kInt16: |
| 3948 | case DataType::Type::kInt32: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 3949 | __ Ubfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 8); |
| 3950 | break; |
| 3951 | case DataType::Type::kInt64: |
| 3952 | __ Ubfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 8); |
| 3953 | break; |
| 3954 | |
| 3955 | default: |
| 3956 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3957 | << " to " << result_type; |
| 3958 | } |
| 3959 | break; |
| 3960 | |
| 3961 | case DataType::Type::kInt8: |
| 3962 | switch (input_type) { |
| 3963 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3964 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 3965 | case DataType::Type::kInt16: |
| 3966 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3967 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 8); |
| 3968 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 3969 | case DataType::Type::kInt64: |
| 3970 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 8); |
| 3971 | break; |
| 3972 | |
| 3973 | default: |
| 3974 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3975 | << " to " << result_type; |
| 3976 | } |
| 3977 | break; |
| 3978 | |
| 3979 | case DataType::Type::kUint16: |
| 3980 | switch (input_type) { |
| 3981 | case DataType::Type::kInt8: |
| 3982 | case DataType::Type::kInt16: |
| 3983 | case DataType::Type::kInt32: |
| 3984 | __ Ubfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 3985 | break; |
| 3986 | case DataType::Type::kInt64: |
| 3987 | __ Ubfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
| 3988 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3989 | |
| 3990 | default: |
| 3991 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3992 | << " to " << result_type; |
| 3993 | } |
| 3994 | break; |
| 3995 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3996 | case DataType::Type::kInt16: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3997 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3998 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 3999 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4000 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 4001 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 4002 | case DataType::Type::kInt64: |
| 4003 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
| 4004 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4005 | |
| 4006 | default: |
| 4007 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4008 | << " to " << result_type; |
| 4009 | } |
| 4010 | break; |
| 4011 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4012 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4013 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4014 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4015 | DCHECK(out.IsRegister()); |
| 4016 | if (in.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4017 | __ Mov(OutputRegister(conversion), LowRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4018 | } else if (in.IsDoubleStackSlot()) { |
| 4019 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 4020 | OutputRegister(conversion), |
| 4021 | sp, |
| 4022 | in.GetStackIndex()); |
| 4023 | } else { |
| 4024 | DCHECK(in.IsConstant()); |
| 4025 | DCHECK(in.GetConstant()->IsLongConstant()); |
Vladimir Marko | ba1a48e | 2017-04-13 11:50:14 +0100 | [diff] [blame] | 4026 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 4027 | __ Mov(OutputRegister(conversion), static_cast<int32_t>(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4028 | } |
| 4029 | break; |
| 4030 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4031 | case DataType::Type::kFloat32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4032 | vixl32::SRegister temp = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4033 | __ Vcvt(S32, F32, temp, InputSRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4034 | __ Vmov(OutputRegister(conversion), temp); |
| 4035 | break; |
| 4036 | } |
| 4037 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4038 | case DataType::Type::kFloat64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4039 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4040 | __ Vcvt(S32, F64, temp_s, DRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4041 | __ Vmov(OutputRegister(conversion), temp_s); |
| 4042 | break; |
| 4043 | } |
| 4044 | |
| 4045 | default: |
| 4046 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4047 | << " to " << result_type; |
| 4048 | } |
| 4049 | break; |
| 4050 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4051 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4052 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4053 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 4054 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4055 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 4056 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4057 | case DataType::Type::kInt16: |
| 4058 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4059 | DCHECK(out.IsRegisterPair()); |
| 4060 | DCHECK(in.IsRegister()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4061 | __ Mov(LowRegisterFrom(out), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4062 | // Sign extension. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4063 | __ Asr(HighRegisterFrom(out), LowRegisterFrom(out), 31); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4064 | break; |
| 4065 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4066 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4067 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
| 4068 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 4069 | break; |
| 4070 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4071 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4072 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
| 4073 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 4074 | break; |
| 4075 | |
| 4076 | default: |
| 4077 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4078 | << " to " << result_type; |
| 4079 | } |
| 4080 | break; |
| 4081 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4082 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4083 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4084 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 4085 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4086 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 4087 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4088 | case DataType::Type::kInt16: |
| 4089 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4090 | __ Vmov(OutputSRegister(conversion), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4091 | __ Vcvt(F32, S32, OutputSRegister(conversion), OutputSRegister(conversion)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4092 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4093 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4094 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4095 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
| 4096 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 4097 | break; |
| 4098 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4099 | case DataType::Type::kFloat64: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4100 | __ Vcvt(F32, F64, OutputSRegister(conversion), DRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4101 | break; |
| 4102 | |
| 4103 | default: |
| 4104 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4105 | << " to " << result_type; |
| 4106 | }; |
| 4107 | break; |
| 4108 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4109 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4110 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4111 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 4112 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4113 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 4114 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4115 | case DataType::Type::kInt16: |
| 4116 | case DataType::Type::kInt32: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4117 | __ Vmov(LowSRegisterFrom(out), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4118 | __ Vcvt(F64, S32, DRegisterFrom(out), LowSRegisterFrom(out)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4119 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4120 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4121 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4122 | vixl32::Register low = LowRegisterFrom(in); |
| 4123 | vixl32::Register high = HighRegisterFrom(in); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4124 | vixl32::SRegister out_s = LowSRegisterFrom(out); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4125 | vixl32::DRegister out_d = DRegisterFrom(out); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4126 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4127 | vixl32::DRegister temp_d = DRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4128 | vixl32::DRegister constant_d = DRegisterFrom(locations->GetTemp(1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4129 | |
| 4130 | // temp_d = int-to-double(high) |
| 4131 | __ Vmov(temp_s, high); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4132 | __ Vcvt(F64, S32, temp_d, temp_s); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4133 | // constant_d = k2Pow32EncodingForDouble |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4134 | __ Vmov(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4135 | // out_d = unsigned-to-double(low) |
| 4136 | __ Vmov(out_s, low); |
| 4137 | __ Vcvt(F64, U32, out_d, out_s); |
| 4138 | // out_d += temp_d * constant_d |
| 4139 | __ Vmla(F64, out_d, temp_d, constant_d); |
| 4140 | break; |
| 4141 | } |
| 4142 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4143 | case DataType::Type::kFloat32: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4144 | __ Vcvt(F64, F32, DRegisterFrom(out), InputSRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4145 | break; |
| 4146 | |
| 4147 | default: |
| 4148 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4149 | << " to " << result_type; |
| 4150 | }; |
| 4151 | break; |
| 4152 | |
| 4153 | default: |
| 4154 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4155 | << " to " << result_type; |
| 4156 | } |
| 4157 | } |
| 4158 | |
| 4159 | void LocationsBuilderARMVIXL::VisitAdd(HAdd* add) { |
| 4160 | LocationSummary* locations = |
| 4161 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
| 4162 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4163 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4164 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4165 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 4166 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4167 | break; |
| 4168 | } |
| 4169 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4170 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4171 | locations->SetInAt(0, Location::RequiresRegister()); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4172 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4173 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4174 | break; |
| 4175 | } |
| 4176 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4177 | case DataType::Type::kFloat32: |
| 4178 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4179 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4180 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4181 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4182 | break; |
| 4183 | } |
| 4184 | |
| 4185 | default: |
| 4186 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 4187 | } |
| 4188 | } |
| 4189 | |
| 4190 | void InstructionCodeGeneratorARMVIXL::VisitAdd(HAdd* add) { |
| 4191 | LocationSummary* locations = add->GetLocations(); |
| 4192 | Location out = locations->Out(); |
| 4193 | Location first = locations->InAt(0); |
| 4194 | Location second = locations->InAt(1); |
| 4195 | |
| 4196 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4197 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4198 | __ Add(OutputRegister(add), InputRegisterAt(add, 0), InputOperandAt(add, 1)); |
| 4199 | } |
| 4200 | break; |
| 4201 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4202 | case DataType::Type::kInt64: { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4203 | if (second.IsConstant()) { |
| 4204 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 4205 | GenerateAddLongConst(out, first, value); |
| 4206 | } else { |
| 4207 | DCHECK(second.IsRegisterPair()); |
| 4208 | __ Adds(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 4209 | __ Adc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 4210 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4211 | break; |
| 4212 | } |
| 4213 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4214 | case DataType::Type::kFloat32: |
| 4215 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4216 | __ Vadd(OutputVRegister(add), InputVRegisterAt(add, 0), InputVRegisterAt(add, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4217 | break; |
| 4218 | |
| 4219 | default: |
| 4220 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 4221 | } |
| 4222 | } |
| 4223 | |
| 4224 | void LocationsBuilderARMVIXL::VisitSub(HSub* sub) { |
| 4225 | LocationSummary* locations = |
| 4226 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
| 4227 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4228 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4229 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4230 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
| 4231 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4232 | break; |
| 4233 | } |
| 4234 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4235 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4236 | locations->SetInAt(0, Location::RequiresRegister()); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4237 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4238 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4239 | break; |
| 4240 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4241 | case DataType::Type::kFloat32: |
| 4242 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4243 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4244 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4245 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4246 | break; |
| 4247 | } |
| 4248 | default: |
| 4249 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 4250 | } |
| 4251 | } |
| 4252 | |
| 4253 | void InstructionCodeGeneratorARMVIXL::VisitSub(HSub* sub) { |
| 4254 | LocationSummary* locations = sub->GetLocations(); |
| 4255 | Location out = locations->Out(); |
| 4256 | Location first = locations->InAt(0); |
| 4257 | Location second = locations->InAt(1); |
| 4258 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4259 | case DataType::Type::kInt32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4260 | __ Sub(OutputRegister(sub), InputRegisterAt(sub, 0), InputOperandAt(sub, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4261 | break; |
| 4262 | } |
| 4263 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4264 | case DataType::Type::kInt64: { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4265 | if (second.IsConstant()) { |
| 4266 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 4267 | GenerateAddLongConst(out, first, -value); |
| 4268 | } else { |
| 4269 | DCHECK(second.IsRegisterPair()); |
| 4270 | __ Subs(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 4271 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 4272 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4273 | break; |
| 4274 | } |
| 4275 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4276 | case DataType::Type::kFloat32: |
| 4277 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4278 | __ Vsub(OutputVRegister(sub), InputVRegisterAt(sub, 0), InputVRegisterAt(sub, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4279 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4280 | |
| 4281 | default: |
| 4282 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 4283 | } |
| 4284 | } |
| 4285 | |
| 4286 | void LocationsBuilderARMVIXL::VisitMul(HMul* mul) { |
| 4287 | LocationSummary* locations = |
| 4288 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 4289 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4290 | case DataType::Type::kInt32: |
| 4291 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4292 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4293 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4294 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4295 | break; |
| 4296 | } |
| 4297 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4298 | case DataType::Type::kFloat32: |
| 4299 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4300 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4301 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4302 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4303 | break; |
| 4304 | } |
| 4305 | |
| 4306 | default: |
| 4307 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4308 | } |
| 4309 | } |
| 4310 | |
| 4311 | void InstructionCodeGeneratorARMVIXL::VisitMul(HMul* mul) { |
| 4312 | LocationSummary* locations = mul->GetLocations(); |
| 4313 | Location out = locations->Out(); |
| 4314 | Location first = locations->InAt(0); |
| 4315 | Location second = locations->InAt(1); |
| 4316 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4317 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4318 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 4319 | break; |
| 4320 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4321 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4322 | vixl32::Register out_hi = HighRegisterFrom(out); |
| 4323 | vixl32::Register out_lo = LowRegisterFrom(out); |
| 4324 | vixl32::Register in1_hi = HighRegisterFrom(first); |
| 4325 | vixl32::Register in1_lo = LowRegisterFrom(first); |
| 4326 | vixl32::Register in2_hi = HighRegisterFrom(second); |
| 4327 | vixl32::Register in2_lo = LowRegisterFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4328 | |
| 4329 | // Extra checks to protect caused by the existence of R1_R2. |
| 4330 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 4331 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4332 | DCHECK(!out_hi.Is(in1_lo)); |
| 4333 | DCHECK(!out_hi.Is(in2_lo)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4334 | |
| 4335 | // input: in1 - 64 bits, in2 - 64 bits |
| 4336 | // output: out |
| 4337 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 4338 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 4339 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 4340 | |
| 4341 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4342 | vixl32::Register temp = temps.Acquire(); |
| 4343 | // temp <- in1.lo * in2.hi |
| 4344 | __ Mul(temp, in1_lo, in2_hi); |
| 4345 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 4346 | __ Mla(out_hi, in1_hi, in2_lo, temp); |
| 4347 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 4348 | __ Umull(out_lo, temp, in1_lo, in2_lo); |
| 4349 | // 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] | 4350 | __ Add(out_hi, out_hi, temp); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4351 | break; |
| 4352 | } |
| 4353 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4354 | case DataType::Type::kFloat32: |
| 4355 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4356 | __ Vmul(OutputVRegister(mul), InputVRegisterAt(mul, 0), InputVRegisterAt(mul, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4357 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4358 | |
| 4359 | default: |
| 4360 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4361 | } |
| 4362 | } |
| 4363 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4364 | void InstructionCodeGeneratorARMVIXL::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 4365 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4366 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4367 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4368 | Location second = instruction->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4369 | DCHECK(second.IsConstant()); |
| 4370 | |
| 4371 | vixl32::Register out = OutputRegister(instruction); |
| 4372 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4373 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4374 | DCHECK(imm == 1 || imm == -1); |
| 4375 | |
| 4376 | if (instruction->IsRem()) { |
| 4377 | __ Mov(out, 0); |
| 4378 | } else { |
| 4379 | if (imm == 1) { |
| 4380 | __ Mov(out, dividend); |
| 4381 | } else { |
| 4382 | __ Rsb(out, dividend, 0); |
| 4383 | } |
| 4384 | } |
| 4385 | } |
| 4386 | |
| 4387 | void InstructionCodeGeneratorARMVIXL::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 4388 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4389 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4390 | |
| 4391 | LocationSummary* locations = instruction->GetLocations(); |
| 4392 | Location second = locations->InAt(1); |
| 4393 | DCHECK(second.IsConstant()); |
| 4394 | |
| 4395 | vixl32::Register out = OutputRegister(instruction); |
| 4396 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4397 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4398 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4399 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 4400 | int ctz_imm = CTZ(abs_imm); |
| 4401 | |
| 4402 | if (ctz_imm == 1) { |
| 4403 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 4404 | } else { |
| 4405 | __ Asr(temp, dividend, 31); |
| 4406 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 4407 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4408 | __ Add(out, temp, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4409 | |
| 4410 | if (instruction->IsDiv()) { |
| 4411 | __ Asr(out, out, ctz_imm); |
| 4412 | if (imm < 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4413 | __ Rsb(out, out, 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4414 | } |
| 4415 | } else { |
| 4416 | __ Ubfx(out, out, 0, ctz_imm); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4417 | __ Sub(out, out, temp); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4418 | } |
| 4419 | } |
| 4420 | |
| 4421 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 4422 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4423 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4424 | |
| 4425 | LocationSummary* locations = instruction->GetLocations(); |
| 4426 | Location second = locations->InAt(1); |
| 4427 | DCHECK(second.IsConstant()); |
| 4428 | |
| 4429 | vixl32::Register out = OutputRegister(instruction); |
| 4430 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4431 | vixl32::Register temp1 = RegisterFrom(locations->GetTemp(0)); |
| 4432 | vixl32::Register temp2 = RegisterFrom(locations->GetTemp(1)); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4433 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4434 | |
| 4435 | int64_t magic; |
| 4436 | int shift; |
| 4437 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 4438 | |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4439 | // TODO(VIXL): Change the static cast to Operand::From() after VIXL is fixed. |
| 4440 | __ Mov(temp1, static_cast<int32_t>(magic)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4441 | __ Smull(temp2, temp1, dividend, temp1); |
| 4442 | |
| 4443 | if (imm > 0 && magic < 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4444 | __ Add(temp1, temp1, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4445 | } else if (imm < 0 && magic > 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4446 | __ Sub(temp1, temp1, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4447 | } |
| 4448 | |
| 4449 | if (shift != 0) { |
| 4450 | __ Asr(temp1, temp1, shift); |
| 4451 | } |
| 4452 | |
| 4453 | if (instruction->IsDiv()) { |
| 4454 | __ Sub(out, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 4455 | } else { |
| 4456 | __ Sub(temp1, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 4457 | // TODO: Strength reduction for mls. |
| 4458 | __ Mov(temp2, imm); |
| 4459 | __ Mls(out, temp1, temp2, dividend); |
| 4460 | } |
| 4461 | } |
| 4462 | |
| 4463 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemConstantIntegral( |
| 4464 | HBinaryOperation* instruction) { |
| 4465 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4466 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4467 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4468 | Location second = instruction->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4469 | DCHECK(second.IsConstant()); |
| 4470 | |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4471 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4472 | if (imm == 0) { |
| 4473 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4474 | } else if (imm == 1 || imm == -1) { |
| 4475 | DivRemOneOrMinusOne(instruction); |
| 4476 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 4477 | DivRemByPowerOfTwo(instruction); |
| 4478 | } else { |
| 4479 | DCHECK(imm <= -2 || imm >= 2); |
| 4480 | GenerateDivRemWithAnyConstant(instruction); |
| 4481 | } |
| 4482 | } |
| 4483 | |
| 4484 | void LocationsBuilderARMVIXL::VisitDiv(HDiv* div) { |
| 4485 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4486 | if (div->GetResultType() == DataType::Type::kInt64) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4487 | // pLdiv runtime call. |
| 4488 | call_kind = LocationSummary::kCallOnMainOnly; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4489 | } else if (div->GetResultType() == DataType::Type::kInt32 && div->InputAt(1)->IsConstant()) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4490 | // sdiv will be replaced by other instruction sequence. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4491 | } else if (div->GetResultType() == DataType::Type::kInt32 && |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4492 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4493 | // pIdivmod runtime call. |
| 4494 | call_kind = LocationSummary::kCallOnMainOnly; |
| 4495 | } |
| 4496 | |
| 4497 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 4498 | |
| 4499 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4500 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4501 | if (div->InputAt(1)->IsConstant()) { |
| 4502 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4503 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
| 4504 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4505 | int32_t value = Int32ConstantFrom(div->InputAt(1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4506 | if (value == 1 || value == 0 || value == -1) { |
| 4507 | // No temp register required. |
| 4508 | } else { |
| 4509 | locations->AddTemp(Location::RequiresRegister()); |
| 4510 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
| 4511 | locations->AddTemp(Location::RequiresRegister()); |
| 4512 | } |
| 4513 | } |
| 4514 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4515 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4516 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4517 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4518 | } else { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4519 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4520 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4521 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4522 | // 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] | 4523 | // we only need the former. |
| 4524 | locations->SetOut(LocationFrom(r0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4525 | } |
| 4526 | break; |
| 4527 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4528 | case DataType::Type::kInt64: { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4529 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4530 | locations->SetInAt(0, LocationFrom( |
| 4531 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4532 | locations->SetInAt(1, LocationFrom( |
| 4533 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4534 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4535 | break; |
| 4536 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4537 | case DataType::Type::kFloat32: |
| 4538 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4539 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4540 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4541 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4542 | break; |
| 4543 | } |
| 4544 | |
| 4545 | default: |
| 4546 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4547 | } |
| 4548 | } |
| 4549 | |
| 4550 | void InstructionCodeGeneratorARMVIXL::VisitDiv(HDiv* div) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4551 | Location lhs = div->GetLocations()->InAt(0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4552 | Location rhs = div->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4553 | |
| 4554 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4555 | case DataType::Type::kInt32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4556 | if (rhs.IsConstant()) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4557 | GenerateDivRemConstantIntegral(div); |
| 4558 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4559 | __ Sdiv(OutputRegister(div), InputRegisterAt(div, 0), InputRegisterAt(div, 1)); |
| 4560 | } else { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4561 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4562 | DCHECK(calling_convention.GetRegisterAt(0).Is(RegisterFrom(lhs))); |
| 4563 | DCHECK(calling_convention.GetRegisterAt(1).Is(RegisterFrom(rhs))); |
| 4564 | DCHECK(r0.Is(OutputRegister(div))); |
| 4565 | |
| 4566 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
| 4567 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4568 | } |
| 4569 | break; |
| 4570 | } |
| 4571 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4572 | case DataType::Type::kInt64: { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4573 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4574 | DCHECK(calling_convention.GetRegisterAt(0).Is(LowRegisterFrom(lhs))); |
| 4575 | DCHECK(calling_convention.GetRegisterAt(1).Is(HighRegisterFrom(lhs))); |
| 4576 | DCHECK(calling_convention.GetRegisterAt(2).Is(LowRegisterFrom(rhs))); |
| 4577 | DCHECK(calling_convention.GetRegisterAt(3).Is(HighRegisterFrom(rhs))); |
| 4578 | DCHECK(LowRegisterFrom(div->GetLocations()->Out()).Is(r0)); |
| 4579 | DCHECK(HighRegisterFrom(div->GetLocations()->Out()).Is(r1)); |
| 4580 | |
| 4581 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
| 4582 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4583 | break; |
| 4584 | } |
| 4585 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4586 | case DataType::Type::kFloat32: |
| 4587 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4588 | __ Vdiv(OutputVRegister(div), InputVRegisterAt(div, 0), InputVRegisterAt(div, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4589 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4590 | |
| 4591 | default: |
| 4592 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4593 | } |
| 4594 | } |
| 4595 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4596 | void LocationsBuilderARMVIXL::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4597 | DataType::Type type = rem->GetResultType(); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4598 | |
| 4599 | // Most remainders are implemented in the runtime. |
| 4600 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4601 | if (rem->GetResultType() == DataType::Type::kInt32 && rem->InputAt(1)->IsConstant()) { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4602 | // sdiv will be replaced by other instruction sequence. |
| 4603 | call_kind = LocationSummary::kNoCall; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4604 | } else if ((rem->GetResultType() == DataType::Type::kInt32) |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4605 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4606 | // Have hardware divide instruction for int, do it with three instructions. |
| 4607 | call_kind = LocationSummary::kNoCall; |
| 4608 | } |
| 4609 | |
| 4610 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 4611 | |
| 4612 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4613 | case DataType::Type::kInt32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4614 | if (rem->InputAt(1)->IsConstant()) { |
| 4615 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4616 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
| 4617 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4618 | int32_t value = Int32ConstantFrom(rem->InputAt(1)); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4619 | if (value == 1 || value == 0 || value == -1) { |
| 4620 | // No temp register required. |
| 4621 | } else { |
| 4622 | locations->AddTemp(Location::RequiresRegister()); |
| 4623 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
| 4624 | locations->AddTemp(Location::RequiresRegister()); |
| 4625 | } |
| 4626 | } |
| 4627 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4628 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4629 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4630 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4631 | locations->AddTemp(Location::RequiresRegister()); |
| 4632 | } else { |
| 4633 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4634 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4635 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4636 | // 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] | 4637 | // we only need the latter. |
| 4638 | locations->SetOut(LocationFrom(r1)); |
| 4639 | } |
| 4640 | break; |
| 4641 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4642 | case DataType::Type::kInt64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4643 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4644 | locations->SetInAt(0, LocationFrom( |
| 4645 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4646 | locations->SetInAt(1, LocationFrom( |
| 4647 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4648 | // The runtime helper puts the output in R2,R3. |
| 4649 | locations->SetOut(LocationFrom(r2, r3)); |
| 4650 | break; |
| 4651 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4652 | case DataType::Type::kFloat32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4653 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4654 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 4655 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 4656 | locations->SetOut(LocationFrom(s0)); |
| 4657 | break; |
| 4658 | } |
| 4659 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4660 | case DataType::Type::kFloat64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4661 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4662 | locations->SetInAt(0, LocationFrom( |
| 4663 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 4664 | locations->SetInAt(1, LocationFrom( |
| 4665 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 4666 | locations->SetOut(LocationFrom(s0, s1)); |
| 4667 | break; |
| 4668 | } |
| 4669 | |
| 4670 | default: |
| 4671 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4672 | } |
| 4673 | } |
| 4674 | |
| 4675 | void InstructionCodeGeneratorARMVIXL::VisitRem(HRem* rem) { |
| 4676 | LocationSummary* locations = rem->GetLocations(); |
| 4677 | Location second = locations->InAt(1); |
| 4678 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4679 | DataType::Type type = rem->GetResultType(); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4680 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4681 | case DataType::Type::kInt32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4682 | vixl32::Register reg1 = InputRegisterAt(rem, 0); |
| 4683 | vixl32::Register out_reg = OutputRegister(rem); |
| 4684 | if (second.IsConstant()) { |
| 4685 | GenerateDivRemConstantIntegral(rem); |
| 4686 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4687 | vixl32::Register reg2 = RegisterFrom(second); |
| 4688 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 4689 | |
| 4690 | // temp = reg1 / reg2 (integer division) |
| 4691 | // dest = reg1 - temp * reg2 |
| 4692 | __ Sdiv(temp, reg1, reg2); |
| 4693 | __ Mls(out_reg, temp, reg2, reg1); |
| 4694 | } else { |
| 4695 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4696 | DCHECK(reg1.Is(calling_convention.GetRegisterAt(0))); |
| 4697 | DCHECK(RegisterFrom(second).Is(calling_convention.GetRegisterAt(1))); |
| 4698 | DCHECK(out_reg.Is(r1)); |
| 4699 | |
| 4700 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
| 4701 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
| 4702 | } |
| 4703 | break; |
| 4704 | } |
| 4705 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4706 | case DataType::Type::kInt64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4707 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
| 4708 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 4709 | break; |
| 4710 | } |
| 4711 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4712 | case DataType::Type::kFloat32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4713 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
| 4714 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 4715 | break; |
| 4716 | } |
| 4717 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4718 | case DataType::Type::kFloat64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4719 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
| 4720 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 4721 | break; |
| 4722 | } |
| 4723 | |
| 4724 | default: |
| 4725 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4726 | } |
| 4727 | } |
| 4728 | |
| 4729 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4730 | void LocationsBuilderARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 4731 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4732 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4733 | } |
| 4734 | |
| 4735 | void InstructionCodeGeneratorARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 4736 | DivZeroCheckSlowPathARMVIXL* slow_path = |
| 4737 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARMVIXL(instruction); |
| 4738 | codegen_->AddSlowPath(slow_path); |
| 4739 | |
| 4740 | LocationSummary* locations = instruction->GetLocations(); |
| 4741 | Location value = locations->InAt(0); |
| 4742 | |
| 4743 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4744 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 4745 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4746 | case DataType::Type::kInt8: |
| 4747 | case DataType::Type::kUint16: |
| 4748 | case DataType::Type::kInt16: |
| 4749 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4750 | if (value.IsRegister()) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 4751 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4752 | } else { |
| 4753 | DCHECK(value.IsConstant()) << value; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4754 | if (Int32ConstantFrom(value) == 0) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4755 | __ B(slow_path->GetEntryLabel()); |
| 4756 | } |
| 4757 | } |
| 4758 | break; |
| 4759 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4760 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4761 | if (value.IsRegisterPair()) { |
| 4762 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4763 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4764 | __ Orrs(temp, LowRegisterFrom(value), HighRegisterFrom(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4765 | __ B(eq, slow_path->GetEntryLabel()); |
| 4766 | } else { |
| 4767 | DCHECK(value.IsConstant()) << value; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4768 | if (Int64ConstantFrom(value) == 0) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4769 | __ B(slow_path->GetEntryLabel()); |
| 4770 | } |
| 4771 | } |
| 4772 | break; |
| 4773 | } |
| 4774 | default: |
| 4775 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4776 | } |
| 4777 | } |
| 4778 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4779 | void InstructionCodeGeneratorARMVIXL::HandleIntegerRotate(HRor* ror) { |
| 4780 | LocationSummary* locations = ror->GetLocations(); |
| 4781 | vixl32::Register in = InputRegisterAt(ror, 0); |
| 4782 | Location rhs = locations->InAt(1); |
| 4783 | vixl32::Register out = OutputRegister(ror); |
| 4784 | |
| 4785 | if (rhs.IsConstant()) { |
| 4786 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 4787 | // so map all rotations to a +ve. equivalent in that range. |
| 4788 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 4789 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 4790 | if (rot) { |
| 4791 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 4792 | // (e.g. left by 2 bits == right by 30.) |
| 4793 | __ Ror(out, in, rot); |
| 4794 | } else if (!out.Is(in)) { |
| 4795 | __ Mov(out, in); |
| 4796 | } |
| 4797 | } else { |
| 4798 | __ Ror(out, in, RegisterFrom(rhs)); |
| 4799 | } |
| 4800 | } |
| 4801 | |
| 4802 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 4803 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 4804 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 4805 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 4806 | void InstructionCodeGeneratorARMVIXL::HandleLongRotate(HRor* ror) { |
| 4807 | LocationSummary* locations = ror->GetLocations(); |
| 4808 | vixl32::Register in_reg_lo = LowRegisterFrom(locations->InAt(0)); |
| 4809 | vixl32::Register in_reg_hi = HighRegisterFrom(locations->InAt(0)); |
| 4810 | Location rhs = locations->InAt(1); |
| 4811 | vixl32::Register out_reg_lo = LowRegisterFrom(locations->Out()); |
| 4812 | vixl32::Register out_reg_hi = HighRegisterFrom(locations->Out()); |
| 4813 | |
| 4814 | if (rhs.IsConstant()) { |
| 4815 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 4816 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
| 4817 | rot &= kMaxLongShiftDistance; |
| 4818 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 4819 | // logic below to a simple pair of binary orr. |
| 4820 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 4821 | if (rot >= kArmBitsPerWord) { |
| 4822 | rot -= kArmBitsPerWord; |
| 4823 | std::swap(in_reg_hi, in_reg_lo); |
| 4824 | } |
| 4825 | // Rotate, or mov to out for zero or word size rotations. |
| 4826 | if (rot != 0u) { |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4827 | __ Lsr(out_reg_hi, in_reg_hi, Operand::From(rot)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4828 | __ 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] | 4829 | __ Lsr(out_reg_lo, in_reg_lo, Operand::From(rot)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4830 | __ Orr(out_reg_lo, out_reg_lo, Operand(in_reg_hi, ShiftType::LSL, kArmBitsPerWord - rot)); |
| 4831 | } else { |
| 4832 | __ Mov(out_reg_lo, in_reg_lo); |
| 4833 | __ Mov(out_reg_hi, in_reg_hi); |
| 4834 | } |
| 4835 | } else { |
| 4836 | vixl32::Register shift_right = RegisterFrom(locations->GetTemp(0)); |
| 4837 | vixl32::Register shift_left = RegisterFrom(locations->GetTemp(1)); |
| 4838 | vixl32::Label end; |
| 4839 | vixl32::Label shift_by_32_plus_shift_right; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4840 | vixl32::Label* final_label = codegen_->GetFinalLabel(ror, &end); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4841 | |
| 4842 | __ And(shift_right, RegisterFrom(rhs), 0x1F); |
| 4843 | __ Lsrs(shift_left, RegisterFrom(rhs), 6); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 4844 | __ Rsb(LeaveFlags, shift_left, shift_right, Operand::From(kArmBitsPerWord)); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 4845 | __ B(cc, &shift_by_32_plus_shift_right, /* far_target */ false); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4846 | |
| 4847 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 4848 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 4849 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 4850 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4851 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 4852 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4853 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 4854 | __ Add(out_reg_lo, out_reg_lo, shift_left); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4855 | __ B(final_label); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4856 | |
| 4857 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 4858 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 4859 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 4860 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 4861 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4862 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 4863 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4864 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 4865 | __ Add(out_reg_lo, out_reg_lo, shift_right); |
| 4866 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4867 | if (end.IsReferenced()) { |
| 4868 | __ Bind(&end); |
| 4869 | } |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4870 | } |
| 4871 | } |
| 4872 | |
| 4873 | void LocationsBuilderARMVIXL::VisitRor(HRor* ror) { |
| 4874 | LocationSummary* locations = |
| 4875 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 4876 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4877 | case DataType::Type::kInt32: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4878 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4879 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 4880 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4881 | break; |
| 4882 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4883 | case DataType::Type::kInt64: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4884 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4885 | if (ror->InputAt(1)->IsConstant()) { |
| 4886 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 4887 | } else { |
| 4888 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4889 | locations->AddTemp(Location::RequiresRegister()); |
| 4890 | locations->AddTemp(Location::RequiresRegister()); |
| 4891 | } |
| 4892 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4893 | break; |
| 4894 | } |
| 4895 | default: |
| 4896 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4897 | } |
| 4898 | } |
| 4899 | |
| 4900 | void InstructionCodeGeneratorARMVIXL::VisitRor(HRor* ror) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4901 | DataType::Type type = ror->GetResultType(); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4902 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4903 | case DataType::Type::kInt32: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4904 | HandleIntegerRotate(ror); |
| 4905 | break; |
| 4906 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4907 | case DataType::Type::kInt64: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4908 | HandleLongRotate(ror); |
| 4909 | break; |
| 4910 | } |
| 4911 | default: |
| 4912 | LOG(FATAL) << "Unexpected operation type " << type; |
| 4913 | UNREACHABLE(); |
| 4914 | } |
| 4915 | } |
| 4916 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4917 | void LocationsBuilderARMVIXL::HandleShift(HBinaryOperation* op) { |
| 4918 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4919 | |
| 4920 | LocationSummary* locations = |
| 4921 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 4922 | |
| 4923 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4924 | case DataType::Type::kInt32: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4925 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4926 | if (op->InputAt(1)->IsConstant()) { |
| 4927 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 4928 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4929 | } else { |
| 4930 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4931 | // Make the output overlap, as it will be used to hold the masked |
| 4932 | // second input. |
| 4933 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4934 | } |
| 4935 | break; |
| 4936 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4937 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4938 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4939 | if (op->InputAt(1)->IsConstant()) { |
| 4940 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 4941 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 4942 | // don't clash with high registers which the register allocator currently guarantees. |
| 4943 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4944 | } else { |
| 4945 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4946 | locations->AddTemp(Location::RequiresRegister()); |
| 4947 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4948 | } |
| 4949 | break; |
| 4950 | } |
| 4951 | default: |
| 4952 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 4953 | } |
| 4954 | } |
| 4955 | |
| 4956 | void InstructionCodeGeneratorARMVIXL::HandleShift(HBinaryOperation* op) { |
| 4957 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4958 | |
| 4959 | LocationSummary* locations = op->GetLocations(); |
| 4960 | Location out = locations->Out(); |
| 4961 | Location first = locations->InAt(0); |
| 4962 | Location second = locations->InAt(1); |
| 4963 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4964 | DataType::Type type = op->GetResultType(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4965 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4966 | case DataType::Type::kInt32: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4967 | vixl32::Register out_reg = OutputRegister(op); |
| 4968 | vixl32::Register first_reg = InputRegisterAt(op, 0); |
| 4969 | if (second.IsRegister()) { |
| 4970 | vixl32::Register second_reg = RegisterFrom(second); |
| 4971 | // ARM doesn't mask the shift count so we need to do it ourselves. |
| 4972 | __ And(out_reg, second_reg, kMaxIntShiftDistance); |
| 4973 | if (op->IsShl()) { |
| 4974 | __ Lsl(out_reg, first_reg, out_reg); |
| 4975 | } else if (op->IsShr()) { |
| 4976 | __ Asr(out_reg, first_reg, out_reg); |
| 4977 | } else { |
| 4978 | __ Lsr(out_reg, first_reg, out_reg); |
| 4979 | } |
| 4980 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4981 | int32_t cst = Int32ConstantFrom(second); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4982 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
| 4983 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
| 4984 | __ Mov(out_reg, first_reg); |
| 4985 | } else if (op->IsShl()) { |
| 4986 | __ Lsl(out_reg, first_reg, shift_value); |
| 4987 | } else if (op->IsShr()) { |
| 4988 | __ Asr(out_reg, first_reg, shift_value); |
| 4989 | } else { |
| 4990 | __ Lsr(out_reg, first_reg, shift_value); |
| 4991 | } |
| 4992 | } |
| 4993 | break; |
| 4994 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4995 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4996 | vixl32::Register o_h = HighRegisterFrom(out); |
| 4997 | vixl32::Register o_l = LowRegisterFrom(out); |
| 4998 | |
| 4999 | vixl32::Register high = HighRegisterFrom(first); |
| 5000 | vixl32::Register low = LowRegisterFrom(first); |
| 5001 | |
| 5002 | if (second.IsRegister()) { |
| 5003 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5004 | |
| 5005 | vixl32::Register second_reg = RegisterFrom(second); |
| 5006 | |
| 5007 | if (op->IsShl()) { |
| 5008 | __ And(o_l, second_reg, kMaxLongShiftDistance); |
| 5009 | // Shift the high part |
| 5010 | __ Lsl(o_h, high, o_l); |
| 5011 | // Shift the low part and `or` what overflew on the high part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5012 | __ Rsb(temp, o_l, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5013 | __ Lsr(temp, low, temp); |
| 5014 | __ Orr(o_h, o_h, temp); |
| 5015 | // If the shift is > 32 bits, override the high part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5016 | __ Subs(temp, o_l, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5017 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5018 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5019 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5020 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5021 | __ it(pl); |
| 5022 | __ lsl(pl, o_h, low, temp); |
| 5023 | } |
| 5024 | // Shift the low part |
| 5025 | __ Lsl(o_l, low, o_l); |
| 5026 | } else if (op->IsShr()) { |
| 5027 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 5028 | // Shift the low part |
| 5029 | __ Lsr(o_l, low, o_h); |
| 5030 | // Shift the high part and `or` what underflew on the low part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5031 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5032 | __ Lsl(temp, high, temp); |
| 5033 | __ Orr(o_l, o_l, temp); |
| 5034 | // If the shift is > 32 bits, override the low part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5035 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5036 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5037 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5038 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5039 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5040 | __ it(pl); |
| 5041 | __ asr(pl, o_l, high, temp); |
| 5042 | } |
| 5043 | // Shift the high part |
| 5044 | __ Asr(o_h, high, o_h); |
| 5045 | } else { |
| 5046 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 5047 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 5048 | __ Lsr(o_l, low, o_h); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5049 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5050 | __ Lsl(temp, high, temp); |
| 5051 | __ Orr(o_l, o_l, temp); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5052 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5053 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5054 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5055 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5056 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5057 | __ it(pl); |
| 5058 | __ lsr(pl, o_l, high, temp); |
| 5059 | } |
| 5060 | __ Lsr(o_h, high, o_h); |
| 5061 | } |
| 5062 | } else { |
| 5063 | // Register allocator doesn't create partial overlap. |
| 5064 | DCHECK(!o_l.Is(high)); |
| 5065 | DCHECK(!o_h.Is(low)); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5066 | int32_t cst = Int32ConstantFrom(second); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5067 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
| 5068 | if (shift_value > 32) { |
| 5069 | if (op->IsShl()) { |
| 5070 | __ Lsl(o_h, low, shift_value - 32); |
| 5071 | __ Mov(o_l, 0); |
| 5072 | } else if (op->IsShr()) { |
| 5073 | __ Asr(o_l, high, shift_value - 32); |
| 5074 | __ Asr(o_h, high, 31); |
| 5075 | } else { |
| 5076 | __ Lsr(o_l, high, shift_value - 32); |
| 5077 | __ Mov(o_h, 0); |
| 5078 | } |
| 5079 | } else if (shift_value == 32) { |
| 5080 | if (op->IsShl()) { |
| 5081 | __ Mov(o_h, low); |
| 5082 | __ Mov(o_l, 0); |
| 5083 | } else if (op->IsShr()) { |
| 5084 | __ Mov(o_l, high); |
| 5085 | __ Asr(o_h, high, 31); |
| 5086 | } else { |
| 5087 | __ Mov(o_l, high); |
| 5088 | __ Mov(o_h, 0); |
| 5089 | } |
| 5090 | } else if (shift_value == 1) { |
| 5091 | if (op->IsShl()) { |
| 5092 | __ Lsls(o_l, low, 1); |
| 5093 | __ Adc(o_h, high, high); |
| 5094 | } else if (op->IsShr()) { |
| 5095 | __ Asrs(o_h, high, 1); |
| 5096 | __ Rrx(o_l, low); |
| 5097 | } else { |
| 5098 | __ Lsrs(o_h, high, 1); |
| 5099 | __ Rrx(o_l, low); |
| 5100 | } |
| 5101 | } else { |
| 5102 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
| 5103 | if (op->IsShl()) { |
| 5104 | __ Lsl(o_h, high, shift_value); |
| 5105 | __ Orr(o_h, o_h, Operand(low, ShiftType::LSR, 32 - shift_value)); |
| 5106 | __ Lsl(o_l, low, shift_value); |
| 5107 | } else if (op->IsShr()) { |
| 5108 | __ Lsr(o_l, low, shift_value); |
| 5109 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 5110 | __ Asr(o_h, high, shift_value); |
| 5111 | } else { |
| 5112 | __ Lsr(o_l, low, shift_value); |
| 5113 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 5114 | __ Lsr(o_h, high, shift_value); |
| 5115 | } |
| 5116 | } |
| 5117 | } |
| 5118 | break; |
| 5119 | } |
| 5120 | default: |
| 5121 | LOG(FATAL) << "Unexpected operation type " << type; |
| 5122 | UNREACHABLE(); |
| 5123 | } |
| 5124 | } |
| 5125 | |
| 5126 | void LocationsBuilderARMVIXL::VisitShl(HShl* shl) { |
| 5127 | HandleShift(shl); |
| 5128 | } |
| 5129 | |
| 5130 | void InstructionCodeGeneratorARMVIXL::VisitShl(HShl* shl) { |
| 5131 | HandleShift(shl); |
| 5132 | } |
| 5133 | |
| 5134 | void LocationsBuilderARMVIXL::VisitShr(HShr* shr) { |
| 5135 | HandleShift(shr); |
| 5136 | } |
| 5137 | |
| 5138 | void InstructionCodeGeneratorARMVIXL::VisitShr(HShr* shr) { |
| 5139 | HandleShift(shr); |
| 5140 | } |
| 5141 | |
| 5142 | void LocationsBuilderARMVIXL::VisitUShr(HUShr* ushr) { |
| 5143 | HandleShift(ushr); |
| 5144 | } |
| 5145 | |
| 5146 | void InstructionCodeGeneratorARMVIXL::VisitUShr(HUShr* ushr) { |
| 5147 | HandleShift(ushr); |
| 5148 | } |
| 5149 | |
| 5150 | void LocationsBuilderARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
| 5151 | LocationSummary* locations = |
| 5152 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| 5153 | if (instruction->IsStringAlloc()) { |
| 5154 | locations->AddTemp(LocationFrom(kMethodRegister)); |
| 5155 | } else { |
| 5156 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 5157 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5158 | } |
| 5159 | locations->SetOut(LocationFrom(r0)); |
| 5160 | } |
| 5161 | |
| 5162 | void InstructionCodeGeneratorARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
| 5163 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5164 | // of poisoning the reference. |
| 5165 | if (instruction->IsStringAlloc()) { |
| 5166 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 5167 | vixl32::Register temp = RegisterFrom(instruction->GetLocations()->GetTemp(0)); |
| 5168 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
| 5169 | GetAssembler()->LoadFromOffset(kLoadWord, temp, tr, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 5170 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, code_offset.Int32Value()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5171 | // 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] | 5172 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5173 | vixl32::k16BitT32InstructionSizeInBytes, |
| 5174 | CodeBufferCheckScope::kExactSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5175 | __ blx(lr); |
| 5176 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5177 | } else { |
| 5178 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 5179 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5180 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 5181 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 10); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5182 | } |
| 5183 | |
| 5184 | void LocationsBuilderARMVIXL::VisitNewArray(HNewArray* instruction) { |
| 5185 | LocationSummary* locations = |
| 5186 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| 5187 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5188 | locations->SetOut(LocationFrom(r0)); |
Nicolas Geoffray | 8c7c4f1 | 2017-01-26 10:13:11 +0000 | [diff] [blame] | 5189 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5190 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5191 | } |
| 5192 | |
| 5193 | void InstructionCodeGeneratorARMVIXL::VisitNewArray(HNewArray* instruction) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5194 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5195 | // of poisoning the reference. |
Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 5196 | QuickEntrypointEnum entrypoint = |
| 5197 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 5198 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5199 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 5200 | DCHECK(!codegen_->IsLeafMethod()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 5201 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 11); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5202 | } |
| 5203 | |
| 5204 | void LocationsBuilderARMVIXL::VisitParameterValue(HParameterValue* instruction) { |
| 5205 | LocationSummary* locations = |
| 5206 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5207 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5208 | if (location.IsStackSlot()) { |
| 5209 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5210 | } else if (location.IsDoubleStackSlot()) { |
| 5211 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5212 | } |
| 5213 | locations->SetOut(location); |
| 5214 | } |
| 5215 | |
| 5216 | void InstructionCodeGeneratorARMVIXL::VisitParameterValue( |
| 5217 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 5218 | // Nothing to do, the parameter is already at its location. |
| 5219 | } |
| 5220 | |
| 5221 | void LocationsBuilderARMVIXL::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5222 | LocationSummary* locations = |
| 5223 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5224 | locations->SetOut(LocationFrom(kMethodRegister)); |
| 5225 | } |
| 5226 | |
| 5227 | void InstructionCodeGeneratorARMVIXL::VisitCurrentMethod( |
| 5228 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5229 | // Nothing to do, the method is already at its location. |
| 5230 | } |
| 5231 | |
| 5232 | void LocationsBuilderARMVIXL::VisitNot(HNot* not_) { |
| 5233 | LocationSummary* locations = |
| 5234 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
| 5235 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5236 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5237 | } |
| 5238 | |
| 5239 | void InstructionCodeGeneratorARMVIXL::VisitNot(HNot* not_) { |
| 5240 | LocationSummary* locations = not_->GetLocations(); |
| 5241 | Location out = locations->Out(); |
| 5242 | Location in = locations->InAt(0); |
| 5243 | switch (not_->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5244 | case DataType::Type::kInt32: |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5245 | __ Mvn(OutputRegister(not_), InputRegisterAt(not_, 0)); |
| 5246 | break; |
| 5247 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5248 | case DataType::Type::kInt64: |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5249 | __ Mvn(LowRegisterFrom(out), LowRegisterFrom(in)); |
| 5250 | __ Mvn(HighRegisterFrom(out), HighRegisterFrom(in)); |
| 5251 | break; |
| 5252 | |
| 5253 | default: |
| 5254 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 5255 | } |
| 5256 | } |
| 5257 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5258 | void LocationsBuilderARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5259 | LocationSummary* locations = |
| 5260 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 5261 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5262 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5263 | } |
| 5264 | |
| 5265 | void InstructionCodeGeneratorARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5266 | __ Eor(OutputRegister(bool_not), InputRegister(bool_not), 1); |
| 5267 | } |
| 5268 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5269 | void LocationsBuilderARMVIXL::VisitCompare(HCompare* compare) { |
| 5270 | LocationSummary* locations = |
| 5271 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| 5272 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5273 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 5274 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5275 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5276 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 5277 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5278 | case DataType::Type::kInt32: |
| 5279 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5280 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5281 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5282 | // Output overlaps because it is written before doing the low comparison. |
| 5283 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5284 | break; |
| 5285 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5286 | case DataType::Type::kFloat32: |
| 5287 | case DataType::Type::kFloat64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5288 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5289 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
| 5290 | locations->SetOut(Location::RequiresRegister()); |
| 5291 | break; |
| 5292 | } |
| 5293 | default: |
| 5294 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 5295 | } |
| 5296 | } |
| 5297 | |
| 5298 | void InstructionCodeGeneratorARMVIXL::VisitCompare(HCompare* compare) { |
| 5299 | LocationSummary* locations = compare->GetLocations(); |
| 5300 | vixl32::Register out = OutputRegister(compare); |
| 5301 | Location left = locations->InAt(0); |
| 5302 | Location right = locations->InAt(1); |
| 5303 | |
| 5304 | vixl32::Label less, greater, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5305 | vixl32::Label* final_label = codegen_->GetFinalLabel(compare, &done); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5306 | DataType::Type type = compare->InputAt(0)->GetType(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5307 | vixl32::Condition less_cond = vixl32::Condition(kNone); |
| 5308 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5309 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 5310 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5311 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5312 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 5313 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5314 | case DataType::Type::kInt32: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5315 | // Emit move to `out` before the `Cmp`, as `Mov` might affect the status flags. |
| 5316 | __ Mov(out, 0); |
| 5317 | __ Cmp(RegisterFrom(left), RegisterFrom(right)); // Signed compare. |
| 5318 | less_cond = lt; |
| 5319 | break; |
| 5320 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5321 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5322 | __ Cmp(HighRegisterFrom(left), HighRegisterFrom(right)); // Signed compare. |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 5323 | __ B(lt, &less, /* far_target */ false); |
| 5324 | __ B(gt, &greater, /* far_target */ false); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5325 | // Emit move to `out` before the last `Cmp`, as `Mov` might affect the status flags. |
| 5326 | __ Mov(out, 0); |
| 5327 | __ Cmp(LowRegisterFrom(left), LowRegisterFrom(right)); // Unsigned compare. |
| 5328 | less_cond = lo; |
| 5329 | break; |
| 5330 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5331 | case DataType::Type::kFloat32: |
| 5332 | case DataType::Type::kFloat64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5333 | __ Mov(out, 0); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 5334 | GenerateVcmp(compare, codegen_); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5335 | // To branch on the FP compare result we transfer FPSCR to APSR (encoded as PC in VMRS). |
| 5336 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 5337 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
| 5338 | break; |
| 5339 | } |
| 5340 | default: |
| 5341 | LOG(FATAL) << "Unexpected compare type " << type; |
| 5342 | UNREACHABLE(); |
| 5343 | } |
| 5344 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5345 | __ B(eq, final_label, /* far_target */ false); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 5346 | __ B(less_cond, &less, /* far_target */ false); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5347 | |
| 5348 | __ Bind(&greater); |
| 5349 | __ Mov(out, 1); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5350 | __ B(final_label); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5351 | |
| 5352 | __ Bind(&less); |
| 5353 | __ Mov(out, -1); |
| 5354 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5355 | if (done.IsReferenced()) { |
| 5356 | __ Bind(&done); |
| 5357 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5358 | } |
| 5359 | |
| 5360 | void LocationsBuilderARMVIXL::VisitPhi(HPhi* instruction) { |
| 5361 | LocationSummary* locations = |
| 5362 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5363 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| 5364 | locations->SetInAt(i, Location::Any()); |
| 5365 | } |
| 5366 | locations->SetOut(Location::Any()); |
| 5367 | } |
| 5368 | |
| 5369 | void InstructionCodeGeneratorARMVIXL::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 5370 | LOG(FATAL) << "Unreachable"; |
| 5371 | } |
| 5372 | |
| 5373 | void CodeGeneratorARMVIXL::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 5374 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 5375 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
| 5376 | switch (kind) { |
| 5377 | case MemBarrierKind::kAnyStore: |
| 5378 | case MemBarrierKind::kLoadAny: |
| 5379 | case MemBarrierKind::kAnyAny: { |
| 5380 | flavor = DmbOptions::ISH; |
| 5381 | break; |
| 5382 | } |
| 5383 | case MemBarrierKind::kStoreStore: { |
| 5384 | flavor = DmbOptions::ISHST; |
| 5385 | break; |
| 5386 | } |
| 5387 | default: |
| 5388 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 5389 | } |
| 5390 | __ Dmb(flavor); |
| 5391 | } |
| 5392 | |
| 5393 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicLoad(vixl32::Register addr, |
| 5394 | uint32_t offset, |
| 5395 | vixl32::Register out_lo, |
| 5396 | vixl32::Register out_hi) { |
| 5397 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5398 | if (offset != 0) { |
| 5399 | vixl32::Register temp = temps.Acquire(); |
| 5400 | __ Add(temp, addr, offset); |
| 5401 | addr = temp; |
| 5402 | } |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5403 | __ Ldrexd(out_lo, out_hi, MemOperand(addr)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5404 | } |
| 5405 | |
| 5406 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicStore(vixl32::Register addr, |
| 5407 | uint32_t offset, |
| 5408 | vixl32::Register value_lo, |
| 5409 | vixl32::Register value_hi, |
| 5410 | vixl32::Register temp1, |
| 5411 | vixl32::Register temp2, |
| 5412 | HInstruction* instruction) { |
| 5413 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5414 | vixl32::Label fail; |
| 5415 | if (offset != 0) { |
| 5416 | vixl32::Register temp = temps.Acquire(); |
| 5417 | __ Add(temp, addr, offset); |
| 5418 | addr = temp; |
| 5419 | } |
| 5420 | __ Bind(&fail); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5421 | { |
| 5422 | // Ensure the pc position is recorded immediately after the `ldrexd` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5423 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5424 | vixl32::kMaxInstructionSizeInBytes, |
| 5425 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5426 | // We need a load followed by store. (The address used in a STREX instruction must |
| 5427 | // be the same as the address in the most recently executed LDREX instruction.) |
| 5428 | __ ldrexd(temp1, temp2, MemOperand(addr)); |
| 5429 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5430 | } |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5431 | __ Strexd(temp1, value_lo, value_hi, MemOperand(addr)); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5432 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5433 | } |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5434 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5435 | void LocationsBuilderARMVIXL::HandleFieldSet( |
| 5436 | HInstruction* instruction, const FieldInfo& field_info) { |
| 5437 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5438 | |
| 5439 | LocationSummary* locations = |
| 5440 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5441 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5442 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5443 | DataType::Type field_type = field_info.GetFieldType(); |
| 5444 | if (DataType::IsFloatingPointType(field_type)) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5445 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5446 | } else { |
| 5447 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5448 | } |
| 5449 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5450 | 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] | 5451 | bool generate_volatile = field_info.IsVolatile() |
| 5452 | && is_wide |
| 5453 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5454 | bool needs_write_barrier = |
| 5455 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 5456 | // Temporary registers for the write barrier. |
| 5457 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
| 5458 | if (needs_write_barrier) { |
| 5459 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
| 5460 | locations->AddTemp(Location::RequiresRegister()); |
| 5461 | } else if (generate_volatile) { |
| 5462 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 5463 | // - registers need to be consecutive |
| 5464 | // - the first register should be even but not R14. |
| 5465 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5466 | // revisit this if we ever enable ARM encoding. |
| 5467 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5468 | |
| 5469 | locations->AddTemp(Location::RequiresRegister()); |
| 5470 | locations->AddTemp(Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5471 | if (field_type == DataType::Type::kFloat64) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5472 | // For doubles we need two more registers to copy the value. |
| 5473 | locations->AddTemp(LocationFrom(r2)); |
| 5474 | locations->AddTemp(LocationFrom(r3)); |
| 5475 | } |
| 5476 | } |
| 5477 | } |
| 5478 | |
| 5479 | void InstructionCodeGeneratorARMVIXL::HandleFieldSet(HInstruction* instruction, |
| 5480 | const FieldInfo& field_info, |
| 5481 | bool value_can_be_null) { |
| 5482 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5483 | |
| 5484 | LocationSummary* locations = instruction->GetLocations(); |
| 5485 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 5486 | Location value = locations->InAt(1); |
| 5487 | |
| 5488 | bool is_volatile = field_info.IsVolatile(); |
| 5489 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5490 | DataType::Type field_type = field_info.GetFieldType(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5491 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5492 | bool needs_write_barrier = |
| 5493 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 5494 | |
| 5495 | if (is_volatile) { |
| 5496 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 5497 | } |
| 5498 | |
| 5499 | switch (field_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5500 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 5501 | case DataType::Type::kUint8: |
| 5502 | case DataType::Type::kInt8: |
| 5503 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5504 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 5505 | case DataType::Type::kInt32: { |
| 5506 | StoreOperandType operand_type = GetStoreOperandType(field_type); |
| 5507 | GetAssembler()->StoreToOffset(operand_type, RegisterFrom(value), base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5508 | break; |
| 5509 | } |
| 5510 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5511 | case DataType::Type::kReference: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5512 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5513 | // Note that in the case where `value` is a null reference, |
| 5514 | // we do not enter this block, as a null reference does not |
| 5515 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5516 | DCHECK_EQ(field_type, DataType::Type::kReference); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5517 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5518 | __ Mov(temp, RegisterFrom(value)); |
| 5519 | GetAssembler()->PoisonHeapReference(temp); |
| 5520 | GetAssembler()->StoreToOffset(kStoreWord, temp, base, offset); |
| 5521 | } else { |
| 5522 | GetAssembler()->StoreToOffset(kStoreWord, RegisterFrom(value), base, offset); |
| 5523 | } |
| 5524 | break; |
| 5525 | } |
| 5526 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5527 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5528 | if (is_volatile && !atomic_ldrd_strd) { |
| 5529 | GenerateWideAtomicStore(base, |
| 5530 | offset, |
| 5531 | LowRegisterFrom(value), |
| 5532 | HighRegisterFrom(value), |
| 5533 | RegisterFrom(locations->GetTemp(0)), |
| 5534 | RegisterFrom(locations->GetTemp(1)), |
| 5535 | instruction); |
| 5536 | } else { |
| 5537 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), base, offset); |
| 5538 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5539 | } |
| 5540 | break; |
| 5541 | } |
| 5542 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5543 | case DataType::Type::kFloat32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5544 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), base, offset); |
| 5545 | break; |
| 5546 | } |
| 5547 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5548 | case DataType::Type::kFloat64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5549 | vixl32::DRegister value_reg = DRegisterFrom(value); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5550 | if (is_volatile && !atomic_ldrd_strd) { |
| 5551 | vixl32::Register value_reg_lo = RegisterFrom(locations->GetTemp(0)); |
| 5552 | vixl32::Register value_reg_hi = RegisterFrom(locations->GetTemp(1)); |
| 5553 | |
| 5554 | __ Vmov(value_reg_lo, value_reg_hi, value_reg); |
| 5555 | |
| 5556 | GenerateWideAtomicStore(base, |
| 5557 | offset, |
| 5558 | value_reg_lo, |
| 5559 | value_reg_hi, |
| 5560 | RegisterFrom(locations->GetTemp(2)), |
| 5561 | RegisterFrom(locations->GetTemp(3)), |
| 5562 | instruction); |
| 5563 | } else { |
| 5564 | GetAssembler()->StoreDToOffset(value_reg, base, offset); |
| 5565 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5566 | } |
| 5567 | break; |
| 5568 | } |
| 5569 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5570 | case DataType::Type::kVoid: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5571 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5572 | UNREACHABLE(); |
| 5573 | } |
| 5574 | |
| 5575 | // Longs and doubles are handled in the switch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5576 | if (field_type != DataType::Type::kInt64 && field_type != DataType::Type::kFloat64) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5577 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, we |
| 5578 | // should use a scope and the assembler to emit the store instruction to guarantee that we |
| 5579 | // record the pc at the correct position. But the `Assembler` does not automatically handle |
| 5580 | // unencodable offsets. Practically, everything is fine because the helper and VIXL, at the time |
| 5581 | // of writing, do generate the store instruction last. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5582 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5583 | } |
| 5584 | |
| 5585 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5586 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5587 | vixl32::Register card = RegisterFrom(locations->GetTemp(1)); |
| 5588 | codegen_->MarkGCCard(temp, card, base, RegisterFrom(value), value_can_be_null); |
| 5589 | } |
| 5590 | |
| 5591 | if (is_volatile) { |
| 5592 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 5593 | } |
| 5594 | } |
| 5595 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5596 | void LocationsBuilderARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 5597 | const FieldInfo& field_info) { |
| 5598 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 5599 | |
| 5600 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5601 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == DataType::Type::kReference); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5602 | LocationSummary* locations = |
| 5603 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5604 | object_field_get_with_read_barrier ? |
| 5605 | LocationSummary::kCallOnSlowPath : |
| 5606 | LocationSummary::kNoCall); |
| 5607 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5608 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 5609 | } |
| 5610 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5611 | |
| 5612 | bool volatile_for_double = field_info.IsVolatile() |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5613 | && (field_info.GetFieldType() == DataType::Type::kFloat64) |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5614 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5615 | // The output overlaps in case of volatile long: we don't want the |
| 5616 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 5617 | // object's location. Likewise, in the case of an object field get |
| 5618 | // with read barriers enabled, we do not want the load to overwrite |
| 5619 | // 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] | 5620 | bool overlap = |
| 5621 | (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) || |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5622 | object_field_get_with_read_barrier; |
| 5623 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5624 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5625 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5626 | } else { |
| 5627 | locations->SetOut(Location::RequiresRegister(), |
| 5628 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 5629 | } |
| 5630 | if (volatile_for_double) { |
| 5631 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 5632 | // - registers need to be consecutive |
| 5633 | // - the first register should be even but not R14. |
| 5634 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5635 | // revisit this if we ever enable ARM encoding. |
| 5636 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5637 | locations->AddTemp(Location::RequiresRegister()); |
| 5638 | locations->AddTemp(Location::RequiresRegister()); |
| 5639 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5640 | // We need a temporary register for the read barrier marking slow |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 5641 | // path in CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 5642 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 5643 | !Runtime::Current()->UseJitCompilation()) { |
| 5644 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 5645 | // loads we need a temporary only if the offset is too big. |
| 5646 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 5647 | locations->AddTemp(Location::RequiresRegister()); |
| 5648 | } |
| 5649 | // And we always need the reserved entrypoint register. |
| 5650 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 5651 | } else { |
| 5652 | locations->AddTemp(Location::RequiresRegister()); |
| 5653 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5654 | } |
| 5655 | } |
| 5656 | |
| 5657 | Location LocationsBuilderARMVIXL::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5658 | DCHECK(DataType::IsFloatingPointType(input->GetType())) << input->GetType(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5659 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 5660 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 5661 | return Location::ConstantLocation(input->AsConstant()); |
| 5662 | } else { |
| 5663 | return Location::RequiresFpuRegister(); |
| 5664 | } |
| 5665 | } |
| 5666 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5667 | Location LocationsBuilderARMVIXL::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 5668 | Opcode opcode) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5669 | DCHECK(!DataType::IsFloatingPointType(constant->GetType())); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5670 | if (constant->IsConstant() && |
| 5671 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 5672 | return Location::ConstantLocation(constant->AsConstant()); |
| 5673 | } |
| 5674 | return Location::RequiresRegister(); |
| 5675 | } |
| 5676 | |
| 5677 | bool LocationsBuilderARMVIXL::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 5678 | Opcode opcode) { |
| 5679 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5680 | if (DataType::Is64BitType(input_cst->GetType())) { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5681 | Opcode high_opcode = opcode; |
| 5682 | SetCc low_set_cc = kCcDontCare; |
| 5683 | switch (opcode) { |
| 5684 | case SUB: |
| 5685 | // Flip the operation to an ADD. |
| 5686 | value = -value; |
| 5687 | opcode = ADD; |
| 5688 | FALLTHROUGH_INTENDED; |
| 5689 | case ADD: |
| 5690 | if (Low32Bits(value) == 0u) { |
| 5691 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 5692 | } |
| 5693 | high_opcode = ADC; |
| 5694 | low_set_cc = kCcSet; |
| 5695 | break; |
| 5696 | default: |
| 5697 | break; |
| 5698 | } |
| 5699 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 5700 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
| 5701 | } else { |
| 5702 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 5703 | } |
| 5704 | } |
| 5705 | |
| 5706 | // TODO(VIXL): Replace art::arm::SetCc` with `vixl32::FlagsUpdate after flags set optimization |
| 5707 | // enabled. |
| 5708 | bool LocationsBuilderARMVIXL::CanEncodeConstantAsImmediate(uint32_t value, |
| 5709 | Opcode opcode, |
| 5710 | SetCc set_cc) { |
| 5711 | ArmVIXLAssembler* assembler = codegen_->GetAssembler(); |
| 5712 | if (assembler->ShifterOperandCanHold(opcode, value, set_cc)) { |
| 5713 | return true; |
| 5714 | } |
| 5715 | Opcode neg_opcode = kNoOperand; |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5716 | uint32_t neg_value = 0; |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5717 | switch (opcode) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5718 | case AND: neg_opcode = BIC; neg_value = ~value; break; |
| 5719 | case ORR: neg_opcode = ORN; neg_value = ~value; break; |
| 5720 | case ADD: neg_opcode = SUB; neg_value = -value; break; |
| 5721 | case ADC: neg_opcode = SBC; neg_value = ~value; break; |
| 5722 | case SUB: neg_opcode = ADD; neg_value = -value; break; |
| 5723 | case SBC: neg_opcode = ADC; neg_value = ~value; break; |
| 5724 | case MOV: neg_opcode = MVN; neg_value = ~value; break; |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5725 | default: |
| 5726 | return false; |
| 5727 | } |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5728 | |
| 5729 | if (assembler->ShifterOperandCanHold(neg_opcode, neg_value, set_cc)) { |
| 5730 | return true; |
| 5731 | } |
| 5732 | |
| 5733 | return opcode == AND && IsPowerOfTwo(value + 1); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5734 | } |
| 5735 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5736 | void InstructionCodeGeneratorARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 5737 | const FieldInfo& field_info) { |
| 5738 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 5739 | |
| 5740 | LocationSummary* locations = instruction->GetLocations(); |
| 5741 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 5742 | Location out = locations->Out(); |
| 5743 | bool is_volatile = field_info.IsVolatile(); |
| 5744 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5745 | DataType::Type field_type = field_info.GetFieldType(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5746 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5747 | |
| 5748 | switch (field_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5749 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 5750 | case DataType::Type::kUint8: |
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: { |
| 5755 | LoadOperandType operand_type = GetLoadOperandType(field_type); |
| 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: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5815 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5816 | UNREACHABLE(); |
| 5817 | } |
| 5818 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5819 | if (field_type == DataType::Type::kReference || field_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 | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5833 | if (field_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 = |
| 5963 | new (GetGraph()->GetArena()) NullCheckSlowPathARMVIXL(instruction); |
| 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 | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame^] | 5981 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5982 | case DataType::Type::kInt8: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5983 | __ Ldrsb(cond, RegisterFrom(out_loc), mem_address); |
| 5984 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5985 | case DataType::Type::kBool: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5986 | __ Ldrb(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 = |
| 6044 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 6045 | object_array_get_with_read_barrier ? |
| 6046 | LocationSummary::kCallOnSlowPath : |
| 6047 | LocationSummary::kNoCall); |
| 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 | |
| 6328 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 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) { |
| 6436 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARMVIXL(instruction); |
| 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 = |
| 6610 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 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 = |
| 6634 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 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 = |
| 6697 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARMVIXL(instruction); |
| 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 = |
| 6708 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARMVIXL(instruction); |
| 6709 | __ Cmp(RegisterFrom(index_loc), length); |
| 6710 | codegen_->AddSlowPath(slow_path); |
| 6711 | __ B(hs, slow_path->GetEntryLabel()); |
| 6712 | } else { |
| 6713 | SlowPathCodeARMVIXL* slow_path = |
| 6714 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARMVIXL(instruction); |
| 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) { |
| 6744 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6745 | } |
| 6746 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6747 | void LocationsBuilderARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6748 | LocationSummary* locations = |
| 6749 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 6750 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6751 | } |
| 6752 | |
| 6753 | void InstructionCodeGeneratorARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 6754 | HBasicBlock* block = instruction->GetBlock(); |
| 6755 | if (block->GetLoopInformation() != nullptr) { |
| 6756 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6757 | // The back edge will generate the suspend check. |
| 6758 | return; |
| 6759 | } |
| 6760 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6761 | // The goto will generate the suspend check. |
| 6762 | return; |
| 6763 | } |
| 6764 | GenerateSuspendCheck(instruction, nullptr); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 6765 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 12); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6766 | } |
| 6767 | |
| 6768 | void InstructionCodeGeneratorARMVIXL::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 6769 | HBasicBlock* successor) { |
| 6770 | SuspendCheckSlowPathARMVIXL* slow_path = |
| 6771 | down_cast<SuspendCheckSlowPathARMVIXL*>(instruction->GetSlowPath()); |
| 6772 | if (slow_path == nullptr) { |
| 6773 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARMVIXL(instruction, successor); |
| 6774 | instruction->SetSlowPath(slow_path); |
| 6775 | codegen_->AddSlowPath(slow_path); |
| 6776 | if (successor != nullptr) { |
| 6777 | DCHECK(successor->IsLoopHeader()); |
| 6778 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 6779 | } |
| 6780 | } else { |
| 6781 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 6782 | } |
| 6783 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6784 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6785 | vixl32::Register temp = temps.Acquire(); |
| 6786 | GetAssembler()->LoadFromOffset( |
| 6787 | kLoadUnsignedHalfword, temp, tr, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
| 6788 | if (successor == nullptr) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6789 | __ CompareAndBranchIfNonZero(temp, slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6790 | __ Bind(slow_path->GetReturnLabel()); |
| 6791 | } else { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6792 | __ CompareAndBranchIfZero(temp, codegen_->GetLabelOf(successor)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6793 | __ B(slow_path->GetEntryLabel()); |
| 6794 | } |
| 6795 | } |
| 6796 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6797 | ArmVIXLAssembler* ParallelMoveResolverARMVIXL::GetAssembler() const { |
| 6798 | return codegen_->GetAssembler(); |
| 6799 | } |
| 6800 | |
| 6801 | void ParallelMoveResolverARMVIXL::EmitMove(size_t index) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6802 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6803 | MoveOperands* move = moves_[index]; |
| 6804 | Location source = move->GetSource(); |
| 6805 | Location destination = move->GetDestination(); |
| 6806 | |
| 6807 | if (source.IsRegister()) { |
| 6808 | if (destination.IsRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6809 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6810 | } else if (destination.IsFpuRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6811 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6812 | } else { |
| 6813 | DCHECK(destination.IsStackSlot()); |
| 6814 | GetAssembler()->StoreToOffset(kStoreWord, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6815 | RegisterFrom(source), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6816 | sp, |
| 6817 | destination.GetStackIndex()); |
| 6818 | } |
| 6819 | } else if (source.IsStackSlot()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6820 | if (destination.IsRegister()) { |
| 6821 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 6822 | RegisterFrom(destination), |
| 6823 | sp, |
| 6824 | source.GetStackIndex()); |
| 6825 | } else if (destination.IsFpuRegister()) { |
| 6826 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 6827 | } else { |
| 6828 | DCHECK(destination.IsStackSlot()); |
| 6829 | vixl32::Register temp = temps.Acquire(); |
| 6830 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 6831 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6832 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6833 | } else if (source.IsFpuRegister()) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6834 | if (destination.IsRegister()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6835 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6836 | } else if (destination.IsFpuRegister()) { |
| 6837 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 6838 | } else { |
| 6839 | DCHECK(destination.IsStackSlot()); |
| 6840 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 6841 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6842 | } else if (source.IsDoubleStackSlot()) { |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6843 | if (destination.IsDoubleStackSlot()) { |
| 6844 | vixl32::DRegister temp = temps.AcquireD(); |
| 6845 | GetAssembler()->LoadDFromOffset(temp, sp, source.GetStackIndex()); |
| 6846 | GetAssembler()->StoreDToOffset(temp, sp, destination.GetStackIndex()); |
| 6847 | } else if (destination.IsRegisterPair()) { |
| 6848 | DCHECK(ExpectedPairLayout(destination)); |
| 6849 | GetAssembler()->LoadFromOffset( |
| 6850 | kLoadWordPair, LowRegisterFrom(destination), sp, source.GetStackIndex()); |
| 6851 | } else { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6852 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 6853 | GetAssembler()->LoadDFromOffset(DRegisterFrom(destination), sp, source.GetStackIndex()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6854 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6855 | } else if (source.IsRegisterPair()) { |
| 6856 | if (destination.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6857 | __ Mov(LowRegisterFrom(destination), LowRegisterFrom(source)); |
| 6858 | __ Mov(HighRegisterFrom(destination), HighRegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6859 | } else if (destination.IsFpuRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6860 | __ Vmov(DRegisterFrom(destination), LowRegisterFrom(source), HighRegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6861 | } else { |
| 6862 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6863 | DCHECK(ExpectedPairLayout(source)); |
| 6864 | GetAssembler()->StoreToOffset(kStoreWordPair, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6865 | LowRegisterFrom(source), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6866 | sp, |
| 6867 | destination.GetStackIndex()); |
| 6868 | } |
| 6869 | } else if (source.IsFpuRegisterPair()) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6870 | if (destination.IsRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6871 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), DRegisterFrom(source)); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6872 | } else if (destination.IsFpuRegisterPair()) { |
| 6873 | __ Vmov(DRegisterFrom(destination), DRegisterFrom(source)); |
| 6874 | } else { |
| 6875 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6876 | GetAssembler()->StoreDToOffset(DRegisterFrom(source), sp, destination.GetStackIndex()); |
| 6877 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6878 | } else { |
| 6879 | DCHECK(source.IsConstant()) << source; |
| 6880 | HConstant* constant = source.GetConstant(); |
| 6881 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 6882 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
| 6883 | if (destination.IsRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6884 | __ Mov(RegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6885 | } else { |
| 6886 | DCHECK(destination.IsStackSlot()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6887 | vixl32::Register temp = temps.Acquire(); |
| 6888 | __ Mov(temp, value); |
| 6889 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6890 | } |
| 6891 | } else if (constant->IsLongConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6892 | int64_t value = Int64ConstantFrom(source); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6893 | if (destination.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6894 | __ Mov(LowRegisterFrom(destination), Low32Bits(value)); |
| 6895 | __ Mov(HighRegisterFrom(destination), High32Bits(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6896 | } else { |
| 6897 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6898 | vixl32::Register temp = temps.Acquire(); |
| 6899 | __ Mov(temp, Low32Bits(value)); |
| 6900 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6901 | __ Mov(temp, High32Bits(value)); |
| 6902 | GetAssembler()->StoreToOffset(kStoreWord, |
| 6903 | temp, |
| 6904 | sp, |
| 6905 | destination.GetHighStackIndex(kArmWordSize)); |
| 6906 | } |
| 6907 | } else if (constant->IsDoubleConstant()) { |
| 6908 | double value = constant->AsDoubleConstant()->GetValue(); |
| 6909 | if (destination.IsFpuRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6910 | __ Vmov(DRegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6911 | } else { |
| 6912 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6913 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6914 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6915 | __ Mov(temp, Low32Bits(int_value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6916 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6917 | __ Mov(temp, High32Bits(int_value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6918 | GetAssembler()->StoreToOffset(kStoreWord, |
| 6919 | temp, |
| 6920 | sp, |
| 6921 | destination.GetHighStackIndex(kArmWordSize)); |
| 6922 | } |
| 6923 | } else { |
| 6924 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
| 6925 | float value = constant->AsFloatConstant()->GetValue(); |
| 6926 | if (destination.IsFpuRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6927 | __ Vmov(SRegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6928 | } else { |
| 6929 | DCHECK(destination.IsStackSlot()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6930 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6931 | __ Mov(temp, bit_cast<int32_t, float>(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6932 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6933 | } |
| 6934 | } |
| 6935 | } |
| 6936 | } |
| 6937 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6938 | void ParallelMoveResolverARMVIXL::Exchange(vixl32::Register reg, int mem) { |
| 6939 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 6940 | vixl32::Register temp = temps.Acquire(); |
| 6941 | __ Mov(temp, reg); |
| 6942 | GetAssembler()->LoadFromOffset(kLoadWord, reg, sp, mem); |
| 6943 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6944 | } |
| 6945 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6946 | void ParallelMoveResolverARMVIXL::Exchange(int mem1, int mem2) { |
| 6947 | // TODO(VIXL32): Double check the performance of this implementation. |
| 6948 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6949 | vixl32::Register temp1 = temps.Acquire(); |
| 6950 | ScratchRegisterScope ensure_scratch( |
| 6951 | this, temp1.GetCode(), r0.GetCode(), codegen_->GetNumberOfCoreRegisters()); |
| 6952 | vixl32::Register temp2(ensure_scratch.GetRegister()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6953 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6954 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 6955 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, sp, mem1 + stack_offset); |
| 6956 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, sp, mem2 + stack_offset); |
| 6957 | GetAssembler()->StoreToOffset(kStoreWord, temp1, sp, mem2 + stack_offset); |
| 6958 | GetAssembler()->StoreToOffset(kStoreWord, temp2, sp, mem1 + stack_offset); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6959 | } |
| 6960 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6961 | void ParallelMoveResolverARMVIXL::EmitSwap(size_t index) { |
| 6962 | MoveOperands* move = moves_[index]; |
| 6963 | Location source = move->GetSource(); |
| 6964 | Location destination = move->GetDestination(); |
| 6965 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 6966 | |
| 6967 | if (source.IsRegister() && destination.IsRegister()) { |
| 6968 | vixl32::Register temp = temps.Acquire(); |
| 6969 | DCHECK(!RegisterFrom(source).Is(temp)); |
| 6970 | DCHECK(!RegisterFrom(destination).Is(temp)); |
| 6971 | __ Mov(temp, RegisterFrom(destination)); |
| 6972 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 6973 | __ Mov(RegisterFrom(source), temp); |
| 6974 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| 6975 | Exchange(RegisterFrom(source), destination.GetStackIndex()); |
| 6976 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| 6977 | Exchange(RegisterFrom(destination), source.GetStackIndex()); |
| 6978 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 6979 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6980 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6981 | vixl32::Register temp = temps.Acquire(); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 6982 | __ Vmov(temp, SRegisterFrom(source)); |
| 6983 | __ Vmov(SRegisterFrom(source), SRegisterFrom(destination)); |
| 6984 | __ Vmov(SRegisterFrom(destination), temp); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6985 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
| 6986 | vixl32::DRegister temp = temps.AcquireD(); |
| 6987 | __ Vmov(temp, LowRegisterFrom(source), HighRegisterFrom(source)); |
| 6988 | __ Mov(LowRegisterFrom(source), LowRegisterFrom(destination)); |
| 6989 | __ Mov(HighRegisterFrom(source), HighRegisterFrom(destination)); |
| 6990 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), temp); |
| 6991 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
| 6992 | vixl32::Register low_reg = LowRegisterFrom(source.IsRegisterPair() ? source : destination); |
| 6993 | int mem = source.IsRegisterPair() ? destination.GetStackIndex() : source.GetStackIndex(); |
| 6994 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
| 6995 | vixl32::DRegister temp = temps.AcquireD(); |
| 6996 | __ Vmov(temp, low_reg, vixl32::Register(low_reg.GetCode() + 1)); |
| 6997 | GetAssembler()->LoadFromOffset(kLoadWordPair, low_reg, sp, mem); |
| 6998 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
| 6999 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7000 | vixl32::DRegister first = DRegisterFrom(source); |
| 7001 | vixl32::DRegister second = DRegisterFrom(destination); |
| 7002 | vixl32::DRegister temp = temps.AcquireD(); |
| 7003 | __ Vmov(temp, first); |
| 7004 | __ Vmov(first, second); |
| 7005 | __ Vmov(second, temp); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7006 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7007 | vixl32::DRegister reg = source.IsFpuRegisterPair() |
| 7008 | ? DRegisterFrom(source) |
| 7009 | : DRegisterFrom(destination); |
| 7010 | int mem = source.IsFpuRegisterPair() |
| 7011 | ? destination.GetStackIndex() |
| 7012 | : source.GetStackIndex(); |
| 7013 | vixl32::DRegister temp = temps.AcquireD(); |
| 7014 | __ Vmov(temp, reg); |
| 7015 | GetAssembler()->LoadDFromOffset(reg, sp, mem); |
| 7016 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7017 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7018 | vixl32::SRegister reg = source.IsFpuRegister() |
| 7019 | ? SRegisterFrom(source) |
| 7020 | : SRegisterFrom(destination); |
| 7021 | int mem = source.IsFpuRegister() |
| 7022 | ? destination.GetStackIndex() |
| 7023 | : source.GetStackIndex(); |
| 7024 | vixl32::Register temp = temps.Acquire(); |
| 7025 | __ Vmov(temp, reg); |
| 7026 | GetAssembler()->LoadSFromOffset(reg, sp, mem); |
| 7027 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7028 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 7029 | vixl32::DRegister temp1 = temps.AcquireD(); |
| 7030 | vixl32::DRegister temp2 = temps.AcquireD(); |
| 7031 | __ Vldr(temp1, MemOperand(sp, source.GetStackIndex())); |
| 7032 | __ Vldr(temp2, MemOperand(sp, destination.GetStackIndex())); |
| 7033 | __ Vstr(temp1, MemOperand(sp, destination.GetStackIndex())); |
| 7034 | __ Vstr(temp2, MemOperand(sp, source.GetStackIndex())); |
| 7035 | } else { |
| 7036 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
| 7037 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7038 | } |
| 7039 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7040 | void ParallelMoveResolverARMVIXL::SpillScratch(int reg) { |
| 7041 | __ Push(vixl32::Register(reg)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7042 | } |
| 7043 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7044 | void ParallelMoveResolverARMVIXL::RestoreScratch(int reg) { |
| 7045 | __ Pop(vixl32::Register(reg)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7046 | } |
| 7047 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7048 | HLoadClass::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadClassKind( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7049 | HLoadClass::LoadKind desired_class_load_kind) { |
| 7050 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7051 | case HLoadClass::LoadKind::kInvalid: |
| 7052 | LOG(FATAL) << "UNREACHABLE"; |
| 7053 | UNREACHABLE(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7054 | case HLoadClass::LoadKind::kReferrersClass: |
| 7055 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7056 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7057 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7058 | case HLoadClass::LoadKind::kBssEntry: |
| 7059 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 7060 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7061 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7062 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7063 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 7064 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7065 | case HLoadClass::LoadKind::kRuntimeCall: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7066 | break; |
| 7067 | } |
| 7068 | return desired_class_load_kind; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7069 | } |
| 7070 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7071 | void LocationsBuilderARMVIXL::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7072 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7073 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7074 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7075 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7076 | cls, |
| 7077 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7078 | LocationFrom(r0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7079 | DCHECK(calling_convention.GetRegisterAt(0).Is(r0)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7080 | return; |
| 7081 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7082 | DCHECK(!cls->NeedsAccessCheck()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7083 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7084 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 7085 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7086 | ? LocationSummary::kCallOnSlowPath |
| 7087 | : LocationSummary::kNoCall; |
| 7088 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7089 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7090 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7091 | } |
| 7092 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7093 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7094 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7095 | } |
| 7096 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7097 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 7098 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 7099 | // Rely on the type resolution or initialization and marking to save everything we need. |
| 7100 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 7101 | // to the custom calling convention) or by marking, so we request a different temp. |
| 7102 | locations->AddTemp(Location::RequiresRegister()); |
| 7103 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 7104 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7105 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7106 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 7107 | // that the the kPrimNot result register is the same as the first argument register. |
| 7108 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 7109 | } else { |
| 7110 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7111 | } |
| 7112 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 7113 | if (kUseBakerReadBarrier && kBakerReadBarrierLinkTimeThunksEnableForGcRoots) { |
| 7114 | if (load_kind == HLoadClass::LoadKind::kBssEntry || |
| 7115 | (load_kind == HLoadClass::LoadKind::kReferrersClass && |
| 7116 | !Runtime::Current()->UseJitCompilation())) { |
| 7117 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 7118 | } |
| 7119 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7120 | } |
| 7121 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7122 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7123 | // move. |
| 7124 | void InstructionCodeGeneratorARMVIXL::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7125 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7126 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7127 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 7128 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 13); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7129 | return; |
| 7130 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7131 | DCHECK(!cls->NeedsAccessCheck()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7132 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7133 | LocationSummary* locations = cls->GetLocations(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7134 | Location out_loc = locations->Out(); |
| 7135 | vixl32::Register out = OutputRegister(cls); |
| 7136 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7137 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 7138 | ? kWithoutReadBarrier |
| 7139 | : kCompilerReadBarrierOption; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7140 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7141 | switch (load_kind) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7142 | case HLoadClass::LoadKind::kReferrersClass: { |
| 7143 | DCHECK(!cls->CanCallRuntime()); |
| 7144 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 7145 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 7146 | vixl32::Register current_method = InputRegisterAt(cls, 0); |
| 7147 | GenerateGcRootFieldLoad(cls, |
| 7148 | out_loc, |
| 7149 | current_method, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 7150 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7151 | read_barrier_option); |
| 7152 | break; |
| 7153 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7154 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7155 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7156 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 7157 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 7158 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 7159 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 7160 | break; |
| 7161 | } |
| 7162 | case HLoadClass::LoadKind::kBootImageAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7163 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7164 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 7165 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 7166 | DCHECK_NE(address, 0u); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7167 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7168 | break; |
| 7169 | } |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7170 | case HLoadClass::LoadKind::kBootImageClassTable: { |
| 7171 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7172 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 7173 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 7174 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 7175 | __ Ldr(out, MemOperand(out, /* offset */ 0)); |
| 7176 | // Extract the reference from the slot data, i.e. clear the hash bits. |
| 7177 | int32_t masked_hash = ClassTable::TableSlot::MaskHash( |
| 7178 | ComputeModifiedUtf8Hash(cls->GetDexFile().StringByTypeIdx(cls->GetTypeIndex()))); |
| 7179 | if (masked_hash != 0) { |
| 7180 | __ Sub(out, out, Operand(masked_hash)); |
| 7181 | } |
| 7182 | break; |
| 7183 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7184 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7185 | vixl32::Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 7186 | ? RegisterFrom(locations->GetTemp(0)) |
| 7187 | : out; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7188 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7189 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7190 | codegen_->EmitMovwMovtPlaceholder(labels, temp); |
| 7191 | GenerateGcRootFieldLoad(cls, out_loc, temp, /* offset */ 0, read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7192 | generate_null_check = true; |
| 7193 | break; |
| 7194 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7195 | case HLoadClass::LoadKind::kJitTableAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7196 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 7197 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7198 | cls->GetClass())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7199 | // /* GcRoot<mirror::Class> */ out = *out |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7200 | GenerateGcRootFieldLoad(cls, out_loc, out, /* offset */ 0, read_barrier_option); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7201 | break; |
| 7202 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7203 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7204 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7205 | LOG(FATAL) << "UNREACHABLE"; |
| 7206 | UNREACHABLE(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7207 | } |
| 7208 | |
| 7209 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 7210 | DCHECK(cls->CanCallRuntime()); |
| 7211 | LoadClassSlowPathARMVIXL* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARMVIXL( |
| 7212 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 7213 | codegen_->AddSlowPath(slow_path); |
| 7214 | if (generate_null_check) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7215 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7216 | } |
| 7217 | if (cls->MustGenerateClinitCheck()) { |
| 7218 | GenerateClassInitializationCheck(slow_path, out); |
| 7219 | } else { |
| 7220 | __ Bind(slow_path->GetExitLabel()); |
| 7221 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 7222 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 14); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7223 | } |
| 7224 | } |
| 7225 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7226 | void LocationsBuilderARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 7227 | LocationSummary* locations = |
| 7228 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 7229 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7230 | if (check->HasUses()) { |
| 7231 | locations->SetOut(Location::SameAsFirstInput()); |
| 7232 | } |
| 7233 | } |
| 7234 | |
| 7235 | void InstructionCodeGeneratorARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 7236 | // We assume the class is not null. |
| 7237 | LoadClassSlowPathARMVIXL* slow_path = |
| 7238 | new (GetGraph()->GetArena()) LoadClassSlowPathARMVIXL(check->GetLoadClass(), |
| 7239 | check, |
| 7240 | check->GetDexPc(), |
| 7241 | /* do_clinit */ true); |
| 7242 | codegen_->AddSlowPath(slow_path); |
| 7243 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 7244 | } |
| 7245 | |
| 7246 | void InstructionCodeGeneratorARMVIXL::GenerateClassInitializationCheck( |
| 7247 | LoadClassSlowPathARMVIXL* slow_path, vixl32::Register class_reg) { |
| 7248 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 7249 | vixl32::Register temp = temps.Acquire(); |
| 7250 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 7251 | temp, |
| 7252 | class_reg, |
| 7253 | mirror::Class::StatusOffset().Int32Value()); |
| 7254 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 7255 | __ B(lt, slow_path->GetEntryLabel()); |
| 7256 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 7257 | // properly. Therefore, we do a memory fence. |
| 7258 | __ Dmb(ISH); |
| 7259 | __ Bind(slow_path->GetExitLabel()); |
| 7260 | } |
| 7261 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7262 | HLoadString::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadStringKind( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7263 | HLoadString::LoadKind desired_string_load_kind) { |
| 7264 | switch (desired_string_load_kind) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7265 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7266 | case HLoadString::LoadKind::kBootImageInternTable: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7267 | case HLoadString::LoadKind::kBssEntry: |
| 7268 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 7269 | break; |
| 7270 | case HLoadString::LoadKind::kJitTableAddress: |
| 7271 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7272 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 7273 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7274 | case HLoadString::LoadKind::kRuntimeCall: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7275 | break; |
| 7276 | } |
| 7277 | return desired_string_load_kind; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7278 | } |
| 7279 | |
| 7280 | void LocationsBuilderARMVIXL::VisitLoadString(HLoadString* load) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7281 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7282 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7283 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7284 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7285 | locations->SetOut(LocationFrom(r0)); |
| 7286 | } else { |
| 7287 | locations->SetOut(Location::RequiresRegister()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7288 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 7289 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7290 | // Rely on the pResolveString and marking to save everything we need, including temps. |
| 7291 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 7292 | // 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] | 7293 | locations->AddTemp(Location::RequiresRegister()); |
| 7294 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 7295 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7296 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7297 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 7298 | // that the the kPrimNot result register is the same as the first argument register. |
| 7299 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 7300 | if (kUseBakerReadBarrier && kBakerReadBarrierLinkTimeThunksEnableForGcRoots) { |
| 7301 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 7302 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7303 | } else { |
| 7304 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7305 | } |
| 7306 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7307 | } |
| 7308 | } |
| 7309 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7310 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7311 | // move. |
| 7312 | void InstructionCodeGeneratorARMVIXL::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7313 | LocationSummary* locations = load->GetLocations(); |
| 7314 | Location out_loc = locations->Out(); |
| 7315 | vixl32::Register out = OutputRegister(load); |
| 7316 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 7317 | |
| 7318 | switch (load_kind) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7319 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 7320 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| 7321 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7322 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7323 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7324 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7325 | } |
| 7326 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7327 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 7328 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 7329 | DCHECK_NE(address, 0u); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7330 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7331 | return; |
| 7332 | } |
| 7333 | case HLoadString::LoadKind::kBootImageInternTable: { |
| 7334 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7335 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 7336 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
| 7337 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 7338 | __ Ldr(out, MemOperand(out, /* offset */ 0)); |
| 7339 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7340 | } |
| 7341 | case HLoadString::LoadKind::kBssEntry: { |
| 7342 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7343 | vixl32::Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 7344 | ? RegisterFrom(locations->GetTemp(0)) |
| 7345 | : out; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7346 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7347 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7348 | codegen_->EmitMovwMovtPlaceholder(labels, temp); |
| 7349 | GenerateGcRootFieldLoad(load, out_loc, temp, /* offset */ 0, kCompilerReadBarrierOption); |
| 7350 | LoadStringSlowPathARMVIXL* slow_path = |
| 7351 | new (GetGraph()->GetArena()) LoadStringSlowPathARMVIXL(load); |
| 7352 | codegen_->AddSlowPath(slow_path); |
| 7353 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 7354 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 7355 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 15); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7356 | return; |
| 7357 | } |
| 7358 | case HLoadString::LoadKind::kJitTableAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7359 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7360 | load->GetStringIndex(), |
| 7361 | load->GetString())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7362 | // /* GcRoot<mirror::String> */ out = *out |
| 7363 | GenerateGcRootFieldLoad(load, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
| 7364 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7365 | } |
| 7366 | default: |
| 7367 | break; |
| 7368 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7369 | |
| 7370 | // 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] | 7371 | DCHECK_EQ(load->GetLoadKind(), HLoadString::LoadKind::kRuntimeCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7372 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7373 | __ Mov(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7374 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 7375 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 7376 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 16); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7377 | } |
| 7378 | |
| 7379 | static int32_t GetExceptionTlsOffset() { |
| 7380 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
| 7381 | } |
| 7382 | |
| 7383 | void LocationsBuilderARMVIXL::VisitLoadException(HLoadException* load) { |
| 7384 | LocationSummary* locations = |
| 7385 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 7386 | locations->SetOut(Location::RequiresRegister()); |
| 7387 | } |
| 7388 | |
| 7389 | void InstructionCodeGeneratorARMVIXL::VisitLoadException(HLoadException* load) { |
| 7390 | vixl32::Register out = OutputRegister(load); |
| 7391 | GetAssembler()->LoadFromOffset(kLoadWord, out, tr, GetExceptionTlsOffset()); |
| 7392 | } |
| 7393 | |
| 7394 | |
| 7395 | void LocationsBuilderARMVIXL::VisitClearException(HClearException* clear) { |
| 7396 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 7397 | } |
| 7398 | |
| 7399 | void InstructionCodeGeneratorARMVIXL::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 7400 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 7401 | vixl32::Register temp = temps.Acquire(); |
| 7402 | __ Mov(temp, 0); |
| 7403 | GetAssembler()->StoreToOffset(kStoreWord, temp, tr, GetExceptionTlsOffset()); |
| 7404 | } |
| 7405 | |
| 7406 | void LocationsBuilderARMVIXL::VisitThrow(HThrow* instruction) { |
| 7407 | LocationSummary* locations = |
| 7408 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| 7409 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7410 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7411 | } |
| 7412 | |
| 7413 | void InstructionCodeGeneratorARMVIXL::VisitThrow(HThrow* instruction) { |
| 7414 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| 7415 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 7416 | } |
| 7417 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7418 | // Temp is used for read barrier. |
| 7419 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 7420 | if (kEmitCompilerReadBarrier && |
| 7421 | (kUseBakerReadBarrier || |
| 7422 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7423 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7424 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 7425 | return 1; |
| 7426 | } |
| 7427 | return 0; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7428 | } |
| 7429 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7430 | // Interface case has 3 temps, one for holding the number of interfaces, one for the current |
| 7431 | // interface pointer, one for loading the current interface. |
| 7432 | // The other checks have one temp for loading the object's class. |
| 7433 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 7434 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7435 | return 3; |
| 7436 | } |
| 7437 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 7438 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7439 | |
| 7440 | void LocationsBuilderARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 7441 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7442 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7443 | bool baker_read_barrier_slow_path = false; |
| 7444 | switch (type_check_kind) { |
| 7445 | case TypeCheckKind::kExactCheck: |
| 7446 | case TypeCheckKind::kAbstractClassCheck: |
| 7447 | case TypeCheckKind::kClassHierarchyCheck: |
| 7448 | case TypeCheckKind::kArrayObjectCheck: |
| 7449 | call_kind = |
| 7450 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 7451 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
| 7452 | break; |
| 7453 | case TypeCheckKind::kArrayCheck: |
| 7454 | case TypeCheckKind::kUnresolvedCheck: |
| 7455 | case TypeCheckKind::kInterfaceCheck: |
| 7456 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7457 | break; |
| 7458 | } |
| 7459 | |
| 7460 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 7461 | if (baker_read_barrier_slow_path) { |
| 7462 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 7463 | } |
| 7464 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7465 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7466 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 7467 | // Note that TypeCheckSlowPathARM uses this register too. |
| 7468 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7469 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 7470 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 7471 | codegen_->MaybeAddBakerCcEntrypointTempForFields(locations); |
| 7472 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7473 | } |
| 7474 | |
| 7475 | void InstructionCodeGeneratorARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 7476 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7477 | LocationSummary* locations = instruction->GetLocations(); |
| 7478 | Location obj_loc = locations->InAt(0); |
| 7479 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 7480 | vixl32::Register cls = InputRegisterAt(instruction, 1); |
| 7481 | Location out_loc = locations->Out(); |
| 7482 | vixl32::Register out = OutputRegister(instruction); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7483 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7484 | DCHECK_LE(num_temps, 1u); |
| 7485 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7486 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7487 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7488 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7489 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7490 | vixl32::Label done; |
| 7491 | vixl32::Label* const final_label = codegen_->GetFinalLabel(instruction, &done); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7492 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 7493 | |
| 7494 | // Return 0 if `obj` is null. |
| 7495 | // avoid null check if we know obj is not null. |
| 7496 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7497 | DCHECK(!out.Is(obj)); |
| 7498 | __ Mov(out, 0); |
| 7499 | __ CompareAndBranchIfZero(obj, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7500 | } |
| 7501 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7502 | switch (type_check_kind) { |
| 7503 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7504 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7505 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7506 | out_loc, |
| 7507 | obj_loc, |
| 7508 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7509 | maybe_temp_loc, |
| 7510 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7511 | // Classes must be equal for the instanceof to succeed. |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7512 | __ Cmp(out, cls); |
| 7513 | // We speculatively set the result to false without changing the condition |
| 7514 | // flags, which allows us to avoid some branching later. |
| 7515 | __ Mov(LeaveFlags, out, 0); |
| 7516 | |
| 7517 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7518 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7519 | // encoding can be used. |
| 7520 | if (out.IsLow()) { |
| 7521 | // We use the scope because of the IT block that follows. |
| 7522 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7523 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7524 | CodeBufferCheckScope::kExactSize); |
| 7525 | |
| 7526 | __ it(eq); |
| 7527 | __ mov(eq, out, 1); |
| 7528 | } else { |
| 7529 | __ B(ne, final_label, /* far_target */ false); |
| 7530 | __ Mov(out, 1); |
| 7531 | } |
| 7532 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7533 | break; |
| 7534 | } |
| 7535 | |
| 7536 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7537 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7538 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7539 | out_loc, |
| 7540 | obj_loc, |
| 7541 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7542 | maybe_temp_loc, |
| 7543 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7544 | // If the class is abstract, we eagerly fetch the super class of the |
| 7545 | // object to avoid doing a comparison we know will fail. |
| 7546 | vixl32::Label loop; |
| 7547 | __ Bind(&loop); |
| 7548 | // /* HeapReference<Class> */ out = out->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7549 | GenerateReferenceLoadOneRegister(instruction, |
| 7550 | out_loc, |
| 7551 | super_offset, |
| 7552 | maybe_temp_loc, |
| 7553 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7554 | // 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] | 7555 | __ CompareAndBranchIfZero(out, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7556 | __ Cmp(out, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7557 | __ B(ne, &loop, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7558 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7559 | break; |
| 7560 | } |
| 7561 | |
| 7562 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7563 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7564 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7565 | out_loc, |
| 7566 | obj_loc, |
| 7567 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7568 | maybe_temp_loc, |
| 7569 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7570 | // Walk over the class hierarchy to find a match. |
| 7571 | vixl32::Label loop, success; |
| 7572 | __ Bind(&loop); |
| 7573 | __ Cmp(out, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7574 | __ B(eq, &success, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7575 | // /* HeapReference<Class> */ out = out->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7576 | GenerateReferenceLoadOneRegister(instruction, |
| 7577 | out_loc, |
| 7578 | super_offset, |
| 7579 | maybe_temp_loc, |
| 7580 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7581 | // This is essentially a null check, but it sets the condition flags to the |
| 7582 | // proper value for the code that follows the loop, i.e. not `eq`. |
| 7583 | __ Cmp(out, 1); |
| 7584 | __ B(hs, &loop, /* far_target */ false); |
| 7585 | |
| 7586 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7587 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7588 | // encoding can be used. |
| 7589 | if (out.IsLow()) { |
| 7590 | // If `out` is null, we use it for the result, and the condition flags |
| 7591 | // have already been set to `ne`, so the IT block that comes afterwards |
| 7592 | // (and which handles the successful case) turns into a NOP (instead of |
| 7593 | // overwriting `out`). |
| 7594 | __ Bind(&success); |
| 7595 | |
| 7596 | // We use the scope because of the IT block that follows. |
| 7597 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7598 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7599 | CodeBufferCheckScope::kExactSize); |
| 7600 | |
| 7601 | // There is only one branch to the `success` label (which is bound to this |
| 7602 | // IT block), and it has the same condition, `eq`, so in that case the MOV |
| 7603 | // is executed. |
| 7604 | __ it(eq); |
| 7605 | __ mov(eq, out, 1); |
| 7606 | } else { |
| 7607 | // 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] | 7608 | __ B(final_label); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7609 | __ Bind(&success); |
| 7610 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7611 | } |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7612 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7613 | break; |
| 7614 | } |
| 7615 | |
| 7616 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7617 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7618 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7619 | out_loc, |
| 7620 | obj_loc, |
| 7621 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7622 | maybe_temp_loc, |
| 7623 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7624 | // Do an exact check. |
| 7625 | vixl32::Label exact_check; |
| 7626 | __ Cmp(out, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7627 | __ B(eq, &exact_check, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7628 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 7629 | // /* HeapReference<Class> */ out = out->component_type_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7630 | GenerateReferenceLoadOneRegister(instruction, |
| 7631 | out_loc, |
| 7632 | component_offset, |
| 7633 | maybe_temp_loc, |
| 7634 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7635 | // 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] | 7636 | __ CompareAndBranchIfZero(out, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7637 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 7638 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7639 | __ Cmp(out, 0); |
| 7640 | // We speculatively set the result to false without changing the condition |
| 7641 | // flags, which allows us to avoid some branching later. |
| 7642 | __ Mov(LeaveFlags, out, 0); |
| 7643 | |
| 7644 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7645 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7646 | // encoding can be used. |
| 7647 | if (out.IsLow()) { |
| 7648 | __ Bind(&exact_check); |
| 7649 | |
| 7650 | // We use the scope because of the IT block that follows. |
| 7651 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7652 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7653 | CodeBufferCheckScope::kExactSize); |
| 7654 | |
| 7655 | __ it(eq); |
| 7656 | __ mov(eq, out, 1); |
| 7657 | } else { |
| 7658 | __ B(ne, final_label, /* far_target */ false); |
| 7659 | __ Bind(&exact_check); |
| 7660 | __ Mov(out, 1); |
| 7661 | } |
| 7662 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7663 | break; |
| 7664 | } |
| 7665 | |
| 7666 | case TypeCheckKind::kArrayCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7667 | // No read barrier since the slow path will retry upon failure. |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7668 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7669 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7670 | out_loc, |
| 7671 | obj_loc, |
| 7672 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7673 | maybe_temp_loc, |
| 7674 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7675 | __ Cmp(out, cls); |
| 7676 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 7677 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARMVIXL(instruction, |
| 7678 | /* is_fatal */ false); |
| 7679 | codegen_->AddSlowPath(slow_path); |
| 7680 | __ B(ne, slow_path->GetEntryLabel()); |
| 7681 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7682 | break; |
| 7683 | } |
| 7684 | |
| 7685 | case TypeCheckKind::kUnresolvedCheck: |
| 7686 | case TypeCheckKind::kInterfaceCheck: { |
| 7687 | // Note that we indeed only call on slow path, but we always go |
| 7688 | // into the slow path for the unresolved and interface check |
| 7689 | // cases. |
| 7690 | // |
| 7691 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7692 | // entry point without resorting to a type checking slow path |
| 7693 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7694 | // require to assign fixed registers for the inputs of this |
| 7695 | // HInstanceOf instruction (following the runtime calling |
| 7696 | // convention), which might be cluttered by the potential first |
| 7697 | // read barrier emission at the beginning of this method. |
| 7698 | // |
| 7699 | // TODO: Introduce a new runtime entry point taking the object |
| 7700 | // to test (instead of its class) as argument, and let it deal |
| 7701 | // with the read barrier issues. This will let us refactor this |
| 7702 | // case of the `switch` code as it was previously (with a direct |
| 7703 | // call to the runtime not using a type checking slow path). |
| 7704 | // This should also be beneficial for the other cases above. |
| 7705 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 7706 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARMVIXL(instruction, |
| 7707 | /* is_fatal */ false); |
| 7708 | codegen_->AddSlowPath(slow_path); |
| 7709 | __ B(slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7710 | break; |
| 7711 | } |
| 7712 | } |
| 7713 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7714 | if (done.IsReferenced()) { |
| 7715 | __ Bind(&done); |
| 7716 | } |
| 7717 | |
| 7718 | if (slow_path != nullptr) { |
| 7719 | __ Bind(slow_path->GetExitLabel()); |
| 7720 | } |
| 7721 | } |
| 7722 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7723 | void LocationsBuilderARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
| 7724 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7725 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 7726 | |
| 7727 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7728 | switch (type_check_kind) { |
| 7729 | case TypeCheckKind::kExactCheck: |
| 7730 | case TypeCheckKind::kAbstractClassCheck: |
| 7731 | case TypeCheckKind::kClassHierarchyCheck: |
| 7732 | case TypeCheckKind::kArrayObjectCheck: |
| 7733 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 7734 | LocationSummary::kCallOnSlowPath : |
| 7735 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
| 7736 | break; |
| 7737 | case TypeCheckKind::kArrayCheck: |
| 7738 | case TypeCheckKind::kUnresolvedCheck: |
| 7739 | case TypeCheckKind::kInterfaceCheck: |
| 7740 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7741 | break; |
| 7742 | } |
| 7743 | |
| 7744 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 7745 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7746 | locations->SetInAt(1, Location::RequiresRegister()); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7747 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7748 | } |
| 7749 | |
| 7750 | void InstructionCodeGeneratorARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
| 7751 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7752 | LocationSummary* locations = instruction->GetLocations(); |
| 7753 | Location obj_loc = locations->InAt(0); |
| 7754 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 7755 | vixl32::Register cls = InputRegisterAt(instruction, 1); |
| 7756 | Location temp_loc = locations->GetTemp(0); |
| 7757 | vixl32::Register temp = RegisterFrom(temp_loc); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7758 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 7759 | DCHECK_LE(num_temps, 3u); |
| 7760 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 7761 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 7762 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7763 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7764 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7765 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 7766 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 7767 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 7768 | const uint32_t object_array_data_offset = |
| 7769 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7770 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7771 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 7772 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 7773 | // read barriers is done for performance and code size reasons. |
| 7774 | bool is_type_check_slow_path_fatal = false; |
| 7775 | if (!kEmitCompilerReadBarrier) { |
| 7776 | is_type_check_slow_path_fatal = |
| 7777 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 7778 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7779 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7780 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 7781 | !instruction->CanThrowIntoCatchBlock(); |
| 7782 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7783 | SlowPathCodeARMVIXL* type_check_slow_path = |
| 7784 | new (GetGraph()->GetArena()) TypeCheckSlowPathARMVIXL(instruction, |
| 7785 | is_type_check_slow_path_fatal); |
| 7786 | codegen_->AddSlowPath(type_check_slow_path); |
| 7787 | |
| 7788 | vixl32::Label done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7789 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7790 | // Avoid null check if we know obj is not null. |
| 7791 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7792 | __ CompareAndBranchIfZero(obj, final_label, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7793 | } |
| 7794 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7795 | switch (type_check_kind) { |
| 7796 | case TypeCheckKind::kExactCheck: |
| 7797 | case TypeCheckKind::kArrayCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7798 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7799 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7800 | temp_loc, |
| 7801 | obj_loc, |
| 7802 | class_offset, |
| 7803 | maybe_temp2_loc, |
| 7804 | kWithoutReadBarrier); |
| 7805 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7806 | __ Cmp(temp, cls); |
| 7807 | // Jump to slow path for throwing the exception or doing a |
| 7808 | // more involved array check. |
| 7809 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 7810 | break; |
| 7811 | } |
| 7812 | |
| 7813 | case TypeCheckKind::kAbstractClassCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7814 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7815 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7816 | temp_loc, |
| 7817 | obj_loc, |
| 7818 | class_offset, |
| 7819 | maybe_temp2_loc, |
| 7820 | kWithoutReadBarrier); |
| 7821 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7822 | // If the class is abstract, we eagerly fetch the super class of the |
| 7823 | // object to avoid doing a comparison we know will fail. |
| 7824 | vixl32::Label loop; |
| 7825 | __ Bind(&loop); |
| 7826 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7827 | GenerateReferenceLoadOneRegister(instruction, |
| 7828 | temp_loc, |
| 7829 | super_offset, |
| 7830 | maybe_temp2_loc, |
| 7831 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7832 | |
| 7833 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7834 | // exception. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7835 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7836 | |
| 7837 | // Otherwise, compare the classes. |
| 7838 | __ Cmp(temp, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7839 | __ B(ne, &loop, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7840 | break; |
| 7841 | } |
| 7842 | |
| 7843 | case TypeCheckKind::kClassHierarchyCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7844 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7845 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7846 | temp_loc, |
| 7847 | obj_loc, |
| 7848 | class_offset, |
| 7849 | maybe_temp2_loc, |
| 7850 | kWithoutReadBarrier); |
| 7851 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7852 | // Walk over the class hierarchy to find a match. |
| 7853 | vixl32::Label loop; |
| 7854 | __ Bind(&loop); |
| 7855 | __ Cmp(temp, cls); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7856 | __ B(eq, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7857 | |
| 7858 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7859 | GenerateReferenceLoadOneRegister(instruction, |
| 7860 | temp_loc, |
| 7861 | super_offset, |
| 7862 | maybe_temp2_loc, |
| 7863 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7864 | |
| 7865 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7866 | // exception. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7867 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7868 | // Otherwise, jump to the beginning of the loop. |
| 7869 | __ B(&loop); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7870 | break; |
| 7871 | } |
| 7872 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7873 | case TypeCheckKind::kArrayObjectCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7874 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7875 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7876 | temp_loc, |
| 7877 | obj_loc, |
| 7878 | class_offset, |
| 7879 | maybe_temp2_loc, |
| 7880 | kWithoutReadBarrier); |
| 7881 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7882 | // Do an exact check. |
| 7883 | __ Cmp(temp, cls); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7884 | __ B(eq, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7885 | |
| 7886 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 7887 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7888 | GenerateReferenceLoadOneRegister(instruction, |
| 7889 | temp_loc, |
| 7890 | component_offset, |
| 7891 | maybe_temp2_loc, |
| 7892 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7893 | // 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] | 7894 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7895 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 7896 | // to further check that this component type is not a primitive type. |
| 7897 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7898 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7899 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7900 | break; |
| 7901 | } |
| 7902 | |
| 7903 | case TypeCheckKind::kUnresolvedCheck: |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7904 | // 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] | 7905 | // We cannot directly call the CheckCast runtime entry point |
| 7906 | // without resorting to a type checking slow path here (i.e. by |
| 7907 | // calling InvokeRuntime directly), as it would require to |
| 7908 | // assign fixed registers for the inputs of this HInstanceOf |
| 7909 | // instruction (following the runtime calling convention), which |
| 7910 | // might be cluttered by the potential first read barrier |
| 7911 | // emission at the beginning of this method. |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7912 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7913 | __ B(type_check_slow_path->GetEntryLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7914 | break; |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7915 | |
| 7916 | case TypeCheckKind::kInterfaceCheck: { |
| 7917 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 7918 | // positives by doing this. |
| 7919 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7920 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7921 | temp_loc, |
| 7922 | obj_loc, |
| 7923 | class_offset, |
| 7924 | maybe_temp2_loc, |
| 7925 | kWithoutReadBarrier); |
| 7926 | |
| 7927 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 7928 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7929 | temp_loc, |
| 7930 | temp_loc, |
| 7931 | iftable_offset, |
| 7932 | maybe_temp2_loc, |
| 7933 | kWithoutReadBarrier); |
| 7934 | // Iftable is never null. |
| 7935 | __ Ldr(RegisterFrom(maybe_temp2_loc), MemOperand(temp, array_length_offset)); |
| 7936 | // Loop through the iftable and check if any class matches. |
| 7937 | vixl32::Label start_loop; |
| 7938 | __ Bind(&start_loop); |
| 7939 | __ CompareAndBranchIfZero(RegisterFrom(maybe_temp2_loc), |
| 7940 | type_check_slow_path->GetEntryLabel()); |
| 7941 | __ Ldr(RegisterFrom(maybe_temp3_loc), MemOperand(temp, object_array_data_offset)); |
| 7942 | GetAssembler()->MaybeUnpoisonHeapReference(RegisterFrom(maybe_temp3_loc)); |
| 7943 | // Go to next interface. |
| 7944 | __ Add(temp, temp, Operand::From(2 * kHeapReferenceSize)); |
| 7945 | __ Sub(RegisterFrom(maybe_temp2_loc), RegisterFrom(maybe_temp2_loc), 2); |
| 7946 | // Compare the classes and continue the loop if they do not match. |
| 7947 | __ Cmp(cls, RegisterFrom(maybe_temp3_loc)); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7948 | __ B(ne, &start_loop, /* far_target */ false); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7949 | break; |
| 7950 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7951 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7952 | if (done.IsReferenced()) { |
| 7953 | __ Bind(&done); |
| 7954 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7955 | |
| 7956 | __ Bind(type_check_slow_path->GetExitLabel()); |
| 7957 | } |
| 7958 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 7959 | void LocationsBuilderARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 7960 | LocationSummary* locations = |
| 7961 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| 7962 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7963 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7964 | } |
| 7965 | |
| 7966 | void InstructionCodeGeneratorARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 7967 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 7968 | instruction, |
| 7969 | instruction->GetDexPc()); |
| 7970 | if (instruction->IsEnter()) { |
| 7971 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 7972 | } else { |
| 7973 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 7974 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 7975 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 17); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 7976 | } |
| 7977 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 7978 | void LocationsBuilderARMVIXL::VisitAnd(HAnd* instruction) { |
| 7979 | HandleBitwiseOperation(instruction, AND); |
| 7980 | } |
| 7981 | |
| 7982 | void LocationsBuilderARMVIXL::VisitOr(HOr* instruction) { |
| 7983 | HandleBitwiseOperation(instruction, ORR); |
| 7984 | } |
| 7985 | |
| 7986 | void LocationsBuilderARMVIXL::VisitXor(HXor* instruction) { |
| 7987 | HandleBitwiseOperation(instruction, EOR); |
| 7988 | } |
| 7989 | |
| 7990 | void LocationsBuilderARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
| 7991 | LocationSummary* locations = |
| 7992 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7993 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 7994 | || instruction->GetResultType() == DataType::Type::kInt64); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 7995 | // Note: GVN reorders commutative operations to have the constant on the right hand side. |
| 7996 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7997 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
| 7998 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7999 | } |
| 8000 | |
| 8001 | void InstructionCodeGeneratorARMVIXL::VisitAnd(HAnd* instruction) { |
| 8002 | HandleBitwiseOperation(instruction); |
| 8003 | } |
| 8004 | |
| 8005 | void InstructionCodeGeneratorARMVIXL::VisitOr(HOr* instruction) { |
| 8006 | HandleBitwiseOperation(instruction); |
| 8007 | } |
| 8008 | |
| 8009 | void InstructionCodeGeneratorARMVIXL::VisitXor(HXor* instruction) { |
| 8010 | HandleBitwiseOperation(instruction); |
| 8011 | } |
| 8012 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8013 | void LocationsBuilderARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 8014 | LocationSummary* locations = |
| 8015 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8016 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 8017 | || instruction->GetResultType() == DataType::Type::kInt64); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8018 | |
| 8019 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8020 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8021 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8022 | } |
| 8023 | |
| 8024 | void InstructionCodeGeneratorARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 8025 | LocationSummary* locations = instruction->GetLocations(); |
| 8026 | Location first = locations->InAt(0); |
| 8027 | Location second = locations->InAt(1); |
| 8028 | Location out = locations->Out(); |
| 8029 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8030 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8031 | vixl32::Register first_reg = RegisterFrom(first); |
| 8032 | vixl32::Register second_reg = RegisterFrom(second); |
| 8033 | vixl32::Register out_reg = RegisterFrom(out); |
| 8034 | |
| 8035 | switch (instruction->GetOpKind()) { |
| 8036 | case HInstruction::kAnd: |
| 8037 | __ Bic(out_reg, first_reg, second_reg); |
| 8038 | break; |
| 8039 | case HInstruction::kOr: |
| 8040 | __ Orn(out_reg, first_reg, second_reg); |
| 8041 | break; |
| 8042 | // There is no EON on arm. |
| 8043 | case HInstruction::kXor: |
| 8044 | default: |
| 8045 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 8046 | UNREACHABLE(); |
| 8047 | } |
| 8048 | return; |
| 8049 | |
| 8050 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8051 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8052 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8053 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8054 | vixl32::Register second_low = LowRegisterFrom(second); |
| 8055 | vixl32::Register second_high = HighRegisterFrom(second); |
| 8056 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8057 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8058 | |
| 8059 | switch (instruction->GetOpKind()) { |
| 8060 | case HInstruction::kAnd: |
| 8061 | __ Bic(out_low, first_low, second_low); |
| 8062 | __ Bic(out_high, first_high, second_high); |
| 8063 | break; |
| 8064 | case HInstruction::kOr: |
| 8065 | __ Orn(out_low, first_low, second_low); |
| 8066 | __ Orn(out_high, first_high, second_high); |
| 8067 | break; |
| 8068 | // There is no EON on arm. |
| 8069 | case HInstruction::kXor: |
| 8070 | default: |
| 8071 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 8072 | UNREACHABLE(); |
| 8073 | } |
| 8074 | } |
| 8075 | } |
| 8076 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8077 | void LocationsBuilderARMVIXL::VisitDataProcWithShifterOp( |
| 8078 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8079 | DCHECK(instruction->GetType() == DataType::Type::kInt32 || |
| 8080 | instruction->GetType() == DataType::Type::kInt64); |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8081 | LocationSummary* locations = |
| 8082 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8083 | const bool overlap = instruction->GetType() == DataType::Type::kInt64 && |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8084 | HDataProcWithShifterOp::IsExtensionOp(instruction->GetOpKind()); |
| 8085 | |
| 8086 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8087 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8088 | locations->SetOut(Location::RequiresRegister(), |
| 8089 | overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 8090 | } |
| 8091 | |
| 8092 | void InstructionCodeGeneratorARMVIXL::VisitDataProcWithShifterOp( |
| 8093 | HDataProcWithShifterOp* instruction) { |
| 8094 | const LocationSummary* const locations = instruction->GetLocations(); |
| 8095 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 8096 | const HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 8097 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8098 | if (instruction->GetType() == DataType::Type::kInt32) { |
Anton Kirilov | 420ee30 | 2017-02-21 18:10:26 +0000 | [diff] [blame] | 8099 | const vixl32::Register first = InputRegisterAt(instruction, 0); |
| 8100 | const vixl32::Register output = OutputRegister(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8101 | const vixl32::Register second = instruction->InputAt(1)->GetType() == DataType::Type::kInt64 |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8102 | ? LowRegisterFrom(locations->InAt(1)) |
| 8103 | : InputRegisterAt(instruction, 1); |
| 8104 | |
Anton Kirilov | 420ee30 | 2017-02-21 18:10:26 +0000 | [diff] [blame] | 8105 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 8106 | DCHECK_EQ(kind, HInstruction::kAdd); |
| 8107 | |
| 8108 | switch (op_kind) { |
| 8109 | case HDataProcWithShifterOp::kUXTB: |
| 8110 | __ Uxtab(output, first, second); |
| 8111 | break; |
| 8112 | case HDataProcWithShifterOp::kUXTH: |
| 8113 | __ Uxtah(output, first, second); |
| 8114 | break; |
| 8115 | case HDataProcWithShifterOp::kSXTB: |
| 8116 | __ Sxtab(output, first, second); |
| 8117 | break; |
| 8118 | case HDataProcWithShifterOp::kSXTH: |
| 8119 | __ Sxtah(output, first, second); |
| 8120 | break; |
| 8121 | default: |
| 8122 | LOG(FATAL) << "Unexpected operation kind: " << op_kind; |
| 8123 | UNREACHABLE(); |
| 8124 | } |
| 8125 | } else { |
| 8126 | GenerateDataProcInstruction(kind, |
| 8127 | output, |
| 8128 | first, |
| 8129 | Operand(second, |
| 8130 | ShiftFromOpKind(op_kind), |
| 8131 | instruction->GetShiftAmount()), |
| 8132 | codegen_); |
| 8133 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8134 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8135 | DCHECK_EQ(instruction->GetType(), DataType::Type::kInt64); |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8136 | |
| 8137 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 8138 | const vixl32::Register second = InputRegisterAt(instruction, 1); |
| 8139 | |
| 8140 | DCHECK(!LowRegisterFrom(locations->Out()).Is(second)); |
| 8141 | GenerateDataProc(kind, |
| 8142 | locations->Out(), |
| 8143 | locations->InAt(0), |
| 8144 | second, |
| 8145 | Operand(second, ShiftType::ASR, 31), |
| 8146 | codegen_); |
| 8147 | } else { |
| 8148 | GenerateLongDataProc(instruction, codegen_); |
| 8149 | } |
| 8150 | } |
| 8151 | } |
| 8152 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8153 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8154 | void InstructionCodeGeneratorARMVIXL::GenerateAndConst(vixl32::Register out, |
| 8155 | vixl32::Register first, |
| 8156 | uint32_t value) { |
| 8157 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 8158 | if (value == 0xffffffffu) { |
| 8159 | if (!out.Is(first)) { |
| 8160 | __ Mov(out, first); |
| 8161 | } |
| 8162 | return; |
| 8163 | } |
| 8164 | if (value == 0u) { |
| 8165 | __ Mov(out, 0); |
| 8166 | return; |
| 8167 | } |
| 8168 | if (GetAssembler()->ShifterOperandCanHold(AND, value)) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 8169 | __ And(out, first, value); |
| 8170 | } else if (GetAssembler()->ShifterOperandCanHold(BIC, ~value)) { |
| 8171 | __ Bic(out, first, ~value); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8172 | } else { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 8173 | DCHECK(IsPowerOfTwo(value + 1)); |
| 8174 | __ Ubfx(out, first, 0, WhichPowerOf2(value + 1)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8175 | } |
| 8176 | } |
| 8177 | |
| 8178 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8179 | void InstructionCodeGeneratorARMVIXL::GenerateOrrConst(vixl32::Register out, |
| 8180 | vixl32::Register first, |
| 8181 | uint32_t value) { |
| 8182 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 8183 | if (value == 0u) { |
| 8184 | if (!out.Is(first)) { |
| 8185 | __ Mov(out, first); |
| 8186 | } |
| 8187 | return; |
| 8188 | } |
| 8189 | if (value == 0xffffffffu) { |
| 8190 | __ Mvn(out, 0); |
| 8191 | return; |
| 8192 | } |
| 8193 | if (GetAssembler()->ShifterOperandCanHold(ORR, value)) { |
| 8194 | __ Orr(out, first, value); |
| 8195 | } else { |
| 8196 | DCHECK(GetAssembler()->ShifterOperandCanHold(ORN, ~value)); |
| 8197 | __ Orn(out, first, ~value); |
| 8198 | } |
| 8199 | } |
| 8200 | |
| 8201 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8202 | void InstructionCodeGeneratorARMVIXL::GenerateEorConst(vixl32::Register out, |
| 8203 | vixl32::Register first, |
| 8204 | uint32_t value) { |
| 8205 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 8206 | if (value == 0u) { |
| 8207 | if (!out.Is(first)) { |
| 8208 | __ Mov(out, first); |
| 8209 | } |
| 8210 | return; |
| 8211 | } |
| 8212 | __ Eor(out, first, value); |
| 8213 | } |
| 8214 | |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8215 | void InstructionCodeGeneratorARMVIXL::GenerateAddLongConst(Location out, |
| 8216 | Location first, |
| 8217 | uint64_t value) { |
| 8218 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8219 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8220 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8221 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8222 | uint32_t value_low = Low32Bits(value); |
| 8223 | uint32_t value_high = High32Bits(value); |
| 8224 | if (value_low == 0u) { |
| 8225 | if (!out_low.Is(first_low)) { |
| 8226 | __ Mov(out_low, first_low); |
| 8227 | } |
| 8228 | __ Add(out_high, first_high, value_high); |
| 8229 | return; |
| 8230 | } |
| 8231 | __ Adds(out_low, first_low, value_low); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 8232 | if (GetAssembler()->ShifterOperandCanHold(ADC, value_high, kCcDontCare)) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8233 | __ Adc(out_high, first_high, value_high); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 8234 | } else if (GetAssembler()->ShifterOperandCanHold(SBC, ~value_high, kCcDontCare)) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8235 | __ Sbc(out_high, first_high, ~value_high); |
| 8236 | } else { |
| 8237 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 8238 | UNREACHABLE(); |
| 8239 | } |
| 8240 | } |
| 8241 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8242 | void InstructionCodeGeneratorARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 8243 | LocationSummary* locations = instruction->GetLocations(); |
| 8244 | Location first = locations->InAt(0); |
| 8245 | Location second = locations->InAt(1); |
| 8246 | Location out = locations->Out(); |
| 8247 | |
| 8248 | if (second.IsConstant()) { |
| 8249 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 8250 | uint32_t value_low = Low32Bits(value); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8251 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8252 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 8253 | vixl32::Register out_reg = OutputRegister(instruction); |
| 8254 | if (instruction->IsAnd()) { |
| 8255 | GenerateAndConst(out_reg, first_reg, value_low); |
| 8256 | } else if (instruction->IsOr()) { |
| 8257 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 8258 | } else { |
| 8259 | DCHECK(instruction->IsXor()); |
| 8260 | GenerateEorConst(out_reg, first_reg, value_low); |
| 8261 | } |
| 8262 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8263 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8264 | uint32_t value_high = High32Bits(value); |
| 8265 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8266 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8267 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8268 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8269 | if (instruction->IsAnd()) { |
| 8270 | GenerateAndConst(out_low, first_low, value_low); |
| 8271 | GenerateAndConst(out_high, first_high, value_high); |
| 8272 | } else if (instruction->IsOr()) { |
| 8273 | GenerateOrrConst(out_low, first_low, value_low); |
| 8274 | GenerateOrrConst(out_high, first_high, value_high); |
| 8275 | } else { |
| 8276 | DCHECK(instruction->IsXor()); |
| 8277 | GenerateEorConst(out_low, first_low, value_low); |
| 8278 | GenerateEorConst(out_high, first_high, value_high); |
| 8279 | } |
| 8280 | } |
| 8281 | return; |
| 8282 | } |
| 8283 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8284 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8285 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 8286 | vixl32::Register second_reg = InputRegisterAt(instruction, 1); |
| 8287 | vixl32::Register out_reg = OutputRegister(instruction); |
| 8288 | if (instruction->IsAnd()) { |
| 8289 | __ And(out_reg, first_reg, second_reg); |
| 8290 | } else if (instruction->IsOr()) { |
| 8291 | __ Orr(out_reg, first_reg, second_reg); |
| 8292 | } else { |
| 8293 | DCHECK(instruction->IsXor()); |
| 8294 | __ Eor(out_reg, first_reg, second_reg); |
| 8295 | } |
| 8296 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8297 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8298 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8299 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8300 | vixl32::Register second_low = LowRegisterFrom(second); |
| 8301 | vixl32::Register second_high = HighRegisterFrom(second); |
| 8302 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8303 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8304 | if (instruction->IsAnd()) { |
| 8305 | __ And(out_low, first_low, second_low); |
| 8306 | __ And(out_high, first_high, second_high); |
| 8307 | } else if (instruction->IsOr()) { |
| 8308 | __ Orr(out_low, first_low, second_low); |
| 8309 | __ Orr(out_high, first_high, second_high); |
| 8310 | } else { |
| 8311 | DCHECK(instruction->IsXor()); |
| 8312 | __ Eor(out_low, first_low, second_low); |
| 8313 | __ Eor(out_high, first_high, second_high); |
| 8314 | } |
| 8315 | } |
| 8316 | } |
| 8317 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8318 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadOneRegister( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8319 | HInstruction* instruction, |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8320 | Location out, |
| 8321 | uint32_t offset, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8322 | Location maybe_temp, |
| 8323 | ReadBarrierOption read_barrier_option) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8324 | vixl32::Register out_reg = RegisterFrom(out); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8325 | if (read_barrier_option == kWithReadBarrier) { |
| 8326 | CHECK(kEmitCompilerReadBarrier); |
| 8327 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 8328 | if (kUseBakerReadBarrier) { |
| 8329 | // Load with fast path based Baker's read barrier. |
| 8330 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8331 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 8332 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
| 8333 | } else { |
| 8334 | // Load with slow path based read barrier. |
| 8335 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 8336 | // in the following move operation, as we will need it for the |
| 8337 | // read barrier below. |
| 8338 | __ Mov(RegisterFrom(maybe_temp), out_reg); |
| 8339 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8340 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 8341 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 8342 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8343 | } else { |
| 8344 | // Plain load with no read barrier. |
| 8345 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8346 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 8347 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 8348 | } |
| 8349 | } |
| 8350 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8351 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadTwoRegisters( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8352 | HInstruction* instruction, |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8353 | Location out, |
| 8354 | Location obj, |
| 8355 | uint32_t offset, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8356 | Location maybe_temp, |
| 8357 | ReadBarrierOption read_barrier_option) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8358 | vixl32::Register out_reg = RegisterFrom(out); |
| 8359 | vixl32::Register obj_reg = RegisterFrom(obj); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8360 | if (read_barrier_option == kWithReadBarrier) { |
| 8361 | CHECK(kEmitCompilerReadBarrier); |
| 8362 | if (kUseBakerReadBarrier) { |
| 8363 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 8364 | // Load with fast path based Baker's read barrier. |
| 8365 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8366 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 8367 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
| 8368 | } else { |
| 8369 | // Load with slow path based read barrier. |
| 8370 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8371 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8372 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 8373 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8374 | } else { |
| 8375 | // Plain load with no read barrier. |
| 8376 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8377 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8378 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 8379 | } |
| 8380 | } |
| 8381 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8382 | void InstructionCodeGeneratorARMVIXL::GenerateGcRootFieldLoad( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8383 | HInstruction* instruction, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8384 | Location root, |
| 8385 | vixl32::Register obj, |
| 8386 | uint32_t offset, |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8387 | ReadBarrierOption read_barrier_option) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8388 | vixl32::Register root_reg = RegisterFrom(root); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8389 | if (read_barrier_option == kWithReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8390 | DCHECK(kEmitCompilerReadBarrier); |
| 8391 | if (kUseBakerReadBarrier) { |
| 8392 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8393 | // Baker's read barrier are used. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8394 | if (kBakerReadBarrierLinkTimeThunksEnableForGcRoots && |
| 8395 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8396 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 8397 | // the Marking Register) to decide whether we need to enter |
| 8398 | // the slow path to mark the GC root. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8399 | // |
| 8400 | // We use link-time generated thunks for the slow path. That thunk |
| 8401 | // checks the reference and jumps to the entrypoint if needed. |
| 8402 | // |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8403 | // lr = &return_address; |
| 8404 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8405 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8406 | // goto gc_root_thunk<root_reg>(lr) |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8407 | // } |
| 8408 | // return_address: |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8409 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8410 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8411 | ExcludeIPAndBakerCcEntrypointRegister(&temps, instruction); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8412 | bool narrow = CanEmitNarrowLdr(root_reg, obj, offset); |
| 8413 | uint32_t custom_data = linker::Thumb2RelativePatcher::EncodeBakerReadBarrierGcRootData( |
| 8414 | root_reg.GetCode(), narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8415 | vixl32::Label* bne_label = codegen_->NewBakerReadBarrierPatch(custom_data); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8416 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8417 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), 4 * vixl32::kMaxInstructionSizeInBytes); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8418 | vixl32::Label return_address; |
| 8419 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8420 | __ cmp(mr, Operand(0)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8421 | // Currently the offset is always within range. If that changes, |
| 8422 | // we shall have to split the load the same way as for fields. |
| 8423 | DCHECK_LT(offset, kReferenceLoadMinFarOffset); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8424 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8425 | __ ldr(EncodingSize(narrow ? Narrow : Wide), root_reg, MemOperand(obj, offset)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8426 | EmitPlaceholderBne(codegen_, bne_label); |
| 8427 | __ Bind(&return_address); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8428 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8429 | narrow ? BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_OFFSET |
| 8430 | : BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8431 | } else { |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8432 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 8433 | // the Marking Register) to decide whether we need to enter |
| 8434 | // the slow path to mark the GC root. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8435 | // |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8436 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8437 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8438 | // // Slow path. |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8439 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8440 | // root = entrypoint(root); // root = ReadBarrier::Mark(root); // Entry point call. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8441 | // } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8442 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8443 | // Slow path marking the GC root `root`. The entrypoint will |
| 8444 | // be loaded by the slow path code. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8445 | SlowPathCodeARMVIXL* slow_path = |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8446 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARMVIXL(instruction, root); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8447 | codegen_->AddSlowPath(slow_path); |
| 8448 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8449 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8450 | GetAssembler()->LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8451 | static_assert( |
| 8452 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 8453 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 8454 | "have different sizes."); |
| 8455 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 8456 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 8457 | "have different sizes."); |
| 8458 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8459 | __ CompareAndBranchIfNonZero(mr, slow_path->GetEntryLabel()); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8460 | __ Bind(slow_path->GetExitLabel()); |
| 8461 | } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8462 | } else { |
| 8463 | // GC root loaded through a slow path for read barriers other |
| 8464 | // than Baker's. |
| 8465 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 8466 | __ Add(root_reg, obj, offset); |
| 8467 | // /* mirror::Object* */ root = root->Read() |
| 8468 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 8469 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8470 | } else { |
| 8471 | // Plain GC root load with no read barrier. |
| 8472 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8473 | GetAssembler()->LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8474 | // Note that GC roots are not affected by heap poisoning, thus we |
| 8475 | // do not have to unpoison `root_reg` here. |
| 8476 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8477 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 18); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8478 | } |
| 8479 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8480 | void CodeGeneratorARMVIXL::MaybeAddBakerCcEntrypointTempForFields(LocationSummary* locations) { |
| 8481 | DCHECK(kEmitCompilerReadBarrier); |
| 8482 | DCHECK(kUseBakerReadBarrier); |
| 8483 | if (kBakerReadBarrierLinkTimeThunksEnableForFields) { |
| 8484 | if (!Runtime::Current()->UseJitCompilation()) { |
| 8485 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 8486 | } |
| 8487 | } |
| 8488 | } |
| 8489 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8490 | void CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8491 | Location ref, |
| 8492 | vixl32::Register obj, |
| 8493 | uint32_t offset, |
| 8494 | Location temp, |
| 8495 | bool needs_null_check) { |
| 8496 | DCHECK(kEmitCompilerReadBarrier); |
| 8497 | DCHECK(kUseBakerReadBarrier); |
| 8498 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8499 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 8500 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8501 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 8502 | // Marking Register) to decide whether we need to enter the slow |
| 8503 | // path to mark the reference. Then, in the slow path, check the |
| 8504 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 8505 | // decide whether to mark `ref` or not. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8506 | // |
| 8507 | // We use link-time generated thunks for the slow path. That thunk checks |
| 8508 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 8509 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 8510 | // |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8511 | // lr = &gray_return_address; |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8512 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8513 | // goto field_thunk<holder_reg, base_reg>(lr) |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8514 | // } |
| 8515 | // not_gray_return_address: |
| 8516 | // // Original reference load. If the offset is too large to fit |
| 8517 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8518 | // HeapReference<mirror::Object> reference = *(obj+offset); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8519 | // gray_return_address: |
| 8520 | |
| 8521 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8522 | vixl32::Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8523 | bool narrow = CanEmitNarrowLdr(ref_reg, obj, offset); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8524 | vixl32::Register base = obj; |
| 8525 | if (offset >= kReferenceLoadMinFarOffset) { |
| 8526 | base = RegisterFrom(temp); |
| 8527 | DCHECK(!base.Is(kBakerCcEntrypointRegister)); |
| 8528 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 8529 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 8530 | offset &= (kReferenceLoadMinFarOffset - 1u); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8531 | // Use narrow LDR only for small offsets. Generating narrow encoding LDR for the large |
| 8532 | // offsets with `(offset & (kReferenceLoadMinFarOffset - 1u)) < 32u` would most likely |
| 8533 | // increase the overall code size when taking the generated thunks into account. |
| 8534 | DCHECK(!narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8535 | } |
| 8536 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8537 | ExcludeIPAndBakerCcEntrypointRegister(&temps, instruction); |
| 8538 | uint32_t custom_data = linker::Thumb2RelativePatcher::EncodeBakerReadBarrierFieldData( |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8539 | base.GetCode(), obj.GetCode(), narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8540 | vixl32::Label* bne_label = NewBakerReadBarrierPatch(custom_data); |
| 8541 | |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8542 | { |
| 8543 | vixl::EmissionCheckScope guard( |
| 8544 | GetVIXLAssembler(), |
| 8545 | (kPoisonHeapReferences ? 5u : 4u) * vixl32::kMaxInstructionSizeInBytes); |
| 8546 | vixl32::Label return_address; |
| 8547 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8548 | __ cmp(mr, Operand(0)); |
| 8549 | EmitPlaceholderBne(this, bne_label); |
| 8550 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8551 | __ ldr(EncodingSize(narrow ? Narrow : Wide), ref_reg, MemOperand(base, offset)); |
| 8552 | if (needs_null_check) { |
| 8553 | MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8554 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8555 | // Note: We need a specific width for the unpoisoning NEG. |
| 8556 | if (kPoisonHeapReferences) { |
| 8557 | if (narrow) { |
| 8558 | // The only 16-bit encoding is T1 which sets flags outside IT block (i.e. RSBS, not RSB). |
| 8559 | __ rsbs(EncodingSize(Narrow), ref_reg, ref_reg, Operand(0)); |
| 8560 | } else { |
| 8561 | __ rsb(EncodingSize(Wide), ref_reg, ref_reg, Operand(0)); |
| 8562 | } |
| 8563 | } |
| 8564 | __ Bind(&return_address); |
| 8565 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8566 | narrow ? BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_OFFSET |
| 8567 | : BAKER_MARK_INTROSPECTION_FIELD_LDR_WIDE_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8568 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8569 | MaybeGenerateMarkingRegisterCheck(/* code */ 19, /* temp_loc */ LocationFrom(ip)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8570 | return; |
| 8571 | } |
| 8572 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8573 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 8574 | Location no_index = Location::NoLocation(); |
| 8575 | ScaleFactor no_scale_factor = TIMES_1; |
| 8576 | GenerateReferenceLoadWithBakerReadBarrier( |
| 8577 | 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] | 8578 | } |
| 8579 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8580 | void CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8581 | Location ref, |
| 8582 | vixl32::Register obj, |
| 8583 | uint32_t data_offset, |
| 8584 | Location index, |
| 8585 | Location temp, |
| 8586 | bool needs_null_check) { |
| 8587 | DCHECK(kEmitCompilerReadBarrier); |
| 8588 | DCHECK(kUseBakerReadBarrier); |
| 8589 | |
| 8590 | static_assert( |
| 8591 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 8592 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8593 | ScaleFactor scale_factor = TIMES_4; |
| 8594 | |
| 8595 | if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 8596 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8597 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 8598 | // Marking Register) to decide whether we need to enter the slow |
| 8599 | // path to mark the reference. Then, in the slow path, check the |
| 8600 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 8601 | // decide whether to mark `ref` or not. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8602 | // |
| 8603 | // We use link-time generated thunks for the slow path. That thunk checks |
| 8604 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 8605 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 8606 | // |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8607 | // lr = &gray_return_address; |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8608 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8609 | // goto array_thunk<base_reg>(lr) |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8610 | // } |
| 8611 | // not_gray_return_address: |
| 8612 | // // Original reference load. If the offset is too large to fit |
| 8613 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8614 | // HeapReference<mirror::Object> reference = data[index]; |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8615 | // gray_return_address: |
| 8616 | |
| 8617 | DCHECK(index.IsValid()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8618 | vixl32::Register index_reg = RegisterFrom(index, DataType::Type::kInt32); |
| 8619 | vixl32::Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
| 8620 | vixl32::Register data_reg = RegisterFrom(temp, DataType::Type::kInt32); // Raw pointer. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8621 | DCHECK(!data_reg.Is(kBakerCcEntrypointRegister)); |
| 8622 | |
| 8623 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8624 | ExcludeIPAndBakerCcEntrypointRegister(&temps, instruction); |
| 8625 | uint32_t custom_data = |
| 8626 | linker::Thumb2RelativePatcher::EncodeBakerReadBarrierArrayData(data_reg.GetCode()); |
| 8627 | vixl32::Label* bne_label = NewBakerReadBarrierPatch(custom_data); |
| 8628 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8629 | __ Add(data_reg, obj, Operand(data_offset)); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8630 | { |
| 8631 | vixl::EmissionCheckScope guard( |
| 8632 | GetVIXLAssembler(), |
| 8633 | (kPoisonHeapReferences ? 5u : 4u) * vixl32::kMaxInstructionSizeInBytes); |
| 8634 | vixl32::Label return_address; |
| 8635 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8636 | __ cmp(mr, Operand(0)); |
| 8637 | EmitPlaceholderBne(this, bne_label); |
| 8638 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8639 | __ ldr(ref_reg, MemOperand(data_reg, index_reg, vixl32::LSL, scale_factor)); |
| 8640 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 8641 | // Note: We need a Wide NEG for the unpoisoning. |
| 8642 | if (kPoisonHeapReferences) { |
| 8643 | __ rsb(EncodingSize(Wide), ref_reg, ref_reg, Operand(0)); |
| 8644 | } |
| 8645 | __ Bind(&return_address); |
| 8646 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8647 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8648 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8649 | MaybeGenerateMarkingRegisterCheck(/* code */ 20, /* temp_loc */ LocationFrom(ip)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8650 | return; |
| 8651 | } |
| 8652 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8653 | // /* HeapReference<Object> */ ref = |
| 8654 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8655 | GenerateReferenceLoadWithBakerReadBarrier( |
| 8656 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | 6070e88 | 2016-11-03 17:51:58 +0000 | [diff] [blame] | 8657 | } |
| 8658 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8659 | void CodeGeneratorARMVIXL::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8660 | Location ref, |
| 8661 | vixl32::Register obj, |
| 8662 | uint32_t offset, |
| 8663 | Location index, |
| 8664 | ScaleFactor scale_factor, |
| 8665 | Location temp, |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8666 | bool needs_null_check) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8667 | DCHECK(kEmitCompilerReadBarrier); |
| 8668 | DCHECK(kUseBakerReadBarrier); |
| 8669 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8670 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 8671 | // Marking Register) to decide whether we need to enter the slow |
| 8672 | // path to mark the reference. Then, in the slow path, check the |
| 8673 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 8674 | // decide whether to mark `ref` or not. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8675 | // |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8676 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8677 | // // Slow path. |
| 8678 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8679 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 8680 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 8681 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 8682 | // if (is_gray) { |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8683 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8684 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8685 | // } |
| 8686 | // } else { |
| 8687 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 8688 | // } |
| 8689 | |
| 8690 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 8691 | |
| 8692 | // Slow path marking the object `ref` when the GC is marking. The |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8693 | // entrypoint will be loaded by the slow path code. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8694 | SlowPathCodeARMVIXL* slow_path = |
| 8695 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierSlowPathARMVIXL( |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8696 | instruction, ref, obj, offset, index, scale_factor, needs_null_check, temp_reg); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8697 | AddSlowPath(slow_path); |
| 8698 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8699 | __ CompareAndBranchIfNonZero(mr, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8700 | // Fast path: the GC is not marking: just load the reference. |
| 8701 | GenerateRawReferenceLoad(instruction, ref, obj, offset, index, scale_factor, needs_null_check); |
| 8702 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8703 | MaybeGenerateMarkingRegisterCheck(/* code */ 21); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8704 | } |
| 8705 | |
| 8706 | void CodeGeneratorARMVIXL::UpdateReferenceFieldWithBakerReadBarrier(HInstruction* instruction, |
| 8707 | Location ref, |
| 8708 | vixl32::Register obj, |
| 8709 | Location field_offset, |
| 8710 | Location temp, |
| 8711 | bool needs_null_check, |
| 8712 | vixl32::Register temp2) { |
| 8713 | DCHECK(kEmitCompilerReadBarrier); |
| 8714 | DCHECK(kUseBakerReadBarrier); |
| 8715 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8716 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 8717 | // Marking Register) to decide whether we need to enter the slow |
| 8718 | // path to update the reference field within `obj`. Then, in the |
| 8719 | // slow path, check the gray bit in the lock word of the reference's |
| 8720 | // holder (`obj`) to decide whether to mark `ref` and update the |
| 8721 | // field or not. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8722 | // |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8723 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8724 | // // Slow path. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8725 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8726 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8727 | // HeapReference<mirror::Object> ref = *(obj + field_offset); // Reference load. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8728 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 8729 | // if (is_gray) { |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8730 | // old_ref = ref; |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8731 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8732 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8733 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8734 | // } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8735 | // } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8736 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8737 | vixl32::Register temp_reg = RegisterFrom(temp); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8738 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8739 | // Slow path updating the object reference at address `obj + field_offset` |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8740 | // when the GC is marking. The entrypoint will be loaded by the slow path code. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8741 | SlowPathCodeARMVIXL* slow_path = |
| 8742 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL( |
| 8743 | instruction, |
| 8744 | ref, |
| 8745 | obj, |
| 8746 | /* offset */ 0u, |
| 8747 | /* index */ field_offset, |
| 8748 | /* scale_factor */ ScaleFactor::TIMES_1, |
| 8749 | needs_null_check, |
| 8750 | temp_reg, |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8751 | temp2); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8752 | AddSlowPath(slow_path); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8753 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8754 | __ CompareAndBranchIfNonZero(mr, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8755 | // Fast path: the GC is not marking: nothing to do (the field is |
| 8756 | // up-to-date, and we don't need to load the reference). |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8757 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8758 | MaybeGenerateMarkingRegisterCheck(/* code */ 22); |
Roland Levillain | 844e653 | 2016-11-03 16:09:47 +0000 | [diff] [blame] | 8759 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8760 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8761 | void CodeGeneratorARMVIXL::GenerateRawReferenceLoad(HInstruction* instruction, |
| 8762 | Location ref, |
| 8763 | vixl::aarch32::Register obj, |
| 8764 | uint32_t offset, |
| 8765 | Location index, |
| 8766 | ScaleFactor scale_factor, |
| 8767 | bool needs_null_check) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8768 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8769 | vixl32::Register ref_reg = RegisterFrom(ref, type); |
| 8770 | |
| 8771 | // If needed, vixl::EmissionCheckScope guards are used to ensure |
| 8772 | // that no pools are emitted between the load (macro) instruction |
| 8773 | // and MaybeRecordImplicitNullCheck. |
| 8774 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8775 | if (index.IsValid()) { |
| 8776 | // Load types involving an "index": ArrayGet, |
| 8777 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 8778 | // intrinsics. |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8779 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8780 | if (index.IsConstant()) { |
| 8781 | size_t computed_offset = |
| 8782 | (Int32ConstantFrom(index) << scale_factor) + offset; |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8783 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8784 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8785 | if (needs_null_check) { |
| 8786 | MaybeRecordImplicitNullCheck(instruction); |
| 8787 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8788 | } else { |
| 8789 | // Handle the special case of the |
| 8790 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 8791 | // intrinsics, which use a register pair as index ("long |
| 8792 | // offset"), of which only the low part contains data. |
| 8793 | vixl32::Register index_reg = index.IsRegisterPair() |
| 8794 | ? LowRegisterFrom(index) |
| 8795 | : RegisterFrom(index); |
| 8796 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8797 | vixl32::Register temp = temps.Acquire(); |
| 8798 | __ Add(temp, obj, Operand(index_reg, ShiftType::LSL, scale_factor)); |
| 8799 | { |
| 8800 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 8801 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, temp, offset); |
| 8802 | if (needs_null_check) { |
| 8803 | MaybeRecordImplicitNullCheck(instruction); |
| 8804 | } |
| 8805 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8806 | } |
| 8807 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8808 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
| 8809 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8810 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8811 | if (needs_null_check) { |
| 8812 | MaybeRecordImplicitNullCheck(instruction); |
| 8813 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8814 | } |
| 8815 | |
Roland Levillain | 844e653 | 2016-11-03 16:09:47 +0000 | [diff] [blame] | 8816 | // Object* ref = ref_addr->AsMirrorPtr() |
| 8817 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | 844e653 | 2016-11-03 16:09:47 +0000 | [diff] [blame] | 8818 | } |
| 8819 | |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8820 | void CodeGeneratorARMVIXL::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 8821 | // The following condition is a compile-time one, so it does not have a run-time cost. |
| 8822 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && kIsDebugBuild) { |
| 8823 | // The following condition is a run-time one; it is executed after the |
| 8824 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 8825 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 8826 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8827 | vixl32::Register temp = temp_loc.IsValid() ? RegisterFrom(temp_loc) : temps.Acquire(); |
| 8828 | GetAssembler()->GenerateMarkingRegisterCheck(temp, |
| 8829 | kMarkingRegisterCheckBreakCodeBaseCode + code); |
| 8830 | } |
| 8831 | } |
| 8832 | } |
| 8833 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8834 | void CodeGeneratorARMVIXL::GenerateReadBarrierSlow(HInstruction* instruction, |
| 8835 | Location out, |
| 8836 | Location ref, |
| 8837 | Location obj, |
| 8838 | uint32_t offset, |
| 8839 | Location index) { |
| 8840 | DCHECK(kEmitCompilerReadBarrier); |
| 8841 | |
| 8842 | // Insert a slow path based read barrier *after* the reference load. |
| 8843 | // |
| 8844 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 8845 | // reference will be carried out by the runtime within the slow |
| 8846 | // path. |
| 8847 | // |
| 8848 | // Note that `ref` currently does not get unpoisoned (when heap |
| 8849 | // poisoning is enabled), which is alright as the `ref` argument is |
| 8850 | // not used by the artReadBarrierSlow entry point. |
| 8851 | // |
| 8852 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 8853 | SlowPathCodeARMVIXL* slow_path = new (GetGraph()->GetArena()) |
| 8854 | ReadBarrierForHeapReferenceSlowPathARMVIXL(instruction, out, ref, obj, offset, index); |
| 8855 | AddSlowPath(slow_path); |
| 8856 | |
| 8857 | __ B(slow_path->GetEntryLabel()); |
| 8858 | __ Bind(slow_path->GetExitLabel()); |
| 8859 | } |
| 8860 | |
| 8861 | void CodeGeneratorARMVIXL::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8862 | Location out, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8863 | Location ref, |
| 8864 | Location obj, |
| 8865 | uint32_t offset, |
| 8866 | Location index) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8867 | if (kEmitCompilerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8868 | // Baker's read barriers shall be handled by the fast path |
Roland Levillain | 9983e30 | 2017-07-14 14:34:22 +0100 | [diff] [blame] | 8869 | // (CodeGeneratorARMVIXL::GenerateReferenceLoadWithBakerReadBarrier). |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8870 | DCHECK(!kUseBakerReadBarrier); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8871 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 8872 | // by the runtime within the slow path. |
| 8873 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8874 | } else if (kPoisonHeapReferences) { |
| 8875 | GetAssembler()->UnpoisonHeapReference(RegisterFrom(out)); |
| 8876 | } |
| 8877 | } |
| 8878 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8879 | void CodeGeneratorARMVIXL::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 8880 | Location out, |
| 8881 | Location root) { |
| 8882 | DCHECK(kEmitCompilerReadBarrier); |
| 8883 | |
| 8884 | // Insert a slow path based read barrier *after* the GC root load. |
| 8885 | // |
| 8886 | // Note that GC roots are not affected by heap poisoning, so we do |
| 8887 | // not need to do anything special for this here. |
| 8888 | SlowPathCodeARMVIXL* slow_path = |
| 8889 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARMVIXL(instruction, out, root); |
| 8890 | AddSlowPath(slow_path); |
| 8891 | |
| 8892 | __ B(slow_path->GetEntryLabel()); |
| 8893 | __ Bind(slow_path->GetExitLabel()); |
| 8894 | } |
| 8895 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8896 | // Check if the desired_dispatch_info is supported. If it is, return it, |
| 8897 | // otherwise return a fall-back info that should be used instead. |
| 8898 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARMVIXL::GetSupportedInvokeStaticOrDirectDispatch( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8899 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 8900 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e807ff7 | 2017-01-23 09:03:12 +0000 | [diff] [blame] | 8901 | return desired_dispatch_info; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8902 | } |
| 8903 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8904 | vixl32::Register CodeGeneratorARMVIXL::GetInvokeStaticOrDirectExtraParameter( |
| 8905 | HInvokeStaticOrDirect* invoke, vixl32::Register temp) { |
| 8906 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 8907 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 8908 | if (!invoke->GetLocations()->Intrinsified()) { |
| 8909 | return RegisterFrom(location); |
| 8910 | } |
| 8911 | // For intrinsics we allow any location, so it may be on the stack. |
| 8912 | if (!location.IsRegister()) { |
| 8913 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, location.GetStackIndex()); |
| 8914 | return temp; |
| 8915 | } |
| 8916 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 8917 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 8918 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 8919 | // simple and more robust approach rather that trying to determine if that's the case. |
| 8920 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Scott Wakeling | d5cd497 | 2017-02-03 11:38:35 +0000 | [diff] [blame] | 8921 | if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(RegisterFrom(location).GetCode())) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8922 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(RegisterFrom(location).GetCode()); |
| 8923 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, stack_offset); |
| 8924 | return temp; |
| 8925 | } |
| 8926 | return RegisterFrom(location); |
| 8927 | } |
| 8928 | |
Vladimir Marko | d254f5c | 2017-06-02 15:18:36 +0000 | [diff] [blame] | 8929 | void CodeGeneratorARMVIXL::GenerateStaticOrDirectCall( |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8930 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8931 | 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] | 8932 | switch (invoke->GetMethodLoadKind()) { |
| 8933 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 8934 | uint32_t offset = |
| 8935 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 8936 | // temp = thread->string_init_entrypoint |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8937 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp), tr, offset); |
| 8938 | break; |
| 8939 | } |
| 8940 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 8941 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 8942 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 8943 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 8944 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 8945 | PcRelativePatchInfo* labels = NewPcRelativeMethodPatch(invoke->GetTargetMethod()); |
| 8946 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 8947 | EmitMovwMovtPlaceholder(labels, temp_reg); |
| 8948 | break; |
| 8949 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8950 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 8951 | __ Mov(RegisterFrom(temp), Operand::From(invoke->GetMethodAddress())); |
| 8952 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 8953 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
| 8954 | PcRelativePatchInfo* labels = NewMethodBssEntryPatch( |
| 8955 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex())); |
| 8956 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 8957 | EmitMovwMovtPlaceholder(labels, temp_reg); |
| 8958 | GetAssembler()->LoadFromOffset(kLoadWord, temp_reg, temp_reg, /* offset*/ 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8959 | break; |
| 8960 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8961 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 8962 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 8963 | return; // No code pointer retrieval; the runtime performs the call directly. |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8964 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8965 | } |
| 8966 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8967 | switch (invoke->GetCodePtrLocation()) { |
| 8968 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8969 | { |
| 8970 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 8971 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 8972 | vixl32::k32BitT32InstructionSizeInBytes, |
| 8973 | CodeBufferCheckScope::kMaximumSize); |
| 8974 | __ bl(GetFrameEntryLabel()); |
| 8975 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 8976 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8977 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8978 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 8979 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 8980 | GetAssembler()->LoadFromOffset( |
| 8981 | kLoadWord, |
| 8982 | lr, |
| 8983 | RegisterFrom(callee_method), |
| 8984 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8985 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8986 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8987 | // 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] | 8988 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 8989 | vixl32::k16BitT32InstructionSizeInBytes, |
| 8990 | CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8991 | // LR() |
| 8992 | __ blx(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8993 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8994 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8995 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8996 | } |
| 8997 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8998 | DCHECK(!IsLeafMethod()); |
| 8999 | } |
| 9000 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9001 | void CodeGeneratorARMVIXL::GenerateVirtualCall( |
| 9002 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9003 | vixl32::Register temp = RegisterFrom(temp_location); |
| 9004 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 9005 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
| 9006 | |
| 9007 | // Use the calling convention instead of the location of the receiver, as |
| 9008 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 9009 | // slow path, the arguments have been moved to the right place, so here we are |
| 9010 | // guaranteed that the receiver is the first register of the calling convention. |
| 9011 | InvokeDexCallingConventionARMVIXL calling_convention; |
| 9012 | vixl32::Register receiver = calling_convention.GetRegisterAt(0); |
| 9013 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9014 | { |
| 9015 | // Make sure the pc is recorded immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 9016 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9017 | vixl32::kMaxInstructionSizeInBytes, |
| 9018 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9019 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 9020 | __ ldr(temp, MemOperand(receiver, class_offset)); |
| 9021 | MaybeRecordImplicitNullCheck(invoke); |
| 9022 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9023 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 9024 | // emit a read barrier for the previous class reference load. |
| 9025 | // However this is not required in practice, as this is an |
| 9026 | // intermediate/temporary reference and because the current |
| 9027 | // concurrent copying collector keeps the from-space memory |
| 9028 | // intact/accessible until the end of the marking phase (the |
| 9029 | // concurrent copying collector may not in the future). |
| 9030 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 9031 | |
| 9032 | // temp = temp->GetMethodAt(method_offset); |
| 9033 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 9034 | kArmPointerSize).Int32Value(); |
| 9035 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 9036 | // LR = temp->GetEntryPoint(); |
| 9037 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9038 | { |
| 9039 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 9040 | // blx in T32 has only 16bit encoding that's why a stricter check for the scope is used. |
| 9041 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9042 | vixl32::k16BitT32InstructionSizeInBytes, |
| 9043 | CodeBufferCheckScope::kExactSize); |
| 9044 | // LR(); |
| 9045 | __ blx(lr); |
| 9046 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 9047 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9048 | } |
| 9049 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9050 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeMethodPatch( |
| 9051 | MethodReference target_method) { |
| 9052 | return NewPcRelativePatch(*target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 9053 | target_method.index, |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9054 | &pc_relative_method_patches_); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9055 | } |
| 9056 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9057 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewMethodBssEntryPatch( |
| 9058 | MethodReference target_method) { |
| 9059 | return NewPcRelativePatch(*target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 9060 | target_method.index, |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9061 | &method_bss_entry_patches_); |
| 9062 | } |
| 9063 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9064 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeTypePatch( |
| 9065 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 9066 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
| 9067 | } |
| 9068 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9069 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewTypeBssEntryPatch( |
| 9070 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 9071 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 9072 | } |
| 9073 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9074 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeStringPatch( |
| 9075 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 9076 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
| 9077 | } |
| 9078 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 9079 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewStringBssEntryPatch( |
| 9080 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 9081 | return NewPcRelativePatch(dex_file, string_index.index_, &string_bss_entry_patches_); |
| 9082 | } |
| 9083 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9084 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativePatch( |
| 9085 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 9086 | patches->emplace_back(dex_file, offset_or_index); |
| 9087 | return &patches->back(); |
| 9088 | } |
| 9089 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9090 | vixl::aarch32::Label* CodeGeneratorARMVIXL::NewBakerReadBarrierPatch(uint32_t custom_data) { |
| 9091 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 9092 | return &baker_read_barrier_patches_.back().label; |
| 9093 | } |
| 9094 | |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9095 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateBootImageAddressLiteral(uint32_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 9096 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9097 | } |
| 9098 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 9099 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitStringLiteral( |
| 9100 | const DexFile& dex_file, |
| 9101 | dex::StringIndex string_index, |
| 9102 | Handle<mirror::String> handle) { |
| 9103 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 9104 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9105 | return jit_string_patches_.GetOrCreate( |
| 9106 | StringReference(&dex_file, string_index), |
| 9107 | [this]() { |
| 9108 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 9109 | }); |
| 9110 | } |
| 9111 | |
| 9112 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 9113 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 9114 | Handle<mirror::Class> handle) { |
| 9115 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 9116 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9117 | return jit_class_patches_.GetOrCreate( |
| 9118 | TypeReference(&dex_file, type_index), |
| 9119 | [this]() { |
| 9120 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 9121 | }); |
| 9122 | } |
| 9123 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9124 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9125 | inline void CodeGeneratorARMVIXL::EmitPcRelativeLinkerPatches( |
| 9126 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9127 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9128 | for (const PcRelativePatchInfo& info : infos) { |
| 9129 | const DexFile& dex_file = info.target_dex_file; |
| 9130 | size_t offset_or_index = info.offset_or_index; |
| 9131 | DCHECK(info.add_pc_label.IsBound()); |
| 9132 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.GetLocation()); |
| 9133 | // Add MOVW patch. |
| 9134 | DCHECK(info.movw_label.IsBound()); |
| 9135 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.GetLocation()); |
| 9136 | linker_patches->push_back(Factory(movw_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 9137 | // Add MOVT patch. |
| 9138 | DCHECK(info.movt_label.IsBound()); |
| 9139 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.GetLocation()); |
| 9140 | linker_patches->push_back(Factory(movt_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 9141 | } |
| 9142 | } |
| 9143 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9144 | void CodeGeneratorARMVIXL::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9145 | DCHECK(linker_patches->empty()); |
| 9146 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9147 | /* MOVW+MOVT for each entry */ 2u * pc_relative_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9148 | /* MOVW+MOVT for each entry */ 2u * method_bss_entry_patches_.size() + |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9149 | /* MOVW+MOVT for each entry */ 2u * pc_relative_type_patches_.size() + |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9150 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9151 | /* MOVW+MOVT for each entry */ 2u * pc_relative_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 9152 | /* MOVW+MOVT for each entry */ 2u * string_bss_entry_patches_.size() + |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9153 | baker_read_barrier_patches_.size(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9154 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9155 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9156 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 9157 | pc_relative_method_patches_, linker_patches); |
| 9158 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 9159 | pc_relative_type_patches_, linker_patches); |
| 9160 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| 9161 | pc_relative_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9162 | } else { |
| 9163 | DCHECK(pc_relative_method_patches_.empty()); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9164 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeClassTablePatch>( |
| 9165 | pc_relative_type_patches_, linker_patches); |
| 9166 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringInternTablePatch>( |
| 9167 | pc_relative_string_patches_, linker_patches); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9168 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9169 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 9170 | method_bss_entry_patches_, linker_patches); |
| 9171 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 9172 | type_bss_entry_patches_, linker_patches); |
| 9173 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 9174 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9175 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9176 | linker_patches->push_back(linker::LinkerPatch::BakerReadBarrierBranchPatch( |
| 9177 | info.label.GetLocation(), info.custom_data)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9178 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9179 | DCHECK_EQ(size, linker_patches->size()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9180 | } |
| 9181 | |
| 9182 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateUint32Literal( |
| 9183 | uint32_t value, |
| 9184 | Uint32ToLiteralMap* map) { |
| 9185 | return map->GetOrCreate( |
| 9186 | value, |
| 9187 | [this, value]() { |
| 9188 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ value); |
| 9189 | }); |
| 9190 | } |
| 9191 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 9192 | void LocationsBuilderARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 9193 | LocationSummary* locations = |
| 9194 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 9195 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 9196 | Location::RequiresRegister()); |
| 9197 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 9198 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 9199 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 9200 | } |
| 9201 | |
| 9202 | void InstructionCodeGeneratorARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 9203 | vixl32::Register res = OutputRegister(instr); |
| 9204 | vixl32::Register accumulator = |
| 9205 | InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 9206 | vixl32::Register mul_left = |
| 9207 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 9208 | vixl32::Register mul_right = |
| 9209 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
| 9210 | |
| 9211 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 9212 | __ Mla(res, mul_left, mul_right, accumulator); |
| 9213 | } else { |
| 9214 | __ Mls(res, mul_left, mul_right, accumulator); |
| 9215 | } |
| 9216 | } |
| 9217 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9218 | void LocationsBuilderARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9219 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9220 | LOG(FATAL) << "Unreachable"; |
| 9221 | } |
| 9222 | |
| 9223 | void InstructionCodeGeneratorARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9224 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9225 | LOG(FATAL) << "Unreachable"; |
| 9226 | } |
| 9227 | |
| 9228 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 9229 | void LocationsBuilderARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9230 | LocationSummary* locations = |
| 9231 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 9232 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9233 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
| 9234 | codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 9235 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 9236 | if (switch_instr->GetStartValue() != 0) { |
| 9237 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 9238 | } |
| 9239 | } |
| 9240 | } |
| 9241 | |
| 9242 | // TODO(VIXL): Investigate and reach the parity with old arm codegen. |
| 9243 | void InstructionCodeGeneratorARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9244 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 9245 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9246 | LocationSummary* locations = switch_instr->GetLocations(); |
| 9247 | vixl32::Register value_reg = InputRegisterAt(switch_instr, 0); |
| 9248 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 9249 | |
| 9250 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
| 9251 | !codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 9252 | // Create a series of compare/jumps. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9253 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9254 | vixl32::Register temp_reg = temps.Acquire(); |
| 9255 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 9256 | // the immediate, because IP is used as the destination register. For the other |
| 9257 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 9258 | // and they can be encoded in the instruction without making use of IP register. |
| 9259 | __ Adds(temp_reg, value_reg, -lower_bound); |
| 9260 | |
| 9261 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 9262 | // Jump to successors[0] if value == lower_bound. |
| 9263 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 9264 | int32_t last_index = 0; |
| 9265 | for (; num_entries - last_index > 2; last_index += 2) { |
| 9266 | __ Adds(temp_reg, temp_reg, -2); |
| 9267 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 9268 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9269 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 9270 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 9271 | } |
| 9272 | if (num_entries - last_index == 2) { |
| 9273 | // The last missing case_value. |
| 9274 | __ Cmp(temp_reg, 1); |
| 9275 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9276 | } |
| 9277 | |
| 9278 | // And the default for any other value. |
| 9279 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 9280 | __ B(codegen_->GetLabelOf(default_block)); |
| 9281 | } |
| 9282 | } else { |
| 9283 | // Create a table lookup. |
| 9284 | vixl32::Register table_base = RegisterFrom(locations->GetTemp(0)); |
| 9285 | |
| 9286 | JumpTableARMVIXL* jump_table = codegen_->CreateJumpTable(switch_instr); |
| 9287 | |
| 9288 | // Remove the bias. |
| 9289 | vixl32::Register key_reg; |
| 9290 | if (lower_bound != 0) { |
| 9291 | key_reg = RegisterFrom(locations->GetTemp(1)); |
| 9292 | __ Sub(key_reg, value_reg, lower_bound); |
| 9293 | } else { |
| 9294 | key_reg = value_reg; |
| 9295 | } |
| 9296 | |
| 9297 | // Check whether the value is in the table, jump to default block if not. |
| 9298 | __ Cmp(key_reg, num_entries - 1); |
| 9299 | __ B(hi, codegen_->GetLabelOf(default_block)); |
| 9300 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9301 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9302 | vixl32::Register jump_offset = temps.Acquire(); |
| 9303 | |
| 9304 | // Load jump offset from the table. |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9305 | { |
| 9306 | const size_t jump_size = switch_instr->GetNumEntries() * sizeof(int32_t); |
| 9307 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9308 | (vixl32::kMaxInstructionSizeInBytes * 4) + jump_size, |
| 9309 | CodeBufferCheckScope::kMaximumSize); |
| 9310 | __ adr(table_base, jump_table->GetTableStartLabel()); |
| 9311 | __ ldr(jump_offset, MemOperand(table_base, key_reg, vixl32::LSL, 2)); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9312 | |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9313 | // Jump to target block by branching to table_base(pc related) + offset. |
| 9314 | vixl32::Register target_address = table_base; |
| 9315 | __ add(target_address, table_base, jump_offset); |
| 9316 | __ bx(target_address); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 9317 | |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9318 | jump_table->EmitTable(codegen_); |
| 9319 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9320 | } |
| 9321 | } |
| 9322 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9323 | // Copy the result of a call into the given target. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9324 | void CodeGeneratorARMVIXL::MoveFromReturnRegister(Location trg, DataType::Type type) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9325 | if (!trg.IsValid()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9326 | DCHECK_EQ(type, DataType::Type::kVoid); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9327 | return; |
| 9328 | } |
| 9329 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9330 | DCHECK_NE(type, DataType::Type::kVoid); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9331 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9332 | Location return_loc = InvokeDexCallingConventionVisitorARMVIXL().GetReturnLocation(type); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9333 | if (return_loc.Equals(trg)) { |
| 9334 | return; |
| 9335 | } |
| 9336 | |
| 9337 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 9338 | // with the last branch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9339 | if (type == DataType::Type::kInt64) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9340 | TODO_VIXL32(FATAL); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9341 | } else if (type == DataType::Type::kFloat64) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9342 | TODO_VIXL32(FATAL); |
| 9343 | } else { |
| 9344 | // Let the parallel move resolver take care of all of this. |
| 9345 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 9346 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 9347 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 9348 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9349 | } |
| 9350 | |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9351 | void LocationsBuilderARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 9352 | LocationSummary* locations = |
| 9353 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 9354 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9355 | locations->SetOut(Location::RequiresRegister()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9356 | } |
| 9357 | |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9358 | void InstructionCodeGeneratorARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 9359 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| 9360 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 9361 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
| 9362 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9363 | OutputRegister(instruction), |
| 9364 | InputRegisterAt(instruction, 0), |
| 9365 | method_offset); |
| 9366 | } else { |
| 9367 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 9368 | instruction->GetIndex(), kArmPointerSize)); |
| 9369 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9370 | OutputRegister(instruction), |
| 9371 | InputRegisterAt(instruction, 0), |
| 9372 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 9373 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9374 | OutputRegister(instruction), |
| 9375 | OutputRegister(instruction), |
| 9376 | method_offset); |
| 9377 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9378 | } |
| 9379 | |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9380 | static void PatchJitRootUse(uint8_t* code, |
| 9381 | const uint8_t* roots_data, |
| 9382 | VIXLUInt32Literal* literal, |
| 9383 | uint64_t index_in_table) { |
| 9384 | DCHECK(literal->IsBound()); |
| 9385 | uint32_t literal_offset = literal->GetLocation(); |
| 9386 | uintptr_t address = |
| 9387 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 9388 | uint8_t* data = code + literal_offset; |
| 9389 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 9390 | } |
| 9391 | |
| 9392 | void CodeGeneratorARMVIXL::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 9393 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9394 | const StringReference& string_reference = entry.first; |
| 9395 | VIXLUInt32Literal* table_entry_literal = entry.second; |
| 9396 | const auto it = jit_string_roots_.find(string_reference); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9397 | DCHECK(it != jit_string_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9398 | uint64_t index_in_table = it->second; |
| 9399 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9400 | } |
| 9401 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9402 | const TypeReference& type_reference = entry.first; |
| 9403 | VIXLUInt32Literal* table_entry_literal = entry.second; |
| 9404 | const auto it = jit_class_roots_.find(type_reference); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9405 | DCHECK(it != jit_class_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9406 | uint64_t index_in_table = it->second; |
| 9407 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9408 | } |
| 9409 | } |
| 9410 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9411 | void CodeGeneratorARMVIXL::EmitMovwMovtPlaceholder( |
| 9412 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels, |
| 9413 | vixl32::Register out) { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 9414 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9415 | 3 * vixl32::kMaxInstructionSizeInBytes, |
| 9416 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9417 | // TODO(VIXL): Think about using mov instead of movw. |
| 9418 | __ bind(&labels->movw_label); |
| 9419 | __ movw(out, /* placeholder */ 0u); |
| 9420 | __ bind(&labels->movt_label); |
| 9421 | __ movt(out, /* placeholder */ 0u); |
| 9422 | __ bind(&labels->add_pc_label); |
| 9423 | __ add(out, out, pc); |
| 9424 | } |
| 9425 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9426 | #undef __ |
| 9427 | #undef QUICK_ENTRY_POINT |
| 9428 | #undef TODO_VIXL32 |
| 9429 | |
| 9430 | } // namespace arm |
| 9431 | } // namespace art |