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 | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 32 | #include "linker/linker_patch.h" |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 33 | #include "mirror/array-inl.h" |
| 34 | #include "mirror/class-inl.h" |
| 35 | #include "thread.h" |
| 36 | #include "utils/arm/assembler_arm_vixl.h" |
| 37 | #include "utils/arm/managed_register_arm.h" |
| 38 | #include "utils/assembler.h" |
| 39 | #include "utils/stack_checks.h" |
| 40 | |
| 41 | namespace art { |
| 42 | namespace arm { |
| 43 | |
| 44 | namespace vixl32 = vixl::aarch32; |
| 45 | using namespace vixl32; // NOLINT(build/namespaces) |
| 46 | |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 47 | using helpers::DRegisterFrom; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 48 | using helpers::DWARFReg; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 49 | using helpers::HighDRegisterFrom; |
| 50 | using helpers::HighRegisterFrom; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 51 | using helpers::InputDRegisterAt; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 52 | using helpers::InputOperandAt; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 53 | using helpers::InputRegister; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 54 | using helpers::InputRegisterAt; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 55 | using helpers::InputSRegisterAt; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 56 | using helpers::InputVRegister; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 57 | using helpers::InputVRegisterAt; |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 58 | using helpers::Int32ConstantFrom; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 59 | using helpers::Int64ConstantFrom; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 60 | using helpers::LocationFrom; |
| 61 | using helpers::LowRegisterFrom; |
| 62 | using helpers::LowSRegisterFrom; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 63 | using helpers::OperandFrom; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 64 | using helpers::OutputRegister; |
| 65 | using helpers::OutputSRegister; |
| 66 | using helpers::OutputVRegister; |
| 67 | using helpers::RegisterFrom; |
| 68 | using helpers::SRegisterFrom; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 69 | using helpers::Uint64ConstantFrom; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 70 | |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 71 | using vixl::ExactAssemblyScope; |
| 72 | using vixl::CodeBufferCheckScope; |
| 73 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 74 | using RegisterList = vixl32::RegisterList; |
| 75 | |
| 76 | static bool ExpectedPairLayout(Location location) { |
| 77 | // We expected this for both core and fpu register pairs. |
| 78 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 79 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 80 | // Use a local definition to prevent copying mistakes. |
| 81 | static constexpr size_t kArmWordSize = static_cast<size_t>(kArmPointerSize); |
| 82 | static constexpr size_t kArmBitsPerWord = kArmWordSize * kBitsPerByte; |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 83 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 84 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 85 | // Reference load (except object array loads) is using LDR Rt, [Rn, #offset] which can handle |
| 86 | // offset < 4KiB. For offsets >= 4KiB, the load shall be emitted as two or more instructions. |
| 87 | // For the Baker read barrier implementation using link-generated thunks we need to split |
| 88 | // the offset explicitly. |
| 89 | constexpr uint32_t kReferenceLoadMinFarOffset = 4 * KB; |
| 90 | |
| 91 | // Flags controlling the use of link-time generated thunks for Baker read barriers. |
| 92 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForFields = true; |
| 93 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForArrays = true; |
| 94 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForGcRoots = true; |
| 95 | |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 96 | // Using a base helps identify when we hit Marking Register check breakpoints. |
| 97 | constexpr int kMarkingRegisterCheckBreakCodeBaseCode = 0x10; |
| 98 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 99 | #ifdef __ |
| 100 | #error "ARM Codegen VIXL macro-assembler macro already defined." |
| 101 | #endif |
| 102 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 103 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 104 | #define __ down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()-> // NOLINT |
| 105 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, x).Int32Value() |
| 106 | |
| 107 | // Marker that code is yet to be, and must, be implemented. |
| 108 | #define TODO_VIXL32(level) LOG(level) << __PRETTY_FUNCTION__ << " unimplemented " |
| 109 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 110 | static inline void ExcludeIPAndBakerCcEntrypointRegister(UseScratchRegisterScope* temps, |
| 111 | HInstruction* instruction) { |
| 112 | DCHECK(temps->IsAvailable(ip)); |
| 113 | temps->Exclude(ip); |
| 114 | DCHECK(!temps->IsAvailable(kBakerCcEntrypointRegister)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 115 | DCHECK_NE(instruction->GetLocations()->GetTempCount(), 0u); |
| 116 | DCHECK(RegisterFrom(instruction->GetLocations()->GetTemp( |
| 117 | instruction->GetLocations()->GetTempCount() - 1u)).Is(kBakerCcEntrypointRegister)); |
| 118 | } |
| 119 | |
| 120 | static inline void EmitPlaceholderBne(CodeGeneratorARMVIXL* codegen, vixl32::Label* patch_label) { |
| 121 | ExactAssemblyScope eas(codegen->GetVIXLAssembler(), kMaxInstructionSizeInBytes); |
| 122 | __ bind(patch_label); |
| 123 | vixl32::Label placeholder_label; |
| 124 | __ b(ne, EncodingSize(Wide), &placeholder_label); // Placeholder, patched at link-time. |
| 125 | __ bind(&placeholder_label); |
| 126 | } |
| 127 | |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 128 | static inline bool CanEmitNarrowLdr(vixl32::Register rt, vixl32::Register rn, uint32_t offset) { |
| 129 | return rt.IsLow() && rn.IsLow() && offset < 32u; |
| 130 | } |
| 131 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 132 | class EmitAdrCode { |
| 133 | public: |
| 134 | EmitAdrCode(ArmVIXLMacroAssembler* assembler, vixl32::Register rd, vixl32::Label* label) |
| 135 | : assembler_(assembler), rd_(rd), label_(label) { |
| 136 | ExactAssemblyScope aas(assembler, kMaxInstructionSizeInBytes); |
| 137 | adr_location_ = assembler->GetCursorOffset(); |
| 138 | assembler->adr(EncodingSize(Wide), rd, label); |
| 139 | } |
| 140 | |
| 141 | ~EmitAdrCode() { |
| 142 | DCHECK(label_->IsBound()); |
| 143 | // The ADR emitted by the assembler does not set the Thumb mode bit we need. |
| 144 | // TODO: Maybe extend VIXL to allow ADR for return address? |
| 145 | uint8_t* raw_adr = assembler_->GetBuffer()->GetOffsetAddress<uint8_t*>(adr_location_); |
| 146 | // Expecting ADR encoding T3 with `(offset & 1) == 0`. |
| 147 | DCHECK_EQ(raw_adr[1] & 0xfbu, 0xf2u); // Check bits 24-31, except 26. |
| 148 | DCHECK_EQ(raw_adr[0] & 0xffu, 0x0fu); // Check bits 16-23. |
| 149 | DCHECK_EQ(raw_adr[3] & 0x8fu, rd_.GetCode()); // Check bits 8-11 and 15. |
| 150 | DCHECK_EQ(raw_adr[2] & 0x01u, 0x00u); // Check bit 0, i.e. the `offset & 1`. |
| 151 | // Add the Thumb mode bit. |
| 152 | raw_adr[2] |= 0x01u; |
| 153 | } |
| 154 | |
| 155 | private: |
| 156 | ArmVIXLMacroAssembler* const assembler_; |
| 157 | vixl32::Register rd_; |
| 158 | vixl32::Label* const label_; |
| 159 | int32_t adr_location_; |
| 160 | }; |
| 161 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 162 | // SaveLiveRegisters and RestoreLiveRegisters from SlowPathCodeARM operate on sets of S registers, |
| 163 | // for each live D registers they treat two corresponding S registers as live ones. |
| 164 | // |
| 165 | // Two following functions (SaveContiguousSRegisterList, RestoreContiguousSRegisterList) build |
| 166 | // from a list of contiguous S registers a list of contiguous D registers (processing first/last |
| 167 | // S registers corner cases) and save/restore this new list treating them as D registers. |
| 168 | // - decreasing code size |
| 169 | // - avoiding hazards on Cortex-A57, when a pair of S registers for an actual live D register is |
| 170 | // restored and then used in regular non SlowPath code as D register. |
| 171 | // |
| 172 | // For the following example (v means the S register is live): |
| 173 | // D names: | D0 | D1 | D2 | D4 | ... |
| 174 | // S names: | S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | ... |
| 175 | // Live? | | v | v | v | v | v | v | | ... |
| 176 | // |
| 177 | // S1 and S6 will be saved/restored independently; D registers list (D1, D2) will be processed |
| 178 | // as D registers. |
| 179 | // |
| 180 | // TODO(VIXL): All this code should be unnecessary once the VIXL AArch32 backend provides helpers |
| 181 | // for lists of floating-point registers. |
| 182 | static size_t SaveContiguousSRegisterList(size_t first, |
| 183 | size_t last, |
| 184 | CodeGenerator* codegen, |
| 185 | size_t stack_offset) { |
| 186 | static_assert(kSRegSizeInBytes == kArmWordSize, "Broken assumption on reg/word sizes."); |
| 187 | static_assert(kDRegSizeInBytes == 2 * kArmWordSize, "Broken assumption on reg/word sizes."); |
| 188 | DCHECK_LE(first, last); |
| 189 | if ((first == last) && (first == 0)) { |
| 190 | __ Vstr(vixl32::SRegister(first), MemOperand(sp, stack_offset)); |
| 191 | return stack_offset + kSRegSizeInBytes; |
| 192 | } |
| 193 | if (first % 2 == 1) { |
| 194 | __ Vstr(vixl32::SRegister(first++), MemOperand(sp, stack_offset)); |
| 195 | stack_offset += kSRegSizeInBytes; |
| 196 | } |
| 197 | |
| 198 | bool save_last = false; |
| 199 | if (last % 2 == 0) { |
| 200 | save_last = true; |
| 201 | --last; |
| 202 | } |
| 203 | |
| 204 | if (first < last) { |
| 205 | vixl32::DRegister d_reg = vixl32::DRegister(first / 2); |
| 206 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 207 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 208 | |
| 209 | if (number_of_d_regs == 1) { |
| 210 | __ Vstr(d_reg, MemOperand(sp, stack_offset)); |
| 211 | } else if (number_of_d_regs > 1) { |
| 212 | UseScratchRegisterScope temps(down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 213 | vixl32::Register base = sp; |
| 214 | if (stack_offset != 0) { |
| 215 | base = temps.Acquire(); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 216 | __ Add(base, sp, Operand::From(stack_offset)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 217 | } |
| 218 | __ Vstm(F64, base, NO_WRITE_BACK, DRegisterList(d_reg, number_of_d_regs)); |
| 219 | } |
| 220 | stack_offset += number_of_d_regs * kDRegSizeInBytes; |
| 221 | } |
| 222 | |
| 223 | if (save_last) { |
| 224 | __ Vstr(vixl32::SRegister(last + 1), MemOperand(sp, stack_offset)); |
| 225 | stack_offset += kSRegSizeInBytes; |
| 226 | } |
| 227 | |
| 228 | return stack_offset; |
| 229 | } |
| 230 | |
| 231 | static size_t RestoreContiguousSRegisterList(size_t first, |
| 232 | size_t last, |
| 233 | CodeGenerator* codegen, |
| 234 | size_t stack_offset) { |
| 235 | static_assert(kSRegSizeInBytes == kArmWordSize, "Broken assumption on reg/word sizes."); |
| 236 | static_assert(kDRegSizeInBytes == 2 * kArmWordSize, "Broken assumption on reg/word sizes."); |
| 237 | DCHECK_LE(first, last); |
| 238 | if ((first == last) && (first == 0)) { |
| 239 | __ Vldr(vixl32::SRegister(first), MemOperand(sp, stack_offset)); |
| 240 | return stack_offset + kSRegSizeInBytes; |
| 241 | } |
| 242 | if (first % 2 == 1) { |
| 243 | __ Vldr(vixl32::SRegister(first++), MemOperand(sp, stack_offset)); |
| 244 | stack_offset += kSRegSizeInBytes; |
| 245 | } |
| 246 | |
| 247 | bool restore_last = false; |
| 248 | if (last % 2 == 0) { |
| 249 | restore_last = true; |
| 250 | --last; |
| 251 | } |
| 252 | |
| 253 | if (first < last) { |
| 254 | vixl32::DRegister d_reg = vixl32::DRegister(first / 2); |
| 255 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 256 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 257 | if (number_of_d_regs == 1) { |
| 258 | __ Vldr(d_reg, MemOperand(sp, stack_offset)); |
| 259 | } else if (number_of_d_regs > 1) { |
| 260 | UseScratchRegisterScope temps(down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 261 | vixl32::Register base = sp; |
| 262 | if (stack_offset != 0) { |
| 263 | base = temps.Acquire(); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 264 | __ Add(base, sp, Operand::From(stack_offset)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 265 | } |
| 266 | __ Vldm(F64, base, NO_WRITE_BACK, DRegisterList(d_reg, number_of_d_regs)); |
| 267 | } |
| 268 | stack_offset += number_of_d_regs * kDRegSizeInBytes; |
| 269 | } |
| 270 | |
| 271 | if (restore_last) { |
| 272 | __ Vldr(vixl32::SRegister(last + 1), MemOperand(sp, stack_offset)); |
| 273 | stack_offset += kSRegSizeInBytes; |
| 274 | } |
| 275 | |
| 276 | return stack_offset; |
| 277 | } |
| 278 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 279 | static LoadOperandType GetLoadOperandType(DataType::Type type) { |
| 280 | switch (type) { |
| 281 | case DataType::Type::kReference: |
| 282 | return kLoadWord; |
| 283 | case DataType::Type::kBool: |
| 284 | case DataType::Type::kUint8: |
| 285 | return kLoadUnsignedByte; |
| 286 | case DataType::Type::kInt8: |
| 287 | return kLoadSignedByte; |
| 288 | case DataType::Type::kUint16: |
| 289 | return kLoadUnsignedHalfword; |
| 290 | case DataType::Type::kInt16: |
| 291 | return kLoadSignedHalfword; |
| 292 | case DataType::Type::kInt32: |
| 293 | return kLoadWord; |
| 294 | case DataType::Type::kInt64: |
| 295 | return kLoadWordPair; |
| 296 | case DataType::Type::kFloat32: |
| 297 | return kLoadSWord; |
| 298 | case DataType::Type::kFloat64: |
| 299 | return kLoadDWord; |
| 300 | default: |
| 301 | LOG(FATAL) << "Unreachable type " << type; |
| 302 | UNREACHABLE(); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | static StoreOperandType GetStoreOperandType(DataType::Type type) { |
| 307 | switch (type) { |
| 308 | case DataType::Type::kReference: |
| 309 | return kStoreWord; |
| 310 | case DataType::Type::kBool: |
| 311 | case DataType::Type::kUint8: |
| 312 | case DataType::Type::kInt8: |
| 313 | return kStoreByte; |
| 314 | case DataType::Type::kUint16: |
| 315 | case DataType::Type::kInt16: |
| 316 | return kStoreHalfword; |
| 317 | case DataType::Type::kInt32: |
| 318 | return kStoreWord; |
| 319 | case DataType::Type::kInt64: |
| 320 | return kStoreWordPair; |
| 321 | case DataType::Type::kFloat32: |
| 322 | return kStoreSWord; |
| 323 | case DataType::Type::kFloat64: |
| 324 | return kStoreDWord; |
| 325 | default: |
| 326 | LOG(FATAL) << "Unreachable type " << type; |
| 327 | UNREACHABLE(); |
| 328 | } |
| 329 | } |
| 330 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 331 | void SlowPathCodeARMVIXL::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 332 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 333 | size_t orig_offset = stack_offset; |
| 334 | |
| 335 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 336 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 337 | // If the register holds an object, update the stack mask. |
| 338 | if (locations->RegisterContainsObject(i)) { |
| 339 | locations->SetStackBit(stack_offset / kVRegSize); |
| 340 | } |
| 341 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 342 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 343 | saved_core_stack_offsets_[i] = stack_offset; |
| 344 | stack_offset += kArmWordSize; |
| 345 | } |
| 346 | |
| 347 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 348 | arm_codegen->GetAssembler()->StoreRegisterList(core_spills, orig_offset); |
| 349 | |
| 350 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 351 | orig_offset = stack_offset; |
| 352 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 353 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 354 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 355 | stack_offset += kArmWordSize; |
| 356 | } |
| 357 | |
| 358 | stack_offset = orig_offset; |
| 359 | while (fp_spills != 0u) { |
| 360 | uint32_t begin = CTZ(fp_spills); |
| 361 | uint32_t tmp = fp_spills + (1u << begin); |
| 362 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 363 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 364 | stack_offset = SaveContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 365 | } |
| 366 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 367 | } |
| 368 | |
| 369 | void SlowPathCodeARMVIXL::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 370 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 371 | size_t orig_offset = stack_offset; |
| 372 | |
| 373 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 374 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 375 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 376 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 377 | stack_offset += kArmWordSize; |
| 378 | } |
| 379 | |
| 380 | // TODO(VIXL): Check the coherency of stack_offset after this with a test. |
| 381 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 382 | arm_codegen->GetAssembler()->LoadRegisterList(core_spills, orig_offset); |
| 383 | |
| 384 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 385 | while (fp_spills != 0u) { |
| 386 | uint32_t begin = CTZ(fp_spills); |
| 387 | uint32_t tmp = fp_spills + (1u << begin); |
| 388 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 389 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 390 | stack_offset = RestoreContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 391 | } |
| 392 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 393 | } |
| 394 | |
| 395 | class NullCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 396 | public: |
| 397 | explicit NullCheckSlowPathARMVIXL(HNullCheck* instruction) : SlowPathCodeARMVIXL(instruction) {} |
| 398 | |
| 399 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 400 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 401 | __ Bind(GetEntryLabel()); |
| 402 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 403 | // Live registers will be restored in the catch block if caught. |
| 404 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 405 | } |
| 406 | arm_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 407 | instruction_, |
| 408 | instruction_->GetDexPc(), |
| 409 | this); |
| 410 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| 411 | } |
| 412 | |
| 413 | bool IsFatal() const OVERRIDE { return true; } |
| 414 | |
| 415 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARMVIXL"; } |
| 416 | |
| 417 | private: |
| 418 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARMVIXL); |
| 419 | }; |
| 420 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 421 | class DivZeroCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 422 | public: |
| 423 | explicit DivZeroCheckSlowPathARMVIXL(HDivZeroCheck* instruction) |
| 424 | : SlowPathCodeARMVIXL(instruction) {} |
| 425 | |
| 426 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 427 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 428 | __ Bind(GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 429 | arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 430 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| 431 | } |
| 432 | |
| 433 | bool IsFatal() const OVERRIDE { return true; } |
| 434 | |
| 435 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARMVIXL"; } |
| 436 | |
| 437 | private: |
| 438 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARMVIXL); |
| 439 | }; |
| 440 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 441 | class SuspendCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 442 | public: |
| 443 | SuspendCheckSlowPathARMVIXL(HSuspendCheck* instruction, HBasicBlock* successor) |
| 444 | : SlowPathCodeARMVIXL(instruction), successor_(successor) {} |
| 445 | |
| 446 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 447 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 448 | __ Bind(GetEntryLabel()); |
| 449 | arm_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
| 450 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
| 451 | if (successor_ == nullptr) { |
| 452 | __ B(GetReturnLabel()); |
| 453 | } else { |
| 454 | __ B(arm_codegen->GetLabelOf(successor_)); |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | vixl32::Label* GetReturnLabel() { |
| 459 | DCHECK(successor_ == nullptr); |
| 460 | return &return_label_; |
| 461 | } |
| 462 | |
| 463 | HBasicBlock* GetSuccessor() const { |
| 464 | return successor_; |
| 465 | } |
| 466 | |
| 467 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARMVIXL"; } |
| 468 | |
| 469 | private: |
| 470 | // If not null, the block to branch to after the suspend check. |
| 471 | HBasicBlock* const successor_; |
| 472 | |
| 473 | // If `successor_` is null, the label to branch to after the suspend check. |
| 474 | vixl32::Label return_label_; |
| 475 | |
| 476 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARMVIXL); |
| 477 | }; |
| 478 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 479 | class BoundsCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 480 | public: |
| 481 | explicit BoundsCheckSlowPathARMVIXL(HBoundsCheck* instruction) |
| 482 | : SlowPathCodeARMVIXL(instruction) {} |
| 483 | |
| 484 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 485 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 486 | LocationSummary* locations = instruction_->GetLocations(); |
| 487 | |
| 488 | __ Bind(GetEntryLabel()); |
| 489 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 490 | // Live registers will be restored in the catch block if caught. |
| 491 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 492 | } |
| 493 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 494 | // move resolver. |
| 495 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 496 | codegen->EmitParallelMoves( |
| 497 | locations->InAt(0), |
| 498 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 499 | DataType::Type::kInt32, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 500 | locations->InAt(1), |
| 501 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 502 | DataType::Type::kInt32); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 503 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 504 | ? kQuickThrowStringBounds |
| 505 | : kQuickThrowArrayBounds; |
| 506 | arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
| 507 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
| 508 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| 509 | } |
| 510 | |
| 511 | bool IsFatal() const OVERRIDE { return true; } |
| 512 | |
| 513 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARMVIXL"; } |
| 514 | |
| 515 | private: |
| 516 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARMVIXL); |
| 517 | }; |
| 518 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 519 | class LoadClassSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 520 | public: |
| 521 | LoadClassSlowPathARMVIXL(HLoadClass* cls, HInstruction* at, uint32_t dex_pc, bool do_clinit) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 522 | : SlowPathCodeARMVIXL(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 523 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 524 | } |
| 525 | |
| 526 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 527 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 528 | Location out = locations->Out(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 529 | |
| 530 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 531 | __ Bind(GetEntryLabel()); |
| 532 | SaveLiveRegisters(codegen, locations); |
| 533 | |
| 534 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 535 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 536 | __ Mov(calling_convention.GetRegisterAt(0), type_index.index_); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 537 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 538 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 539 | arm_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 540 | if (do_clinit_) { |
| 541 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 542 | } else { |
| 543 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 544 | } |
| 545 | |
| 546 | // Move the class to the desired location. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 547 | if (out.IsValid()) { |
| 548 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 549 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
| 550 | } |
| 551 | RestoreLiveRegisters(codegen, locations); |
| 552 | __ B(GetExitLabel()); |
| 553 | } |
| 554 | |
| 555 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARMVIXL"; } |
| 556 | |
| 557 | private: |
| 558 | // The class this slow path will load. |
| 559 | HLoadClass* const cls_; |
| 560 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 561 | // The dex PC of `at_`. |
| 562 | const uint32_t dex_pc_; |
| 563 | |
| 564 | // Whether to initialize the class. |
| 565 | const bool do_clinit_; |
| 566 | |
| 567 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARMVIXL); |
| 568 | }; |
| 569 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 570 | class LoadStringSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 571 | public: |
| 572 | explicit LoadStringSlowPathARMVIXL(HLoadString* instruction) |
| 573 | : SlowPathCodeARMVIXL(instruction) {} |
| 574 | |
| 575 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 576 | DCHECK(instruction_->IsLoadString()); |
| 577 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 578 | LocationSummary* locations = instruction_->GetLocations(); |
| 579 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 580 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 581 | |
| 582 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 583 | __ Bind(GetEntryLabel()); |
| 584 | SaveLiveRegisters(codegen, locations); |
| 585 | |
| 586 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 587 | __ Mov(calling_convention.GetRegisterAt(0), string_index.index_); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 588 | arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 589 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 590 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 591 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
| 592 | RestoreLiveRegisters(codegen, locations); |
| 593 | |
| 594 | __ B(GetExitLabel()); |
| 595 | } |
| 596 | |
| 597 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARMVIXL"; } |
| 598 | |
| 599 | private: |
| 600 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARMVIXL); |
| 601 | }; |
| 602 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 603 | class TypeCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 604 | public: |
| 605 | TypeCheckSlowPathARMVIXL(HInstruction* instruction, bool is_fatal) |
| 606 | : SlowPathCodeARMVIXL(instruction), is_fatal_(is_fatal) {} |
| 607 | |
| 608 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 609 | LocationSummary* locations = instruction_->GetLocations(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 610 | DCHECK(instruction_->IsCheckCast() |
| 611 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 612 | |
| 613 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 614 | __ Bind(GetEntryLabel()); |
| 615 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 616 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 617 | SaveLiveRegisters(codegen, locations); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 621 | // move resolver. |
| 622 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 623 | |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 624 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 625 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 626 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 627 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 628 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 629 | DataType::Type::kReference); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 630 | if (instruction_->IsInstanceOf()) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 631 | arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
| 632 | instruction_, |
| 633 | instruction_->GetDexPc(), |
| 634 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 635 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 636 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 637 | } else { |
| 638 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 639 | arm_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 640 | instruction_, |
| 641 | instruction_->GetDexPc(), |
| 642 | this); |
| 643 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | if (!is_fatal_) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 647 | RestoreLiveRegisters(codegen, locations); |
| 648 | __ B(GetExitLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 649 | } |
| 650 | } |
| 651 | |
| 652 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARMVIXL"; } |
| 653 | |
| 654 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 655 | |
| 656 | private: |
| 657 | const bool is_fatal_; |
| 658 | |
| 659 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARMVIXL); |
| 660 | }; |
| 661 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 662 | class DeoptimizationSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 663 | public: |
| 664 | explicit DeoptimizationSlowPathARMVIXL(HDeoptimize* instruction) |
| 665 | : SlowPathCodeARMVIXL(instruction) {} |
| 666 | |
| 667 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 668 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 669 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 670 | LocationSummary* locations = instruction_->GetLocations(); |
| 671 | SaveLiveRegisters(codegen, locations); |
| 672 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 673 | __ Mov(calling_convention.GetRegisterAt(0), |
| 674 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
| 675 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 676 | arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 677 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARMVIXL"; } |
| 681 | |
| 682 | private: |
| 683 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARMVIXL); |
| 684 | }; |
| 685 | |
| 686 | class ArraySetSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 687 | public: |
| 688 | explicit ArraySetSlowPathARMVIXL(HInstruction* instruction) : SlowPathCodeARMVIXL(instruction) {} |
| 689 | |
| 690 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 691 | LocationSummary* locations = instruction_->GetLocations(); |
| 692 | __ Bind(GetEntryLabel()); |
| 693 | SaveLiveRegisters(codegen, locations); |
| 694 | |
| 695 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 696 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 697 | parallel_move.AddMove( |
| 698 | locations->InAt(0), |
| 699 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 700 | DataType::Type::kReference, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 701 | nullptr); |
| 702 | parallel_move.AddMove( |
| 703 | locations->InAt(1), |
| 704 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 705 | DataType::Type::kInt32, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 706 | nullptr); |
| 707 | parallel_move.AddMove( |
| 708 | locations->InAt(2), |
| 709 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 710 | DataType::Type::kReference, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 711 | nullptr); |
| 712 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 713 | |
| 714 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 715 | arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| 716 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 717 | RestoreLiveRegisters(codegen, locations); |
| 718 | __ B(GetExitLabel()); |
| 719 | } |
| 720 | |
| 721 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARMVIXL"; } |
| 722 | |
| 723 | private: |
| 724 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARMVIXL); |
| 725 | }; |
| 726 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 727 | // Abstract base class for read barrier slow paths marking a reference |
| 728 | // `ref`. |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 729 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 730 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 731 | // barrier marking runtime entry point to be invoked or an empty |
| 732 | // location; in the latter case, the read barrier marking runtime |
| 733 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 734 | class ReadBarrierMarkSlowPathBaseARMVIXL : public SlowPathCodeARMVIXL { |
| 735 | protected: |
| 736 | ReadBarrierMarkSlowPathBaseARMVIXL(HInstruction* instruction, Location ref, Location entrypoint) |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 737 | : SlowPathCodeARMVIXL(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 738 | DCHECK(kEmitCompilerReadBarrier); |
| 739 | } |
| 740 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 741 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathBaseARMVIXL"; } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 742 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 743 | // Generate assembly code calling the read barrier marking runtime |
| 744 | // entry point (ReadBarrierMarkRegX). |
| 745 | void GenerateReadBarrierMarkRuntimeCall(CodeGenerator* codegen) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 746 | vixl32::Register ref_reg = RegisterFrom(ref_); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 747 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 748 | // No need to save live registers; it's taken care of by the |
| 749 | // entrypoint. Also, there is no need to update the stack mask, |
| 750 | // as this runtime call will not trigger a garbage collection. |
| 751 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 752 | DCHECK(!ref_reg.Is(sp)); |
| 753 | DCHECK(!ref_reg.Is(lr)); |
| 754 | DCHECK(!ref_reg.Is(pc)); |
| 755 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 756 | // as a temporary, it cannot be the entry point's input/output. |
| 757 | DCHECK(!ref_reg.Is(ip)); |
| 758 | DCHECK(ref_reg.IsRegister()) << ref_reg; |
| 759 | // "Compact" slow path, saving two moves. |
| 760 | // |
| 761 | // Instead of using the standard runtime calling convention (input |
| 762 | // and output in R0): |
| 763 | // |
| 764 | // R0 <- ref |
| 765 | // R0 <- ReadBarrierMark(R0) |
| 766 | // ref <- R0 |
| 767 | // |
| 768 | // we just use rX (the register containing `ref`) as input and output |
| 769 | // of a dedicated entrypoint: |
| 770 | // |
| 771 | // rX <- ReadBarrierMarkRegX(rX) |
| 772 | // |
| 773 | if (entrypoint_.IsValid()) { |
| 774 | arm_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 775 | __ Blx(RegisterFrom(entrypoint_)); |
| 776 | } else { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 777 | // Entrypoint is not already loaded, load from the thread. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 778 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 779 | Thread::ReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg.GetCode()); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 780 | // This runtime call does not require a stack map. |
| 781 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 782 | } |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 783 | } |
| 784 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 785 | // The location (register) of the marked object reference. |
| 786 | const Location ref_; |
| 787 | |
| 788 | // The location of the entrypoint if already loaded. |
| 789 | const Location entrypoint_; |
| 790 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 791 | private: |
| 792 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathBaseARMVIXL); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 793 | }; |
| 794 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 795 | // Slow path marking an object reference `ref` during a read |
| 796 | // barrier. The field `obj.field` in the object `obj` holding this |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 797 | // reference does not get updated by this slow path after marking. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 798 | // |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 799 | // This means that after the execution of this slow path, `ref` will |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 800 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 801 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 802 | // probably still be a from-space reference (unless it gets updated by |
| 803 | // another thread, or if another thread installed another object |
| 804 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 805 | // |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 806 | // Argument `entrypoint` must be a register location holding the read |
| 807 | // barrier marking runtime entry point to be invoked or an empty |
| 808 | // location; in the latter case, the read barrier marking runtime |
| 809 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 810 | class ReadBarrierMarkSlowPathARMVIXL : public ReadBarrierMarkSlowPathBaseARMVIXL { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 811 | public: |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 812 | ReadBarrierMarkSlowPathARMVIXL(HInstruction* instruction, |
| 813 | Location ref, |
| 814 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 815 | : ReadBarrierMarkSlowPathBaseARMVIXL(instruction, ref, entrypoint) { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 816 | DCHECK(kEmitCompilerReadBarrier); |
| 817 | } |
| 818 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 819 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARMVIXL"; } |
| 820 | |
| 821 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 822 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 823 | DCHECK(locations->CanCall()); |
| 824 | DCHECK(ref_.IsRegister()) << ref_; |
| 825 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
| 826 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 827 | << "Unexpected instruction in read barrier marking slow path: " |
| 828 | << instruction_->DebugName(); |
| 829 | |
| 830 | __ Bind(GetEntryLabel()); |
| 831 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 832 | __ B(GetExitLabel()); |
| 833 | } |
| 834 | |
| 835 | private: |
| 836 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARMVIXL); |
| 837 | }; |
| 838 | |
| 839 | // Slow path loading `obj`'s lock word, loading a reference from |
| 840 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 841 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 842 | // read barrier). The field `obj.field` in the object `obj` holding |
| 843 | // this reference does not get updated by this slow path after marking |
| 844 | // (see LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL |
| 845 | // below for that). |
| 846 | // |
| 847 | // This means that after the execution of this slow path, `ref` will |
| 848 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 849 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 850 | // probably still be a from-space reference (unless it gets updated by |
| 851 | // another thread, or if another thread installed another object |
| 852 | // reference (different from `ref`) in `obj.field`). |
| 853 | // |
| 854 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 855 | // barrier marking runtime entry point to be invoked or an empty |
| 856 | // location; in the latter case, the read barrier marking runtime |
| 857 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 858 | class LoadReferenceWithBakerReadBarrierSlowPathARMVIXL : public ReadBarrierMarkSlowPathBaseARMVIXL { |
| 859 | public: |
| 860 | LoadReferenceWithBakerReadBarrierSlowPathARMVIXL(HInstruction* instruction, |
| 861 | Location ref, |
| 862 | vixl32::Register obj, |
| 863 | uint32_t offset, |
| 864 | Location index, |
| 865 | ScaleFactor scale_factor, |
| 866 | bool needs_null_check, |
| 867 | vixl32::Register temp, |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 868 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 869 | : ReadBarrierMarkSlowPathBaseARMVIXL(instruction, ref, entrypoint), |
| 870 | obj_(obj), |
| 871 | offset_(offset), |
| 872 | index_(index), |
| 873 | scale_factor_(scale_factor), |
| 874 | needs_null_check_(needs_null_check), |
| 875 | temp_(temp) { |
| 876 | DCHECK(kEmitCompilerReadBarrier); |
| 877 | DCHECK(kUseBakerReadBarrier); |
| 878 | } |
| 879 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 880 | const char* GetDescription() const OVERRIDE { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 881 | return "LoadReferenceWithBakerReadBarrierSlowPathARMVIXL"; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 885 | LocationSummary* locations = instruction_->GetLocations(); |
| 886 | vixl32::Register ref_reg = RegisterFrom(ref_); |
| 887 | DCHECK(locations->CanCall()); |
| 888 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg.GetCode())) << ref_reg; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 889 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 890 | instruction_->IsStaticFieldGet() || |
| 891 | instruction_->IsArrayGet() || |
| 892 | instruction_->IsArraySet() || |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 893 | instruction_->IsInstanceOf() || |
| 894 | instruction_->IsCheckCast() || |
| 895 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 896 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 897 | << "Unexpected instruction in read barrier marking slow path: " |
| 898 | << instruction_->DebugName(); |
| 899 | // The read barrier instrumentation of object ArrayGet |
| 900 | // instructions does not support the HIntermediateAddress |
| 901 | // instruction. |
| 902 | DCHECK(!(instruction_->IsArrayGet() && |
| 903 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 904 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 905 | // Temporary register `temp_`, used to store the lock word, must |
| 906 | // not be IP, as we may use it to emit the reference load (in the |
| 907 | // call to GenerateRawReferenceLoad below), and we need the lock |
| 908 | // word to still be in `temp_` after the reference load. |
| 909 | DCHECK(!temp_.Is(ip)); |
| 910 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 911 | __ Bind(GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 912 | |
| 913 | // When using MaybeGenerateReadBarrierSlow, the read barrier call is |
| 914 | // inserted after the original load. However, in fast path based |
| 915 | // Baker's read barriers, we need to perform the load of |
| 916 | // mirror::Object::monitor_ *before* the original reference load. |
| 917 | // This load-load ordering is required by the read barrier. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 918 | // The slow path (for Baker's algorithm) should look like: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 919 | // |
| 920 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 921 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 922 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 923 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 924 | // if (is_gray) { |
| 925 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 926 | // } |
| 927 | // |
| 928 | // Note: the original implementation in ReadBarrier::Barrier is |
| 929 | // slightly more complex as it performs additional checks that we do |
| 930 | // not do here for performance reasons. |
| 931 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 932 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 933 | |
| 934 | // /* int32_t */ monitor = obj->monitor_ |
| 935 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 936 | arm_codegen->GetAssembler()->LoadFromOffset(kLoadWord, temp_, obj_, monitor_offset); |
| 937 | if (needs_null_check_) { |
| 938 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 939 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 940 | // /* LockWord */ lock_word = LockWord(monitor) |
| 941 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 942 | "art::LockWord and int32_t have different sizes."); |
| 943 | |
| 944 | // Introduce a dependency on the lock_word including the rb_state, |
| 945 | // which shall prevent load-load reordering without using |
| 946 | // a memory barrier (which would be more expensive). |
| 947 | // `obj` is unchanged by this operation, but its value now depends |
| 948 | // on `temp`. |
| 949 | __ Add(obj_, obj_, Operand(temp_, ShiftType::LSR, 32)); |
| 950 | |
| 951 | // The actual reference load. |
| 952 | // A possible implicit null check has already been handled above. |
| 953 | arm_codegen->GenerateRawReferenceLoad( |
| 954 | instruction_, ref_, obj_, offset_, index_, scale_factor_, /* needs_null_check */ false); |
| 955 | |
| 956 | // Mark the object `ref` when `obj` is gray. |
| 957 | // |
| 958 | // if (rb_state == ReadBarrier::GrayState()) |
| 959 | // ref = ReadBarrier::Mark(ref); |
| 960 | // |
| 961 | // Given the numeric representation, it's enough to check the low bit of the |
| 962 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 963 | // which can be a 16-bit instruction unlike the TST immediate. |
| 964 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 965 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 966 | __ Lsrs(temp_, temp_, LockWord::kReadBarrierStateShift + 1); |
| 967 | __ B(cc, GetExitLabel()); // Carry flag is the last bit shifted out by LSRS. |
| 968 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 969 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 970 | __ B(GetExitLabel()); |
| 971 | } |
| 972 | |
| 973 | private: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 974 | // The register containing the object holding the marked object reference field. |
| 975 | vixl32::Register obj_; |
| 976 | // The offset, index and scale factor to access the reference in `obj_`. |
| 977 | uint32_t offset_; |
| 978 | Location index_; |
| 979 | ScaleFactor scale_factor_; |
| 980 | // Is a null check required? |
| 981 | bool needs_null_check_; |
| 982 | // A temporary register used to hold the lock word of `obj_`. |
| 983 | vixl32::Register temp_; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 984 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 985 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierSlowPathARMVIXL); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 986 | }; |
| 987 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 988 | // Slow path loading `obj`'s lock word, loading a reference from |
| 989 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 990 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 991 | // read barrier). If needed, this slow path also atomically updates |
| 992 | // the field `obj.field` in the object `obj` holding this reference |
| 993 | // after marking (contrary to |
| 994 | // LoadReferenceWithBakerReadBarrierSlowPathARMVIXL above, which never |
| 995 | // tries to update `obj.field`). |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 996 | // |
| 997 | // This means that after the execution of this slow path, both `ref` |
| 998 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 999 | // hold the same to-space reference (unless another thread installed |
| 1000 | // another object reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 1001 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1002 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 1003 | // barrier marking runtime entry point to be invoked or an empty |
| 1004 | // location; in the latter case, the read barrier marking runtime |
| 1005 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1006 | class LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL |
| 1007 | : public ReadBarrierMarkSlowPathBaseARMVIXL { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1008 | public: |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 1009 | LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL( |
| 1010 | HInstruction* instruction, |
| 1011 | Location ref, |
| 1012 | vixl32::Register obj, |
| 1013 | uint32_t offset, |
| 1014 | Location index, |
| 1015 | ScaleFactor scale_factor, |
| 1016 | bool needs_null_check, |
| 1017 | vixl32::Register temp1, |
| 1018 | vixl32::Register temp2, |
| 1019 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1020 | : ReadBarrierMarkSlowPathBaseARMVIXL(instruction, ref, entrypoint), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1021 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1022 | offset_(offset), |
| 1023 | index_(index), |
| 1024 | scale_factor_(scale_factor), |
| 1025 | needs_null_check_(needs_null_check), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1026 | temp1_(temp1), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1027 | temp2_(temp2) { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1028 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1029 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | const char* GetDescription() const OVERRIDE { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1033 | return "LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL"; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1037 | LocationSummary* locations = instruction_->GetLocations(); |
| 1038 | vixl32::Register ref_reg = RegisterFrom(ref_); |
| 1039 | DCHECK(locations->CanCall()); |
| 1040 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg.GetCode())) << ref_reg; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1041 | DCHECK_NE(ref_.reg(), LocationFrom(temp1_).reg()); |
| 1042 | |
| 1043 | // 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] | 1044 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 1045 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 1046 | << instruction_->DebugName(); |
| 1047 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1048 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1049 | DCHECK_EQ(offset_, 0u); |
| 1050 | DCHECK_EQ(scale_factor_, ScaleFactor::TIMES_1); |
| 1051 | Location field_offset = index_; |
| 1052 | DCHECK(field_offset.IsRegisterPair()) << field_offset; |
| 1053 | |
| 1054 | // Temporary register `temp1_`, used to store the lock word, must |
| 1055 | // not be IP, as we may use it to emit the reference load (in the |
| 1056 | // call to GenerateRawReferenceLoad below), and we need the lock |
| 1057 | // word to still be in `temp1_` after the reference load. |
| 1058 | DCHECK(!temp1_.Is(ip)); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1059 | |
| 1060 | __ Bind(GetEntryLabel()); |
| 1061 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 1062 | // The implementation is similar to LoadReferenceWithBakerReadBarrierSlowPathARMVIXL's: |
| 1063 | // |
| 1064 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 1065 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 1066 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 1067 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 1068 | // if (is_gray) { |
| 1069 | // old_ref = ref; |
| 1070 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 1071 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 1072 | // } |
| 1073 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1074 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 1075 | |
| 1076 | // /* int32_t */ monitor = obj->monitor_ |
| 1077 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 1078 | arm_codegen->GetAssembler()->LoadFromOffset(kLoadWord, temp1_, obj_, monitor_offset); |
| 1079 | if (needs_null_check_) { |
| 1080 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| 1081 | } |
| 1082 | // /* LockWord */ lock_word = LockWord(monitor) |
| 1083 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 1084 | "art::LockWord and int32_t have different sizes."); |
| 1085 | |
| 1086 | // Introduce a dependency on the lock_word including the rb_state, |
| 1087 | // which shall prevent load-load reordering without using |
| 1088 | // a memory barrier (which would be more expensive). |
| 1089 | // `obj` is unchanged by this operation, but its value now depends |
| 1090 | // on `temp`. |
| 1091 | __ Add(obj_, obj_, Operand(temp1_, ShiftType::LSR, 32)); |
| 1092 | |
| 1093 | // The actual reference load. |
| 1094 | // A possible implicit null check has already been handled above. |
| 1095 | arm_codegen->GenerateRawReferenceLoad( |
| 1096 | instruction_, ref_, obj_, offset_, index_, scale_factor_, /* needs_null_check */ false); |
| 1097 | |
| 1098 | // Mark the object `ref` when `obj` is gray. |
| 1099 | // |
| 1100 | // if (rb_state == ReadBarrier::GrayState()) |
| 1101 | // ref = ReadBarrier::Mark(ref); |
| 1102 | // |
| 1103 | // Given the numeric representation, it's enough to check the low bit of the |
| 1104 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 1105 | // which can be a 16-bit instruction unlike the TST immediate. |
| 1106 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 1107 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 1108 | __ Lsrs(temp1_, temp1_, LockWord::kReadBarrierStateShift + 1); |
| 1109 | __ B(cc, GetExitLabel()); // Carry flag is the last bit shifted out by LSRS. |
| 1110 | |
| 1111 | // Save the old value of the reference before marking it. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1112 | // Note that we cannot use IP to save the old reference, as IP is |
| 1113 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 1114 | // need the old reference after the call to that entry point. |
| 1115 | DCHECK(!temp1_.Is(ip)); |
| 1116 | __ Mov(temp1_, ref_reg); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 1117 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1118 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1119 | |
| 1120 | // If the new reference is different from the old reference, |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1121 | // update the field in the holder (`*(obj_ + field_offset)`). |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1122 | // |
| 1123 | // Note that this field could also hold a different object, if |
| 1124 | // another thread had concurrently changed it. In that case, the |
Anton Kirilov | 349e61f | 2017-12-15 17:11:33 +0000 | [diff] [blame] | 1125 | // LDREX/CMP/BNE sequence of instructions in the compare-and-set |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1126 | // (CAS) operation below would abort the CAS, leaving the field |
| 1127 | // as-is. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1128 | __ Cmp(temp1_, ref_reg); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1129 | __ B(eq, GetExitLabel()); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1130 | |
| 1131 | // Update the the holder's field atomically. This may fail if |
| 1132 | // mutator updates before us, but it's OK. This is achieved |
| 1133 | // using a strong compare-and-set (CAS) operation with relaxed |
| 1134 | // memory synchronization ordering, where the expected value is |
| 1135 | // the old reference and the desired value is the new reference. |
| 1136 | |
| 1137 | UseScratchRegisterScope temps(arm_codegen->GetVIXLAssembler()); |
| 1138 | // Convenience aliases. |
| 1139 | vixl32::Register base = obj_; |
| 1140 | // The UnsafeCASObject intrinsic uses a register pair as field |
| 1141 | // offset ("long offset"), of which only the low part contains |
| 1142 | // data. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1143 | vixl32::Register offset = LowRegisterFrom(field_offset); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1144 | vixl32::Register expected = temp1_; |
| 1145 | vixl32::Register value = ref_reg; |
| 1146 | vixl32::Register tmp_ptr = temps.Acquire(); // Pointer to actual memory. |
| 1147 | vixl32::Register tmp = temp2_; // Value in memory. |
| 1148 | |
| 1149 | __ Add(tmp_ptr, base, offset); |
| 1150 | |
| 1151 | if (kPoisonHeapReferences) { |
| 1152 | arm_codegen->GetAssembler()->PoisonHeapReference(expected); |
| 1153 | if (value.Is(expected)) { |
| 1154 | // Do not poison `value`, as it is the same register as |
| 1155 | // `expected`, which has just been poisoned. |
| 1156 | } else { |
| 1157 | arm_codegen->GetAssembler()->PoisonHeapReference(value); |
| 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | // do { |
| 1162 | // tmp = [r_ptr] - expected; |
| 1163 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 1164 | |
Anton Kirilov | 349e61f | 2017-12-15 17:11:33 +0000 | [diff] [blame] | 1165 | vixl32::Label loop_head, comparison_failed, exit_loop; |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1166 | __ Bind(&loop_head); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1167 | __ Ldrex(tmp, MemOperand(tmp_ptr)); |
Anton Kirilov | 349e61f | 2017-12-15 17:11:33 +0000 | [diff] [blame] | 1168 | __ Cmp(tmp, expected); |
| 1169 | __ B(ne, &comparison_failed, /* far_target */ false); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1170 | __ Strex(tmp, value, MemOperand(tmp_ptr)); |
Anton Kirilov | 349e61f | 2017-12-15 17:11:33 +0000 | [diff] [blame] | 1171 | __ CompareAndBranchIfZero(tmp, &exit_loop, /* far_target */ false); |
| 1172 | __ B(&loop_head); |
| 1173 | __ Bind(&comparison_failed); |
| 1174 | __ Clrex(); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1175 | __ Bind(&exit_loop); |
| 1176 | |
| 1177 | if (kPoisonHeapReferences) { |
| 1178 | arm_codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 1179 | if (value.Is(expected)) { |
| 1180 | // Do not unpoison `value`, as it is the same register as |
| 1181 | // `expected`, which has just been unpoisoned. |
| 1182 | } else { |
| 1183 | arm_codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 1184 | } |
| 1185 | } |
| 1186 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1187 | __ B(GetExitLabel()); |
| 1188 | } |
| 1189 | |
| 1190 | private: |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1191 | // The register containing the object holding the marked object reference field. |
| 1192 | const vixl32::Register obj_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1193 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1194 | uint32_t offset_; |
| 1195 | Location index_; |
| 1196 | ScaleFactor scale_factor_; |
| 1197 | // Is a null check required? |
| 1198 | bool needs_null_check_; |
| 1199 | // A temporary register used to hold the lock word of `obj_`; and |
| 1200 | // also to hold the original reference value, when the reference is |
| 1201 | // marked. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1202 | const vixl32::Register temp1_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1203 | // A temporary register used in the implementation of the CAS, to |
| 1204 | // update the object's reference field. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1205 | const vixl32::Register temp2_; |
| 1206 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1207 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1208 | }; |
| 1209 | |
| 1210 | // Slow path generating a read barrier for a heap reference. |
| 1211 | class ReadBarrierForHeapReferenceSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 1212 | public: |
| 1213 | ReadBarrierForHeapReferenceSlowPathARMVIXL(HInstruction* instruction, |
| 1214 | Location out, |
| 1215 | Location ref, |
| 1216 | Location obj, |
| 1217 | uint32_t offset, |
| 1218 | Location index) |
| 1219 | : SlowPathCodeARMVIXL(instruction), |
| 1220 | out_(out), |
| 1221 | ref_(ref), |
| 1222 | obj_(obj), |
| 1223 | offset_(offset), |
| 1224 | index_(index) { |
| 1225 | DCHECK(kEmitCompilerReadBarrier); |
| 1226 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 1227 | // has been overwritten by (or after) the heap object reference load |
| 1228 | // to be instrumented, e.g.: |
| 1229 | // |
| 1230 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
| 1231 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| 1232 | // |
| 1233 | // In that case, we have lost the information about the original |
| 1234 | // object, and the emitted read barrier cannot work properly. |
| 1235 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 1236 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 1237 | } |
| 1238 | |
| 1239 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1240 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 1241 | LocationSummary* locations = instruction_->GetLocations(); |
| 1242 | vixl32::Register reg_out = RegisterFrom(out_); |
| 1243 | DCHECK(locations->CanCall()); |
| 1244 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.GetCode())); |
| 1245 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 1246 | instruction_->IsStaticFieldGet() || |
| 1247 | instruction_->IsArrayGet() || |
| 1248 | instruction_->IsInstanceOf() || |
| 1249 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 1250 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1251 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 1252 | << instruction_->DebugName(); |
| 1253 | // The read barrier instrumentation of object ArrayGet |
| 1254 | // instructions does not support the HIntermediateAddress |
| 1255 | // instruction. |
| 1256 | DCHECK(!(instruction_->IsArrayGet() && |
| 1257 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 1258 | |
| 1259 | __ Bind(GetEntryLabel()); |
| 1260 | SaveLiveRegisters(codegen, locations); |
| 1261 | |
| 1262 | // We may have to change the index's value, but as `index_` is a |
| 1263 | // constant member (like other "inputs" of this slow path), |
| 1264 | // introduce a copy of it, `index`. |
| 1265 | Location index = index_; |
| 1266 | if (index_.IsValid()) { |
| 1267 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 1268 | if (instruction_->IsArrayGet()) { |
| 1269 | // Compute the actual memory offset and store it in `index`. |
| 1270 | vixl32::Register index_reg = RegisterFrom(index_); |
| 1271 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg.GetCode())); |
| 1272 | if (codegen->IsCoreCalleeSaveRegister(index_reg.GetCode())) { |
| 1273 | // We are about to change the value of `index_reg` (see the |
Roland Levillain | 9983e30 | 2017-07-14 14:34:22 +0100 | [diff] [blame] | 1274 | // calls to art::arm::ArmVIXLMacroAssembler::Lsl and |
| 1275 | // art::arm::ArmVIXLMacroAssembler::Add below), but it has |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1276 | // not been saved by the previous call to |
| 1277 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1278 | // callee-save register -- |
| 1279 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1280 | // callee-save registers, as it has been designed with the |
| 1281 | // assumption that callee-save registers are supposed to be |
| 1282 | // handled by the called function. So, as a callee-save |
| 1283 | // register, `index_reg` _would_ eventually be saved onto |
| 1284 | // the stack, but it would be too late: we would have |
| 1285 | // changed its value earlier. Therefore, we manually save |
| 1286 | // it here into another freely available register, |
| 1287 | // `free_reg`, chosen of course among the caller-save |
| 1288 | // registers (as a callee-save `free_reg` register would |
| 1289 | // exhibit the same problem). |
| 1290 | // |
| 1291 | // Note we could have requested a temporary register from |
| 1292 | // the register allocator instead; but we prefer not to, as |
| 1293 | // this is a slow path, and we know we can find a |
| 1294 | // caller-save register that is available. |
| 1295 | vixl32::Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1296 | __ Mov(free_reg, index_reg); |
| 1297 | index_reg = free_reg; |
| 1298 | index = LocationFrom(index_reg); |
| 1299 | } else { |
| 1300 | // The initial register stored in `index_` has already been |
| 1301 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1302 | // (as it is not a callee-save register), so we can freely |
| 1303 | // use it. |
| 1304 | } |
| 1305 | // Shifting the index value contained in `index_reg` by the scale |
| 1306 | // factor (2) cannot overflow in practice, as the runtime is |
| 1307 | // unable to allocate object arrays with a size larger than |
| 1308 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 1309 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 1310 | static_assert( |
| 1311 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1312 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1313 | __ Add(index_reg, index_reg, offset_); |
| 1314 | } else { |
| 1315 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1316 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1317 | // (as in the case of ArrayGet), as it is actually an offset |
| 1318 | // to an object field within an object. |
| 1319 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| 1320 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1321 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1322 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1323 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 1324 | DCHECK_EQ(offset_, 0U); |
| 1325 | DCHECK(index_.IsRegisterPair()); |
| 1326 | // UnsafeGet's offset location is a register pair, the low |
| 1327 | // part contains the correct offset. |
| 1328 | index = index_.ToLow(); |
| 1329 | } |
| 1330 | } |
| 1331 | |
| 1332 | // We're moving two or three locations to locations that could |
| 1333 | // overlap, so we need a parallel move resolver. |
| 1334 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1335 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1336 | parallel_move.AddMove(ref_, |
| 1337 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1338 | DataType::Type::kReference, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1339 | nullptr); |
| 1340 | parallel_move.AddMove(obj_, |
| 1341 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1342 | DataType::Type::kReference, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1343 | nullptr); |
| 1344 | if (index.IsValid()) { |
| 1345 | parallel_move.AddMove(index, |
| 1346 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1347 | DataType::Type::kInt32, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1348 | nullptr); |
| 1349 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1350 | } else { |
| 1351 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1352 | __ Mov(calling_convention.GetRegisterAt(2), offset_); |
| 1353 | } |
| 1354 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
| 1355 | CheckEntrypointTypes< |
| 1356 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1357 | arm_codegen->Move32(out_, LocationFrom(r0)); |
| 1358 | |
| 1359 | RestoreLiveRegisters(codegen, locations); |
| 1360 | __ B(GetExitLabel()); |
| 1361 | } |
| 1362 | |
| 1363 | const char* GetDescription() const OVERRIDE { |
| 1364 | return "ReadBarrierForHeapReferenceSlowPathARMVIXL"; |
| 1365 | } |
| 1366 | |
| 1367 | private: |
| 1368 | vixl32::Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 1369 | uint32_t ref = RegisterFrom(ref_).GetCode(); |
| 1370 | uint32_t obj = RegisterFrom(obj_).GetCode(); |
| 1371 | for (uint32_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1372 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1373 | return vixl32::Register(i); |
| 1374 | } |
| 1375 | } |
| 1376 | // We shall never fail to find a free caller-save register, as |
| 1377 | // there are more than two core caller-save registers on ARM |
| 1378 | // (meaning it is possible to find one which is different from |
| 1379 | // `ref` and `obj`). |
| 1380 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1381 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 1382 | UNREACHABLE(); |
| 1383 | } |
| 1384 | |
| 1385 | const Location out_; |
| 1386 | const Location ref_; |
| 1387 | const Location obj_; |
| 1388 | const uint32_t offset_; |
| 1389 | // An additional location containing an index to an array. |
| 1390 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1391 | // UnsafeGetObjectVolatile intrinsics. |
| 1392 | const Location index_; |
| 1393 | |
| 1394 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARMVIXL); |
| 1395 | }; |
| 1396 | |
| 1397 | // Slow path generating a read barrier for a GC root. |
| 1398 | class ReadBarrierForRootSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 1399 | public: |
| 1400 | ReadBarrierForRootSlowPathARMVIXL(HInstruction* instruction, Location out, Location root) |
| 1401 | : SlowPathCodeARMVIXL(instruction), out_(out), root_(root) { |
| 1402 | DCHECK(kEmitCompilerReadBarrier); |
| 1403 | } |
| 1404 | |
| 1405 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1406 | LocationSummary* locations = instruction_->GetLocations(); |
| 1407 | vixl32::Register reg_out = RegisterFrom(out_); |
| 1408 | DCHECK(locations->CanCall()); |
| 1409 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.GetCode())); |
| 1410 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1411 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1412 | << instruction_->DebugName(); |
| 1413 | |
| 1414 | __ Bind(GetEntryLabel()); |
| 1415 | SaveLiveRegisters(codegen, locations); |
| 1416 | |
| 1417 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 1418 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 1419 | arm_codegen->Move32(LocationFrom(calling_convention.GetRegisterAt(0)), root_); |
| 1420 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| 1421 | instruction_, |
| 1422 | instruction_->GetDexPc(), |
| 1423 | this); |
| 1424 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1425 | arm_codegen->Move32(out_, LocationFrom(r0)); |
| 1426 | |
| 1427 | RestoreLiveRegisters(codegen, locations); |
| 1428 | __ B(GetExitLabel()); |
| 1429 | } |
| 1430 | |
| 1431 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARMVIXL"; } |
| 1432 | |
| 1433 | private: |
| 1434 | const Location out_; |
| 1435 | const Location root_; |
| 1436 | |
| 1437 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARMVIXL); |
| 1438 | }; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 1439 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1440 | inline vixl32::Condition ARMCondition(IfCondition cond) { |
| 1441 | switch (cond) { |
| 1442 | case kCondEQ: return eq; |
| 1443 | case kCondNE: return ne; |
| 1444 | case kCondLT: return lt; |
| 1445 | case kCondLE: return le; |
| 1446 | case kCondGT: return gt; |
| 1447 | case kCondGE: return ge; |
| 1448 | case kCondB: return lo; |
| 1449 | case kCondBE: return ls; |
| 1450 | case kCondA: return hi; |
| 1451 | case kCondAE: return hs; |
| 1452 | } |
| 1453 | LOG(FATAL) << "Unreachable"; |
| 1454 | UNREACHABLE(); |
| 1455 | } |
| 1456 | |
| 1457 | // Maps signed condition to unsigned condition. |
| 1458 | inline vixl32::Condition ARMUnsignedCondition(IfCondition cond) { |
| 1459 | switch (cond) { |
| 1460 | case kCondEQ: return eq; |
| 1461 | case kCondNE: return ne; |
| 1462 | // Signed to unsigned. |
| 1463 | case kCondLT: return lo; |
| 1464 | case kCondLE: return ls; |
| 1465 | case kCondGT: return hi; |
| 1466 | case kCondGE: return hs; |
| 1467 | // Unsigned remain unchanged. |
| 1468 | case kCondB: return lo; |
| 1469 | case kCondBE: return ls; |
| 1470 | case kCondA: return hi; |
| 1471 | case kCondAE: return hs; |
| 1472 | } |
| 1473 | LOG(FATAL) << "Unreachable"; |
| 1474 | UNREACHABLE(); |
| 1475 | } |
| 1476 | |
| 1477 | inline vixl32::Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 1478 | // The ARM condition codes can express all the necessary branches, see the |
| 1479 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 1480 | // There is no dex instruction or HIR that would need the missing conditions |
| 1481 | // "equal or unordered" or "not equal". |
| 1482 | switch (cond) { |
| 1483 | case kCondEQ: return eq; |
| 1484 | case kCondNE: return ne /* unordered */; |
| 1485 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 1486 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 1487 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 1488 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 1489 | default: |
| 1490 | LOG(FATAL) << "UNREACHABLE"; |
| 1491 | UNREACHABLE(); |
| 1492 | } |
| 1493 | } |
| 1494 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1495 | inline ShiftType ShiftFromOpKind(HDataProcWithShifterOp::OpKind op_kind) { |
| 1496 | switch (op_kind) { |
| 1497 | case HDataProcWithShifterOp::kASR: return ShiftType::ASR; |
| 1498 | case HDataProcWithShifterOp::kLSL: return ShiftType::LSL; |
| 1499 | case HDataProcWithShifterOp::kLSR: return ShiftType::LSR; |
| 1500 | default: |
| 1501 | LOG(FATAL) << "Unexpected op kind " << op_kind; |
| 1502 | UNREACHABLE(); |
| 1503 | } |
| 1504 | } |
| 1505 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1506 | void CodeGeneratorARMVIXL::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 1507 | stream << vixl32::Register(reg); |
| 1508 | } |
| 1509 | |
| 1510 | void CodeGeneratorARMVIXL::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| 1511 | stream << vixl32::SRegister(reg); |
| 1512 | } |
| 1513 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1514 | static uint32_t ComputeSRegisterListMask(const SRegisterList& regs) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1515 | uint32_t mask = 0; |
| 1516 | for (uint32_t i = regs.GetFirstSRegister().GetCode(); |
| 1517 | i <= regs.GetLastSRegister().GetCode(); |
| 1518 | ++i) { |
| 1519 | mask |= (1 << i); |
| 1520 | } |
| 1521 | return mask; |
| 1522 | } |
| 1523 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1524 | // Saves the register in the stack. Returns the size taken on stack. |
| 1525 | size_t CodeGeneratorARMVIXL::SaveCoreRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1526 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1527 | TODO_VIXL32(FATAL); |
| 1528 | return 0; |
| 1529 | } |
| 1530 | |
| 1531 | // Restores the register from the stack. Returns the size taken on stack. |
| 1532 | size_t CodeGeneratorARMVIXL::RestoreCoreRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1533 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1534 | TODO_VIXL32(FATAL); |
| 1535 | return 0; |
| 1536 | } |
| 1537 | |
| 1538 | size_t CodeGeneratorARMVIXL::SaveFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1539 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1540 | TODO_VIXL32(FATAL); |
| 1541 | return 0; |
| 1542 | } |
| 1543 | |
| 1544 | size_t CodeGeneratorARMVIXL::RestoreFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1545 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1546 | TODO_VIXL32(FATAL); |
| 1547 | return 0; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 1548 | } |
| 1549 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1550 | static void GenerateDataProcInstruction(HInstruction::InstructionKind kind, |
| 1551 | vixl32::Register out, |
| 1552 | vixl32::Register first, |
| 1553 | const Operand& second, |
| 1554 | CodeGeneratorARMVIXL* codegen) { |
| 1555 | if (second.IsImmediate() && second.GetImmediate() == 0) { |
| 1556 | const Operand in = kind == HInstruction::kAnd |
| 1557 | ? Operand(0) |
| 1558 | : Operand(first); |
| 1559 | |
| 1560 | __ Mov(out, in); |
| 1561 | } else { |
| 1562 | switch (kind) { |
| 1563 | case HInstruction::kAdd: |
| 1564 | __ Add(out, first, second); |
| 1565 | break; |
| 1566 | case HInstruction::kAnd: |
| 1567 | __ And(out, first, second); |
| 1568 | break; |
| 1569 | case HInstruction::kOr: |
| 1570 | __ Orr(out, first, second); |
| 1571 | break; |
| 1572 | case HInstruction::kSub: |
| 1573 | __ Sub(out, first, second); |
| 1574 | break; |
| 1575 | case HInstruction::kXor: |
| 1576 | __ Eor(out, first, second); |
| 1577 | break; |
| 1578 | default: |
| 1579 | LOG(FATAL) << "Unexpected instruction kind: " << kind; |
| 1580 | UNREACHABLE(); |
| 1581 | } |
| 1582 | } |
| 1583 | } |
| 1584 | |
| 1585 | static void GenerateDataProc(HInstruction::InstructionKind kind, |
| 1586 | const Location& out, |
| 1587 | const Location& first, |
| 1588 | const Operand& second_lo, |
| 1589 | const Operand& second_hi, |
| 1590 | CodeGeneratorARMVIXL* codegen) { |
| 1591 | const vixl32::Register first_hi = HighRegisterFrom(first); |
| 1592 | const vixl32::Register first_lo = LowRegisterFrom(first); |
| 1593 | const vixl32::Register out_hi = HighRegisterFrom(out); |
| 1594 | const vixl32::Register out_lo = LowRegisterFrom(out); |
| 1595 | |
| 1596 | if (kind == HInstruction::kAdd) { |
| 1597 | __ Adds(out_lo, first_lo, second_lo); |
| 1598 | __ Adc(out_hi, first_hi, second_hi); |
| 1599 | } else if (kind == HInstruction::kSub) { |
| 1600 | __ Subs(out_lo, first_lo, second_lo); |
| 1601 | __ Sbc(out_hi, first_hi, second_hi); |
| 1602 | } else { |
| 1603 | GenerateDataProcInstruction(kind, out_lo, first_lo, second_lo, codegen); |
| 1604 | GenerateDataProcInstruction(kind, out_hi, first_hi, second_hi, codegen); |
| 1605 | } |
| 1606 | } |
| 1607 | |
| 1608 | static Operand GetShifterOperand(vixl32::Register rm, ShiftType shift, uint32_t shift_imm) { |
| 1609 | return shift_imm == 0 ? Operand(rm) : Operand(rm, shift, shift_imm); |
| 1610 | } |
| 1611 | |
| 1612 | static void GenerateLongDataProc(HDataProcWithShifterOp* instruction, |
| 1613 | CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1614 | DCHECK_EQ(instruction->GetType(), DataType::Type::kInt64); |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1615 | DCHECK(HDataProcWithShifterOp::IsShiftOp(instruction->GetOpKind())); |
| 1616 | |
| 1617 | const LocationSummary* const locations = instruction->GetLocations(); |
| 1618 | const uint32_t shift_value = instruction->GetShiftAmount(); |
| 1619 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 1620 | const Location first = locations->InAt(0); |
| 1621 | const Location second = locations->InAt(1); |
| 1622 | const Location out = locations->Out(); |
| 1623 | const vixl32::Register first_hi = HighRegisterFrom(first); |
| 1624 | const vixl32::Register first_lo = LowRegisterFrom(first); |
| 1625 | const vixl32::Register out_hi = HighRegisterFrom(out); |
| 1626 | const vixl32::Register out_lo = LowRegisterFrom(out); |
| 1627 | const vixl32::Register second_hi = HighRegisterFrom(second); |
| 1628 | const vixl32::Register second_lo = LowRegisterFrom(second); |
| 1629 | const ShiftType shift = ShiftFromOpKind(instruction->GetOpKind()); |
| 1630 | |
| 1631 | if (shift_value >= 32) { |
| 1632 | if (shift == ShiftType::LSL) { |
| 1633 | GenerateDataProcInstruction(kind, |
| 1634 | out_hi, |
| 1635 | first_hi, |
| 1636 | Operand(second_lo, ShiftType::LSL, shift_value - 32), |
| 1637 | codegen); |
| 1638 | GenerateDataProcInstruction(kind, out_lo, first_lo, 0, codegen); |
| 1639 | } else if (shift == ShiftType::ASR) { |
| 1640 | GenerateDataProc(kind, |
| 1641 | out, |
| 1642 | first, |
| 1643 | GetShifterOperand(second_hi, ShiftType::ASR, shift_value - 32), |
| 1644 | Operand(second_hi, ShiftType::ASR, 31), |
| 1645 | codegen); |
| 1646 | } else { |
| 1647 | DCHECK_EQ(shift, ShiftType::LSR); |
| 1648 | GenerateDataProc(kind, |
| 1649 | out, |
| 1650 | first, |
| 1651 | GetShifterOperand(second_hi, ShiftType::LSR, shift_value - 32), |
| 1652 | 0, |
| 1653 | codegen); |
| 1654 | } |
| 1655 | } else { |
| 1656 | DCHECK_GT(shift_value, 1U); |
| 1657 | DCHECK_LT(shift_value, 32U); |
| 1658 | |
| 1659 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1660 | |
| 1661 | if (shift == ShiftType::LSL) { |
| 1662 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1663 | // Location::kOutputOverlap; not applicable to other cases. |
| 1664 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1665 | GenerateDataProcInstruction(kind, |
| 1666 | out_hi, |
| 1667 | first_hi, |
| 1668 | Operand(second_hi, ShiftType::LSL, shift_value), |
| 1669 | codegen); |
| 1670 | GenerateDataProcInstruction(kind, |
| 1671 | out_hi, |
| 1672 | out_hi, |
| 1673 | Operand(second_lo, ShiftType::LSR, 32 - shift_value), |
| 1674 | codegen); |
| 1675 | GenerateDataProcInstruction(kind, |
| 1676 | out_lo, |
| 1677 | first_lo, |
| 1678 | Operand(second_lo, ShiftType::LSL, shift_value), |
| 1679 | codegen); |
| 1680 | } else { |
| 1681 | const vixl32::Register temp = temps.Acquire(); |
| 1682 | |
| 1683 | __ Lsl(temp, second_hi, shift_value); |
| 1684 | __ Orr(temp, temp, Operand(second_lo, ShiftType::LSR, 32 - shift_value)); |
| 1685 | GenerateDataProc(kind, |
| 1686 | out, |
| 1687 | first, |
| 1688 | Operand(second_lo, ShiftType::LSL, shift_value), |
| 1689 | temp, |
| 1690 | codegen); |
| 1691 | } |
| 1692 | } else { |
| 1693 | DCHECK(shift == ShiftType::ASR || shift == ShiftType::LSR); |
| 1694 | |
| 1695 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1696 | // Location::kOutputOverlap; not applicable to other cases. |
| 1697 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1698 | GenerateDataProcInstruction(kind, |
| 1699 | out_lo, |
| 1700 | first_lo, |
| 1701 | Operand(second_lo, ShiftType::LSR, shift_value), |
| 1702 | codegen); |
| 1703 | GenerateDataProcInstruction(kind, |
| 1704 | out_lo, |
| 1705 | out_lo, |
| 1706 | Operand(second_hi, ShiftType::LSL, 32 - shift_value), |
| 1707 | codegen); |
| 1708 | GenerateDataProcInstruction(kind, |
| 1709 | out_hi, |
| 1710 | first_hi, |
| 1711 | Operand(second_hi, shift, shift_value), |
| 1712 | codegen); |
| 1713 | } else { |
| 1714 | const vixl32::Register temp = temps.Acquire(); |
| 1715 | |
| 1716 | __ Lsr(temp, second_lo, shift_value); |
| 1717 | __ Orr(temp, temp, Operand(second_hi, ShiftType::LSL, 32 - shift_value)); |
| 1718 | GenerateDataProc(kind, |
| 1719 | out, |
| 1720 | first, |
| 1721 | temp, |
| 1722 | Operand(second_hi, shift, shift_value), |
| 1723 | codegen); |
| 1724 | } |
| 1725 | } |
| 1726 | } |
| 1727 | } |
| 1728 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1729 | static void GenerateVcmp(HInstruction* instruction, CodeGeneratorARMVIXL* codegen) { |
| 1730 | const Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1731 | if (rhs_loc.IsConstant()) { |
| 1732 | // 0.0 is the only immediate that can be encoded directly in |
| 1733 | // a VCMP instruction. |
| 1734 | // |
| 1735 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1736 | // specify that in a floating-point comparison, positive zero |
| 1737 | // and negative zero are considered equal, so we can use the |
| 1738 | // literal 0.0 for both cases here. |
| 1739 | // |
| 1740 | // Note however that some methods (Float.equal, Float.compare, |
| 1741 | // Float.compareTo, Double.equal, Double.compare, |
| 1742 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1743 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1744 | // -0.0. So if we ever translate calls to these methods into a |
| 1745 | // HCompare instruction, we must handle the -0.0 case with |
| 1746 | // care here. |
| 1747 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1748 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1749 | const DataType::Type type = instruction->InputAt(0)->GetType(); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1750 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1751 | if (type == DataType::Type::kFloat32) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1752 | __ Vcmp(F32, InputSRegisterAt(instruction, 0), 0.0); |
| 1753 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1754 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1755 | __ Vcmp(F64, InputDRegisterAt(instruction, 0), 0.0); |
| 1756 | } |
| 1757 | } else { |
| 1758 | __ Vcmp(InputVRegisterAt(instruction, 0), InputVRegisterAt(instruction, 1)); |
| 1759 | } |
| 1760 | } |
| 1761 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1762 | static int64_t AdjustConstantForCondition(int64_t value, |
| 1763 | IfCondition* condition, |
| 1764 | IfCondition* opposite) { |
| 1765 | if (value == 1) { |
| 1766 | if (*condition == kCondB) { |
| 1767 | value = 0; |
| 1768 | *condition = kCondEQ; |
| 1769 | *opposite = kCondNE; |
| 1770 | } else if (*condition == kCondAE) { |
| 1771 | value = 0; |
| 1772 | *condition = kCondNE; |
| 1773 | *opposite = kCondEQ; |
| 1774 | } |
| 1775 | } else if (value == -1) { |
| 1776 | if (*condition == kCondGT) { |
| 1777 | value = 0; |
| 1778 | *condition = kCondGE; |
| 1779 | *opposite = kCondLT; |
| 1780 | } else if (*condition == kCondLE) { |
| 1781 | value = 0; |
| 1782 | *condition = kCondLT; |
| 1783 | *opposite = kCondGE; |
| 1784 | } |
| 1785 | } |
| 1786 | |
| 1787 | return value; |
| 1788 | } |
| 1789 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1790 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateLongTestConstant( |
| 1791 | HCondition* condition, |
| 1792 | bool invert, |
| 1793 | CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1794 | DCHECK_EQ(condition->GetLeft()->GetType(), DataType::Type::kInt64); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1795 | |
| 1796 | const LocationSummary* const locations = condition->GetLocations(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1797 | IfCondition cond = condition->GetCondition(); |
| 1798 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1799 | |
| 1800 | if (invert) { |
| 1801 | std::swap(cond, opposite); |
| 1802 | } |
| 1803 | |
| 1804 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1805 | const Location left = locations->InAt(0); |
| 1806 | const Location right = locations->InAt(1); |
| 1807 | |
| 1808 | DCHECK(right.IsConstant()); |
| 1809 | |
| 1810 | const vixl32::Register left_high = HighRegisterFrom(left); |
| 1811 | const vixl32::Register left_low = LowRegisterFrom(left); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1812 | int64_t value = AdjustConstantForCondition(Int64ConstantFrom(right), &cond, &opposite); |
| 1813 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1814 | |
| 1815 | // Comparisons against 0 are common enough to deserve special attention. |
| 1816 | if (value == 0) { |
| 1817 | switch (cond) { |
| 1818 | case kCondNE: |
| 1819 | // x > 0 iff x != 0 when the comparison is unsigned. |
| 1820 | case kCondA: |
| 1821 | ret = std::make_pair(ne, eq); |
| 1822 | FALLTHROUGH_INTENDED; |
| 1823 | case kCondEQ: |
| 1824 | // x <= 0 iff x == 0 when the comparison is unsigned. |
| 1825 | case kCondBE: |
| 1826 | __ Orrs(temps.Acquire(), left_low, left_high); |
| 1827 | return ret; |
| 1828 | case kCondLT: |
| 1829 | case kCondGE: |
| 1830 | __ Cmp(left_high, 0); |
| 1831 | return std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
| 1832 | // Trivially true or false. |
| 1833 | case kCondB: |
| 1834 | ret = std::make_pair(ne, eq); |
| 1835 | FALLTHROUGH_INTENDED; |
| 1836 | case kCondAE: |
| 1837 | __ Cmp(left_low, left_low); |
| 1838 | return ret; |
| 1839 | default: |
| 1840 | break; |
| 1841 | } |
| 1842 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1843 | |
| 1844 | switch (cond) { |
| 1845 | case kCondEQ: |
| 1846 | case kCondNE: |
| 1847 | case kCondB: |
| 1848 | case kCondBE: |
| 1849 | case kCondA: |
| 1850 | case kCondAE: { |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1851 | const uint32_t value_low = Low32Bits(value); |
| 1852 | Operand operand_low(value_low); |
| 1853 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1854 | __ Cmp(left_high, High32Bits(value)); |
| 1855 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1856 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1857 | // we must ensure that the operands corresponding to the least significant |
| 1858 | // halves of the inputs fit into a 16-bit CMP encoding. |
| 1859 | if (!left_low.IsLow() || !IsUint<8>(value_low)) { |
| 1860 | operand_low = Operand(temps.Acquire()); |
| 1861 | __ Mov(LeaveFlags, operand_low.GetBaseRegister(), value_low); |
| 1862 | } |
| 1863 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1864 | // We use the scope because of the IT block that follows. |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1865 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1866 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1867 | CodeBufferCheckScope::kExactSize); |
| 1868 | |
| 1869 | __ it(eq); |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1870 | __ cmp(eq, left_low, operand_low); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1871 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1872 | break; |
| 1873 | } |
| 1874 | case kCondLE: |
| 1875 | case kCondGT: |
| 1876 | // Trivially true or false. |
| 1877 | if (value == std::numeric_limits<int64_t>::max()) { |
| 1878 | __ Cmp(left_low, left_low); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1879 | 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] | 1880 | break; |
| 1881 | } |
| 1882 | |
| 1883 | if (cond == kCondLE) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1884 | DCHECK_EQ(opposite, kCondGT); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1885 | cond = kCondLT; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1886 | opposite = kCondGE; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1887 | } else { |
| 1888 | DCHECK_EQ(cond, kCondGT); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1889 | DCHECK_EQ(opposite, kCondLE); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1890 | cond = kCondGE; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1891 | opposite = kCondLT; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1892 | } |
| 1893 | |
| 1894 | value++; |
| 1895 | FALLTHROUGH_INTENDED; |
| 1896 | case kCondGE: |
| 1897 | case kCondLT: { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1898 | __ Cmp(left_low, Low32Bits(value)); |
| 1899 | __ Sbcs(temps.Acquire(), left_high, High32Bits(value)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1900 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1901 | break; |
| 1902 | } |
| 1903 | default: |
| 1904 | LOG(FATAL) << "Unreachable"; |
| 1905 | UNREACHABLE(); |
| 1906 | } |
| 1907 | |
| 1908 | return ret; |
| 1909 | } |
| 1910 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1911 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateLongTest( |
| 1912 | HCondition* condition, |
| 1913 | bool invert, |
| 1914 | CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1915 | DCHECK_EQ(condition->GetLeft()->GetType(), DataType::Type::kInt64); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1916 | |
| 1917 | const LocationSummary* const locations = condition->GetLocations(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1918 | IfCondition cond = condition->GetCondition(); |
| 1919 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1920 | |
| 1921 | if (invert) { |
| 1922 | std::swap(cond, opposite); |
| 1923 | } |
| 1924 | |
| 1925 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1926 | Location left = locations->InAt(0); |
| 1927 | Location right = locations->InAt(1); |
| 1928 | |
| 1929 | DCHECK(right.IsRegisterPair()); |
| 1930 | |
| 1931 | switch (cond) { |
| 1932 | case kCondEQ: |
| 1933 | case kCondNE: |
| 1934 | case kCondB: |
| 1935 | case kCondBE: |
| 1936 | case kCondA: |
| 1937 | case kCondAE: { |
| 1938 | __ Cmp(HighRegisterFrom(left), HighRegisterFrom(right)); |
| 1939 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1940 | // We use the scope because of the IT block that follows. |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1941 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1942 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1943 | CodeBufferCheckScope::kExactSize); |
| 1944 | |
| 1945 | __ it(eq); |
| 1946 | __ cmp(eq, LowRegisterFrom(left), LowRegisterFrom(right)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1947 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1948 | break; |
| 1949 | } |
| 1950 | case kCondLE: |
| 1951 | case kCondGT: |
| 1952 | if (cond == kCondLE) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1953 | DCHECK_EQ(opposite, kCondGT); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1954 | cond = kCondGE; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1955 | opposite = kCondLT; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1956 | } else { |
| 1957 | DCHECK_EQ(cond, kCondGT); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1958 | DCHECK_EQ(opposite, kCondLE); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1959 | cond = kCondLT; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1960 | opposite = kCondGE; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1961 | } |
| 1962 | |
| 1963 | std::swap(left, right); |
| 1964 | FALLTHROUGH_INTENDED; |
| 1965 | case kCondGE: |
| 1966 | case kCondLT: { |
| 1967 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1968 | |
| 1969 | __ Cmp(LowRegisterFrom(left), LowRegisterFrom(right)); |
| 1970 | __ Sbcs(temps.Acquire(), HighRegisterFrom(left), HighRegisterFrom(right)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1971 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1972 | break; |
| 1973 | } |
| 1974 | default: |
| 1975 | LOG(FATAL) << "Unreachable"; |
| 1976 | UNREACHABLE(); |
| 1977 | } |
| 1978 | |
| 1979 | return ret; |
| 1980 | } |
| 1981 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1982 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateTest(HCondition* condition, |
| 1983 | bool invert, |
| 1984 | CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1985 | const DataType::Type type = condition->GetLeft()->GetType(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1986 | IfCondition cond = condition->GetCondition(); |
| 1987 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1988 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1989 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1990 | if (invert) { |
| 1991 | std::swap(cond, opposite); |
| 1992 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1993 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1994 | if (type == DataType::Type::kInt64) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1995 | ret = condition->GetLocations()->InAt(1).IsConstant() |
| 1996 | ? GenerateLongTestConstant(condition, invert, codegen) |
| 1997 | : GenerateLongTest(condition, invert, codegen); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1998 | } else if (DataType::IsFloatingPointType(type)) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1999 | GenerateVcmp(condition, codegen); |
| 2000 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 2001 | ret = std::make_pair(ARMFPCondition(cond, condition->IsGtBias()), |
| 2002 | ARMFPCondition(opposite, condition->IsGtBias())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2003 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2004 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2005 | __ Cmp(InputRegisterAt(condition, 0), InputOperandAt(condition, 1)); |
| 2006 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | return ret; |
| 2010 | } |
| 2011 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2012 | static void GenerateConditionGeneric(HCondition* cond, CodeGeneratorARMVIXL* codegen) { |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2013 | const vixl32::Register out = OutputRegister(cond); |
| 2014 | const auto condition = GenerateTest(cond, false, codegen); |
| 2015 | |
| 2016 | __ Mov(LeaveFlags, out, 0); |
| 2017 | |
| 2018 | if (out.IsLow()) { |
| 2019 | // We use the scope because of the IT block that follows. |
| 2020 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 2021 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 2022 | CodeBufferCheckScope::kExactSize); |
| 2023 | |
| 2024 | __ it(condition.first); |
| 2025 | __ mov(condition.first, out, 1); |
| 2026 | } else { |
| 2027 | vixl32::Label done_label; |
| 2028 | vixl32::Label* const final_label = codegen->GetFinalLabel(cond, &done_label); |
| 2029 | |
| 2030 | __ B(condition.second, final_label, /* far_target */ false); |
| 2031 | __ Mov(out, 1); |
| 2032 | |
| 2033 | if (done_label.IsReferenced()) { |
| 2034 | __ Bind(&done_label); |
| 2035 | } |
| 2036 | } |
| 2037 | } |
| 2038 | |
| 2039 | static void GenerateEqualLong(HCondition* cond, CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2040 | DCHECK_EQ(cond->GetLeft()->GetType(), DataType::Type::kInt64); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2041 | |
| 2042 | const LocationSummary* const locations = cond->GetLocations(); |
| 2043 | IfCondition condition = cond->GetCondition(); |
| 2044 | const vixl32::Register out = OutputRegister(cond); |
| 2045 | const Location left = locations->InAt(0); |
| 2046 | const Location right = locations->InAt(1); |
| 2047 | vixl32::Register left_high = HighRegisterFrom(left); |
| 2048 | vixl32::Register left_low = LowRegisterFrom(left); |
| 2049 | vixl32::Register temp; |
| 2050 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 2051 | |
| 2052 | if (right.IsConstant()) { |
| 2053 | IfCondition opposite = cond->GetOppositeCondition(); |
| 2054 | const int64_t value = AdjustConstantForCondition(Int64ConstantFrom(right), |
| 2055 | &condition, |
| 2056 | &opposite); |
| 2057 | Operand right_high = High32Bits(value); |
| 2058 | Operand right_low = Low32Bits(value); |
| 2059 | |
| 2060 | // The output uses Location::kNoOutputOverlap. |
| 2061 | if (out.Is(left_high)) { |
| 2062 | std::swap(left_low, left_high); |
| 2063 | std::swap(right_low, right_high); |
| 2064 | } |
| 2065 | |
| 2066 | __ Sub(out, left_low, right_low); |
| 2067 | temp = temps.Acquire(); |
| 2068 | __ Sub(temp, left_high, right_high); |
| 2069 | } else { |
| 2070 | DCHECK(right.IsRegisterPair()); |
| 2071 | temp = temps.Acquire(); |
| 2072 | __ Sub(temp, left_high, HighRegisterFrom(right)); |
| 2073 | __ Sub(out, left_low, LowRegisterFrom(right)); |
| 2074 | } |
| 2075 | |
| 2076 | // Need to check after calling AdjustConstantForCondition(). |
| 2077 | DCHECK(condition == kCondEQ || condition == kCondNE) << condition; |
| 2078 | |
| 2079 | if (condition == kCondNE && out.IsLow()) { |
| 2080 | __ Orrs(out, out, temp); |
| 2081 | |
| 2082 | // We use the scope because of the IT block that follows. |
| 2083 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 2084 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 2085 | CodeBufferCheckScope::kExactSize); |
| 2086 | |
| 2087 | __ it(ne); |
| 2088 | __ mov(ne, out, 1); |
| 2089 | } else { |
| 2090 | __ Orr(out, out, temp); |
| 2091 | codegen->GenerateConditionWithZero(condition, out, out, temp); |
| 2092 | } |
| 2093 | } |
| 2094 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2095 | static void GenerateConditionLong(HCondition* cond, CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2096 | DCHECK_EQ(cond->GetLeft()->GetType(), DataType::Type::kInt64); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2097 | |
| 2098 | const LocationSummary* const locations = cond->GetLocations(); |
| 2099 | IfCondition condition = cond->GetCondition(); |
| 2100 | const vixl32::Register out = OutputRegister(cond); |
| 2101 | const Location left = locations->InAt(0); |
| 2102 | const Location right = locations->InAt(1); |
| 2103 | |
| 2104 | if (right.IsConstant()) { |
| 2105 | IfCondition opposite = cond->GetOppositeCondition(); |
| 2106 | |
| 2107 | // Comparisons against 0 are common enough to deserve special attention. |
| 2108 | if (AdjustConstantForCondition(Int64ConstantFrom(right), &condition, &opposite) == 0) { |
| 2109 | switch (condition) { |
| 2110 | case kCondNE: |
| 2111 | case kCondA: |
| 2112 | if (out.IsLow()) { |
| 2113 | // We only care if both input registers are 0 or not. |
| 2114 | __ Orrs(out, LowRegisterFrom(left), HighRegisterFrom(left)); |
| 2115 | |
| 2116 | // We use the scope because of the IT block that follows. |
| 2117 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 2118 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 2119 | CodeBufferCheckScope::kExactSize); |
| 2120 | |
| 2121 | __ it(ne); |
| 2122 | __ mov(ne, out, 1); |
| 2123 | return; |
| 2124 | } |
| 2125 | |
| 2126 | FALLTHROUGH_INTENDED; |
| 2127 | case kCondEQ: |
| 2128 | case kCondBE: |
| 2129 | // We only care if both input registers are 0 or not. |
| 2130 | __ Orr(out, LowRegisterFrom(left), HighRegisterFrom(left)); |
| 2131 | codegen->GenerateConditionWithZero(condition, out, out); |
| 2132 | return; |
| 2133 | case kCondLT: |
| 2134 | case kCondGE: |
| 2135 | // We only care about the sign bit. |
| 2136 | FALLTHROUGH_INTENDED; |
| 2137 | case kCondAE: |
| 2138 | case kCondB: |
| 2139 | codegen->GenerateConditionWithZero(condition, out, HighRegisterFrom(left)); |
| 2140 | return; |
| 2141 | case kCondLE: |
| 2142 | case kCondGT: |
| 2143 | default: |
| 2144 | break; |
| 2145 | } |
| 2146 | } |
| 2147 | } |
| 2148 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2149 | // If `out` is a low register, then the GenerateConditionGeneric() |
| 2150 | // function generates a shorter code sequence that is still branchless. |
| 2151 | if ((condition == kCondEQ || condition == kCondNE) && !out.IsLow()) { |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2152 | GenerateEqualLong(cond, codegen); |
| 2153 | return; |
| 2154 | } |
| 2155 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2156 | GenerateConditionGeneric(cond, codegen); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2157 | } |
| 2158 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 2159 | static void GenerateConditionIntegralOrNonPrimitive(HCondition* cond, |
| 2160 | CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2161 | const DataType::Type type = cond->GetLeft()->GetType(); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2162 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2163 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2164 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2165 | if (type == DataType::Type::kInt64) { |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2166 | GenerateConditionLong(cond, codegen); |
| 2167 | return; |
| 2168 | } |
| 2169 | |
| 2170 | IfCondition condition = cond->GetCondition(); |
| 2171 | vixl32::Register in = InputRegisterAt(cond, 0); |
| 2172 | const vixl32::Register out = OutputRegister(cond); |
| 2173 | const Location right = cond->GetLocations()->InAt(1); |
| 2174 | int64_t value; |
| 2175 | |
| 2176 | if (right.IsConstant()) { |
| 2177 | IfCondition opposite = cond->GetOppositeCondition(); |
| 2178 | |
| 2179 | value = AdjustConstantForCondition(Int64ConstantFrom(right), &condition, &opposite); |
| 2180 | |
| 2181 | // Comparisons against 0 are common enough to deserve special attention. |
| 2182 | if (value == 0) { |
| 2183 | switch (condition) { |
| 2184 | case kCondNE: |
| 2185 | case kCondA: |
| 2186 | if (out.IsLow() && out.Is(in)) { |
| 2187 | __ Cmp(out, 0); |
| 2188 | |
| 2189 | // We use the scope because of the IT block that follows. |
| 2190 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 2191 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 2192 | CodeBufferCheckScope::kExactSize); |
| 2193 | |
| 2194 | __ it(ne); |
| 2195 | __ mov(ne, out, 1); |
| 2196 | return; |
| 2197 | } |
| 2198 | |
| 2199 | FALLTHROUGH_INTENDED; |
| 2200 | case kCondEQ: |
| 2201 | case kCondBE: |
| 2202 | case kCondLT: |
| 2203 | case kCondGE: |
| 2204 | case kCondAE: |
| 2205 | case kCondB: |
| 2206 | codegen->GenerateConditionWithZero(condition, out, in); |
| 2207 | return; |
| 2208 | case kCondLE: |
| 2209 | case kCondGT: |
| 2210 | default: |
| 2211 | break; |
| 2212 | } |
| 2213 | } |
| 2214 | } |
| 2215 | |
| 2216 | if (condition == kCondEQ || condition == kCondNE) { |
| 2217 | Operand operand(0); |
| 2218 | |
| 2219 | if (right.IsConstant()) { |
| 2220 | operand = Operand::From(value); |
| 2221 | } else if (out.Is(RegisterFrom(right))) { |
| 2222 | // Avoid 32-bit instructions if possible. |
| 2223 | operand = InputOperandAt(cond, 0); |
| 2224 | in = RegisterFrom(right); |
| 2225 | } else { |
| 2226 | operand = InputOperandAt(cond, 1); |
| 2227 | } |
| 2228 | |
| 2229 | if (condition == kCondNE && out.IsLow()) { |
| 2230 | __ Subs(out, in, operand); |
| 2231 | |
| 2232 | // We use the scope because of the IT block that follows. |
| 2233 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 2234 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 2235 | CodeBufferCheckScope::kExactSize); |
| 2236 | |
| 2237 | __ it(ne); |
| 2238 | __ mov(ne, out, 1); |
| 2239 | } else { |
| 2240 | __ Sub(out, in, operand); |
| 2241 | codegen->GenerateConditionWithZero(condition, out, out); |
| 2242 | } |
| 2243 | |
| 2244 | return; |
| 2245 | } |
| 2246 | |
| 2247 | GenerateConditionGeneric(cond, codegen); |
| 2248 | } |
| 2249 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2250 | static bool CanEncodeConstantAs8BitImmediate(HConstant* constant) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2251 | const DataType::Type type = constant->GetType(); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2252 | bool ret = false; |
| 2253 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2254 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2255 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2256 | if (type == DataType::Type::kInt64) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2257 | const uint64_t value = Uint64ConstantFrom(constant); |
| 2258 | |
| 2259 | ret = IsUint<8>(Low32Bits(value)) && IsUint<8>(High32Bits(value)); |
| 2260 | } else { |
| 2261 | ret = IsUint<8>(Int32ConstantFrom(constant)); |
| 2262 | } |
| 2263 | |
| 2264 | return ret; |
| 2265 | } |
| 2266 | |
| 2267 | static Location Arm8BitEncodableConstantOrRegister(HInstruction* constant) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2268 | DCHECK(!DataType::IsFloatingPointType(constant->GetType())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2269 | |
| 2270 | if (constant->IsConstant() && CanEncodeConstantAs8BitImmediate(constant->AsConstant())) { |
| 2271 | return Location::ConstantLocation(constant->AsConstant()); |
| 2272 | } |
| 2273 | |
| 2274 | return Location::RequiresRegister(); |
| 2275 | } |
| 2276 | |
| 2277 | static bool CanGenerateConditionalMove(const Location& out, const Location& src) { |
| 2278 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 2279 | // we check that we are not dealing with floating-point output (there is no |
| 2280 | // 16-bit VMOV encoding). |
| 2281 | if (!out.IsRegister() && !out.IsRegisterPair()) { |
| 2282 | return false; |
| 2283 | } |
| 2284 | |
| 2285 | // For constants, we also check that the output is in one or two low registers, |
| 2286 | // and that the constants fit in an 8-bit unsigned integer, so that a 16-bit |
| 2287 | // MOV encoding can be used. |
| 2288 | if (src.IsConstant()) { |
| 2289 | if (!CanEncodeConstantAs8BitImmediate(src.GetConstant())) { |
| 2290 | return false; |
| 2291 | } |
| 2292 | |
| 2293 | if (out.IsRegister()) { |
| 2294 | if (!RegisterFrom(out).IsLow()) { |
| 2295 | return false; |
| 2296 | } |
| 2297 | } else { |
| 2298 | DCHECK(out.IsRegisterPair()); |
| 2299 | |
| 2300 | if (!HighRegisterFrom(out).IsLow()) { |
| 2301 | return false; |
| 2302 | } |
| 2303 | } |
| 2304 | } |
| 2305 | |
| 2306 | return true; |
| 2307 | } |
| 2308 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2309 | #undef __ |
| 2310 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2311 | vixl32::Label* CodeGeneratorARMVIXL::GetFinalLabel(HInstruction* instruction, |
| 2312 | vixl32::Label* final_label) { |
| 2313 | DCHECK(!instruction->IsControlFlow() && !instruction->IsSuspendCheck()); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 2314 | DCHECK(!instruction->IsInvoke() || !instruction->GetLocations()->CanCall()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2315 | |
| 2316 | const HBasicBlock* const block = instruction->GetBlock(); |
| 2317 | const HLoopInformation* const info = block->GetLoopInformation(); |
| 2318 | HInstruction* const next = instruction->GetNext(); |
| 2319 | |
| 2320 | // Avoid a branch to a branch. |
| 2321 | if (next->IsGoto() && (info == nullptr || |
| 2322 | !info->IsBackEdge(*block) || |
| 2323 | !info->HasSuspendCheck())) { |
| 2324 | final_label = GetLabelOf(next->AsGoto()->GetSuccessor()); |
| 2325 | } |
| 2326 | |
| 2327 | return final_label; |
| 2328 | } |
| 2329 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2330 | CodeGeneratorARMVIXL::CodeGeneratorARMVIXL(HGraph* graph, |
| 2331 | const ArmInstructionSetFeatures& isa_features, |
| 2332 | const CompilerOptions& compiler_options, |
| 2333 | OptimizingCompilerStats* stats) |
| 2334 | : CodeGenerator(graph, |
| 2335 | kNumberOfCoreRegisters, |
| 2336 | kNumberOfSRegisters, |
| 2337 | kNumberOfRegisterPairs, |
| 2338 | kCoreCalleeSaves.GetList(), |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2339 | ComputeSRegisterListMask(kFpuCalleeSaves), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2340 | compiler_options, |
| 2341 | stats), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2342 | block_labels_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 2343 | jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2344 | location_builder_(graph, this), |
| 2345 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2346 | move_resolver_(graph->GetAllocator(), this), |
| 2347 | assembler_(graph->GetAllocator()), |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2348 | isa_features_(isa_features), |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 2349 | uint32_literals_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2350 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 2351 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2352 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 2353 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2354 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 2355 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2356 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 2357 | baker_read_barrier_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 2358 | jit_string_patches_(StringReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2359 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 2360 | jit_class_patches_(TypeReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2361 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2362 | // Always save the LR register to mimic Quick. |
| 2363 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 2364 | // Give D30 and D31 as scratch register to VIXL. The register allocator only works on |
| 2365 | // S0-S31, which alias to D0-D15. |
| 2366 | GetVIXLAssembler()->GetScratchVRegisterList()->Combine(d31); |
| 2367 | GetVIXLAssembler()->GetScratchVRegisterList()->Combine(d30); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2368 | } |
| 2369 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2370 | void JumpTableARMVIXL::EmitTable(CodeGeneratorARMVIXL* codegen) { |
| 2371 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| 2372 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| 2373 | |
| 2374 | // 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] | 2375 | // underlying code buffer and we have generated a jump table of the right size, using |
| 2376 | // codegen->GetVIXLAssembler()->GetBuffer().Align(); |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 2377 | ExactAssemblyScope aas(codegen->GetVIXLAssembler(), |
| 2378 | num_entries * sizeof(int32_t), |
| 2379 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2380 | // TODO(VIXL): Check that using lower case bind is fine here. |
| 2381 | codegen->GetVIXLAssembler()->bind(&table_start_); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2382 | for (uint32_t i = 0; i < num_entries; i++) { |
| 2383 | codegen->GetVIXLAssembler()->place(bb_addresses_[i].get()); |
| 2384 | } |
| 2385 | } |
| 2386 | |
| 2387 | void JumpTableARMVIXL::FixTable(CodeGeneratorARMVIXL* codegen) { |
| 2388 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| 2389 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| 2390 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2391 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 2392 | for (uint32_t i = 0; i < num_entries; i++) { |
| 2393 | vixl32::Label* target_label = codegen->GetLabelOf(successors[i]); |
| 2394 | DCHECK(target_label->IsBound()); |
| 2395 | int32_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
| 2396 | // When doing BX to address we need to have lower bit set to 1 in T32. |
| 2397 | if (codegen->GetVIXLAssembler()->IsUsingT32()) { |
| 2398 | jump_offset++; |
| 2399 | } |
| 2400 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 2401 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2402 | |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 2403 | bb_addresses_[i].get()->UpdateValue(jump_offset, codegen->GetVIXLAssembler()->GetBuffer()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2404 | } |
| 2405 | } |
| 2406 | |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2407 | void CodeGeneratorARMVIXL::FixJumpTables() { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2408 | for (auto&& jump_table : jump_tables_) { |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2409 | jump_table->FixTable(this); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2410 | } |
| 2411 | } |
| 2412 | |
Andreas Gampe | ca620d7 | 2016-11-08 08:09:33 -0800 | [diff] [blame] | 2413 | #define __ reinterpret_cast<ArmVIXLAssembler*>(GetAssembler())->GetVIXLAssembler()-> // NOLINT |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2414 | |
| 2415 | void CodeGeneratorARMVIXL::Finalize(CodeAllocator* allocator) { |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2416 | FixJumpTables(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2417 | GetAssembler()->FinalizeCode(); |
| 2418 | CodeGenerator::Finalize(allocator); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 2419 | |
| 2420 | // Verify Baker read barrier linker patches. |
| 2421 | if (kIsDebugBuild) { |
| 2422 | ArrayRef<const uint8_t> code = allocator->GetMemory(); |
| 2423 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 2424 | DCHECK(info.label.IsBound()); |
| 2425 | uint32_t literal_offset = info.label.GetLocation(); |
| 2426 | DCHECK_ALIGNED(literal_offset, 2u); |
| 2427 | |
| 2428 | auto GetInsn16 = [&code](uint32_t offset) { |
| 2429 | DCHECK_ALIGNED(offset, 2u); |
| 2430 | return (static_cast<uint32_t>(code[offset + 0]) << 0) + |
| 2431 | (static_cast<uint32_t>(code[offset + 1]) << 8); |
| 2432 | }; |
| 2433 | auto GetInsn32 = [=](uint32_t offset) { |
| 2434 | return (GetInsn16(offset) << 16) + (GetInsn16(offset + 2u) << 0); |
| 2435 | }; |
| 2436 | |
| 2437 | uint32_t encoded_data = info.custom_data; |
| 2438 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 2439 | // Check that the next instruction matches the expected LDR. |
| 2440 | switch (kind) { |
| 2441 | case BakerReadBarrierKind::kField: { |
| 2442 | BakerReadBarrierWidth width = BakerReadBarrierWidthField::Decode(encoded_data); |
| 2443 | if (width == BakerReadBarrierWidth::kWide) { |
| 2444 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 2445 | uint32_t next_insn = GetInsn32(literal_offset + 4u); |
| 2446 | // LDR (immediate), encoding T3, with correct base_reg. |
| 2447 | CheckValidReg((next_insn >> 12) & 0xfu); // Check destination register. |
| 2448 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 2449 | CHECK_EQ(next_insn & 0xffff0000u, 0xf8d00000u | (base_reg << 16)); |
| 2450 | } else { |
| 2451 | DCHECK_GE(code.size() - literal_offset, 6u); |
| 2452 | uint32_t next_insn = GetInsn16(literal_offset + 4u); |
| 2453 | // LDR (immediate), encoding T1, with correct base_reg. |
| 2454 | CheckValidReg(next_insn & 0x7u); // Check destination register. |
| 2455 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 2456 | CHECK_EQ(next_insn & 0xf838u, 0x6800u | (base_reg << 3)); |
| 2457 | } |
| 2458 | break; |
| 2459 | } |
| 2460 | case BakerReadBarrierKind::kArray: { |
| 2461 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 2462 | uint32_t next_insn = GetInsn32(literal_offset + 4u); |
| 2463 | // LDR (register) with correct base_reg, S=1 and option=011 (LDR Wt, [Xn, Xm, LSL #2]). |
| 2464 | CheckValidReg((next_insn >> 12) & 0xfu); // Check destination register. |
| 2465 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 2466 | CHECK_EQ(next_insn & 0xffff0ff0u, 0xf8500020u | (base_reg << 16)); |
| 2467 | CheckValidReg(next_insn & 0xf); // Check index register |
| 2468 | break; |
| 2469 | } |
| 2470 | case BakerReadBarrierKind::kGcRoot: { |
| 2471 | BakerReadBarrierWidth width = BakerReadBarrierWidthField::Decode(encoded_data); |
| 2472 | if (width == BakerReadBarrierWidth::kWide) { |
| 2473 | DCHECK_GE(literal_offset, 4u); |
| 2474 | uint32_t prev_insn = GetInsn32(literal_offset - 4u); |
| 2475 | // LDR (immediate), encoding T3, with correct root_reg. |
| 2476 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 2477 | CHECK_EQ(prev_insn & 0xfff0f000u, 0xf8d00000u | (root_reg << 12)); |
| 2478 | } else { |
| 2479 | DCHECK_GE(literal_offset, 2u); |
| 2480 | uint32_t prev_insn = GetInsn16(literal_offset - 2u); |
| 2481 | // LDR (immediate), encoding T1, with correct root_reg. |
| 2482 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 2483 | CHECK_EQ(prev_insn & 0xf807u, 0x6800u | root_reg); |
| 2484 | } |
| 2485 | break; |
| 2486 | } |
| 2487 | default: |
| 2488 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 2489 | UNREACHABLE(); |
| 2490 | } |
| 2491 | } |
| 2492 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2493 | } |
| 2494 | |
| 2495 | void CodeGeneratorARMVIXL::SetupBlockedRegisters() const { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2496 | // Stack register, LR and PC are always reserved. |
| 2497 | blocked_core_registers_[SP] = true; |
| 2498 | blocked_core_registers_[LR] = true; |
| 2499 | blocked_core_registers_[PC] = true; |
| 2500 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 2501 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2502 | // Reserve marking register. |
| 2503 | blocked_core_registers_[MR] = true; |
| 2504 | } |
| 2505 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2506 | // Reserve thread register. |
| 2507 | blocked_core_registers_[TR] = true; |
| 2508 | |
| 2509 | // Reserve temp register. |
| 2510 | blocked_core_registers_[IP] = true; |
| 2511 | |
| 2512 | if (GetGraph()->IsDebuggable()) { |
| 2513 | // Stubs do not save callee-save floating point registers. If the graph |
| 2514 | // is debuggable, we need to deal with these registers differently. For |
| 2515 | // now, just block them. |
| 2516 | for (uint32_t i = kFpuCalleeSaves.GetFirstSRegister().GetCode(); |
| 2517 | i <= kFpuCalleeSaves.GetLastSRegister().GetCode(); |
| 2518 | ++i) { |
| 2519 | blocked_fpu_registers_[i] = true; |
| 2520 | } |
| 2521 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2522 | } |
| 2523 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2524 | InstructionCodeGeneratorARMVIXL::InstructionCodeGeneratorARMVIXL(HGraph* graph, |
| 2525 | CodeGeneratorARMVIXL* codegen) |
| 2526 | : InstructionCodeGenerator(graph, codegen), |
| 2527 | assembler_(codegen->GetAssembler()), |
| 2528 | codegen_(codegen) {} |
| 2529 | |
| 2530 | void CodeGeneratorARMVIXL::ComputeSpillMask() { |
| 2531 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 2532 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
| 2533 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 2534 | // restore another arbitrary register. |
| 2535 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister.GetCode()); |
| 2536 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 2537 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 2538 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 2539 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 2540 | // but in the range. |
| 2541 | if (fpu_spill_mask_ != 0) { |
| 2542 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 2543 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 2544 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 2545 | fpu_spill_mask_ |= (1 << i); |
| 2546 | } |
| 2547 | } |
| 2548 | } |
| 2549 | |
| 2550 | void CodeGeneratorARMVIXL::GenerateFrameEntry() { |
| 2551 | bool skip_overflow_check = |
| 2552 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
| 2553 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
| 2554 | __ Bind(&frame_entry_label_); |
| 2555 | |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 2556 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 2557 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2558 | vixl32::Register temp = temps.Acquire(); |
| 2559 | __ Ldrh(temp, MemOperand(kMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); |
| 2560 | __ Add(temp, temp, 1); |
| 2561 | __ Strh(temp, MemOperand(kMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); |
| 2562 | } |
| 2563 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2564 | if (HasEmptyFrame()) { |
| 2565 | return; |
| 2566 | } |
| 2567 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2568 | if (!skip_overflow_check) { |
xueliang.zhong | 1004955 | 2018-01-31 17:10:36 +0000 | [diff] [blame] | 2569 | // Using r4 instead of IP saves 2 bytes. |
Nicolas Geoffray | 1a4f3ca | 2018-01-25 14:07:15 +0000 | [diff] [blame] | 2570 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
xueliang.zhong | 1004955 | 2018-01-31 17:10:36 +0000 | [diff] [blame] | 2571 | vixl32::Register temp; |
| 2572 | // TODO: Remove this check when R4 is made a callee-save register |
| 2573 | // in ART compiled code (b/72801708). Currently we need to make |
| 2574 | // sure r4 is not blocked, e.g. in special purpose |
| 2575 | // TestCodeGeneratorARMVIXL; also asserting that r4 is available |
| 2576 | // here. |
| 2577 | if (!blocked_core_registers_[R4]) { |
| 2578 | for (vixl32::Register reg : kParameterCoreRegistersVIXL) { |
| 2579 | DCHECK(!reg.Is(r4)); |
| 2580 | } |
| 2581 | DCHECK(!kCoreCalleeSaves.Includes(r4)); |
| 2582 | temp = r4; |
| 2583 | } else { |
| 2584 | temp = temps.Acquire(); |
| 2585 | } |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 2586 | __ Sub(temp, sp, Operand::From(GetStackOverflowReservedBytes(InstructionSet::kArm))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2587 | // The load must immediately precede RecordPcInfo. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 2588 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2589 | vixl32::kMaxInstructionSizeInBytes, |
| 2590 | CodeBufferCheckScope::kMaximumSize); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2591 | __ ldr(temp, MemOperand(temp)); |
| 2592 | RecordPcInfo(nullptr, 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2593 | } |
| 2594 | |
| 2595 | __ Push(RegisterList(core_spill_mask_)); |
| 2596 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 2597 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(kMethodRegister), |
| 2598 | 0, |
| 2599 | core_spill_mask_, |
| 2600 | kArmWordSize); |
| 2601 | if (fpu_spill_mask_ != 0) { |
| 2602 | uint32_t first = LeastSignificantBit(fpu_spill_mask_); |
| 2603 | |
| 2604 | // Check that list is contiguous. |
| 2605 | DCHECK_EQ(fpu_spill_mask_ >> CTZ(fpu_spill_mask_), ~0u >> (32 - POPCOUNT(fpu_spill_mask_))); |
| 2606 | |
| 2607 | __ Vpush(SRegisterList(vixl32::SRegister(first), POPCOUNT(fpu_spill_mask_))); |
| 2608 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2609 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(s0), 0, fpu_spill_mask_, kArmWordSize); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2610 | } |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 2611 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2612 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 2613 | __ Sub(sp, sp, adjust); |
| 2614 | GetAssembler()->cfi().AdjustCFAOffset(adjust); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 2615 | |
| 2616 | // Save the current method if we need it. Note that we do not |
| 2617 | // do this in HCurrentMethod, as the instruction might have been removed |
| 2618 | // in the SSA graph. |
| 2619 | if (RequiresCurrentMethod()) { |
| 2620 | GetAssembler()->StoreToOffset(kStoreWord, kMethodRegister, sp, 0); |
| 2621 | } |
Nicolas Geoffray | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 2622 | |
| 2623 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 2624 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2625 | vixl32::Register temp = temps.Acquire(); |
| 2626 | // Initialize should_deoptimize flag to 0. |
| 2627 | __ Mov(temp, 0); |
| 2628 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, GetStackOffsetOfShouldDeoptimizeFlag()); |
| 2629 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 2630 | |
| 2631 | MaybeGenerateMarkingRegisterCheck(/* code */ 1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2632 | } |
| 2633 | |
| 2634 | void CodeGeneratorARMVIXL::GenerateFrameExit() { |
| 2635 | if (HasEmptyFrame()) { |
| 2636 | __ Bx(lr); |
| 2637 | return; |
| 2638 | } |
| 2639 | GetAssembler()->cfi().RememberState(); |
| 2640 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 2641 | __ Add(sp, sp, adjust); |
| 2642 | GetAssembler()->cfi().AdjustCFAOffset(-adjust); |
| 2643 | if (fpu_spill_mask_ != 0) { |
| 2644 | uint32_t first = LeastSignificantBit(fpu_spill_mask_); |
| 2645 | |
| 2646 | // Check that list is contiguous. |
| 2647 | DCHECK_EQ(fpu_spill_mask_ >> CTZ(fpu_spill_mask_), ~0u >> (32 - POPCOUNT(fpu_spill_mask_))); |
| 2648 | |
| 2649 | __ Vpop(SRegisterList(vixl32::SRegister(first), POPCOUNT(fpu_spill_mask_))); |
| 2650 | GetAssembler()->cfi().AdjustCFAOffset( |
| 2651 | -static_cast<int>(kArmWordSize) * POPCOUNT(fpu_spill_mask_)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2652 | GetAssembler()->cfi().RestoreMany(DWARFReg(vixl32::SRegister(0)), fpu_spill_mask_); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2653 | } |
| 2654 | // Pop LR into PC to return. |
| 2655 | DCHECK_NE(core_spill_mask_ & (1 << kLrCode), 0U); |
| 2656 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << kLrCode))) | 1 << kPcCode; |
| 2657 | __ Pop(RegisterList(pop_mask)); |
| 2658 | GetAssembler()->cfi().RestoreState(); |
| 2659 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
| 2660 | } |
| 2661 | |
| 2662 | void CodeGeneratorARMVIXL::Bind(HBasicBlock* block) { |
| 2663 | __ Bind(GetLabelOf(block)); |
| 2664 | } |
| 2665 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2666 | Location InvokeDexCallingConventionVisitorARMVIXL::GetNextLocation(DataType::Type type) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2667 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2668 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2669 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2670 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2671 | case DataType::Type::kInt8: |
| 2672 | case DataType::Type::kUint16: |
| 2673 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2674 | case DataType::Type::kInt32: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2675 | uint32_t index = gp_index_++; |
| 2676 | uint32_t stack_index = stack_index_++; |
| 2677 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2678 | return LocationFrom(calling_convention.GetRegisterAt(index)); |
| 2679 | } else { |
| 2680 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2681 | } |
| 2682 | } |
| 2683 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2684 | case DataType::Type::kInt64: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2685 | uint32_t index = gp_index_; |
| 2686 | uint32_t stack_index = stack_index_; |
| 2687 | gp_index_ += 2; |
| 2688 | stack_index_ += 2; |
| 2689 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2690 | if (calling_convention.GetRegisterAt(index).Is(r1)) { |
| 2691 | // Skip R1, and use R2_R3 instead. |
| 2692 | gp_index_++; |
| 2693 | index++; |
| 2694 | } |
| 2695 | } |
| 2696 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2697 | DCHECK_EQ(calling_convention.GetRegisterAt(index).GetCode() + 1, |
| 2698 | calling_convention.GetRegisterAt(index + 1).GetCode()); |
| 2699 | |
| 2700 | return LocationFrom(calling_convention.GetRegisterAt(index), |
| 2701 | calling_convention.GetRegisterAt(index + 1)); |
| 2702 | } else { |
| 2703 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2704 | } |
| 2705 | } |
| 2706 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2707 | case DataType::Type::kFloat32: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2708 | uint32_t stack_index = stack_index_++; |
| 2709 | if (float_index_ % 2 == 0) { |
| 2710 | float_index_ = std::max(double_index_, float_index_); |
| 2711 | } |
| 2712 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 2713 | return LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 2714 | } else { |
| 2715 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2716 | } |
| 2717 | } |
| 2718 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2719 | case DataType::Type::kFloat64: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2720 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 2721 | uint32_t stack_index = stack_index_; |
| 2722 | stack_index_ += 2; |
| 2723 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 2724 | uint32_t index = double_index_; |
| 2725 | double_index_ += 2; |
| 2726 | Location result = LocationFrom( |
| 2727 | calling_convention.GetFpuRegisterAt(index), |
| 2728 | calling_convention.GetFpuRegisterAt(index + 1)); |
| 2729 | DCHECK(ExpectedPairLayout(result)); |
| 2730 | return result; |
| 2731 | } else { |
| 2732 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2733 | } |
| 2734 | } |
| 2735 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2736 | case DataType::Type::kUint32: |
| 2737 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2738 | case DataType::Type::kVoid: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2739 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2740 | break; |
| 2741 | } |
| 2742 | return Location::NoLocation(); |
| 2743 | } |
| 2744 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2745 | Location InvokeDexCallingConventionVisitorARMVIXL::GetReturnLocation(DataType::Type type) const { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2746 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2747 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2748 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2749 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2750 | case DataType::Type::kInt8: |
| 2751 | case DataType::Type::kUint16: |
| 2752 | case DataType::Type::kInt16: |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2753 | case DataType::Type::kUint32: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2754 | case DataType::Type::kInt32: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2755 | return LocationFrom(r0); |
| 2756 | } |
| 2757 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2758 | case DataType::Type::kFloat32: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2759 | return LocationFrom(s0); |
| 2760 | } |
| 2761 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2762 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2763 | case DataType::Type::kInt64: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2764 | return LocationFrom(r0, r1); |
| 2765 | } |
| 2766 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2767 | case DataType::Type::kFloat64: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2768 | return LocationFrom(s0, s1); |
| 2769 | } |
| 2770 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2771 | case DataType::Type::kVoid: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2772 | return Location::NoLocation(); |
| 2773 | } |
| 2774 | |
| 2775 | UNREACHABLE(); |
| 2776 | } |
| 2777 | |
| 2778 | Location InvokeDexCallingConventionVisitorARMVIXL::GetMethodLocation() const { |
| 2779 | return LocationFrom(kMethodRegister); |
| 2780 | } |
| 2781 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2782 | void CodeGeneratorARMVIXL::Move32(Location destination, Location source) { |
| 2783 | if (source.Equals(destination)) { |
| 2784 | return; |
| 2785 | } |
| 2786 | if (destination.IsRegister()) { |
| 2787 | if (source.IsRegister()) { |
| 2788 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 2789 | } else if (source.IsFpuRegister()) { |
| 2790 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
| 2791 | } else { |
| 2792 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 2793 | RegisterFrom(destination), |
| 2794 | sp, |
| 2795 | source.GetStackIndex()); |
| 2796 | } |
| 2797 | } else if (destination.IsFpuRegister()) { |
| 2798 | if (source.IsRegister()) { |
| 2799 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
| 2800 | } else if (source.IsFpuRegister()) { |
| 2801 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 2802 | } else { |
| 2803 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 2804 | } |
| 2805 | } else { |
| 2806 | DCHECK(destination.IsStackSlot()) << destination; |
| 2807 | if (source.IsRegister()) { |
| 2808 | GetAssembler()->StoreToOffset(kStoreWord, |
| 2809 | RegisterFrom(source), |
| 2810 | sp, |
| 2811 | destination.GetStackIndex()); |
| 2812 | } else if (source.IsFpuRegister()) { |
| 2813 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 2814 | } else { |
| 2815 | DCHECK(source.IsStackSlot()) << source; |
| 2816 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2817 | vixl32::Register temp = temps.Acquire(); |
| 2818 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 2819 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 2820 | } |
| 2821 | } |
| 2822 | } |
| 2823 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2824 | void CodeGeneratorARMVIXL::MoveConstant(Location location, int32_t value) { |
| 2825 | DCHECK(location.IsRegister()); |
| 2826 | __ Mov(RegisterFrom(location), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2827 | } |
| 2828 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2829 | void CodeGeneratorARMVIXL::MoveLocation(Location dst, Location src, DataType::Type dst_type) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2830 | // TODO(VIXL): Maybe refactor to have the 'move' implementation here and use it in |
| 2831 | // `ParallelMoveResolverARMVIXL::EmitMove`, as is done in the `arm64` backend. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2832 | HParallelMove move(GetGraph()->GetAllocator()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2833 | move.AddMove(src, dst, dst_type, nullptr); |
| 2834 | GetMoveResolver()->EmitNativeCode(&move); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2835 | } |
| 2836 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2837 | void CodeGeneratorARMVIXL::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 2838 | if (location.IsRegister()) { |
| 2839 | locations->AddTemp(location); |
| 2840 | } else if (location.IsRegisterPair()) { |
| 2841 | locations->AddTemp(LocationFrom(LowRegisterFrom(location))); |
| 2842 | locations->AddTemp(LocationFrom(HighRegisterFrom(location))); |
| 2843 | } else { |
| 2844 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 2845 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2846 | } |
| 2847 | |
| 2848 | void CodeGeneratorARMVIXL::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2849 | HInstruction* instruction, |
| 2850 | uint32_t dex_pc, |
| 2851 | SlowPathCode* slow_path) { |
| 2852 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2853 | __ Ldr(lr, MemOperand(tr, GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value())); |
| 2854 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 2855 | // 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] | 2856 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2857 | vixl32::k16BitT32InstructionSizeInBytes, |
| 2858 | CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2859 | __ blx(lr); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2860 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2861 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2862 | } |
| 2863 | } |
| 2864 | |
| 2865 | void CodeGeneratorARMVIXL::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2866 | HInstruction* instruction, |
| 2867 | SlowPathCode* slow_path) { |
| 2868 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2869 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2870 | __ Blx(lr); |
| 2871 | } |
| 2872 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2873 | void InstructionCodeGeneratorARMVIXL::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 2874 | if (successor->IsExitBlock()) { |
| 2875 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 2876 | return; // no code needed |
| 2877 | } |
| 2878 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2879 | HBasicBlock* block = got->GetBlock(); |
| 2880 | HInstruction* previous = got->GetPrevious(); |
| 2881 | HLoopInformation* info = block->GetLoopInformation(); |
| 2882 | |
| 2883 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 2884 | if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 2885 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2886 | vixl32::Register temp = temps.Acquire(); |
| 2887 | __ Push(vixl32::Register(kMethodRegister)); |
| 2888 | GetAssembler()->LoadFromOffset(kLoadWord, kMethodRegister, sp, kArmWordSize); |
| 2889 | __ Ldrh(temp, MemOperand(kMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); |
| 2890 | __ Add(temp, temp, 1); |
| 2891 | __ Strh(temp, MemOperand(kMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); |
| 2892 | __ Pop(vixl32::Register(kMethodRegister)); |
| 2893 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2894 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2895 | return; |
| 2896 | } |
| 2897 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2898 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 2899 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 2); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2900 | } |
| 2901 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 2902 | __ B(codegen_->GetLabelOf(successor)); |
| 2903 | } |
| 2904 | } |
| 2905 | |
| 2906 | void LocationsBuilderARMVIXL::VisitGoto(HGoto* got) { |
| 2907 | got->SetLocations(nullptr); |
| 2908 | } |
| 2909 | |
| 2910 | void InstructionCodeGeneratorARMVIXL::VisitGoto(HGoto* got) { |
| 2911 | HandleGoto(got, got->GetSuccessor()); |
| 2912 | } |
| 2913 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2914 | void LocationsBuilderARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2915 | try_boundary->SetLocations(nullptr); |
| 2916 | } |
| 2917 | |
| 2918 | void InstructionCodeGeneratorARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2919 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2920 | if (!successor->IsExitBlock()) { |
| 2921 | HandleGoto(try_boundary, successor); |
| 2922 | } |
| 2923 | } |
| 2924 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2925 | void LocationsBuilderARMVIXL::VisitExit(HExit* exit) { |
| 2926 | exit->SetLocations(nullptr); |
| 2927 | } |
| 2928 | |
| 2929 | void InstructionCodeGeneratorARMVIXL::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 2930 | } |
| 2931 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2932 | void InstructionCodeGeneratorARMVIXL::GenerateCompareTestAndBranch(HCondition* condition, |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2933 | vixl32::Label* true_target, |
| 2934 | vixl32::Label* false_target, |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2935 | bool is_far_target) { |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2936 | if (true_target == false_target) { |
| 2937 | DCHECK(true_target != nullptr); |
| 2938 | __ B(true_target); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2939 | return; |
| 2940 | } |
| 2941 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2942 | vixl32::Label* non_fallthrough_target; |
| 2943 | bool invert; |
| 2944 | bool emit_both_branches; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2945 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2946 | if (true_target == nullptr) { |
| 2947 | // The true target is fallthrough. |
| 2948 | DCHECK(false_target != nullptr); |
| 2949 | non_fallthrough_target = false_target; |
| 2950 | invert = true; |
| 2951 | emit_both_branches = false; |
| 2952 | } else { |
| 2953 | non_fallthrough_target = true_target; |
| 2954 | invert = false; |
| 2955 | // Either the false target is fallthrough, or there is no fallthrough |
| 2956 | // and both branches must be emitted. |
| 2957 | emit_both_branches = (false_target != nullptr); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2958 | } |
| 2959 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2960 | const auto cond = GenerateTest(condition, invert, codegen_); |
| 2961 | |
| 2962 | __ B(cond.first, non_fallthrough_target, is_far_target); |
| 2963 | |
| 2964 | if (emit_both_branches) { |
| 2965 | // No target falls through, we need to branch. |
| 2966 | __ B(false_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2967 | } |
| 2968 | } |
| 2969 | |
| 2970 | void InstructionCodeGeneratorARMVIXL::GenerateTestAndBranch(HInstruction* instruction, |
| 2971 | size_t condition_input_index, |
| 2972 | vixl32::Label* true_target, |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2973 | vixl32::Label* false_target, |
| 2974 | bool far_target) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2975 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 2976 | |
| 2977 | if (true_target == nullptr && false_target == nullptr) { |
| 2978 | // Nothing to do. The code always falls through. |
| 2979 | return; |
| 2980 | } else if (cond->IsIntConstant()) { |
| 2981 | // Constant condition, statically compared against "true" (integer value 1). |
| 2982 | if (cond->AsIntConstant()->IsTrue()) { |
| 2983 | if (true_target != nullptr) { |
| 2984 | __ B(true_target); |
| 2985 | } |
| 2986 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 2987 | DCHECK(cond->AsIntConstant()->IsFalse()) << Int32ConstantFrom(cond); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2988 | if (false_target != nullptr) { |
| 2989 | __ B(false_target); |
| 2990 | } |
| 2991 | } |
| 2992 | return; |
| 2993 | } |
| 2994 | |
| 2995 | // The following code generates these patterns: |
| 2996 | // (1) true_target == nullptr && false_target != nullptr |
| 2997 | // - opposite condition true => branch to false_target |
| 2998 | // (2) true_target != nullptr && false_target == nullptr |
| 2999 | // - condition true => branch to true_target |
| 3000 | // (3) true_target != nullptr && false_target != nullptr |
| 3001 | // - condition true => branch to true_target |
| 3002 | // - branch to false_target |
| 3003 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3004 | // Condition has been materialized, compare the output to 0. |
| 3005 | if (kIsDebugBuild) { |
| 3006 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 3007 | DCHECK(cond_val.IsRegister()); |
| 3008 | } |
| 3009 | if (true_target == nullptr) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 3010 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, condition_input_index), |
| 3011 | false_target, |
| 3012 | far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3013 | } else { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 3014 | __ CompareAndBranchIfNonZero(InputRegisterAt(instruction, condition_input_index), |
| 3015 | true_target, |
| 3016 | far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3017 | } |
| 3018 | } else { |
| 3019 | // Condition has not been materialized. Use its inputs as the comparison and |
| 3020 | // its condition as the branch condition. |
| 3021 | HCondition* condition = cond->AsCondition(); |
| 3022 | |
| 3023 | // If this is a long or FP comparison that has been folded into |
| 3024 | // the HCondition, generate the comparison directly. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3025 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 3026 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 3027 | GenerateCompareTestAndBranch(condition, true_target, false_target, far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3028 | return; |
| 3029 | } |
| 3030 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3031 | vixl32::Label* non_fallthrough_target; |
| 3032 | vixl32::Condition arm_cond = vixl32::Condition::None(); |
| 3033 | const vixl32::Register left = InputRegisterAt(cond, 0); |
| 3034 | const Operand right = InputOperandAt(cond, 1); |
| 3035 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3036 | if (true_target == nullptr) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3037 | arm_cond = ARMCondition(condition->GetOppositeCondition()); |
| 3038 | non_fallthrough_target = false_target; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3039 | } else { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3040 | arm_cond = ARMCondition(condition->GetCondition()); |
| 3041 | non_fallthrough_target = true_target; |
| 3042 | } |
| 3043 | |
| 3044 | if (right.IsImmediate() && right.GetImmediate() == 0 && (arm_cond.Is(ne) || arm_cond.Is(eq))) { |
| 3045 | if (arm_cond.Is(eq)) { |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 3046 | __ CompareAndBranchIfZero(left, non_fallthrough_target, far_target); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3047 | } else { |
| 3048 | DCHECK(arm_cond.Is(ne)); |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 3049 | __ CompareAndBranchIfNonZero(left, non_fallthrough_target, far_target); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3050 | } |
| 3051 | } else { |
| 3052 | __ Cmp(left, right); |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 3053 | __ B(arm_cond, non_fallthrough_target, far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3054 | } |
| 3055 | } |
| 3056 | |
| 3057 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3058 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3059 | if (true_target != nullptr && false_target != nullptr) { |
| 3060 | __ B(false_target); |
| 3061 | } |
| 3062 | } |
| 3063 | |
| 3064 | void LocationsBuilderARMVIXL::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3065 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3066 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| 3067 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3068 | } |
| 3069 | } |
| 3070 | |
| 3071 | void InstructionCodeGeneratorARMVIXL::VisitIf(HIf* if_instr) { |
| 3072 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3073 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3074 | vixl32::Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 3075 | nullptr : codegen_->GetLabelOf(true_successor); |
| 3076 | vixl32::Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 3077 | nullptr : codegen_->GetLabelOf(false_successor); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3078 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
| 3079 | } |
| 3080 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3081 | void LocationsBuilderARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3082 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3083 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3084 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3085 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3086 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 3087 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3088 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| 3089 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3090 | } |
| 3091 | } |
| 3092 | |
| 3093 | void InstructionCodeGeneratorARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 3094 | SlowPathCodeARMVIXL* slow_path = |
| 3095 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARMVIXL>(deoptimize); |
| 3096 | GenerateTestAndBranch(deoptimize, |
| 3097 | /* condition_input_index */ 0, |
| 3098 | slow_path->GetEntryLabel(), |
| 3099 | /* false_target */ nullptr); |
| 3100 | } |
| 3101 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3102 | void LocationsBuilderARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3103 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3104 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3105 | locations->SetOut(Location::RequiresRegister()); |
| 3106 | } |
| 3107 | |
| 3108 | void InstructionCodeGeneratorARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3109 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3110 | OutputRegister(flag), |
| 3111 | sp, |
| 3112 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 3113 | } |
| 3114 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3115 | void LocationsBuilderARMVIXL::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3116 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3117 | const bool is_floating_point = DataType::IsFloatingPointType(select->GetType()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3118 | |
| 3119 | if (is_floating_point) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3120 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3121 | locations->SetInAt(1, Location::FpuRegisterOrConstant(select->GetTrueValue())); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3122 | } else { |
| 3123 | locations->SetInAt(0, Location::RequiresRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3124 | locations->SetInAt(1, Arm8BitEncodableConstantOrRegister(select->GetTrueValue())); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3125 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3126 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3127 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3128 | locations->SetInAt(2, Location::RegisterOrConstant(select->GetCondition())); |
| 3129 | // The code generator handles overlap with the values, but not with the condition. |
| 3130 | locations->SetOut(Location::SameAsFirstInput()); |
| 3131 | } else if (is_floating_point) { |
| 3132 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3133 | } else { |
| 3134 | if (!locations->InAt(1).IsConstant()) { |
| 3135 | locations->SetInAt(0, Arm8BitEncodableConstantOrRegister(select->GetFalseValue())); |
| 3136 | } |
| 3137 | |
| 3138 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3139 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3140 | } |
| 3141 | |
| 3142 | void InstructionCodeGeneratorARMVIXL::VisitSelect(HSelect* select) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3143 | HInstruction* const condition = select->GetCondition(); |
| 3144 | const LocationSummary* const locations = select->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3145 | const DataType::Type type = select->GetType(); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3146 | const Location first = locations->InAt(0); |
| 3147 | const Location out = locations->Out(); |
| 3148 | const Location second = locations->InAt(1); |
| 3149 | Location src; |
| 3150 | |
| 3151 | if (condition->IsIntConstant()) { |
| 3152 | if (condition->AsIntConstant()->IsFalse()) { |
| 3153 | src = first; |
| 3154 | } else { |
| 3155 | src = second; |
| 3156 | } |
| 3157 | |
| 3158 | codegen_->MoveLocation(out, src, type); |
| 3159 | return; |
| 3160 | } |
| 3161 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3162 | if (!DataType::IsFloatingPointType(type)) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3163 | bool invert = false; |
| 3164 | |
| 3165 | if (out.Equals(second)) { |
| 3166 | src = first; |
| 3167 | invert = true; |
| 3168 | } else if (out.Equals(first)) { |
| 3169 | src = second; |
| 3170 | } else if (second.IsConstant()) { |
| 3171 | DCHECK(CanEncodeConstantAs8BitImmediate(second.GetConstant())); |
| 3172 | src = second; |
| 3173 | } else if (first.IsConstant()) { |
| 3174 | DCHECK(CanEncodeConstantAs8BitImmediate(first.GetConstant())); |
| 3175 | src = first; |
| 3176 | invert = true; |
| 3177 | } else { |
| 3178 | src = second; |
| 3179 | } |
| 3180 | |
| 3181 | if (CanGenerateConditionalMove(out, src)) { |
| 3182 | if (!out.Equals(first) && !out.Equals(second)) { |
| 3183 | codegen_->MoveLocation(out, src.Equals(first) ? second : first, type); |
| 3184 | } |
| 3185 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3186 | std::pair<vixl32::Condition, vixl32::Condition> cond(eq, ne); |
| 3187 | |
| 3188 | if (IsBooleanValueOrMaterializedCondition(condition)) { |
| 3189 | __ Cmp(InputRegisterAt(select, 2), 0); |
| 3190 | cond = invert ? std::make_pair(eq, ne) : std::make_pair(ne, eq); |
| 3191 | } else { |
| 3192 | cond = GenerateTest(condition->AsCondition(), invert, codegen_); |
| 3193 | } |
| 3194 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3195 | const size_t instr_count = out.IsRegisterPair() ? 4 : 2; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3196 | // We use the scope because of the IT block that follows. |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3197 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 3198 | instr_count * vixl32::k16BitT32InstructionSizeInBytes, |
| 3199 | CodeBufferCheckScope::kExactSize); |
| 3200 | |
| 3201 | if (out.IsRegister()) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3202 | __ it(cond.first); |
| 3203 | __ mov(cond.first, RegisterFrom(out), OperandFrom(src, type)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3204 | } else { |
| 3205 | DCHECK(out.IsRegisterPair()); |
| 3206 | |
| 3207 | Operand operand_high(0); |
| 3208 | Operand operand_low(0); |
| 3209 | |
| 3210 | if (src.IsConstant()) { |
| 3211 | const int64_t value = Int64ConstantFrom(src); |
| 3212 | |
| 3213 | operand_high = High32Bits(value); |
| 3214 | operand_low = Low32Bits(value); |
| 3215 | } else { |
| 3216 | DCHECK(src.IsRegisterPair()); |
| 3217 | operand_high = HighRegisterFrom(src); |
| 3218 | operand_low = LowRegisterFrom(src); |
| 3219 | } |
| 3220 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3221 | __ it(cond.first); |
| 3222 | __ mov(cond.first, LowRegisterFrom(out), operand_low); |
| 3223 | __ it(cond.first); |
| 3224 | __ mov(cond.first, HighRegisterFrom(out), operand_high); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3225 | } |
| 3226 | |
| 3227 | return; |
| 3228 | } |
| 3229 | } |
| 3230 | |
| 3231 | vixl32::Label* false_target = nullptr; |
| 3232 | vixl32::Label* true_target = nullptr; |
| 3233 | vixl32::Label select_end; |
| 3234 | vixl32::Label* const target = codegen_->GetFinalLabel(select, &select_end); |
| 3235 | |
| 3236 | if (out.Equals(second)) { |
| 3237 | true_target = target; |
| 3238 | src = first; |
| 3239 | } else { |
| 3240 | false_target = target; |
| 3241 | src = second; |
| 3242 | |
| 3243 | if (!out.Equals(first)) { |
| 3244 | codegen_->MoveLocation(out, first, type); |
| 3245 | } |
| 3246 | } |
| 3247 | |
| 3248 | GenerateTestAndBranch(select, 2, true_target, false_target, /* far_target */ false); |
| 3249 | codegen_->MoveLocation(out, src, type); |
| 3250 | |
| 3251 | if (select_end.IsReferenced()) { |
| 3252 | __ Bind(&select_end); |
| 3253 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3254 | } |
| 3255 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 3256 | void LocationsBuilderARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3257 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 3258 | } |
| 3259 | |
| 3260 | void InstructionCodeGeneratorARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3261 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| 3262 | } |
| 3263 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3264 | void CodeGeneratorARMVIXL::GenerateNop() { |
| 3265 | __ Nop(); |
| 3266 | } |
| 3267 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3268 | // `temp` is an extra temporary register that is used for some conditions; |
| 3269 | // callers may not specify it, in which case the method will use a scratch |
| 3270 | // register instead. |
| 3271 | void CodeGeneratorARMVIXL::GenerateConditionWithZero(IfCondition condition, |
| 3272 | vixl32::Register out, |
| 3273 | vixl32::Register in, |
| 3274 | vixl32::Register temp) { |
| 3275 | switch (condition) { |
| 3276 | case kCondEQ: |
| 3277 | // x <= 0 iff x == 0 when the comparison is unsigned. |
| 3278 | case kCondBE: |
| 3279 | if (!temp.IsValid() || (out.IsLow() && !out.Is(in))) { |
| 3280 | temp = out; |
| 3281 | } |
| 3282 | |
| 3283 | // Avoid 32-bit instructions if possible; note that `in` and `temp` must be |
| 3284 | // different as well. |
| 3285 | if (in.IsLow() && temp.IsLow() && !in.Is(temp)) { |
| 3286 | // temp = - in; only 0 sets the carry flag. |
| 3287 | __ Rsbs(temp, in, 0); |
| 3288 | |
| 3289 | if (out.Is(in)) { |
| 3290 | std::swap(in, temp); |
| 3291 | } |
| 3292 | |
| 3293 | // out = - in + in + carry = carry |
| 3294 | __ Adc(out, temp, in); |
| 3295 | } else { |
| 3296 | // If `in` is 0, then it has 32 leading zeros, and less than that otherwise. |
| 3297 | __ Clz(out, in); |
| 3298 | // Any number less than 32 logically shifted right by 5 bits results in 0; |
| 3299 | // the same operation on 32 yields 1. |
| 3300 | __ Lsr(out, out, 5); |
| 3301 | } |
| 3302 | |
| 3303 | break; |
| 3304 | case kCondNE: |
| 3305 | // x > 0 iff x != 0 when the comparison is unsigned. |
| 3306 | case kCondA: { |
| 3307 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3308 | |
| 3309 | if (out.Is(in)) { |
| 3310 | if (!temp.IsValid() || in.Is(temp)) { |
| 3311 | temp = temps.Acquire(); |
| 3312 | } |
| 3313 | } else if (!temp.IsValid() || !temp.IsLow()) { |
| 3314 | temp = out; |
| 3315 | } |
| 3316 | |
| 3317 | // temp = in - 1; only 0 does not set the carry flag. |
| 3318 | __ Subs(temp, in, 1); |
| 3319 | // out = in + ~temp + carry = in + (-(in - 1) - 1) + carry = in - in + 1 - 1 + carry = carry |
| 3320 | __ Sbc(out, in, temp); |
| 3321 | break; |
| 3322 | } |
| 3323 | case kCondGE: |
| 3324 | __ Mvn(out, in); |
| 3325 | in = out; |
| 3326 | FALLTHROUGH_INTENDED; |
| 3327 | case kCondLT: |
| 3328 | // We only care about the sign bit. |
| 3329 | __ Lsr(out, in, 31); |
| 3330 | break; |
| 3331 | case kCondAE: |
| 3332 | // Trivially true. |
| 3333 | __ Mov(out, 1); |
| 3334 | break; |
| 3335 | case kCondB: |
| 3336 | // Trivially false. |
| 3337 | __ Mov(out, 0); |
| 3338 | break; |
| 3339 | default: |
| 3340 | LOG(FATAL) << "Unexpected condition " << condition; |
| 3341 | UNREACHABLE(); |
| 3342 | } |
| 3343 | } |
| 3344 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3345 | void LocationsBuilderARMVIXL::HandleCondition(HCondition* cond) { |
| 3346 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3347 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3348 | // Handle the long/FP comparisons made in instruction simplification. |
| 3349 | switch (cond->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3350 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3351 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3352 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 3353 | if (!cond->IsEmittedAtUseSite()) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3354 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3355 | } |
| 3356 | break; |
| 3357 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3358 | case DataType::Type::kFloat32: |
| 3359 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3360 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 3361 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3362 | if (!cond->IsEmittedAtUseSite()) { |
| 3363 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3364 | } |
| 3365 | break; |
| 3366 | |
| 3367 | default: |
| 3368 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3369 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 3370 | if (!cond->IsEmittedAtUseSite()) { |
| 3371 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3372 | } |
| 3373 | } |
| 3374 | } |
| 3375 | |
| 3376 | void InstructionCodeGeneratorARMVIXL::HandleCondition(HCondition* cond) { |
| 3377 | if (cond->IsEmittedAtUseSite()) { |
| 3378 | return; |
| 3379 | } |
| 3380 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3381 | const DataType::Type type = cond->GetLeft()->GetType(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3382 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3383 | if (DataType::IsFloatingPointType(type)) { |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3384 | GenerateConditionGeneric(cond, codegen_); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3385 | return; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3386 | } |
| 3387 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3388 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3389 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3390 | const IfCondition condition = cond->GetCondition(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3391 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3392 | // A condition with only one boolean input, or two boolean inputs without being equality or |
| 3393 | // inequality results from transformations done by the instruction simplifier, and is handled |
| 3394 | // as a regular condition with integral inputs. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3395 | if (type == DataType::Type::kBool && |
| 3396 | cond->GetRight()->GetType() == DataType::Type::kBool && |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3397 | (condition == kCondEQ || condition == kCondNE)) { |
| 3398 | vixl32::Register left = InputRegisterAt(cond, 0); |
| 3399 | const vixl32::Register out = OutputRegister(cond); |
| 3400 | const Location right_loc = cond->GetLocations()->InAt(1); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3401 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3402 | // The constant case is handled by the instruction simplifier. |
| 3403 | DCHECK(!right_loc.IsConstant()); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3404 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3405 | vixl32::Register right = RegisterFrom(right_loc); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3406 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3407 | // Avoid 32-bit instructions if possible. |
| 3408 | if (out.Is(right)) { |
| 3409 | std::swap(left, right); |
| 3410 | } |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3411 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3412 | __ Eor(out, left, right); |
| 3413 | |
| 3414 | if (condition == kCondEQ) { |
| 3415 | __ Eor(out, out, 1); |
| 3416 | } |
| 3417 | |
| 3418 | return; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3419 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 3420 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3421 | GenerateConditionIntegralOrNonPrimitive(cond, codegen_); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3422 | } |
| 3423 | |
| 3424 | void LocationsBuilderARMVIXL::VisitEqual(HEqual* comp) { |
| 3425 | HandleCondition(comp); |
| 3426 | } |
| 3427 | |
| 3428 | void InstructionCodeGeneratorARMVIXL::VisitEqual(HEqual* comp) { |
| 3429 | HandleCondition(comp); |
| 3430 | } |
| 3431 | |
| 3432 | void LocationsBuilderARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 3433 | HandleCondition(comp); |
| 3434 | } |
| 3435 | |
| 3436 | void InstructionCodeGeneratorARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 3437 | HandleCondition(comp); |
| 3438 | } |
| 3439 | |
| 3440 | void LocationsBuilderARMVIXL::VisitLessThan(HLessThan* comp) { |
| 3441 | HandleCondition(comp); |
| 3442 | } |
| 3443 | |
| 3444 | void InstructionCodeGeneratorARMVIXL::VisitLessThan(HLessThan* comp) { |
| 3445 | HandleCondition(comp); |
| 3446 | } |
| 3447 | |
| 3448 | void LocationsBuilderARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 3449 | HandleCondition(comp); |
| 3450 | } |
| 3451 | |
| 3452 | void InstructionCodeGeneratorARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 3453 | HandleCondition(comp); |
| 3454 | } |
| 3455 | |
| 3456 | void LocationsBuilderARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 3457 | HandleCondition(comp); |
| 3458 | } |
| 3459 | |
| 3460 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 3461 | HandleCondition(comp); |
| 3462 | } |
| 3463 | |
| 3464 | void LocationsBuilderARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 3465 | HandleCondition(comp); |
| 3466 | } |
| 3467 | |
| 3468 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 3469 | HandleCondition(comp); |
| 3470 | } |
| 3471 | |
| 3472 | void LocationsBuilderARMVIXL::VisitBelow(HBelow* comp) { |
| 3473 | HandleCondition(comp); |
| 3474 | } |
| 3475 | |
| 3476 | void InstructionCodeGeneratorARMVIXL::VisitBelow(HBelow* comp) { |
| 3477 | HandleCondition(comp); |
| 3478 | } |
| 3479 | |
| 3480 | void LocationsBuilderARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 3481 | HandleCondition(comp); |
| 3482 | } |
| 3483 | |
| 3484 | void InstructionCodeGeneratorARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 3485 | HandleCondition(comp); |
| 3486 | } |
| 3487 | |
| 3488 | void LocationsBuilderARMVIXL::VisitAbove(HAbove* comp) { |
| 3489 | HandleCondition(comp); |
| 3490 | } |
| 3491 | |
| 3492 | void InstructionCodeGeneratorARMVIXL::VisitAbove(HAbove* comp) { |
| 3493 | HandleCondition(comp); |
| 3494 | } |
| 3495 | |
| 3496 | void LocationsBuilderARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 3497 | HandleCondition(comp); |
| 3498 | } |
| 3499 | |
| 3500 | void InstructionCodeGeneratorARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 3501 | HandleCondition(comp); |
| 3502 | } |
| 3503 | |
| 3504 | void LocationsBuilderARMVIXL::VisitIntConstant(HIntConstant* constant) { |
| 3505 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3506 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3507 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3508 | } |
| 3509 | |
| 3510 | void InstructionCodeGeneratorARMVIXL::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 3511 | // Will be generated at use site. |
| 3512 | } |
| 3513 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3514 | void LocationsBuilderARMVIXL::VisitNullConstant(HNullConstant* constant) { |
| 3515 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3516 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3517 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3518 | } |
| 3519 | |
| 3520 | void InstructionCodeGeneratorARMVIXL::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 3521 | // Will be generated at use site. |
| 3522 | } |
| 3523 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3524 | void LocationsBuilderARMVIXL::VisitLongConstant(HLongConstant* constant) { |
| 3525 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3526 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3527 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3528 | } |
| 3529 | |
| 3530 | void InstructionCodeGeneratorARMVIXL::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 3531 | // Will be generated at use site. |
| 3532 | } |
| 3533 | |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3534 | void LocationsBuilderARMVIXL::VisitFloatConstant(HFloatConstant* constant) { |
| 3535 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3536 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3537 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3538 | } |
| 3539 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3540 | void InstructionCodeGeneratorARMVIXL::VisitFloatConstant( |
| 3541 | HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3542 | // Will be generated at use site. |
| 3543 | } |
| 3544 | |
| 3545 | void LocationsBuilderARMVIXL::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3546 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3547 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3548 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3549 | } |
| 3550 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3551 | void InstructionCodeGeneratorARMVIXL::VisitDoubleConstant( |
| 3552 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3553 | // Will be generated at use site. |
| 3554 | } |
| 3555 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 3556 | void LocationsBuilderARMVIXL::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 3557 | constructor_fence->SetLocations(nullptr); |
| 3558 | } |
| 3559 | |
| 3560 | void InstructionCodeGeneratorARMVIXL::VisitConstructorFence( |
| 3561 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 3562 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 3563 | } |
| 3564 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3565 | void LocationsBuilderARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3566 | memory_barrier->SetLocations(nullptr); |
| 3567 | } |
| 3568 | |
| 3569 | void InstructionCodeGeneratorARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3570 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 3571 | } |
| 3572 | |
| 3573 | void LocationsBuilderARMVIXL::VisitReturnVoid(HReturnVoid* ret) { |
| 3574 | ret->SetLocations(nullptr); |
| 3575 | } |
| 3576 | |
| 3577 | void InstructionCodeGeneratorARMVIXL::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 3578 | codegen_->GenerateFrameExit(); |
| 3579 | } |
| 3580 | |
| 3581 | void LocationsBuilderARMVIXL::VisitReturn(HReturn* ret) { |
| 3582 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3583 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3584 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
| 3585 | } |
| 3586 | |
| 3587 | void InstructionCodeGeneratorARMVIXL::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 3588 | codegen_->GenerateFrameExit(); |
| 3589 | } |
| 3590 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3591 | void LocationsBuilderARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3592 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3593 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3594 | // the method_idx. |
| 3595 | HandleInvoke(invoke); |
| 3596 | } |
| 3597 | |
| 3598 | void InstructionCodeGeneratorARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3599 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3600 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 3); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3601 | } |
| 3602 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3603 | void LocationsBuilderARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3604 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3605 | // art::PrepareForRegisterAllocation. |
| 3606 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 3607 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3608 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3609 | if (intrinsic.TryDispatch(invoke)) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3610 | return; |
| 3611 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3612 | |
| 3613 | HandleInvoke(invoke); |
| 3614 | } |
| 3615 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3616 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARMVIXL* codegen) { |
| 3617 | if (invoke->GetLocations()->Intrinsified()) { |
| 3618 | IntrinsicCodeGeneratorARMVIXL intrinsic(codegen); |
| 3619 | intrinsic.Dispatch(invoke); |
| 3620 | return true; |
| 3621 | } |
| 3622 | return false; |
| 3623 | } |
| 3624 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3625 | void InstructionCodeGeneratorARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3626 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3627 | // art::PrepareForRegisterAllocation. |
| 3628 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 3629 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3630 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3631 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 4); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3632 | return; |
| 3633 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3634 | |
| 3635 | LocationSummary* locations = invoke->GetLocations(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3636 | codegen_->GenerateStaticOrDirectCall( |
| 3637 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3638 | |
| 3639 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 5); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3640 | } |
| 3641 | |
| 3642 | void LocationsBuilderARMVIXL::HandleInvoke(HInvoke* invoke) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3643 | InvokeDexCallingConventionVisitorARMVIXL calling_convention_visitor; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3644 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 3645 | } |
| 3646 | |
| 3647 | void LocationsBuilderARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3648 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3649 | if (intrinsic.TryDispatch(invoke)) { |
| 3650 | return; |
| 3651 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3652 | |
| 3653 | HandleInvoke(invoke); |
| 3654 | } |
| 3655 | |
| 3656 | void InstructionCodeGeneratorARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3657 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3658 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 6); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3659 | return; |
| 3660 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3661 | |
| 3662 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3663 | DCHECK(!codegen_->IsLeafMethod()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3664 | |
| 3665 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 7); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3666 | } |
| 3667 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3668 | void LocationsBuilderARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3669 | HandleInvoke(invoke); |
| 3670 | // Add the hidden argument. |
| 3671 | invoke->GetLocations()->AddTemp(LocationFrom(r12)); |
| 3672 | } |
| 3673 | |
| 3674 | void InstructionCodeGeneratorARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3675 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 3676 | LocationSummary* locations = invoke->GetLocations(); |
| 3677 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 3678 | vixl32::Register hidden_reg = RegisterFrom(locations->GetTemp(1)); |
| 3679 | Location receiver = locations->InAt(0); |
| 3680 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3681 | |
| 3682 | DCHECK(!receiver.IsStackSlot()); |
| 3683 | |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3684 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
| 3685 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 3686 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 3687 | vixl32::kMaxInstructionSizeInBytes, |
| 3688 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3689 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 3690 | __ ldr(temp, MemOperand(RegisterFrom(receiver), class_offset)); |
| 3691 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 3692 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3693 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3694 | // emit a read barrier for the previous class reference load. |
| 3695 | // However this is not required in practice, as this is an |
| 3696 | // intermediate/temporary reference and because the current |
| 3697 | // concurrent copying collector keeps the from-space memory |
| 3698 | // intact/accessible until the end of the marking phase (the |
| 3699 | // concurrent copying collector may not in the future). |
| 3700 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 3701 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3702 | temp, |
| 3703 | temp, |
| 3704 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 3705 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 3706 | invoke->GetImtIndex(), kArmPointerSize)); |
| 3707 | // temp = temp->GetImtEntryAt(method_offset); |
| 3708 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 3709 | uint32_t entry_point = |
| 3710 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
| 3711 | // LR = temp->GetEntryPoint(); |
| 3712 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
| 3713 | |
| 3714 | // Set the hidden (in r12) argument. It is done here, right before a BLX to prevent other |
| 3715 | // instruction from clobbering it as they might use r12 as a scratch register. |
| 3716 | DCHECK(hidden_reg.Is(r12)); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3717 | |
| 3718 | { |
| 3719 | // The VIXL macro assembler may clobber any of the scratch registers that are available to it, |
| 3720 | // so it checks if the application is using them (by passing them to the macro assembler |
| 3721 | // methods). The following application of UseScratchRegisterScope corrects VIXL's notion of |
| 3722 | // what is available, and is the opposite of the standard usage: Instead of requesting a |
| 3723 | // temporary location, it imposes an external constraint (i.e. a specific register is reserved |
| 3724 | // for the hidden argument). Note that this works even if VIXL needs a scratch register itself |
| 3725 | // (to materialize the constant), since the destination register becomes available for such use |
| 3726 | // internally for the duration of the macro instruction. |
| 3727 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3728 | temps.Exclude(hidden_reg); |
| 3729 | __ Mov(hidden_reg, invoke->GetDexMethodIndex()); |
| 3730 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3731 | { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3732 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 3733 | // 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] | 3734 | ExactAssemblyScope aas(GetVIXLAssembler(), |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3735 | vixl32::k16BitT32InstructionSizeInBytes, |
| 3736 | CodeBufferCheckScope::kExactSize); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3737 | // LR(); |
| 3738 | __ blx(lr); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3739 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3740 | DCHECK(!codegen_->IsLeafMethod()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3741 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3742 | |
| 3743 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 8); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3744 | } |
| 3745 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3746 | void LocationsBuilderARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3747 | HandleInvoke(invoke); |
| 3748 | } |
| 3749 | |
| 3750 | void InstructionCodeGeneratorARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3751 | codegen_->GenerateInvokePolymorphicCall(invoke); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3752 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 9); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3753 | } |
| 3754 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3755 | void LocationsBuilderARMVIXL::VisitNeg(HNeg* neg) { |
| 3756 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3757 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3758 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3759 | case DataType::Type::kInt32: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3760 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3761 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3762 | break; |
| 3763 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3764 | case DataType::Type::kInt64: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3765 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3766 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3767 | break; |
| 3768 | } |
| 3769 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3770 | case DataType::Type::kFloat32: |
| 3771 | case DataType::Type::kFloat64: |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3772 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3773 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3774 | break; |
| 3775 | |
| 3776 | default: |
| 3777 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3778 | } |
| 3779 | } |
| 3780 | |
| 3781 | void InstructionCodeGeneratorARMVIXL::VisitNeg(HNeg* neg) { |
| 3782 | LocationSummary* locations = neg->GetLocations(); |
| 3783 | Location out = locations->Out(); |
| 3784 | Location in = locations->InAt(0); |
| 3785 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3786 | case DataType::Type::kInt32: |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3787 | __ Rsb(OutputRegister(neg), InputRegisterAt(neg, 0), 0); |
| 3788 | break; |
| 3789 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3790 | case DataType::Type::kInt64: |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3791 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 3792 | __ Rsbs(LowRegisterFrom(out), LowRegisterFrom(in), 0); |
| 3793 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 3794 | // instruction here, as it does not exist in the Thumb-2 |
| 3795 | // instruction set. We use the following approach |
| 3796 | // using SBC and SUB instead. |
| 3797 | // |
| 3798 | // out.hi = -C |
| 3799 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(out)); |
| 3800 | // out.hi = out.hi - in.hi |
| 3801 | __ Sub(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(in)); |
| 3802 | break; |
| 3803 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3804 | case DataType::Type::kFloat32: |
| 3805 | case DataType::Type::kFloat64: |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 3806 | __ Vneg(OutputVRegister(neg), InputVRegister(neg)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3807 | break; |
| 3808 | |
| 3809 | default: |
| 3810 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3811 | } |
| 3812 | } |
| 3813 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3814 | void LocationsBuilderARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3815 | DataType::Type result_type = conversion->GetResultType(); |
| 3816 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3817 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 3818 | << input_type << " -> " << result_type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3819 | |
| 3820 | // The float-to-long, double-to-long and long-to-float type conversions |
| 3821 | // rely on a call to the runtime. |
| 3822 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3823 | (((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) |
| 3824 | && result_type == DataType::Type::kInt64) |
| 3825 | || (input_type == DataType::Type::kInt64 && result_type == DataType::Type::kFloat32)) |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3826 | ? LocationSummary::kCallOnMainOnly |
| 3827 | : LocationSummary::kNoCall; |
| 3828 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3829 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3830 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3831 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3832 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3833 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3834 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3835 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3836 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 3837 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3838 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3839 | break; |
| 3840 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3841 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3842 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3843 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3844 | locations->SetInAt(0, Location::Any()); |
| 3845 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3846 | break; |
| 3847 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3848 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3849 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3850 | locations->SetOut(Location::RequiresRegister()); |
| 3851 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3852 | break; |
| 3853 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3854 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3855 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3856 | locations->SetOut(Location::RequiresRegister()); |
| 3857 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3858 | break; |
| 3859 | |
| 3860 | default: |
| 3861 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3862 | << " to " << result_type; |
| 3863 | } |
| 3864 | break; |
| 3865 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3866 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3867 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3868 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3869 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3870 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3871 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3872 | case DataType::Type::kInt16: |
| 3873 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3874 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3875 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3876 | break; |
| 3877 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3878 | case DataType::Type::kFloat32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3879 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3880 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 3881 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3882 | break; |
| 3883 | } |
| 3884 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3885 | case DataType::Type::kFloat64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3886 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3887 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0), |
| 3888 | calling_convention.GetFpuRegisterAt(1))); |
| 3889 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3890 | break; |
| 3891 | } |
| 3892 | |
| 3893 | default: |
| 3894 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3895 | << " to " << result_type; |
| 3896 | } |
| 3897 | break; |
| 3898 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3899 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3900 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3901 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3902 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3903 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3904 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3905 | case DataType::Type::kInt16: |
| 3906 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3907 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3908 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3909 | break; |
| 3910 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3911 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3912 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3913 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0), |
| 3914 | calling_convention.GetRegisterAt(1))); |
| 3915 | locations->SetOut(LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3916 | break; |
| 3917 | } |
| 3918 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3919 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3920 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3921 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3922 | break; |
| 3923 | |
| 3924 | default: |
| 3925 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3926 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3927 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3928 | break; |
| 3929 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3930 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3931 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3932 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3933 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3934 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3935 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3936 | case DataType::Type::kInt16: |
| 3937 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3938 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3939 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3940 | break; |
| 3941 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3942 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3943 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3944 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3945 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3946 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3947 | break; |
| 3948 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3949 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3950 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3951 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3952 | break; |
| 3953 | |
| 3954 | default: |
| 3955 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3956 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3957 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3958 | break; |
| 3959 | |
| 3960 | default: |
| 3961 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3962 | << " to " << result_type; |
| 3963 | } |
| 3964 | } |
| 3965 | |
| 3966 | void InstructionCodeGeneratorARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
| 3967 | LocationSummary* locations = conversion->GetLocations(); |
| 3968 | Location out = locations->Out(); |
| 3969 | Location in = locations->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3970 | DataType::Type result_type = conversion->GetResultType(); |
| 3971 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3972 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 3973 | << input_type << " -> " << result_type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3974 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3975 | case DataType::Type::kUint8: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3976 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3977 | case DataType::Type::kInt8: |
| 3978 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3979 | case DataType::Type::kInt16: |
| 3980 | case DataType::Type::kInt32: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3981 | __ Ubfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 8); |
| 3982 | break; |
| 3983 | case DataType::Type::kInt64: |
| 3984 | __ Ubfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 8); |
| 3985 | break; |
| 3986 | |
| 3987 | default: |
| 3988 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3989 | << " to " << result_type; |
| 3990 | } |
| 3991 | break; |
| 3992 | |
| 3993 | case DataType::Type::kInt8: |
| 3994 | switch (input_type) { |
| 3995 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3996 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3997 | case DataType::Type::kInt16: |
| 3998 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3999 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 8); |
| 4000 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4001 | case DataType::Type::kInt64: |
| 4002 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 8); |
| 4003 | break; |
| 4004 | |
| 4005 | default: |
| 4006 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4007 | << " to " << result_type; |
| 4008 | } |
| 4009 | break; |
| 4010 | |
| 4011 | case DataType::Type::kUint16: |
| 4012 | switch (input_type) { |
| 4013 | case DataType::Type::kInt8: |
| 4014 | case DataType::Type::kInt16: |
| 4015 | case DataType::Type::kInt32: |
| 4016 | __ Ubfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 4017 | break; |
| 4018 | case DataType::Type::kInt64: |
| 4019 | __ Ubfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
| 4020 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4021 | |
| 4022 | default: |
| 4023 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4024 | << " to " << result_type; |
| 4025 | } |
| 4026 | break; |
| 4027 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4028 | case DataType::Type::kInt16: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4029 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4030 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4031 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4032 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 4033 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4034 | case DataType::Type::kInt64: |
| 4035 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
| 4036 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4037 | |
| 4038 | default: |
| 4039 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4040 | << " to " << result_type; |
| 4041 | } |
| 4042 | break; |
| 4043 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4044 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4045 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4046 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4047 | DCHECK(out.IsRegister()); |
| 4048 | if (in.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4049 | __ Mov(OutputRegister(conversion), LowRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4050 | } else if (in.IsDoubleStackSlot()) { |
| 4051 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 4052 | OutputRegister(conversion), |
| 4053 | sp, |
| 4054 | in.GetStackIndex()); |
| 4055 | } else { |
| 4056 | DCHECK(in.IsConstant()); |
| 4057 | DCHECK(in.GetConstant()->IsLongConstant()); |
Vladimir Marko | ba1a48e | 2017-04-13 11:50:14 +0100 | [diff] [blame] | 4058 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 4059 | __ Mov(OutputRegister(conversion), static_cast<int32_t>(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4060 | } |
| 4061 | break; |
| 4062 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4063 | case DataType::Type::kFloat32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4064 | vixl32::SRegister temp = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4065 | __ Vcvt(S32, F32, temp, InputSRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4066 | __ Vmov(OutputRegister(conversion), temp); |
| 4067 | break; |
| 4068 | } |
| 4069 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4070 | case DataType::Type::kFloat64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4071 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4072 | __ Vcvt(S32, F64, temp_s, DRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4073 | __ Vmov(OutputRegister(conversion), temp_s); |
| 4074 | break; |
| 4075 | } |
| 4076 | |
| 4077 | default: |
| 4078 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4079 | << " to " << result_type; |
| 4080 | } |
| 4081 | break; |
| 4082 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4083 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4084 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4085 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4086 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4087 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4088 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4089 | case DataType::Type::kInt16: |
| 4090 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4091 | DCHECK(out.IsRegisterPair()); |
| 4092 | DCHECK(in.IsRegister()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4093 | __ Mov(LowRegisterFrom(out), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4094 | // Sign extension. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4095 | __ Asr(HighRegisterFrom(out), LowRegisterFrom(out), 31); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4096 | break; |
| 4097 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4098 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4099 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
| 4100 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 4101 | break; |
| 4102 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4103 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4104 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
| 4105 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 4106 | break; |
| 4107 | |
| 4108 | default: |
| 4109 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4110 | << " to " << result_type; |
| 4111 | } |
| 4112 | break; |
| 4113 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4114 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4115 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4116 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4117 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4118 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4119 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4120 | case DataType::Type::kInt16: |
| 4121 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4122 | __ Vmov(OutputSRegister(conversion), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4123 | __ Vcvt(F32, S32, OutputSRegister(conversion), OutputSRegister(conversion)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4124 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4125 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4126 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4127 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
| 4128 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 4129 | break; |
| 4130 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4131 | case DataType::Type::kFloat64: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4132 | __ Vcvt(F32, F64, OutputSRegister(conversion), DRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4133 | break; |
| 4134 | |
| 4135 | default: |
| 4136 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4137 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 4138 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4139 | break; |
| 4140 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4141 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4142 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4143 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4144 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4145 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4146 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4147 | case DataType::Type::kInt16: |
| 4148 | case DataType::Type::kInt32: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4149 | __ Vmov(LowSRegisterFrom(out), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4150 | __ Vcvt(F64, S32, DRegisterFrom(out), LowSRegisterFrom(out)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4151 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4152 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4153 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4154 | vixl32::Register low = LowRegisterFrom(in); |
| 4155 | vixl32::Register high = HighRegisterFrom(in); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4156 | vixl32::SRegister out_s = LowSRegisterFrom(out); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4157 | vixl32::DRegister out_d = DRegisterFrom(out); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4158 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4159 | vixl32::DRegister temp_d = DRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4160 | vixl32::DRegister constant_d = DRegisterFrom(locations->GetTemp(1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4161 | |
| 4162 | // temp_d = int-to-double(high) |
| 4163 | __ Vmov(temp_s, high); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4164 | __ Vcvt(F64, S32, temp_d, temp_s); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4165 | // constant_d = k2Pow32EncodingForDouble |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4166 | __ Vmov(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4167 | // out_d = unsigned-to-double(low) |
| 4168 | __ Vmov(out_s, low); |
| 4169 | __ Vcvt(F64, U32, out_d, out_s); |
| 4170 | // out_d += temp_d * constant_d |
| 4171 | __ Vmla(F64, out_d, temp_d, constant_d); |
| 4172 | break; |
| 4173 | } |
| 4174 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4175 | case DataType::Type::kFloat32: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4176 | __ Vcvt(F64, F32, DRegisterFrom(out), InputSRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4177 | break; |
| 4178 | |
| 4179 | default: |
| 4180 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4181 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 4182 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4183 | break; |
| 4184 | |
| 4185 | default: |
| 4186 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4187 | << " to " << result_type; |
| 4188 | } |
| 4189 | } |
| 4190 | |
| 4191 | void LocationsBuilderARMVIXL::VisitAdd(HAdd* add) { |
| 4192 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4193 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4194 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4195 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4196 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4197 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 4198 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4199 | break; |
| 4200 | } |
| 4201 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4202 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4203 | locations->SetInAt(0, Location::RequiresRegister()); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4204 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4205 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4206 | break; |
| 4207 | } |
| 4208 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4209 | case DataType::Type::kFloat32: |
| 4210 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4211 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4212 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4213 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4214 | break; |
| 4215 | } |
| 4216 | |
| 4217 | default: |
| 4218 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 4219 | } |
| 4220 | } |
| 4221 | |
| 4222 | void InstructionCodeGeneratorARMVIXL::VisitAdd(HAdd* add) { |
| 4223 | LocationSummary* locations = add->GetLocations(); |
| 4224 | Location out = locations->Out(); |
| 4225 | Location first = locations->InAt(0); |
| 4226 | Location second = locations->InAt(1); |
| 4227 | |
| 4228 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4229 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4230 | __ Add(OutputRegister(add), InputRegisterAt(add, 0), InputOperandAt(add, 1)); |
| 4231 | } |
| 4232 | break; |
| 4233 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4234 | case DataType::Type::kInt64: { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4235 | if (second.IsConstant()) { |
| 4236 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 4237 | GenerateAddLongConst(out, first, value); |
| 4238 | } else { |
| 4239 | DCHECK(second.IsRegisterPair()); |
| 4240 | __ Adds(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 4241 | __ Adc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 4242 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4243 | break; |
| 4244 | } |
| 4245 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4246 | case DataType::Type::kFloat32: |
| 4247 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4248 | __ Vadd(OutputVRegister(add), InputVRegisterAt(add, 0), InputVRegisterAt(add, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4249 | break; |
| 4250 | |
| 4251 | default: |
| 4252 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 4253 | } |
| 4254 | } |
| 4255 | |
| 4256 | void LocationsBuilderARMVIXL::VisitSub(HSub* sub) { |
| 4257 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4258 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4259 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4260 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4261 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4262 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
| 4263 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4264 | break; |
| 4265 | } |
| 4266 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4267 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4268 | locations->SetInAt(0, Location::RequiresRegister()); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4269 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4270 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4271 | break; |
| 4272 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4273 | case DataType::Type::kFloat32: |
| 4274 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4275 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4276 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4277 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4278 | break; |
| 4279 | } |
| 4280 | default: |
| 4281 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 4282 | } |
| 4283 | } |
| 4284 | |
| 4285 | void InstructionCodeGeneratorARMVIXL::VisitSub(HSub* sub) { |
| 4286 | LocationSummary* locations = sub->GetLocations(); |
| 4287 | Location out = locations->Out(); |
| 4288 | Location first = locations->InAt(0); |
| 4289 | Location second = locations->InAt(1); |
| 4290 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4291 | case DataType::Type::kInt32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4292 | __ Sub(OutputRegister(sub), InputRegisterAt(sub, 0), InputOperandAt(sub, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4293 | break; |
| 4294 | } |
| 4295 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4296 | case DataType::Type::kInt64: { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4297 | if (second.IsConstant()) { |
| 4298 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 4299 | GenerateAddLongConst(out, first, -value); |
| 4300 | } else { |
| 4301 | DCHECK(second.IsRegisterPair()); |
| 4302 | __ Subs(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 4303 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 4304 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4305 | break; |
| 4306 | } |
| 4307 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4308 | case DataType::Type::kFloat32: |
| 4309 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4310 | __ Vsub(OutputVRegister(sub), InputVRegisterAt(sub, 0), InputVRegisterAt(sub, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4311 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4312 | |
| 4313 | default: |
| 4314 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 4315 | } |
| 4316 | } |
| 4317 | |
| 4318 | void LocationsBuilderARMVIXL::VisitMul(HMul* mul) { |
| 4319 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4320 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4321 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4322 | case DataType::Type::kInt32: |
| 4323 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4324 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4325 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4326 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4327 | break; |
| 4328 | } |
| 4329 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4330 | case DataType::Type::kFloat32: |
| 4331 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4332 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4333 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4334 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4335 | break; |
| 4336 | } |
| 4337 | |
| 4338 | default: |
| 4339 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4340 | } |
| 4341 | } |
| 4342 | |
| 4343 | void InstructionCodeGeneratorARMVIXL::VisitMul(HMul* mul) { |
| 4344 | LocationSummary* locations = mul->GetLocations(); |
| 4345 | Location out = locations->Out(); |
| 4346 | Location first = locations->InAt(0); |
| 4347 | Location second = locations->InAt(1); |
| 4348 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4349 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4350 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 4351 | break; |
| 4352 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4353 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4354 | vixl32::Register out_hi = HighRegisterFrom(out); |
| 4355 | vixl32::Register out_lo = LowRegisterFrom(out); |
| 4356 | vixl32::Register in1_hi = HighRegisterFrom(first); |
| 4357 | vixl32::Register in1_lo = LowRegisterFrom(first); |
| 4358 | vixl32::Register in2_hi = HighRegisterFrom(second); |
| 4359 | vixl32::Register in2_lo = LowRegisterFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4360 | |
| 4361 | // Extra checks to protect caused by the existence of R1_R2. |
| 4362 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 4363 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4364 | DCHECK(!out_hi.Is(in1_lo)); |
| 4365 | DCHECK(!out_hi.Is(in2_lo)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4366 | |
| 4367 | // input: in1 - 64 bits, in2 - 64 bits |
| 4368 | // output: out |
| 4369 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 4370 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 4371 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 4372 | |
| 4373 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4374 | vixl32::Register temp = temps.Acquire(); |
| 4375 | // temp <- in1.lo * in2.hi |
| 4376 | __ Mul(temp, in1_lo, in2_hi); |
| 4377 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 4378 | __ Mla(out_hi, in1_hi, in2_lo, temp); |
| 4379 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 4380 | __ Umull(out_lo, temp, in1_lo, in2_lo); |
| 4381 | // 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] | 4382 | __ Add(out_hi, out_hi, temp); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4383 | break; |
| 4384 | } |
| 4385 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4386 | case DataType::Type::kFloat32: |
| 4387 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4388 | __ Vmul(OutputVRegister(mul), InputVRegisterAt(mul, 0), InputVRegisterAt(mul, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4389 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4390 | |
| 4391 | default: |
| 4392 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4393 | } |
| 4394 | } |
| 4395 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4396 | void InstructionCodeGeneratorARMVIXL::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 4397 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4398 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4399 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4400 | Location second = instruction->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4401 | DCHECK(second.IsConstant()); |
| 4402 | |
| 4403 | vixl32::Register out = OutputRegister(instruction); |
| 4404 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4405 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4406 | DCHECK(imm == 1 || imm == -1); |
| 4407 | |
| 4408 | if (instruction->IsRem()) { |
| 4409 | __ Mov(out, 0); |
| 4410 | } else { |
| 4411 | if (imm == 1) { |
| 4412 | __ Mov(out, dividend); |
| 4413 | } else { |
| 4414 | __ Rsb(out, dividend, 0); |
| 4415 | } |
| 4416 | } |
| 4417 | } |
| 4418 | |
| 4419 | void InstructionCodeGeneratorARMVIXL::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 4420 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4421 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4422 | |
| 4423 | LocationSummary* locations = instruction->GetLocations(); |
| 4424 | Location second = locations->InAt(1); |
| 4425 | DCHECK(second.IsConstant()); |
| 4426 | |
| 4427 | vixl32::Register out = OutputRegister(instruction); |
| 4428 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4429 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4430 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4431 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 4432 | int ctz_imm = CTZ(abs_imm); |
| 4433 | |
| 4434 | if (ctz_imm == 1) { |
| 4435 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 4436 | } else { |
| 4437 | __ Asr(temp, dividend, 31); |
| 4438 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 4439 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4440 | __ Add(out, temp, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4441 | |
| 4442 | if (instruction->IsDiv()) { |
| 4443 | __ Asr(out, out, ctz_imm); |
| 4444 | if (imm < 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4445 | __ Rsb(out, out, 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4446 | } |
| 4447 | } else { |
| 4448 | __ Ubfx(out, out, 0, ctz_imm); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4449 | __ Sub(out, out, temp); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4450 | } |
| 4451 | } |
| 4452 | |
| 4453 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 4454 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4455 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4456 | |
| 4457 | LocationSummary* locations = instruction->GetLocations(); |
| 4458 | Location second = locations->InAt(1); |
| 4459 | DCHECK(second.IsConstant()); |
| 4460 | |
| 4461 | vixl32::Register out = OutputRegister(instruction); |
| 4462 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4463 | vixl32::Register temp1 = RegisterFrom(locations->GetTemp(0)); |
| 4464 | vixl32::Register temp2 = RegisterFrom(locations->GetTemp(1)); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4465 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4466 | |
| 4467 | int64_t magic; |
| 4468 | int shift; |
| 4469 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 4470 | |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4471 | // TODO(VIXL): Change the static cast to Operand::From() after VIXL is fixed. |
| 4472 | __ Mov(temp1, static_cast<int32_t>(magic)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4473 | __ Smull(temp2, temp1, dividend, temp1); |
| 4474 | |
| 4475 | if (imm > 0 && magic < 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4476 | __ Add(temp1, temp1, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4477 | } else if (imm < 0 && magic > 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4478 | __ Sub(temp1, temp1, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4479 | } |
| 4480 | |
| 4481 | if (shift != 0) { |
| 4482 | __ Asr(temp1, temp1, shift); |
| 4483 | } |
| 4484 | |
| 4485 | if (instruction->IsDiv()) { |
| 4486 | __ Sub(out, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 4487 | } else { |
| 4488 | __ Sub(temp1, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 4489 | // TODO: Strength reduction for mls. |
| 4490 | __ Mov(temp2, imm); |
| 4491 | __ Mls(out, temp1, temp2, dividend); |
| 4492 | } |
| 4493 | } |
| 4494 | |
| 4495 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemConstantIntegral( |
| 4496 | HBinaryOperation* instruction) { |
| 4497 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4498 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4499 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4500 | Location second = instruction->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4501 | DCHECK(second.IsConstant()); |
| 4502 | |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4503 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4504 | if (imm == 0) { |
| 4505 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4506 | } else if (imm == 1 || imm == -1) { |
| 4507 | DivRemOneOrMinusOne(instruction); |
| 4508 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 4509 | DivRemByPowerOfTwo(instruction); |
| 4510 | } else { |
| 4511 | DCHECK(imm <= -2 || imm >= 2); |
| 4512 | GenerateDivRemWithAnyConstant(instruction); |
| 4513 | } |
| 4514 | } |
| 4515 | |
| 4516 | void LocationsBuilderARMVIXL::VisitDiv(HDiv* div) { |
| 4517 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4518 | if (div->GetResultType() == DataType::Type::kInt64) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4519 | // pLdiv runtime call. |
| 4520 | call_kind = LocationSummary::kCallOnMainOnly; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4521 | } else if (div->GetResultType() == DataType::Type::kInt32 && div->InputAt(1)->IsConstant()) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4522 | // sdiv will be replaced by other instruction sequence. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4523 | } else if (div->GetResultType() == DataType::Type::kInt32 && |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4524 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4525 | // pIdivmod runtime call. |
| 4526 | call_kind = LocationSummary::kCallOnMainOnly; |
| 4527 | } |
| 4528 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4529 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4530 | |
| 4531 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4532 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4533 | if (div->InputAt(1)->IsConstant()) { |
| 4534 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4535 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
| 4536 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4537 | int32_t value = Int32ConstantFrom(div->InputAt(1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4538 | if (value == 1 || value == 0 || value == -1) { |
| 4539 | // No temp register required. |
| 4540 | } else { |
| 4541 | locations->AddTemp(Location::RequiresRegister()); |
| 4542 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
| 4543 | locations->AddTemp(Location::RequiresRegister()); |
| 4544 | } |
| 4545 | } |
| 4546 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4547 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4548 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4549 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4550 | } else { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4551 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4552 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4553 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4554 | // 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] | 4555 | // we only need the former. |
| 4556 | locations->SetOut(LocationFrom(r0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4557 | } |
| 4558 | break; |
| 4559 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4560 | case DataType::Type::kInt64: { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4561 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4562 | locations->SetInAt(0, LocationFrom( |
| 4563 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4564 | locations->SetInAt(1, LocationFrom( |
| 4565 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4566 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4567 | break; |
| 4568 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4569 | case DataType::Type::kFloat32: |
| 4570 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4571 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4572 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4573 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4574 | break; |
| 4575 | } |
| 4576 | |
| 4577 | default: |
| 4578 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4579 | } |
| 4580 | } |
| 4581 | |
| 4582 | void InstructionCodeGeneratorARMVIXL::VisitDiv(HDiv* div) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4583 | Location lhs = div->GetLocations()->InAt(0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4584 | Location rhs = div->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4585 | |
| 4586 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4587 | case DataType::Type::kInt32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4588 | if (rhs.IsConstant()) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4589 | GenerateDivRemConstantIntegral(div); |
| 4590 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4591 | __ Sdiv(OutputRegister(div), InputRegisterAt(div, 0), InputRegisterAt(div, 1)); |
| 4592 | } else { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4593 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4594 | DCHECK(calling_convention.GetRegisterAt(0).Is(RegisterFrom(lhs))); |
| 4595 | DCHECK(calling_convention.GetRegisterAt(1).Is(RegisterFrom(rhs))); |
| 4596 | DCHECK(r0.Is(OutputRegister(div))); |
| 4597 | |
| 4598 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
| 4599 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4600 | } |
| 4601 | break; |
| 4602 | } |
| 4603 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4604 | case DataType::Type::kInt64: { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4605 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4606 | DCHECK(calling_convention.GetRegisterAt(0).Is(LowRegisterFrom(lhs))); |
| 4607 | DCHECK(calling_convention.GetRegisterAt(1).Is(HighRegisterFrom(lhs))); |
| 4608 | DCHECK(calling_convention.GetRegisterAt(2).Is(LowRegisterFrom(rhs))); |
| 4609 | DCHECK(calling_convention.GetRegisterAt(3).Is(HighRegisterFrom(rhs))); |
| 4610 | DCHECK(LowRegisterFrom(div->GetLocations()->Out()).Is(r0)); |
| 4611 | DCHECK(HighRegisterFrom(div->GetLocations()->Out()).Is(r1)); |
| 4612 | |
| 4613 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
| 4614 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4615 | break; |
| 4616 | } |
| 4617 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4618 | case DataType::Type::kFloat32: |
| 4619 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4620 | __ Vdiv(OutputVRegister(div), InputVRegisterAt(div, 0), InputVRegisterAt(div, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4621 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4622 | |
| 4623 | default: |
| 4624 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4625 | } |
| 4626 | } |
| 4627 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4628 | void LocationsBuilderARMVIXL::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4629 | DataType::Type type = rem->GetResultType(); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4630 | |
| 4631 | // Most remainders are implemented in the runtime. |
| 4632 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4633 | if (rem->GetResultType() == DataType::Type::kInt32 && rem->InputAt(1)->IsConstant()) { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4634 | // sdiv will be replaced by other instruction sequence. |
| 4635 | call_kind = LocationSummary::kNoCall; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4636 | } else if ((rem->GetResultType() == DataType::Type::kInt32) |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4637 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4638 | // Have hardware divide instruction for int, do it with three instructions. |
| 4639 | call_kind = LocationSummary::kNoCall; |
| 4640 | } |
| 4641 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4642 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4643 | |
| 4644 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4645 | case DataType::Type::kInt32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4646 | if (rem->InputAt(1)->IsConstant()) { |
| 4647 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4648 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
| 4649 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4650 | int32_t value = Int32ConstantFrom(rem->InputAt(1)); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4651 | if (value == 1 || value == 0 || value == -1) { |
| 4652 | // No temp register required. |
| 4653 | } else { |
| 4654 | locations->AddTemp(Location::RequiresRegister()); |
| 4655 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
| 4656 | locations->AddTemp(Location::RequiresRegister()); |
| 4657 | } |
| 4658 | } |
| 4659 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4660 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4661 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4662 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4663 | locations->AddTemp(Location::RequiresRegister()); |
| 4664 | } else { |
| 4665 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4666 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4667 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4668 | // 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] | 4669 | // we only need the latter. |
| 4670 | locations->SetOut(LocationFrom(r1)); |
| 4671 | } |
| 4672 | break; |
| 4673 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4674 | case DataType::Type::kInt64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4675 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4676 | locations->SetInAt(0, LocationFrom( |
| 4677 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4678 | locations->SetInAt(1, LocationFrom( |
| 4679 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4680 | // The runtime helper puts the output in R2,R3. |
| 4681 | locations->SetOut(LocationFrom(r2, r3)); |
| 4682 | break; |
| 4683 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4684 | case DataType::Type::kFloat32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4685 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4686 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 4687 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 4688 | locations->SetOut(LocationFrom(s0)); |
| 4689 | break; |
| 4690 | } |
| 4691 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4692 | case DataType::Type::kFloat64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4693 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4694 | locations->SetInAt(0, LocationFrom( |
| 4695 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 4696 | locations->SetInAt(1, LocationFrom( |
| 4697 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 4698 | locations->SetOut(LocationFrom(s0, s1)); |
| 4699 | break; |
| 4700 | } |
| 4701 | |
| 4702 | default: |
| 4703 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4704 | } |
| 4705 | } |
| 4706 | |
| 4707 | void InstructionCodeGeneratorARMVIXL::VisitRem(HRem* rem) { |
| 4708 | LocationSummary* locations = rem->GetLocations(); |
| 4709 | Location second = locations->InAt(1); |
| 4710 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4711 | DataType::Type type = rem->GetResultType(); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4712 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4713 | case DataType::Type::kInt32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4714 | vixl32::Register reg1 = InputRegisterAt(rem, 0); |
| 4715 | vixl32::Register out_reg = OutputRegister(rem); |
| 4716 | if (second.IsConstant()) { |
| 4717 | GenerateDivRemConstantIntegral(rem); |
| 4718 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4719 | vixl32::Register reg2 = RegisterFrom(second); |
| 4720 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 4721 | |
| 4722 | // temp = reg1 / reg2 (integer division) |
| 4723 | // dest = reg1 - temp * reg2 |
| 4724 | __ Sdiv(temp, reg1, reg2); |
| 4725 | __ Mls(out_reg, temp, reg2, reg1); |
| 4726 | } else { |
| 4727 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4728 | DCHECK(reg1.Is(calling_convention.GetRegisterAt(0))); |
| 4729 | DCHECK(RegisterFrom(second).Is(calling_convention.GetRegisterAt(1))); |
| 4730 | DCHECK(out_reg.Is(r1)); |
| 4731 | |
| 4732 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
| 4733 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
| 4734 | } |
| 4735 | break; |
| 4736 | } |
| 4737 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4738 | case DataType::Type::kInt64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4739 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
| 4740 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 4741 | break; |
| 4742 | } |
| 4743 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4744 | case DataType::Type::kFloat32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4745 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
| 4746 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 4747 | break; |
| 4748 | } |
| 4749 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4750 | case DataType::Type::kFloat64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4751 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
| 4752 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 4753 | break; |
| 4754 | } |
| 4755 | |
| 4756 | default: |
| 4757 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4758 | } |
| 4759 | } |
| 4760 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4761 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 4762 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 4763 | switch (minmax->GetResultType()) { |
| 4764 | case DataType::Type::kInt32: |
| 4765 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4766 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4767 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4768 | break; |
| 4769 | case DataType::Type::kInt64: |
| 4770 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4771 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4772 | locations->SetOut(Location::SameAsFirstInput()); |
| 4773 | break; |
| 4774 | case DataType::Type::kFloat32: |
| 4775 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4776 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4777 | locations->SetOut(Location::SameAsFirstInput()); |
| 4778 | locations->AddTemp(Location::RequiresRegister()); |
| 4779 | break; |
| 4780 | case DataType::Type::kFloat64: |
| 4781 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4782 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4783 | locations->SetOut(Location::SameAsFirstInput()); |
| 4784 | break; |
| 4785 | default: |
| 4786 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 4787 | } |
| 4788 | } |
| 4789 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4790 | void InstructionCodeGeneratorARMVIXL::GenerateMinMaxInt(LocationSummary* locations, bool is_min) { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4791 | Location op1_loc = locations->InAt(0); |
| 4792 | Location op2_loc = locations->InAt(1); |
| 4793 | Location out_loc = locations->Out(); |
| 4794 | |
| 4795 | vixl32::Register op1 = RegisterFrom(op1_loc); |
| 4796 | vixl32::Register op2 = RegisterFrom(op2_loc); |
| 4797 | vixl32::Register out = RegisterFrom(out_loc); |
| 4798 | |
| 4799 | __ Cmp(op1, op2); |
| 4800 | |
| 4801 | { |
| 4802 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 4803 | 3 * kMaxInstructionSizeInBytes, |
| 4804 | CodeBufferCheckScope::kMaximumSize); |
| 4805 | |
| 4806 | __ ite(is_min ? lt : gt); |
| 4807 | __ mov(is_min ? lt : gt, out, op1); |
| 4808 | __ mov(is_min ? ge : le, out, op2); |
| 4809 | } |
| 4810 | } |
| 4811 | |
| 4812 | void InstructionCodeGeneratorARMVIXL::GenerateMinMaxLong(LocationSummary* locations, bool is_min) { |
| 4813 | Location op1_loc = locations->InAt(0); |
| 4814 | Location op2_loc = locations->InAt(1); |
| 4815 | Location out_loc = locations->Out(); |
| 4816 | |
| 4817 | // Optimization: don't generate any code if inputs are the same. |
| 4818 | if (op1_loc.Equals(op2_loc)) { |
| 4819 | DCHECK(out_loc.Equals(op1_loc)); // out_loc is set as SameAsFirstInput() in location builder. |
| 4820 | return; |
| 4821 | } |
| 4822 | |
| 4823 | vixl32::Register op1_lo = LowRegisterFrom(op1_loc); |
| 4824 | vixl32::Register op1_hi = HighRegisterFrom(op1_loc); |
| 4825 | vixl32::Register op2_lo = LowRegisterFrom(op2_loc); |
| 4826 | vixl32::Register op2_hi = HighRegisterFrom(op2_loc); |
| 4827 | vixl32::Register out_lo = LowRegisterFrom(out_loc); |
| 4828 | vixl32::Register out_hi = HighRegisterFrom(out_loc); |
| 4829 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4830 | const vixl32::Register temp = temps.Acquire(); |
| 4831 | |
| 4832 | DCHECK(op1_lo.Is(out_lo)); |
| 4833 | DCHECK(op1_hi.Is(out_hi)); |
| 4834 | |
| 4835 | // Compare op1 >= op2, or op1 < op2. |
| 4836 | __ Cmp(out_lo, op2_lo); |
| 4837 | __ Sbcs(temp, out_hi, op2_hi); |
| 4838 | |
| 4839 | // Now GE/LT condition code is correct for the long comparison. |
| 4840 | { |
| 4841 | vixl32::ConditionType cond = is_min ? ge : lt; |
| 4842 | ExactAssemblyScope it_scope(GetVIXLAssembler(), |
| 4843 | 3 * kMaxInstructionSizeInBytes, |
| 4844 | CodeBufferCheckScope::kMaximumSize); |
| 4845 | __ itt(cond); |
| 4846 | __ mov(cond, out_lo, op2_lo); |
| 4847 | __ mov(cond, out_hi, op2_hi); |
| 4848 | } |
| 4849 | } |
| 4850 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4851 | void InstructionCodeGeneratorARMVIXL::GenerateMinMaxFloat(HInstruction* minmax, bool is_min) { |
| 4852 | LocationSummary* locations = minmax->GetLocations(); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4853 | Location op1_loc = locations->InAt(0); |
| 4854 | Location op2_loc = locations->InAt(1); |
| 4855 | Location out_loc = locations->Out(); |
| 4856 | |
| 4857 | // Optimization: don't generate any code if inputs are the same. |
| 4858 | if (op1_loc.Equals(op2_loc)) { |
| 4859 | DCHECK(out_loc.Equals(op1_loc)); // out_loc is set as SameAsFirstInput() in location builder. |
| 4860 | return; |
| 4861 | } |
| 4862 | |
| 4863 | vixl32::SRegister op1 = SRegisterFrom(op1_loc); |
| 4864 | vixl32::SRegister op2 = SRegisterFrom(op2_loc); |
| 4865 | vixl32::SRegister out = SRegisterFrom(out_loc); |
| 4866 | |
| 4867 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4868 | const vixl32::Register temp1 = temps.Acquire(); |
| 4869 | vixl32::Register temp2 = RegisterFrom(locations->GetTemp(0)); |
| 4870 | vixl32::Label nan, done; |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4871 | vixl32::Label* final_label = codegen_->GetFinalLabel(minmax, &done); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4872 | |
| 4873 | DCHECK(op1.Is(out)); |
| 4874 | |
| 4875 | __ Vcmp(op1, op2); |
| 4876 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 4877 | __ B(vs, &nan, /* far_target */ false); // if un-ordered, go to NaN handling. |
| 4878 | |
| 4879 | // op1 <> op2 |
| 4880 | vixl32::ConditionType cond = is_min ? gt : lt; |
| 4881 | { |
| 4882 | ExactAssemblyScope it_scope(GetVIXLAssembler(), |
| 4883 | 2 * kMaxInstructionSizeInBytes, |
| 4884 | CodeBufferCheckScope::kMaximumSize); |
| 4885 | __ it(cond); |
| 4886 | __ vmov(cond, F32, out, op2); |
| 4887 | } |
| 4888 | // for <>(not equal), we've done min/max calculation. |
| 4889 | __ B(ne, final_label, /* far_target */ false); |
| 4890 | |
| 4891 | // handle op1 == op2, max(+0.0,-0.0), min(+0.0,-0.0). |
| 4892 | __ Vmov(temp1, op1); |
| 4893 | __ Vmov(temp2, op2); |
| 4894 | if (is_min) { |
| 4895 | __ Orr(temp1, temp1, temp2); |
| 4896 | } else { |
| 4897 | __ And(temp1, temp1, temp2); |
| 4898 | } |
| 4899 | __ Vmov(out, temp1); |
| 4900 | __ B(final_label); |
| 4901 | |
| 4902 | // handle NaN input. |
| 4903 | __ Bind(&nan); |
| 4904 | __ Movt(temp1, High16Bits(kNanFloat)); // 0x7FC0xxxx is a NaN. |
| 4905 | __ Vmov(out, temp1); |
| 4906 | |
| 4907 | if (done.IsReferenced()) { |
| 4908 | __ Bind(&done); |
| 4909 | } |
| 4910 | } |
| 4911 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4912 | void InstructionCodeGeneratorARMVIXL::GenerateMinMaxDouble(HInstruction* minmax, bool is_min) { |
| 4913 | LocationSummary* locations = minmax->GetLocations(); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4914 | Location op1_loc = locations->InAt(0); |
| 4915 | Location op2_loc = locations->InAt(1); |
| 4916 | Location out_loc = locations->Out(); |
| 4917 | |
| 4918 | // Optimization: don't generate any code if inputs are the same. |
| 4919 | if (op1_loc.Equals(op2_loc)) { |
| 4920 | DCHECK(out_loc.Equals(op1_loc)); // out_loc is set as SameAsFirstInput() in. |
| 4921 | return; |
| 4922 | } |
| 4923 | |
| 4924 | vixl32::DRegister op1 = DRegisterFrom(op1_loc); |
| 4925 | vixl32::DRegister op2 = DRegisterFrom(op2_loc); |
| 4926 | vixl32::DRegister out = DRegisterFrom(out_loc); |
| 4927 | vixl32::Label handle_nan_eq, done; |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4928 | vixl32::Label* final_label = codegen_->GetFinalLabel(minmax, &done); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4929 | |
| 4930 | DCHECK(op1.Is(out)); |
| 4931 | |
| 4932 | __ Vcmp(op1, op2); |
| 4933 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 4934 | __ B(vs, &handle_nan_eq, /* far_target */ false); // if un-ordered, go to NaN handling. |
| 4935 | |
| 4936 | // op1 <> op2 |
| 4937 | vixl32::ConditionType cond = is_min ? gt : lt; |
| 4938 | { |
| 4939 | ExactAssemblyScope it_scope(GetVIXLAssembler(), |
| 4940 | 2 * kMaxInstructionSizeInBytes, |
| 4941 | CodeBufferCheckScope::kMaximumSize); |
| 4942 | __ it(cond); |
| 4943 | __ vmov(cond, F64, out, op2); |
| 4944 | } |
| 4945 | // for <>(not equal), we've done min/max calculation. |
| 4946 | __ B(ne, final_label, /* far_target */ false); |
| 4947 | |
| 4948 | // handle op1 == op2, max(+0.0,-0.0). |
| 4949 | if (!is_min) { |
| 4950 | __ Vand(F64, out, op1, op2); |
| 4951 | __ B(final_label); |
| 4952 | } |
| 4953 | |
| 4954 | // handle op1 == op2, min(+0.0,-0.0), NaN input. |
| 4955 | __ Bind(&handle_nan_eq); |
| 4956 | __ Vorr(F64, out, op1, op2); // assemble op1/-0.0/NaN. |
| 4957 | |
| 4958 | if (done.IsReferenced()) { |
| 4959 | __ Bind(&done); |
| 4960 | } |
| 4961 | } |
| 4962 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4963 | void InstructionCodeGeneratorARMVIXL::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 4964 | DataType::Type type = minmax->GetResultType(); |
| 4965 | switch (type) { |
| 4966 | case DataType::Type::kInt32: |
| 4967 | GenerateMinMaxInt(minmax->GetLocations(), is_min); |
| 4968 | break; |
| 4969 | case DataType::Type::kInt64: |
| 4970 | GenerateMinMaxLong(minmax->GetLocations(), is_min); |
| 4971 | break; |
| 4972 | case DataType::Type::kFloat32: |
| 4973 | GenerateMinMaxFloat(minmax, is_min); |
| 4974 | break; |
| 4975 | case DataType::Type::kFloat64: |
| 4976 | GenerateMinMaxDouble(minmax, is_min); |
| 4977 | break; |
| 4978 | default: |
| 4979 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 4980 | } |
| 4981 | } |
| 4982 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4983 | void LocationsBuilderARMVIXL::VisitMin(HMin* min) { |
| 4984 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 4985 | } |
| 4986 | |
| 4987 | void InstructionCodeGeneratorARMVIXL::VisitMin(HMin* min) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4988 | GenerateMinMax(min, /*is_min*/ true); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4989 | } |
| 4990 | |
| 4991 | void LocationsBuilderARMVIXL::VisitMax(HMax* max) { |
| 4992 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 4993 | } |
| 4994 | |
| 4995 | void InstructionCodeGeneratorARMVIXL::VisitMax(HMax* max) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4996 | GenerateMinMax(max, /*is_min*/ false); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4997 | } |
| 4998 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 4999 | void LocationsBuilderARMVIXL::VisitAbs(HAbs* abs) { |
| 5000 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 5001 | switch (abs->GetResultType()) { |
| 5002 | case DataType::Type::kInt32: |
| 5003 | case DataType::Type::kInt64: |
| 5004 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5005 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5006 | locations->AddTemp(Location::RequiresRegister()); |
| 5007 | break; |
| 5008 | case DataType::Type::kFloat32: |
| 5009 | case DataType::Type::kFloat64: |
| 5010 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5011 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5012 | break; |
| 5013 | default: |
| 5014 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 5015 | } |
| 5016 | } |
| 5017 | |
| 5018 | void InstructionCodeGeneratorARMVIXL::VisitAbs(HAbs* abs) { |
| 5019 | LocationSummary* locations = abs->GetLocations(); |
| 5020 | switch (abs->GetResultType()) { |
| 5021 | case DataType::Type::kInt32: { |
| 5022 | vixl32::Register in_reg = RegisterFrom(locations->InAt(0)); |
| 5023 | vixl32::Register out_reg = RegisterFrom(locations->Out()); |
| 5024 | vixl32::Register mask = RegisterFrom(locations->GetTemp(0)); |
| 5025 | __ Asr(mask, in_reg, 31); |
| 5026 | __ Add(out_reg, in_reg, mask); |
| 5027 | __ Eor(out_reg, out_reg, mask); |
| 5028 | break; |
| 5029 | } |
| 5030 | case DataType::Type::kInt64: { |
| 5031 | Location in = locations->InAt(0); |
| 5032 | vixl32::Register in_reg_lo = LowRegisterFrom(in); |
| 5033 | vixl32::Register in_reg_hi = HighRegisterFrom(in); |
| 5034 | Location output = locations->Out(); |
| 5035 | vixl32::Register out_reg_lo = LowRegisterFrom(output); |
| 5036 | vixl32::Register out_reg_hi = HighRegisterFrom(output); |
| 5037 | DCHECK(!out_reg_lo.Is(in_reg_hi)) << "Diagonal overlap unexpected."; |
| 5038 | vixl32::Register mask = RegisterFrom(locations->GetTemp(0)); |
| 5039 | __ Asr(mask, in_reg_hi, 31); |
| 5040 | __ Adds(out_reg_lo, in_reg_lo, mask); |
| 5041 | __ Adc(out_reg_hi, in_reg_hi, mask); |
| 5042 | __ Eor(out_reg_lo, out_reg_lo, mask); |
| 5043 | __ Eor(out_reg_hi, out_reg_hi, mask); |
| 5044 | break; |
| 5045 | } |
| 5046 | case DataType::Type::kFloat32: |
| 5047 | case DataType::Type::kFloat64: |
| 5048 | __ Vabs(OutputVRegister(abs), InputVRegisterAt(abs, 0)); |
| 5049 | break; |
| 5050 | default: |
| 5051 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 5052 | } |
| 5053 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 5054 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5055 | void LocationsBuilderARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 5056 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5057 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5058 | } |
| 5059 | |
| 5060 | void InstructionCodeGeneratorARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 5061 | DivZeroCheckSlowPathARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5062 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathARMVIXL(instruction); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5063 | codegen_->AddSlowPath(slow_path); |
| 5064 | |
| 5065 | LocationSummary* locations = instruction->GetLocations(); |
| 5066 | Location value = locations->InAt(0); |
| 5067 | |
| 5068 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5069 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5070 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5071 | case DataType::Type::kInt8: |
| 5072 | case DataType::Type::kUint16: |
| 5073 | case DataType::Type::kInt16: |
| 5074 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5075 | if (value.IsRegister()) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5076 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5077 | } else { |
| 5078 | DCHECK(value.IsConstant()) << value; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5079 | if (Int32ConstantFrom(value) == 0) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5080 | __ B(slow_path->GetEntryLabel()); |
| 5081 | } |
| 5082 | } |
| 5083 | break; |
| 5084 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5085 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5086 | if (value.IsRegisterPair()) { |
| 5087 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5088 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5089 | __ Orrs(temp, LowRegisterFrom(value), HighRegisterFrom(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5090 | __ B(eq, slow_path->GetEntryLabel()); |
| 5091 | } else { |
| 5092 | DCHECK(value.IsConstant()) << value; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5093 | if (Int64ConstantFrom(value) == 0) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5094 | __ B(slow_path->GetEntryLabel()); |
| 5095 | } |
| 5096 | } |
| 5097 | break; |
| 5098 | } |
| 5099 | default: |
| 5100 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 5101 | } |
| 5102 | } |
| 5103 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5104 | void InstructionCodeGeneratorARMVIXL::HandleIntegerRotate(HRor* ror) { |
| 5105 | LocationSummary* locations = ror->GetLocations(); |
| 5106 | vixl32::Register in = InputRegisterAt(ror, 0); |
| 5107 | Location rhs = locations->InAt(1); |
| 5108 | vixl32::Register out = OutputRegister(ror); |
| 5109 | |
| 5110 | if (rhs.IsConstant()) { |
| 5111 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 5112 | // so map all rotations to a +ve. equivalent in that range. |
| 5113 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 5114 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 5115 | if (rot) { |
| 5116 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 5117 | // (e.g. left by 2 bits == right by 30.) |
| 5118 | __ Ror(out, in, rot); |
| 5119 | } else if (!out.Is(in)) { |
| 5120 | __ Mov(out, in); |
| 5121 | } |
| 5122 | } else { |
| 5123 | __ Ror(out, in, RegisterFrom(rhs)); |
| 5124 | } |
| 5125 | } |
| 5126 | |
| 5127 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 5128 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 5129 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 5130 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 5131 | void InstructionCodeGeneratorARMVIXL::HandleLongRotate(HRor* ror) { |
| 5132 | LocationSummary* locations = ror->GetLocations(); |
| 5133 | vixl32::Register in_reg_lo = LowRegisterFrom(locations->InAt(0)); |
| 5134 | vixl32::Register in_reg_hi = HighRegisterFrom(locations->InAt(0)); |
| 5135 | Location rhs = locations->InAt(1); |
| 5136 | vixl32::Register out_reg_lo = LowRegisterFrom(locations->Out()); |
| 5137 | vixl32::Register out_reg_hi = HighRegisterFrom(locations->Out()); |
| 5138 | |
| 5139 | if (rhs.IsConstant()) { |
| 5140 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 5141 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
| 5142 | rot &= kMaxLongShiftDistance; |
| 5143 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 5144 | // logic below to a simple pair of binary orr. |
| 5145 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 5146 | if (rot >= kArmBitsPerWord) { |
| 5147 | rot -= kArmBitsPerWord; |
| 5148 | std::swap(in_reg_hi, in_reg_lo); |
| 5149 | } |
| 5150 | // Rotate, or mov to out for zero or word size rotations. |
| 5151 | if (rot != 0u) { |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5152 | __ Lsr(out_reg_hi, in_reg_hi, Operand::From(rot)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5153 | __ 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] | 5154 | __ Lsr(out_reg_lo, in_reg_lo, Operand::From(rot)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5155 | __ Orr(out_reg_lo, out_reg_lo, Operand(in_reg_hi, ShiftType::LSL, kArmBitsPerWord - rot)); |
| 5156 | } else { |
| 5157 | __ Mov(out_reg_lo, in_reg_lo); |
| 5158 | __ Mov(out_reg_hi, in_reg_hi); |
| 5159 | } |
| 5160 | } else { |
| 5161 | vixl32::Register shift_right = RegisterFrom(locations->GetTemp(0)); |
| 5162 | vixl32::Register shift_left = RegisterFrom(locations->GetTemp(1)); |
| 5163 | vixl32::Label end; |
| 5164 | vixl32::Label shift_by_32_plus_shift_right; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5165 | vixl32::Label* final_label = codegen_->GetFinalLabel(ror, &end); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5166 | |
| 5167 | __ And(shift_right, RegisterFrom(rhs), 0x1F); |
| 5168 | __ Lsrs(shift_left, RegisterFrom(rhs), 6); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 5169 | __ Rsb(LeaveFlags, shift_left, shift_right, Operand::From(kArmBitsPerWord)); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 5170 | __ B(cc, &shift_by_32_plus_shift_right, /* far_target */ false); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5171 | |
| 5172 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 5173 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 5174 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 5175 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 5176 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 5177 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 5178 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 5179 | __ Add(out_reg_lo, out_reg_lo, shift_left); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5180 | __ B(final_label); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5181 | |
| 5182 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 5183 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 5184 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 5185 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 5186 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 5187 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 5188 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 5189 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 5190 | __ Add(out_reg_lo, out_reg_lo, shift_right); |
| 5191 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5192 | if (end.IsReferenced()) { |
| 5193 | __ Bind(&end); |
| 5194 | } |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5195 | } |
| 5196 | } |
| 5197 | |
| 5198 | void LocationsBuilderARMVIXL::VisitRor(HRor* ror) { |
| 5199 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5200 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5201 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5202 | case DataType::Type::kInt32: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5203 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5204 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 5205 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5206 | break; |
| 5207 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5208 | case DataType::Type::kInt64: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5209 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5210 | if (ror->InputAt(1)->IsConstant()) { |
| 5211 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 5212 | } else { |
| 5213 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5214 | locations->AddTemp(Location::RequiresRegister()); |
| 5215 | locations->AddTemp(Location::RequiresRegister()); |
| 5216 | } |
| 5217 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5218 | break; |
| 5219 | } |
| 5220 | default: |
| 5221 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 5222 | } |
| 5223 | } |
| 5224 | |
| 5225 | void InstructionCodeGeneratorARMVIXL::VisitRor(HRor* ror) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5226 | DataType::Type type = ror->GetResultType(); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5227 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5228 | case DataType::Type::kInt32: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5229 | HandleIntegerRotate(ror); |
| 5230 | break; |
| 5231 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5232 | case DataType::Type::kInt64: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5233 | HandleLongRotate(ror); |
| 5234 | break; |
| 5235 | } |
| 5236 | default: |
| 5237 | LOG(FATAL) << "Unexpected operation type " << type; |
| 5238 | UNREACHABLE(); |
| 5239 | } |
| 5240 | } |
| 5241 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5242 | void LocationsBuilderARMVIXL::HandleShift(HBinaryOperation* op) { |
| 5243 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 5244 | |
| 5245 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5246 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5247 | |
| 5248 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5249 | case DataType::Type::kInt32: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5250 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5251 | if (op->InputAt(1)->IsConstant()) { |
| 5252 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 5253 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5254 | } else { |
| 5255 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5256 | // Make the output overlap, as it will be used to hold the masked |
| 5257 | // second input. |
| 5258 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5259 | } |
| 5260 | break; |
| 5261 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5262 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5263 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5264 | if (op->InputAt(1)->IsConstant()) { |
| 5265 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 5266 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 5267 | // don't clash with high registers which the register allocator currently guarantees. |
| 5268 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5269 | } else { |
| 5270 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5271 | locations->AddTemp(Location::RequiresRegister()); |
| 5272 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5273 | } |
| 5274 | break; |
| 5275 | } |
| 5276 | default: |
| 5277 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 5278 | } |
| 5279 | } |
| 5280 | |
| 5281 | void InstructionCodeGeneratorARMVIXL::HandleShift(HBinaryOperation* op) { |
| 5282 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 5283 | |
| 5284 | LocationSummary* locations = op->GetLocations(); |
| 5285 | Location out = locations->Out(); |
| 5286 | Location first = locations->InAt(0); |
| 5287 | Location second = locations->InAt(1); |
| 5288 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5289 | DataType::Type type = op->GetResultType(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5290 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5291 | case DataType::Type::kInt32: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5292 | vixl32::Register out_reg = OutputRegister(op); |
| 5293 | vixl32::Register first_reg = InputRegisterAt(op, 0); |
| 5294 | if (second.IsRegister()) { |
| 5295 | vixl32::Register second_reg = RegisterFrom(second); |
| 5296 | // ARM doesn't mask the shift count so we need to do it ourselves. |
| 5297 | __ And(out_reg, second_reg, kMaxIntShiftDistance); |
| 5298 | if (op->IsShl()) { |
| 5299 | __ Lsl(out_reg, first_reg, out_reg); |
| 5300 | } else if (op->IsShr()) { |
| 5301 | __ Asr(out_reg, first_reg, out_reg); |
| 5302 | } else { |
| 5303 | __ Lsr(out_reg, first_reg, out_reg); |
| 5304 | } |
| 5305 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5306 | int32_t cst = Int32ConstantFrom(second); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5307 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
| 5308 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
| 5309 | __ Mov(out_reg, first_reg); |
| 5310 | } else if (op->IsShl()) { |
| 5311 | __ Lsl(out_reg, first_reg, shift_value); |
| 5312 | } else if (op->IsShr()) { |
| 5313 | __ Asr(out_reg, first_reg, shift_value); |
| 5314 | } else { |
| 5315 | __ Lsr(out_reg, first_reg, shift_value); |
| 5316 | } |
| 5317 | } |
| 5318 | break; |
| 5319 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5320 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5321 | vixl32::Register o_h = HighRegisterFrom(out); |
| 5322 | vixl32::Register o_l = LowRegisterFrom(out); |
| 5323 | |
| 5324 | vixl32::Register high = HighRegisterFrom(first); |
| 5325 | vixl32::Register low = LowRegisterFrom(first); |
| 5326 | |
| 5327 | if (second.IsRegister()) { |
| 5328 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5329 | |
| 5330 | vixl32::Register second_reg = RegisterFrom(second); |
| 5331 | |
| 5332 | if (op->IsShl()) { |
| 5333 | __ And(o_l, second_reg, kMaxLongShiftDistance); |
| 5334 | // Shift the high part |
| 5335 | __ Lsl(o_h, high, o_l); |
| 5336 | // Shift the low part and `or` what overflew on the high part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5337 | __ Rsb(temp, o_l, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5338 | __ Lsr(temp, low, temp); |
| 5339 | __ Orr(o_h, o_h, temp); |
| 5340 | // If the shift is > 32 bits, override the high part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5341 | __ Subs(temp, o_l, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5342 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5343 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5344 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5345 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5346 | __ it(pl); |
| 5347 | __ lsl(pl, o_h, low, temp); |
| 5348 | } |
| 5349 | // Shift the low part |
| 5350 | __ Lsl(o_l, low, o_l); |
| 5351 | } else if (op->IsShr()) { |
| 5352 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 5353 | // Shift the low part |
| 5354 | __ Lsr(o_l, low, o_h); |
| 5355 | // Shift the high part and `or` what underflew on the low part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5356 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5357 | __ Lsl(temp, high, temp); |
| 5358 | __ Orr(o_l, o_l, temp); |
| 5359 | // If the shift is > 32 bits, override the low part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5360 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5361 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5362 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5363 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5364 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5365 | __ it(pl); |
| 5366 | __ asr(pl, o_l, high, temp); |
| 5367 | } |
| 5368 | // Shift the high part |
| 5369 | __ Asr(o_h, high, o_h); |
| 5370 | } else { |
| 5371 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 5372 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 5373 | __ Lsr(o_l, low, o_h); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5374 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5375 | __ Lsl(temp, high, temp); |
| 5376 | __ Orr(o_l, o_l, temp); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5377 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5378 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5379 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5380 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5381 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5382 | __ it(pl); |
| 5383 | __ lsr(pl, o_l, high, temp); |
| 5384 | } |
| 5385 | __ Lsr(o_h, high, o_h); |
| 5386 | } |
| 5387 | } else { |
| 5388 | // Register allocator doesn't create partial overlap. |
| 5389 | DCHECK(!o_l.Is(high)); |
| 5390 | DCHECK(!o_h.Is(low)); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5391 | int32_t cst = Int32ConstantFrom(second); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5392 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
| 5393 | if (shift_value > 32) { |
| 5394 | if (op->IsShl()) { |
| 5395 | __ Lsl(o_h, low, shift_value - 32); |
| 5396 | __ Mov(o_l, 0); |
| 5397 | } else if (op->IsShr()) { |
| 5398 | __ Asr(o_l, high, shift_value - 32); |
| 5399 | __ Asr(o_h, high, 31); |
| 5400 | } else { |
| 5401 | __ Lsr(o_l, high, shift_value - 32); |
| 5402 | __ Mov(o_h, 0); |
| 5403 | } |
| 5404 | } else if (shift_value == 32) { |
| 5405 | if (op->IsShl()) { |
| 5406 | __ Mov(o_h, low); |
| 5407 | __ Mov(o_l, 0); |
| 5408 | } else if (op->IsShr()) { |
| 5409 | __ Mov(o_l, high); |
| 5410 | __ Asr(o_h, high, 31); |
| 5411 | } else { |
| 5412 | __ Mov(o_l, high); |
| 5413 | __ Mov(o_h, 0); |
| 5414 | } |
| 5415 | } else if (shift_value == 1) { |
| 5416 | if (op->IsShl()) { |
| 5417 | __ Lsls(o_l, low, 1); |
| 5418 | __ Adc(o_h, high, high); |
| 5419 | } else if (op->IsShr()) { |
| 5420 | __ Asrs(o_h, high, 1); |
| 5421 | __ Rrx(o_l, low); |
| 5422 | } else { |
| 5423 | __ Lsrs(o_h, high, 1); |
| 5424 | __ Rrx(o_l, low); |
| 5425 | } |
| 5426 | } else { |
| 5427 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
| 5428 | if (op->IsShl()) { |
| 5429 | __ Lsl(o_h, high, shift_value); |
| 5430 | __ Orr(o_h, o_h, Operand(low, ShiftType::LSR, 32 - shift_value)); |
| 5431 | __ Lsl(o_l, low, shift_value); |
| 5432 | } else if (op->IsShr()) { |
| 5433 | __ Lsr(o_l, low, shift_value); |
| 5434 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 5435 | __ Asr(o_h, high, shift_value); |
| 5436 | } else { |
| 5437 | __ Lsr(o_l, low, shift_value); |
| 5438 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 5439 | __ Lsr(o_h, high, shift_value); |
| 5440 | } |
| 5441 | } |
| 5442 | } |
| 5443 | break; |
| 5444 | } |
| 5445 | default: |
| 5446 | LOG(FATAL) << "Unexpected operation type " << type; |
| 5447 | UNREACHABLE(); |
| 5448 | } |
| 5449 | } |
| 5450 | |
| 5451 | void LocationsBuilderARMVIXL::VisitShl(HShl* shl) { |
| 5452 | HandleShift(shl); |
| 5453 | } |
| 5454 | |
| 5455 | void InstructionCodeGeneratorARMVIXL::VisitShl(HShl* shl) { |
| 5456 | HandleShift(shl); |
| 5457 | } |
| 5458 | |
| 5459 | void LocationsBuilderARMVIXL::VisitShr(HShr* shr) { |
| 5460 | HandleShift(shr); |
| 5461 | } |
| 5462 | |
| 5463 | void InstructionCodeGeneratorARMVIXL::VisitShr(HShr* shr) { |
| 5464 | HandleShift(shr); |
| 5465 | } |
| 5466 | |
| 5467 | void LocationsBuilderARMVIXL::VisitUShr(HUShr* ushr) { |
| 5468 | HandleShift(ushr); |
| 5469 | } |
| 5470 | |
| 5471 | void InstructionCodeGeneratorARMVIXL::VisitUShr(HUShr* ushr) { |
| 5472 | HandleShift(ushr); |
| 5473 | } |
| 5474 | |
| 5475 | void LocationsBuilderARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5476 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5477 | instruction, LocationSummary::kCallOnMainOnly); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5478 | if (instruction->IsStringAlloc()) { |
| 5479 | locations->AddTemp(LocationFrom(kMethodRegister)); |
| 5480 | } else { |
| 5481 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 5482 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5483 | } |
| 5484 | locations->SetOut(LocationFrom(r0)); |
| 5485 | } |
| 5486 | |
| 5487 | void InstructionCodeGeneratorARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
| 5488 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5489 | // of poisoning the reference. |
| 5490 | if (instruction->IsStringAlloc()) { |
| 5491 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 5492 | vixl32::Register temp = RegisterFrom(instruction->GetLocations()->GetTemp(0)); |
| 5493 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
| 5494 | GetAssembler()->LoadFromOffset(kLoadWord, temp, tr, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 5495 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, code_offset.Int32Value()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5496 | // 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] | 5497 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5498 | vixl32::k16BitT32InstructionSizeInBytes, |
| 5499 | CodeBufferCheckScope::kExactSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5500 | __ blx(lr); |
| 5501 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5502 | } else { |
| 5503 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 5504 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5505 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 5506 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 10); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5507 | } |
| 5508 | |
| 5509 | void LocationsBuilderARMVIXL::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5510 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5511 | instruction, LocationSummary::kCallOnMainOnly); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5512 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5513 | locations->SetOut(LocationFrom(r0)); |
Nicolas Geoffray | 8c7c4f1 | 2017-01-26 10:13:11 +0000 | [diff] [blame] | 5514 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5515 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5516 | } |
| 5517 | |
| 5518 | void InstructionCodeGeneratorARMVIXL::VisitNewArray(HNewArray* instruction) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5519 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5520 | // of poisoning the reference. |
Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 5521 | QuickEntrypointEnum entrypoint = |
| 5522 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 5523 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5524 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 5525 | DCHECK(!codegen_->IsLeafMethod()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 5526 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 11); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5527 | } |
| 5528 | |
| 5529 | void LocationsBuilderARMVIXL::VisitParameterValue(HParameterValue* instruction) { |
| 5530 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5531 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5532 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5533 | if (location.IsStackSlot()) { |
| 5534 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5535 | } else if (location.IsDoubleStackSlot()) { |
| 5536 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5537 | } |
| 5538 | locations->SetOut(location); |
| 5539 | } |
| 5540 | |
| 5541 | void InstructionCodeGeneratorARMVIXL::VisitParameterValue( |
| 5542 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 5543 | // Nothing to do, the parameter is already at its location. |
| 5544 | } |
| 5545 | |
| 5546 | void LocationsBuilderARMVIXL::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5547 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5548 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5549 | locations->SetOut(LocationFrom(kMethodRegister)); |
| 5550 | } |
| 5551 | |
| 5552 | void InstructionCodeGeneratorARMVIXL::VisitCurrentMethod( |
| 5553 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5554 | // Nothing to do, the method is already at its location. |
| 5555 | } |
| 5556 | |
| 5557 | void LocationsBuilderARMVIXL::VisitNot(HNot* not_) { |
| 5558 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5559 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5560 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5561 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5562 | } |
| 5563 | |
| 5564 | void InstructionCodeGeneratorARMVIXL::VisitNot(HNot* not_) { |
| 5565 | LocationSummary* locations = not_->GetLocations(); |
| 5566 | Location out = locations->Out(); |
| 5567 | Location in = locations->InAt(0); |
| 5568 | switch (not_->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5569 | case DataType::Type::kInt32: |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5570 | __ Mvn(OutputRegister(not_), InputRegisterAt(not_, 0)); |
| 5571 | break; |
| 5572 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5573 | case DataType::Type::kInt64: |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5574 | __ Mvn(LowRegisterFrom(out), LowRegisterFrom(in)); |
| 5575 | __ Mvn(HighRegisterFrom(out), HighRegisterFrom(in)); |
| 5576 | break; |
| 5577 | |
| 5578 | default: |
| 5579 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 5580 | } |
| 5581 | } |
| 5582 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5583 | void LocationsBuilderARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5584 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5585 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5586 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5587 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5588 | } |
| 5589 | |
| 5590 | void InstructionCodeGeneratorARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5591 | __ Eor(OutputRegister(bool_not), InputRegister(bool_not), 1); |
| 5592 | } |
| 5593 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5594 | void LocationsBuilderARMVIXL::VisitCompare(HCompare* compare) { |
| 5595 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5596 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5597 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5598 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5599 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5600 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5601 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5602 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5603 | case DataType::Type::kInt32: |
| 5604 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5605 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5606 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5607 | // Output overlaps because it is written before doing the low comparison. |
| 5608 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5609 | break; |
| 5610 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5611 | case DataType::Type::kFloat32: |
| 5612 | case DataType::Type::kFloat64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5613 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5614 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
| 5615 | locations->SetOut(Location::RequiresRegister()); |
| 5616 | break; |
| 5617 | } |
| 5618 | default: |
| 5619 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 5620 | } |
| 5621 | } |
| 5622 | |
| 5623 | void InstructionCodeGeneratorARMVIXL::VisitCompare(HCompare* compare) { |
| 5624 | LocationSummary* locations = compare->GetLocations(); |
| 5625 | vixl32::Register out = OutputRegister(compare); |
| 5626 | Location left = locations->InAt(0); |
| 5627 | Location right = locations->InAt(1); |
| 5628 | |
| 5629 | vixl32::Label less, greater, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5630 | vixl32::Label* final_label = codegen_->GetFinalLabel(compare, &done); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5631 | DataType::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 5632 | vixl32::Condition less_cond = vixl32::Condition::None(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5633 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5634 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5635 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5636 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5637 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5638 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5639 | case DataType::Type::kInt32: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5640 | // Emit move to `out` before the `Cmp`, as `Mov` might affect the status flags. |
| 5641 | __ Mov(out, 0); |
| 5642 | __ Cmp(RegisterFrom(left), RegisterFrom(right)); // Signed compare. |
| 5643 | less_cond = lt; |
| 5644 | break; |
| 5645 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5646 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5647 | __ Cmp(HighRegisterFrom(left), HighRegisterFrom(right)); // Signed compare. |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 5648 | __ B(lt, &less, /* far_target */ false); |
| 5649 | __ B(gt, &greater, /* far_target */ false); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5650 | // Emit move to `out` before the last `Cmp`, as `Mov` might affect the status flags. |
| 5651 | __ Mov(out, 0); |
| 5652 | __ Cmp(LowRegisterFrom(left), LowRegisterFrom(right)); // Unsigned compare. |
| 5653 | less_cond = lo; |
| 5654 | break; |
| 5655 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5656 | case DataType::Type::kFloat32: |
| 5657 | case DataType::Type::kFloat64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5658 | __ Mov(out, 0); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 5659 | GenerateVcmp(compare, codegen_); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5660 | // To branch on the FP compare result we transfer FPSCR to APSR (encoded as PC in VMRS). |
| 5661 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 5662 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
| 5663 | break; |
| 5664 | } |
| 5665 | default: |
| 5666 | LOG(FATAL) << "Unexpected compare type " << type; |
| 5667 | UNREACHABLE(); |
| 5668 | } |
| 5669 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5670 | __ B(eq, final_label, /* far_target */ false); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 5671 | __ B(less_cond, &less, /* far_target */ false); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5672 | |
| 5673 | __ Bind(&greater); |
| 5674 | __ Mov(out, 1); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5675 | __ B(final_label); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5676 | |
| 5677 | __ Bind(&less); |
| 5678 | __ Mov(out, -1); |
| 5679 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5680 | if (done.IsReferenced()) { |
| 5681 | __ Bind(&done); |
| 5682 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5683 | } |
| 5684 | |
| 5685 | void LocationsBuilderARMVIXL::VisitPhi(HPhi* instruction) { |
| 5686 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5687 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5688 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| 5689 | locations->SetInAt(i, Location::Any()); |
| 5690 | } |
| 5691 | locations->SetOut(Location::Any()); |
| 5692 | } |
| 5693 | |
| 5694 | void InstructionCodeGeneratorARMVIXL::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 5695 | LOG(FATAL) << "Unreachable"; |
| 5696 | } |
| 5697 | |
| 5698 | void CodeGeneratorARMVIXL::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 5699 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 5700 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
| 5701 | switch (kind) { |
| 5702 | case MemBarrierKind::kAnyStore: |
| 5703 | case MemBarrierKind::kLoadAny: |
| 5704 | case MemBarrierKind::kAnyAny: { |
| 5705 | flavor = DmbOptions::ISH; |
| 5706 | break; |
| 5707 | } |
| 5708 | case MemBarrierKind::kStoreStore: { |
| 5709 | flavor = DmbOptions::ISHST; |
| 5710 | break; |
| 5711 | } |
| 5712 | default: |
| 5713 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 5714 | } |
| 5715 | __ Dmb(flavor); |
| 5716 | } |
| 5717 | |
| 5718 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicLoad(vixl32::Register addr, |
| 5719 | uint32_t offset, |
| 5720 | vixl32::Register out_lo, |
| 5721 | vixl32::Register out_hi) { |
| 5722 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5723 | if (offset != 0) { |
| 5724 | vixl32::Register temp = temps.Acquire(); |
| 5725 | __ Add(temp, addr, offset); |
| 5726 | addr = temp; |
| 5727 | } |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5728 | __ Ldrexd(out_lo, out_hi, MemOperand(addr)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5729 | } |
| 5730 | |
| 5731 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicStore(vixl32::Register addr, |
| 5732 | uint32_t offset, |
| 5733 | vixl32::Register value_lo, |
| 5734 | vixl32::Register value_hi, |
| 5735 | vixl32::Register temp1, |
| 5736 | vixl32::Register temp2, |
| 5737 | HInstruction* instruction) { |
| 5738 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5739 | vixl32::Label fail; |
| 5740 | if (offset != 0) { |
| 5741 | vixl32::Register temp = temps.Acquire(); |
| 5742 | __ Add(temp, addr, offset); |
| 5743 | addr = temp; |
| 5744 | } |
| 5745 | __ Bind(&fail); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5746 | { |
| 5747 | // Ensure the pc position is recorded immediately after the `ldrexd` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5748 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5749 | vixl32::kMaxInstructionSizeInBytes, |
| 5750 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5751 | // We need a load followed by store. (The address used in a STREX instruction must |
| 5752 | // be the same as the address in the most recently executed LDREX instruction.) |
| 5753 | __ ldrexd(temp1, temp2, MemOperand(addr)); |
| 5754 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5755 | } |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5756 | __ Strexd(temp1, value_lo, value_hi, MemOperand(addr)); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5757 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5758 | } |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5759 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5760 | void LocationsBuilderARMVIXL::HandleFieldSet( |
| 5761 | HInstruction* instruction, const FieldInfo& field_info) { |
| 5762 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5763 | |
| 5764 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5765 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5766 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5767 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5768 | DataType::Type field_type = field_info.GetFieldType(); |
| 5769 | if (DataType::IsFloatingPointType(field_type)) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5770 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5771 | } else { |
| 5772 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5773 | } |
| 5774 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5775 | 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] | 5776 | bool generate_volatile = field_info.IsVolatile() |
| 5777 | && is_wide |
| 5778 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5779 | bool needs_write_barrier = |
| 5780 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 5781 | // Temporary registers for the write barrier. |
| 5782 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
| 5783 | if (needs_write_barrier) { |
| 5784 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
| 5785 | locations->AddTemp(Location::RequiresRegister()); |
| 5786 | } else if (generate_volatile) { |
| 5787 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 5788 | // - registers need to be consecutive |
| 5789 | // - the first register should be even but not R14. |
| 5790 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5791 | // revisit this if we ever enable ARM encoding. |
| 5792 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5793 | |
| 5794 | locations->AddTemp(Location::RequiresRegister()); |
| 5795 | locations->AddTemp(Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5796 | if (field_type == DataType::Type::kFloat64) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5797 | // For doubles we need two more registers to copy the value. |
| 5798 | locations->AddTemp(LocationFrom(r2)); |
| 5799 | locations->AddTemp(LocationFrom(r3)); |
| 5800 | } |
| 5801 | } |
| 5802 | } |
| 5803 | |
| 5804 | void InstructionCodeGeneratorARMVIXL::HandleFieldSet(HInstruction* instruction, |
| 5805 | const FieldInfo& field_info, |
| 5806 | bool value_can_be_null) { |
| 5807 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5808 | |
| 5809 | LocationSummary* locations = instruction->GetLocations(); |
| 5810 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 5811 | Location value = locations->InAt(1); |
| 5812 | |
| 5813 | bool is_volatile = field_info.IsVolatile(); |
| 5814 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5815 | DataType::Type field_type = field_info.GetFieldType(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5816 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5817 | bool needs_write_barrier = |
| 5818 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 5819 | |
| 5820 | if (is_volatile) { |
| 5821 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 5822 | } |
| 5823 | |
| 5824 | switch (field_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5825 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5826 | case DataType::Type::kUint8: |
| 5827 | case DataType::Type::kInt8: |
| 5828 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5829 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5830 | case DataType::Type::kInt32: { |
| 5831 | StoreOperandType operand_type = GetStoreOperandType(field_type); |
| 5832 | GetAssembler()->StoreToOffset(operand_type, RegisterFrom(value), base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5833 | break; |
| 5834 | } |
| 5835 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5836 | case DataType::Type::kReference: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5837 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5838 | // Note that in the case where `value` is a null reference, |
| 5839 | // we do not enter this block, as a null reference does not |
| 5840 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5841 | DCHECK_EQ(field_type, DataType::Type::kReference); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5842 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5843 | __ Mov(temp, RegisterFrom(value)); |
| 5844 | GetAssembler()->PoisonHeapReference(temp); |
| 5845 | GetAssembler()->StoreToOffset(kStoreWord, temp, base, offset); |
| 5846 | } else { |
| 5847 | GetAssembler()->StoreToOffset(kStoreWord, RegisterFrom(value), base, offset); |
| 5848 | } |
| 5849 | break; |
| 5850 | } |
| 5851 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5852 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5853 | if (is_volatile && !atomic_ldrd_strd) { |
| 5854 | GenerateWideAtomicStore(base, |
| 5855 | offset, |
| 5856 | LowRegisterFrom(value), |
| 5857 | HighRegisterFrom(value), |
| 5858 | RegisterFrom(locations->GetTemp(0)), |
| 5859 | RegisterFrom(locations->GetTemp(1)), |
| 5860 | instruction); |
| 5861 | } else { |
| 5862 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), base, offset); |
| 5863 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5864 | } |
| 5865 | break; |
| 5866 | } |
| 5867 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5868 | case DataType::Type::kFloat32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5869 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), base, offset); |
| 5870 | break; |
| 5871 | } |
| 5872 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5873 | case DataType::Type::kFloat64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5874 | vixl32::DRegister value_reg = DRegisterFrom(value); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5875 | if (is_volatile && !atomic_ldrd_strd) { |
| 5876 | vixl32::Register value_reg_lo = RegisterFrom(locations->GetTemp(0)); |
| 5877 | vixl32::Register value_reg_hi = RegisterFrom(locations->GetTemp(1)); |
| 5878 | |
| 5879 | __ Vmov(value_reg_lo, value_reg_hi, value_reg); |
| 5880 | |
| 5881 | GenerateWideAtomicStore(base, |
| 5882 | offset, |
| 5883 | value_reg_lo, |
| 5884 | value_reg_hi, |
| 5885 | RegisterFrom(locations->GetTemp(2)), |
| 5886 | RegisterFrom(locations->GetTemp(3)), |
| 5887 | instruction); |
| 5888 | } else { |
| 5889 | GetAssembler()->StoreDToOffset(value_reg, base, offset); |
| 5890 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5891 | } |
| 5892 | break; |
| 5893 | } |
| 5894 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5895 | case DataType::Type::kUint32: |
| 5896 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5897 | case DataType::Type::kVoid: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5898 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5899 | UNREACHABLE(); |
| 5900 | } |
| 5901 | |
| 5902 | // Longs and doubles are handled in the switch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5903 | if (field_type != DataType::Type::kInt64 && field_type != DataType::Type::kFloat64) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5904 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, we |
| 5905 | // should use a scope and the assembler to emit the store instruction to guarantee that we |
| 5906 | // record the pc at the correct position. But the `Assembler` does not automatically handle |
| 5907 | // unencodable offsets. Practically, everything is fine because the helper and VIXL, at the time |
| 5908 | // of writing, do generate the store instruction last. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5909 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5910 | } |
| 5911 | |
| 5912 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5913 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5914 | vixl32::Register card = RegisterFrom(locations->GetTemp(1)); |
| 5915 | codegen_->MarkGCCard(temp, card, base, RegisterFrom(value), value_can_be_null); |
| 5916 | } |
| 5917 | |
| 5918 | if (is_volatile) { |
| 5919 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 5920 | } |
| 5921 | } |
| 5922 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5923 | void LocationsBuilderARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 5924 | const FieldInfo& field_info) { |
| 5925 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 5926 | |
| 5927 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5928 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == DataType::Type::kReference); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5929 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5930 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5931 | object_field_get_with_read_barrier |
| 5932 | ? LocationSummary::kCallOnSlowPath |
| 5933 | : LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5934 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5935 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 5936 | } |
| 5937 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5938 | |
| 5939 | bool volatile_for_double = field_info.IsVolatile() |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5940 | && (field_info.GetFieldType() == DataType::Type::kFloat64) |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5941 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5942 | // The output overlaps in case of volatile long: we don't want the |
| 5943 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 5944 | // object's location. Likewise, in the case of an object field get |
| 5945 | // with read barriers enabled, we do not want the load to overwrite |
| 5946 | // 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] | 5947 | bool overlap = |
| 5948 | (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) || |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5949 | object_field_get_with_read_barrier; |
| 5950 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5951 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5952 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5953 | } else { |
| 5954 | locations->SetOut(Location::RequiresRegister(), |
| 5955 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 5956 | } |
| 5957 | if (volatile_for_double) { |
| 5958 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 5959 | // - registers need to be consecutive |
| 5960 | // - the first register should be even but not R14. |
| 5961 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5962 | // revisit this if we ever enable ARM encoding. |
| 5963 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5964 | locations->AddTemp(Location::RequiresRegister()); |
| 5965 | locations->AddTemp(Location::RequiresRegister()); |
| 5966 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5967 | // We need a temporary register for the read barrier marking slow |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 5968 | // path in CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 5969 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 5970 | !Runtime::Current()->UseJitCompilation()) { |
| 5971 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 5972 | // loads we need a temporary only if the offset is too big. |
| 5973 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 5974 | locations->AddTemp(Location::RequiresRegister()); |
| 5975 | } |
| 5976 | // And we always need the reserved entrypoint register. |
| 5977 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 5978 | } else { |
| 5979 | locations->AddTemp(Location::RequiresRegister()); |
| 5980 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5981 | } |
| 5982 | } |
| 5983 | |
| 5984 | Location LocationsBuilderARMVIXL::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5985 | DCHECK(DataType::IsFloatingPointType(input->GetType())) << input->GetType(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5986 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 5987 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 5988 | return Location::ConstantLocation(input->AsConstant()); |
| 5989 | } else { |
| 5990 | return Location::RequiresFpuRegister(); |
| 5991 | } |
| 5992 | } |
| 5993 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5994 | Location LocationsBuilderARMVIXL::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 5995 | Opcode opcode) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5996 | DCHECK(!DataType::IsFloatingPointType(constant->GetType())); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5997 | if (constant->IsConstant() && |
| 5998 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 5999 | return Location::ConstantLocation(constant->AsConstant()); |
| 6000 | } |
| 6001 | return Location::RequiresRegister(); |
| 6002 | } |
| 6003 | |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 6004 | static bool CanEncode32BitConstantAsImmediate( |
| 6005 | CodeGeneratorARMVIXL* codegen, |
| 6006 | uint32_t value, |
| 6007 | Opcode opcode, |
| 6008 | vixl32::FlagsUpdate flags_update = vixl32::FlagsUpdate::DontCare) { |
| 6009 | ArmVIXLAssembler* assembler = codegen->GetAssembler(); |
| 6010 | if (assembler->ShifterOperandCanHold(opcode, value, flags_update)) { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 6011 | return true; |
| 6012 | } |
| 6013 | Opcode neg_opcode = kNoOperand; |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 6014 | uint32_t neg_value = 0; |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 6015 | switch (opcode) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 6016 | case AND: neg_opcode = BIC; neg_value = ~value; break; |
| 6017 | case ORR: neg_opcode = ORN; neg_value = ~value; break; |
| 6018 | case ADD: neg_opcode = SUB; neg_value = -value; break; |
| 6019 | case ADC: neg_opcode = SBC; neg_value = ~value; break; |
| 6020 | case SUB: neg_opcode = ADD; neg_value = -value; break; |
| 6021 | case SBC: neg_opcode = ADC; neg_value = ~value; break; |
| 6022 | case MOV: neg_opcode = MVN; neg_value = ~value; break; |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 6023 | default: |
| 6024 | return false; |
| 6025 | } |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 6026 | |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 6027 | if (assembler->ShifterOperandCanHold(neg_opcode, neg_value, flags_update)) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 6028 | return true; |
| 6029 | } |
| 6030 | |
| 6031 | return opcode == AND && IsPowerOfTwo(value + 1); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 6032 | } |
| 6033 | |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 6034 | bool LocationsBuilderARMVIXL::CanEncodeConstantAsImmediate(HConstant* input_cst, Opcode opcode) { |
| 6035 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 6036 | if (DataType::Is64BitType(input_cst->GetType())) { |
| 6037 | Opcode high_opcode = opcode; |
| 6038 | vixl32::FlagsUpdate low_flags_update = vixl32::FlagsUpdate::DontCare; |
| 6039 | switch (opcode) { |
| 6040 | case SUB: |
| 6041 | // Flip the operation to an ADD. |
| 6042 | value = -value; |
| 6043 | opcode = ADD; |
| 6044 | FALLTHROUGH_INTENDED; |
| 6045 | case ADD: |
| 6046 | if (Low32Bits(value) == 0u) { |
| 6047 | return CanEncode32BitConstantAsImmediate(codegen_, High32Bits(value), opcode); |
| 6048 | } |
| 6049 | high_opcode = ADC; |
| 6050 | low_flags_update = vixl32::FlagsUpdate::SetFlags; |
| 6051 | break; |
| 6052 | default: |
| 6053 | break; |
| 6054 | } |
| 6055 | return CanEncode32BitConstantAsImmediate(codegen_, High32Bits(value), high_opcode) && |
| 6056 | CanEncode32BitConstantAsImmediate(codegen_, Low32Bits(value), opcode, low_flags_update); |
| 6057 | } else { |
| 6058 | return CanEncode32BitConstantAsImmediate(codegen_, Low32Bits(value), opcode); |
| 6059 | } |
| 6060 | } |
| 6061 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6062 | void InstructionCodeGeneratorARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 6063 | const FieldInfo& field_info) { |
| 6064 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 6065 | |
| 6066 | LocationSummary* locations = instruction->GetLocations(); |
| 6067 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 6068 | Location out = locations->Out(); |
| 6069 | bool is_volatile = field_info.IsVolatile(); |
| 6070 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6071 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 6072 | DataType::Type load_type = instruction->GetType(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6073 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 6074 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6075 | switch (load_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6076 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6077 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6078 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6079 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6080 | case DataType::Type::kInt16: |
| 6081 | case DataType::Type::kInt32: { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6082 | LoadOperandType operand_type = GetLoadOperandType(load_type); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6083 | GetAssembler()->LoadFromOffset(operand_type, RegisterFrom(out), base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6084 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6085 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6086 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6087 | case DataType::Type::kReference: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6088 | // /* HeapReference<Object> */ out = *(base + offset) |
| 6089 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6090 | Location temp_loc = locations->GetTemp(0); |
| 6091 | // Note that a potential implicit null check is handled in this |
| 6092 | // CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier call. |
| 6093 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 6094 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 6095 | if (is_volatile) { |
| 6096 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6097 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6098 | } else { |
| 6099 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(out), base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6100 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6101 | if (is_volatile) { |
| 6102 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6103 | } |
| 6104 | // If read barriers are enabled, emit read barriers other than |
| 6105 | // Baker's using a slow path (and also unpoison the loaded |
| 6106 | // reference, if heap poisoning is enabled). |
| 6107 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, locations->InAt(0), offset); |
| 6108 | } |
| 6109 | break; |
| 6110 | } |
| 6111 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6112 | case DataType::Type::kInt64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6113 | if (is_volatile && !atomic_ldrd_strd) { |
| 6114 | GenerateWideAtomicLoad(base, offset, LowRegisterFrom(out), HighRegisterFrom(out)); |
| 6115 | } else { |
| 6116 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out), base, offset); |
| 6117 | } |
| 6118 | break; |
| 6119 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6120 | case DataType::Type::kFloat32: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6121 | GetAssembler()->LoadSFromOffset(SRegisterFrom(out), base, offset); |
| 6122 | break; |
| 6123 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6124 | case DataType::Type::kFloat64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6125 | vixl32::DRegister out_dreg = DRegisterFrom(out); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6126 | if (is_volatile && !atomic_ldrd_strd) { |
| 6127 | vixl32::Register lo = RegisterFrom(locations->GetTemp(0)); |
| 6128 | vixl32::Register hi = RegisterFrom(locations->GetTemp(1)); |
| 6129 | GenerateWideAtomicLoad(base, offset, lo, hi); |
| 6130 | // TODO(VIXL): Do we need to be immediately after the ldrexd instruction? If so we need a |
| 6131 | // scope. |
| 6132 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6133 | __ Vmov(out_dreg, lo, hi); |
| 6134 | } else { |
| 6135 | GetAssembler()->LoadDFromOffset(out_dreg, base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6136 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6137 | } |
| 6138 | break; |
| 6139 | } |
| 6140 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6141 | case DataType::Type::kUint32: |
| 6142 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6143 | case DataType::Type::kVoid: |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6144 | LOG(FATAL) << "Unreachable type " << load_type; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6145 | UNREACHABLE(); |
| 6146 | } |
| 6147 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6148 | if (load_type == DataType::Type::kReference || load_type == DataType::Type::kFloat64) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6149 | // Potential implicit null checks, in the case of reference or |
| 6150 | // double fields, are handled in the previous switch statement. |
| 6151 | } else { |
| 6152 | // 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] | 6153 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, we |
| 6154 | // should use a scope and the assembler to emit the load instruction to guarantee that we |
| 6155 | // record the pc at the correct position. But the `Assembler` does not automatically handle |
| 6156 | // unencodable offsets. Practically, everything is fine because the helper and VIXL, at the time |
| 6157 | // of writing, do generate the store instruction last. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6158 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6159 | } |
| 6160 | |
| 6161 | if (is_volatile) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6162 | if (load_type == DataType::Type::kReference) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6163 | // Memory barriers, in the case of references, are also handled |
| 6164 | // in the previous switch statement. |
| 6165 | } else { |
| 6166 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6167 | } |
| 6168 | } |
| 6169 | } |
| 6170 | |
| 6171 | void LocationsBuilderARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 6172 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6173 | } |
| 6174 | |
| 6175 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 6176 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 6177 | } |
| 6178 | |
| 6179 | void LocationsBuilderARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6180 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6181 | } |
| 6182 | |
| 6183 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6184 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6185 | } |
| 6186 | |
| 6187 | void LocationsBuilderARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6188 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6189 | } |
| 6190 | |
| 6191 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6192 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6193 | } |
| 6194 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6195 | void LocationsBuilderARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 6196 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6197 | } |
| 6198 | |
| 6199 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 6200 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 6201 | } |
| 6202 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6203 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 6204 | HUnresolvedInstanceFieldGet* instruction) { |
| 6205 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6206 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6207 | instruction, instruction->GetFieldType(), calling_convention); |
| 6208 | } |
| 6209 | |
| 6210 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 6211 | HUnresolvedInstanceFieldGet* instruction) { |
| 6212 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6213 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6214 | instruction->GetFieldType(), |
| 6215 | instruction->GetFieldIndex(), |
| 6216 | instruction->GetDexPc(), |
| 6217 | calling_convention); |
| 6218 | } |
| 6219 | |
| 6220 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 6221 | HUnresolvedInstanceFieldSet* instruction) { |
| 6222 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6223 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6224 | instruction, instruction->GetFieldType(), calling_convention); |
| 6225 | } |
| 6226 | |
| 6227 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 6228 | HUnresolvedInstanceFieldSet* instruction) { |
| 6229 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6230 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6231 | instruction->GetFieldType(), |
| 6232 | instruction->GetFieldIndex(), |
| 6233 | instruction->GetDexPc(), |
| 6234 | calling_convention); |
| 6235 | } |
| 6236 | |
| 6237 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldGet( |
| 6238 | HUnresolvedStaticFieldGet* instruction) { |
| 6239 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6240 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6241 | instruction, instruction->GetFieldType(), calling_convention); |
| 6242 | } |
| 6243 | |
| 6244 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldGet( |
| 6245 | HUnresolvedStaticFieldGet* instruction) { |
| 6246 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6247 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6248 | instruction->GetFieldType(), |
| 6249 | instruction->GetFieldIndex(), |
| 6250 | instruction->GetDexPc(), |
| 6251 | calling_convention); |
| 6252 | } |
| 6253 | |
| 6254 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldSet( |
| 6255 | HUnresolvedStaticFieldSet* instruction) { |
| 6256 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6257 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6258 | instruction, instruction->GetFieldType(), calling_convention); |
| 6259 | } |
| 6260 | |
| 6261 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldSet( |
| 6262 | HUnresolvedStaticFieldSet* instruction) { |
| 6263 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6264 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6265 | instruction->GetFieldType(), |
| 6266 | instruction->GetFieldIndex(), |
| 6267 | instruction->GetDexPc(), |
| 6268 | calling_convention); |
| 6269 | } |
| 6270 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6271 | void LocationsBuilderARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6272 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6273 | locations->SetInAt(0, Location::RequiresRegister()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6274 | } |
| 6275 | |
| 6276 | void CodeGeneratorARMVIXL::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 6277 | if (CanMoveNullCheckToUser(instruction)) { |
| 6278 | return; |
| 6279 | } |
| 6280 | |
| 6281 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6282 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6283 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6284 | vixl32::kMaxInstructionSizeInBytes, |
| 6285 | CodeBufferCheckScope::kMaximumSize); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6286 | __ ldr(temps.Acquire(), MemOperand(InputRegisterAt(instruction, 0))); |
| 6287 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 6288 | } |
| 6289 | |
| 6290 | void CodeGeneratorARMVIXL::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| 6291 | NullCheckSlowPathARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6292 | new (GetScopedAllocator()) NullCheckSlowPathARMVIXL(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6293 | AddSlowPath(slow_path); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6294 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6295 | } |
| 6296 | |
| 6297 | void InstructionCodeGeneratorARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
| 6298 | codegen_->GenerateNullCheck(instruction); |
| 6299 | } |
| 6300 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6301 | void CodeGeneratorARMVIXL::LoadFromShiftedRegOffset(DataType::Type type, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6302 | Location out_loc, |
| 6303 | vixl32::Register base, |
| 6304 | vixl32::Register reg_index, |
| 6305 | vixl32::Condition cond) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6306 | uint32_t shift_count = DataType::SizeShift(type); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6307 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 6308 | |
| 6309 | switch (type) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6310 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6311 | case DataType::Type::kUint8: |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6312 | __ Ldrb(cond, RegisterFrom(out_loc), mem_address); |
| 6313 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6314 | case DataType::Type::kInt8: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6315 | __ Ldrsb(cond, RegisterFrom(out_loc), mem_address); |
| 6316 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6317 | case DataType::Type::kUint16: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6318 | __ Ldrh(cond, RegisterFrom(out_loc), mem_address); |
| 6319 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6320 | case DataType::Type::kInt16: |
| 6321 | __ Ldrsh(cond, RegisterFrom(out_loc), mem_address); |
| 6322 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6323 | case DataType::Type::kReference: |
| 6324 | case DataType::Type::kInt32: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6325 | __ Ldr(cond, RegisterFrom(out_loc), mem_address); |
| 6326 | break; |
| 6327 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6328 | case DataType::Type::kInt64: |
| 6329 | case DataType::Type::kFloat32: |
| 6330 | case DataType::Type::kFloat64: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6331 | default: |
| 6332 | LOG(FATAL) << "Unreachable type " << type; |
| 6333 | UNREACHABLE(); |
| 6334 | } |
| 6335 | } |
| 6336 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6337 | void CodeGeneratorARMVIXL::StoreToShiftedRegOffset(DataType::Type type, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6338 | Location loc, |
| 6339 | vixl32::Register base, |
| 6340 | vixl32::Register reg_index, |
| 6341 | vixl32::Condition cond) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6342 | uint32_t shift_count = DataType::SizeShift(type); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6343 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 6344 | |
| 6345 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6346 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6347 | case DataType::Type::kUint8: |
| 6348 | case DataType::Type::kInt8: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6349 | __ Strb(cond, RegisterFrom(loc), mem_address); |
| 6350 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6351 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6352 | case DataType::Type::kInt16: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6353 | __ Strh(cond, RegisterFrom(loc), mem_address); |
| 6354 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6355 | case DataType::Type::kReference: |
| 6356 | case DataType::Type::kInt32: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6357 | __ Str(cond, RegisterFrom(loc), mem_address); |
| 6358 | break; |
| 6359 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6360 | case DataType::Type::kInt64: |
| 6361 | case DataType::Type::kFloat32: |
| 6362 | case DataType::Type::kFloat64: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6363 | default: |
| 6364 | LOG(FATAL) << "Unreachable type " << type; |
| 6365 | UNREACHABLE(); |
| 6366 | } |
| 6367 | } |
| 6368 | |
| 6369 | void LocationsBuilderARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
| 6370 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6371 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6372 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6373 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 6374 | object_array_get_with_read_barrier |
| 6375 | ? LocationSummary::kCallOnSlowPath |
| 6376 | : LocationSummary::kNoCall); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6377 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6378 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6379 | } |
| 6380 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6381 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6382 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6383 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6384 | } else { |
| 6385 | // The output overlaps in the case of an object array get with |
| 6386 | // read barriers enabled: we do not want the move to overwrite the |
| 6387 | // array's location, as we need it to emit the read barrier. |
| 6388 | locations->SetOut( |
| 6389 | Location::RequiresRegister(), |
| 6390 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 6391 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6392 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 6393 | // We need a temporary register for the read barrier marking slow |
| 6394 | // path in CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier. |
| 6395 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 6396 | !Runtime::Current()->UseJitCompilation() && |
| 6397 | instruction->GetIndex()->IsConstant()) { |
| 6398 | // Array loads with constant index are treated as field loads. |
| 6399 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 6400 | // constant index loads we need a temporary only if the offset is too big. |
| 6401 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 6402 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6403 | offset += index << DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6404 | if (offset >= kReferenceLoadMinFarOffset) { |
| 6405 | locations->AddTemp(Location::RequiresRegister()); |
| 6406 | } |
| 6407 | // And we always need the reserved entrypoint register. |
| 6408 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 6409 | } else if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 6410 | !Runtime::Current()->UseJitCompilation() && |
| 6411 | !instruction->GetIndex()->IsConstant()) { |
| 6412 | // We need a non-scratch temporary for the array data pointer. |
| 6413 | locations->AddTemp(Location::RequiresRegister()); |
| 6414 | // And we always need the reserved entrypoint register. |
| 6415 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 6416 | } else { |
| 6417 | locations->AddTemp(Location::RequiresRegister()); |
| 6418 | } |
| 6419 | } else if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 6420 | // Also need a temporary for String compression feature. |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6421 | locations->AddTemp(Location::RequiresRegister()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6422 | } |
| 6423 | } |
| 6424 | |
| 6425 | void InstructionCodeGeneratorARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6426 | LocationSummary* locations = instruction->GetLocations(); |
| 6427 | Location obj_loc = locations->InAt(0); |
| 6428 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 6429 | Location index = locations->InAt(1); |
| 6430 | Location out_loc = locations->Out(); |
| 6431 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6432 | DataType::Type type = instruction->GetType(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6433 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 6434 | instruction->IsStringCharAt(); |
| 6435 | HInstruction* array_instr = instruction->GetArray(); |
| 6436 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6437 | |
| 6438 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6439 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6440 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6441 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6442 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6443 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6444 | case DataType::Type::kInt32: { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6445 | vixl32::Register length; |
| 6446 | if (maybe_compressed_char_at) { |
| 6447 | length = RegisterFrom(locations->GetTemp(0)); |
| 6448 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 6449 | GetAssembler()->LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 6450 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6451 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6452 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6453 | int32_t const_index = Int32ConstantFrom(index); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6454 | if (maybe_compressed_char_at) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6455 | vixl32::Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6456 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6457 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 6458 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6459 | "Expecting 0=compressed, 1=uncompressed"); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 6460 | __ B(cs, &uncompressed_load, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6461 | GetAssembler()->LoadFromOffset(kLoadUnsignedByte, |
| 6462 | RegisterFrom(out_loc), |
| 6463 | obj, |
| 6464 | data_offset + const_index); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6465 | __ B(final_label); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6466 | __ Bind(&uncompressed_load); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6467 | GetAssembler()->LoadFromOffset(GetLoadOperandType(DataType::Type::kUint16), |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6468 | RegisterFrom(out_loc), |
| 6469 | obj, |
| 6470 | data_offset + (const_index << 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6471 | if (done.IsReferenced()) { |
| 6472 | __ Bind(&done); |
| 6473 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6474 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6475 | uint32_t full_offset = data_offset + (const_index << DataType::SizeShift(type)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6476 | |
| 6477 | LoadOperandType load_type = GetLoadOperandType(type); |
| 6478 | GetAssembler()->LoadFromOffset(load_type, RegisterFrom(out_loc), obj, full_offset); |
| 6479 | } |
| 6480 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6481 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6482 | vixl32::Register temp = temps.Acquire(); |
| 6483 | |
| 6484 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6485 | // We do not need to compute the intermediate address from the array: the |
| 6486 | // input instruction has done it already. See the comment in |
| 6487 | // `TryExtractArrayAccessAddress()`. |
| 6488 | if (kIsDebugBuild) { |
| 6489 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6490 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6491 | } |
| 6492 | temp = obj; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6493 | } else { |
| 6494 | __ Add(temp, obj, data_offset); |
| 6495 | } |
| 6496 | if (maybe_compressed_char_at) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6497 | vixl32::Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6498 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6499 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 6500 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6501 | "Expecting 0=compressed, 1=uncompressed"); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 6502 | __ B(cs, &uncompressed_load, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6503 | __ Ldrb(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 0)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6504 | __ B(final_label); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6505 | __ Bind(&uncompressed_load); |
| 6506 | __ Ldrh(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6507 | if (done.IsReferenced()) { |
| 6508 | __ Bind(&done); |
| 6509 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6510 | } else { |
| 6511 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
| 6512 | } |
| 6513 | } |
| 6514 | break; |
| 6515 | } |
| 6516 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6517 | case DataType::Type::kReference: { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6518 | // The read barrier instrumentation of object ArrayGet |
| 6519 | // instructions does not support the HIntermediateAddress |
| 6520 | // instruction. |
| 6521 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 6522 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6523 | static_assert( |
| 6524 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6525 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 6526 | // /* HeapReference<Object> */ out = |
| 6527 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6528 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6529 | Location temp = locations->GetTemp(0); |
| 6530 | // Note that a potential implicit null check is handled in this |
| 6531 | // CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6532 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 6533 | if (index.IsConstant()) { |
| 6534 | // 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] | 6535 | data_offset += Int32ConstantFrom(index) << DataType::SizeShift(type); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6536 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6537 | out_loc, |
| 6538 | obj, |
| 6539 | data_offset, |
| 6540 | locations->GetTemp(0), |
| 6541 | /* needs_null_check */ false); |
| 6542 | } else { |
| 6543 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 6544 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ false); |
| 6545 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6546 | } else { |
| 6547 | vixl32::Register out = OutputRegister(instruction); |
| 6548 | if (index.IsConstant()) { |
| 6549 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6550 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6551 | GetAssembler()->LoadFromOffset(kLoadWord, out, obj, offset); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6552 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, |
| 6553 | // we should use a scope and the assembler to emit the load instruction to guarantee that |
| 6554 | // we record the pc at the correct position. But the `Assembler` does not automatically |
| 6555 | // handle unencodable offsets. Practically, everything is fine because the helper and |
| 6556 | // VIXL, at the time of writing, do generate the store instruction last. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6557 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6558 | // If read barriers are enabled, emit read barriers other than |
| 6559 | // Baker's using a slow path (and also unpoison the loaded |
| 6560 | // reference, if heap poisoning is enabled). |
| 6561 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 6562 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6563 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6564 | vixl32::Register temp = temps.Acquire(); |
| 6565 | |
| 6566 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6567 | // We do not need to compute the intermediate address from the array: the |
| 6568 | // input instruction has done it already. See the comment in |
| 6569 | // `TryExtractArrayAccessAddress()`. |
| 6570 | if (kIsDebugBuild) { |
| 6571 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6572 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6573 | } |
| 6574 | temp = obj; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6575 | } else { |
| 6576 | __ Add(temp, obj, data_offset); |
| 6577 | } |
| 6578 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6579 | temps.Close(); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6580 | // TODO(VIXL): Use a scope to ensure that we record the pc position immediately after the |
| 6581 | // load instruction. Practically, everything is fine because the helper and VIXL, at the |
| 6582 | // time of writing, do generate the store instruction last. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6583 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6584 | // If read barriers are enabled, emit read barriers other than |
| 6585 | // Baker's using a slow path (and also unpoison the loaded |
| 6586 | // reference, if heap poisoning is enabled). |
| 6587 | codegen_->MaybeGenerateReadBarrierSlow( |
| 6588 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 6589 | } |
| 6590 | } |
| 6591 | break; |
| 6592 | } |
| 6593 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6594 | case DataType::Type::kInt64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6595 | if (index.IsConstant()) { |
| 6596 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6597 | (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6598 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), obj, offset); |
| 6599 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6600 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6601 | vixl32::Register temp = temps.Acquire(); |
| 6602 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6603 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), temp, data_offset); |
| 6604 | } |
| 6605 | break; |
| 6606 | } |
| 6607 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6608 | case DataType::Type::kFloat32: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6609 | vixl32::SRegister out = SRegisterFrom(out_loc); |
| 6610 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6611 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6612 | GetAssembler()->LoadSFromOffset(out, obj, offset); |
| 6613 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6614 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6615 | vixl32::Register temp = temps.Acquire(); |
| 6616 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 6617 | GetAssembler()->LoadSFromOffset(out, temp, data_offset); |
| 6618 | } |
| 6619 | break; |
| 6620 | } |
| 6621 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6622 | case DataType::Type::kFloat64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6623 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6624 | size_t offset = (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6625 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), obj, offset); |
| 6626 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6627 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6628 | vixl32::Register temp = temps.Acquire(); |
| 6629 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6630 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), temp, data_offset); |
| 6631 | } |
| 6632 | break; |
| 6633 | } |
| 6634 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6635 | case DataType::Type::kUint32: |
| 6636 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6637 | case DataType::Type::kVoid: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6638 | LOG(FATAL) << "Unreachable type " << type; |
| 6639 | UNREACHABLE(); |
| 6640 | } |
| 6641 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6642 | if (type == DataType::Type::kReference) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6643 | // Potential implicit null checks, in the case of reference |
| 6644 | // arrays, are handled in the previous switch statement. |
| 6645 | } else if (!maybe_compressed_char_at) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6646 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after |
| 6647 | // the preceding load instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6648 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6649 | } |
| 6650 | } |
| 6651 | |
| 6652 | void LocationsBuilderARMVIXL::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6653 | DataType::Type value_type = instruction->GetComponentType(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6654 | |
| 6655 | bool needs_write_barrier = |
| 6656 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 6657 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 6658 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6659 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6660 | instruction, |
| 6661 | may_need_runtime_call_for_type_check ? |
| 6662 | LocationSummary::kCallOnSlowPath : |
| 6663 | LocationSummary::kNoCall); |
| 6664 | |
| 6665 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6666 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6667 | if (DataType::IsFloatingPointType(value_type)) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6668 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 6669 | } else { |
| 6670 | locations->SetInAt(2, Location::RequiresRegister()); |
| 6671 | } |
| 6672 | if (needs_write_barrier) { |
| 6673 | // Temporary registers for the write barrier. |
| 6674 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 6675 | locations->AddTemp(Location::RequiresRegister()); |
| 6676 | } |
| 6677 | } |
| 6678 | |
| 6679 | void InstructionCodeGeneratorARMVIXL::VisitArraySet(HArraySet* instruction) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6680 | LocationSummary* locations = instruction->GetLocations(); |
| 6681 | vixl32::Register array = InputRegisterAt(instruction, 0); |
| 6682 | Location index = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6683 | DataType::Type value_type = instruction->GetComponentType(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6684 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 6685 | bool needs_write_barrier = |
| 6686 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 6687 | uint32_t data_offset = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6688 | mirror::Array::DataOffset(DataType::Size(value_type)).Uint32Value(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6689 | Location value_loc = locations->InAt(2); |
| 6690 | HInstruction* array_instr = instruction->GetArray(); |
| 6691 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6692 | |
| 6693 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6694 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6695 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6696 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6697 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6698 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6699 | case DataType::Type::kInt32: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6700 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6701 | int32_t const_index = Int32ConstantFrom(index); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6702 | uint32_t full_offset = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6703 | data_offset + (const_index << DataType::SizeShift(value_type)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6704 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 6705 | GetAssembler()->StoreToOffset(store_type, RegisterFrom(value_loc), array, full_offset); |
| 6706 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6707 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6708 | vixl32::Register temp = temps.Acquire(); |
| 6709 | |
| 6710 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6711 | // We do not need to compute the intermediate address from the array: the |
| 6712 | // input instruction has done it already. See the comment in |
| 6713 | // `TryExtractArrayAccessAddress()`. |
| 6714 | if (kIsDebugBuild) { |
| 6715 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6716 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6717 | } |
| 6718 | temp = array; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6719 | } else { |
| 6720 | __ Add(temp, array, data_offset); |
| 6721 | } |
| 6722 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 6723 | } |
| 6724 | break; |
| 6725 | } |
| 6726 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6727 | case DataType::Type::kReference: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6728 | vixl32::Register value = RegisterFrom(value_loc); |
| 6729 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 6730 | // See the comment in instruction_simplifier_shared.cc. |
| 6731 | DCHECK(!has_intermediate_address); |
| 6732 | |
| 6733 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 6734 | // Just setting null. |
| 6735 | if (index.IsConstant()) { |
| 6736 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6737 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6738 | GetAssembler()->StoreToOffset(kStoreWord, value, array, offset); |
| 6739 | } else { |
| 6740 | DCHECK(index.IsRegister()) << index; |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6741 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6742 | vixl32::Register temp = temps.Acquire(); |
| 6743 | __ Add(temp, array, data_offset); |
| 6744 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 6745 | } |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6746 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after the preceding |
| 6747 | // store instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6748 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6749 | DCHECK(!needs_write_barrier); |
| 6750 | DCHECK(!may_need_runtime_call_for_type_check); |
| 6751 | break; |
| 6752 | } |
| 6753 | |
| 6754 | DCHECK(needs_write_barrier); |
| 6755 | Location temp1_loc = locations->GetTemp(0); |
| 6756 | vixl32::Register temp1 = RegisterFrom(temp1_loc); |
| 6757 | Location temp2_loc = locations->GetTemp(1); |
| 6758 | vixl32::Register temp2 = RegisterFrom(temp2_loc); |
| 6759 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6760 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6761 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6762 | vixl32::Label done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6763 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6764 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 6765 | |
| 6766 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6767 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathARMVIXL(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6768 | codegen_->AddSlowPath(slow_path); |
| 6769 | if (instruction->GetValueCanBeNull()) { |
| 6770 | vixl32::Label non_zero; |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6771 | __ CompareAndBranchIfNonZero(value, &non_zero); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6772 | if (index.IsConstant()) { |
| 6773 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6774 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6775 | GetAssembler()->StoreToOffset(kStoreWord, value, array, offset); |
| 6776 | } else { |
| 6777 | DCHECK(index.IsRegister()) << index; |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6778 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6779 | vixl32::Register temp = temps.Acquire(); |
| 6780 | __ Add(temp, array, data_offset); |
| 6781 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 6782 | } |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6783 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after the preceding |
| 6784 | // store instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6785 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6786 | __ B(final_label); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6787 | __ Bind(&non_zero); |
| 6788 | } |
| 6789 | |
| 6790 | // Note that when read barriers are enabled, the type checks |
| 6791 | // are performed without read barriers. This is fine, even in |
| 6792 | // the case where a class object is in the from-space after |
| 6793 | // the flip, as a comparison involving such a type would not |
| 6794 | // produce a false positive; it may of course produce a false |
| 6795 | // negative, in which case we would take the ArraySet slow |
| 6796 | // path. |
| 6797 | |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6798 | { |
| 6799 | // Ensure we record the pc position immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6800 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6801 | vixl32::kMaxInstructionSizeInBytes, |
| 6802 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6803 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 6804 | __ ldr(temp1, MemOperand(array, class_offset)); |
| 6805 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6806 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6807 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 6808 | |
| 6809 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 6810 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 6811 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 6812 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 6813 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 6814 | // nor `temp2`, as we are comparing two poisoned references. |
| 6815 | __ Cmp(temp1, temp2); |
| 6816 | |
| 6817 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 6818 | vixl32::Label do_put; |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 6819 | __ B(eq, &do_put, /* far_target */ false); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6820 | // If heap poisoning is enabled, the `temp1` reference has |
| 6821 | // not been unpoisoned yet; unpoison it now. |
| 6822 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 6823 | |
| 6824 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 6825 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 6826 | // If heap poisoning is enabled, no need to unpoison |
| 6827 | // `temp1`, as we are comparing against null below. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6828 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6829 | __ Bind(&do_put); |
| 6830 | } else { |
| 6831 | __ B(ne, slow_path->GetEntryLabel()); |
| 6832 | } |
| 6833 | } |
| 6834 | |
| 6835 | vixl32::Register source = value; |
| 6836 | if (kPoisonHeapReferences) { |
| 6837 | // Note that in the case where `value` is a null reference, |
| 6838 | // we do not enter this block, as a null reference does not |
| 6839 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6840 | DCHECK_EQ(value_type, DataType::Type::kReference); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6841 | __ Mov(temp1, value); |
| 6842 | GetAssembler()->PoisonHeapReference(temp1); |
| 6843 | source = temp1; |
| 6844 | } |
| 6845 | |
| 6846 | if (index.IsConstant()) { |
| 6847 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6848 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6849 | GetAssembler()->StoreToOffset(kStoreWord, source, array, offset); |
| 6850 | } else { |
| 6851 | DCHECK(index.IsRegister()) << index; |
| 6852 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6853 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6854 | vixl32::Register temp = temps.Acquire(); |
| 6855 | __ Add(temp, array, data_offset); |
| 6856 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6857 | LocationFrom(source), |
| 6858 | temp, |
| 6859 | RegisterFrom(index)); |
| 6860 | } |
| 6861 | |
| 6862 | if (!may_need_runtime_call_for_type_check) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6863 | // TODO(VIXL): Ensure we record the pc position immediately after the preceding store |
| 6864 | // instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6865 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6866 | } |
| 6867 | |
| 6868 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 6869 | |
| 6870 | if (done.IsReferenced()) { |
| 6871 | __ Bind(&done); |
| 6872 | } |
| 6873 | |
| 6874 | if (slow_path != nullptr) { |
| 6875 | __ Bind(slow_path->GetExitLabel()); |
| 6876 | } |
| 6877 | |
| 6878 | break; |
| 6879 | } |
| 6880 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6881 | case DataType::Type::kInt64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6882 | Location value = locations->InAt(2); |
| 6883 | if (index.IsConstant()) { |
| 6884 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6885 | (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6886 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), array, offset); |
| 6887 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6888 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6889 | vixl32::Register temp = temps.Acquire(); |
| 6890 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6891 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), temp, data_offset); |
| 6892 | } |
| 6893 | break; |
| 6894 | } |
| 6895 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6896 | case DataType::Type::kFloat32: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6897 | Location value = locations->InAt(2); |
| 6898 | DCHECK(value.IsFpuRegister()); |
| 6899 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6900 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6901 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), array, offset); |
| 6902 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6903 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6904 | vixl32::Register temp = temps.Acquire(); |
| 6905 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 6906 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), temp, data_offset); |
| 6907 | } |
| 6908 | break; |
| 6909 | } |
| 6910 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6911 | case DataType::Type::kFloat64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6912 | Location value = locations->InAt(2); |
| 6913 | DCHECK(value.IsFpuRegisterPair()); |
| 6914 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6915 | size_t offset = (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6916 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), array, offset); |
| 6917 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6918 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6919 | vixl32::Register temp = temps.Acquire(); |
| 6920 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6921 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), temp, data_offset); |
| 6922 | } |
| 6923 | break; |
| 6924 | } |
| 6925 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6926 | case DataType::Type::kUint32: |
| 6927 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6928 | case DataType::Type::kVoid: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6929 | LOG(FATAL) << "Unreachable type " << value_type; |
| 6930 | UNREACHABLE(); |
| 6931 | } |
| 6932 | |
| 6933 | // Objects are handled in the switch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6934 | if (value_type != DataType::Type::kReference) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6935 | // TODO(VIXL): Ensure we record the pc position immediately after the preceding store |
| 6936 | // instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6937 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6938 | } |
| 6939 | } |
| 6940 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6941 | void LocationsBuilderARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 6942 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6943 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6944 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6945 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6946 | } |
| 6947 | |
| 6948 | void InstructionCodeGeneratorARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 6949 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| 6950 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 6951 | vixl32::Register out = OutputRegister(instruction); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6952 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6953 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6954 | vixl32::kMaxInstructionSizeInBytes, |
| 6955 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6956 | __ ldr(out, MemOperand(obj, offset)); |
| 6957 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6958 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6959 | // Mask out compression flag from String's array length. |
| 6960 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6961 | __ Lsr(out, out, 1u); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6962 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6963 | } |
| 6964 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6965 | void LocationsBuilderARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6966 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6967 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6968 | |
| 6969 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6970 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 6971 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6972 | } |
| 6973 | |
| 6974 | void InstructionCodeGeneratorARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 6975 | vixl32::Register out = OutputRegister(instruction); |
| 6976 | vixl32::Register first = InputRegisterAt(instruction, 0); |
| 6977 | Location second = instruction->GetLocations()->InAt(1); |
| 6978 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6979 | if (second.IsRegister()) { |
| 6980 | __ Add(out, first, RegisterFrom(second)); |
| 6981 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6982 | __ Add(out, first, Int32ConstantFrom(second)); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6983 | } |
| 6984 | } |
| 6985 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 6986 | void LocationsBuilderARMVIXL::VisitIntermediateAddressIndex( |
| 6987 | HIntermediateAddressIndex* instruction) { |
| 6988 | LOG(FATAL) << "Unreachable " << instruction->GetId(); |
| 6989 | } |
| 6990 | |
| 6991 | void InstructionCodeGeneratorARMVIXL::VisitIntermediateAddressIndex( |
| 6992 | HIntermediateAddressIndex* instruction) { |
| 6993 | LOG(FATAL) << "Unreachable " << instruction->GetId(); |
| 6994 | } |
| 6995 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6996 | void LocationsBuilderARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 6997 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6998 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 6999 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7000 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(1))); |
| 7001 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 7002 | |
| 7003 | HInstruction* index = instruction->InputAt(0); |
| 7004 | HInstruction* length = instruction->InputAt(1); |
| 7005 | // If both index and length are constants we can statically check the bounds. But if at least one |
| 7006 | // of them is not encodable ArmEncodableConstantOrRegister will create |
| 7007 | // Location::RequiresRegister() which is not desired to happen. Instead we create constant |
| 7008 | // locations. |
| 7009 | bool both_const = index->IsConstant() && length->IsConstant(); |
| 7010 | locations->SetInAt(0, both_const |
| 7011 | ? Location::ConstantLocation(index->AsConstant()) |
| 7012 | : ArmEncodableConstantOrRegister(index, CMP)); |
| 7013 | locations->SetInAt(1, both_const |
| 7014 | ? Location::ConstantLocation(length->AsConstant()) |
| 7015 | : ArmEncodableConstantOrRegister(length, CMP)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7016 | } |
| 7017 | |
| 7018 | void InstructionCodeGeneratorARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 7019 | LocationSummary* locations = instruction->GetLocations(); |
| 7020 | Location index_loc = locations->InAt(0); |
| 7021 | Location length_loc = locations->InAt(1); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7022 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 7023 | if (length_loc.IsConstant()) { |
| 7024 | int32_t length = Int32ConstantFrom(length_loc); |
| 7025 | if (index_loc.IsConstant()) { |
| 7026 | // BCE will remove the bounds check if we are guaranteed to pass. |
| 7027 | int32_t index = Int32ConstantFrom(index_loc); |
| 7028 | if (index < 0 || index >= length) { |
| 7029 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7030 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARMVIXL(instruction); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 7031 | codegen_->AddSlowPath(slow_path); |
| 7032 | __ B(slow_path->GetEntryLabel()); |
| 7033 | } else { |
| 7034 | // Some optimization after BCE may have generated this, and we should not |
| 7035 | // generate a bounds check if it is a valid range. |
| 7036 | } |
| 7037 | return; |
| 7038 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7039 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 7040 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7041 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARMVIXL(instruction); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 7042 | __ Cmp(RegisterFrom(index_loc), length); |
| 7043 | codegen_->AddSlowPath(slow_path); |
| 7044 | __ B(hs, slow_path->GetEntryLabel()); |
| 7045 | } else { |
| 7046 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7047 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARMVIXL(instruction); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 7048 | __ Cmp(RegisterFrom(length_loc), InputOperandAt(instruction, 0)); |
| 7049 | codegen_->AddSlowPath(slow_path); |
| 7050 | __ B(ls, slow_path->GetEntryLabel()); |
| 7051 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7052 | } |
| 7053 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7054 | void CodeGeneratorARMVIXL::MarkGCCard(vixl32::Register temp, |
| 7055 | vixl32::Register card, |
| 7056 | vixl32::Register object, |
| 7057 | vixl32::Register value, |
| 7058 | bool can_be_null) { |
| 7059 | vixl32::Label is_null; |
| 7060 | if (can_be_null) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7061 | __ CompareAndBranchIfZero(value, &is_null); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7062 | } |
| 7063 | GetAssembler()->LoadFromOffset( |
| 7064 | kLoadWord, card, tr, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 7065 | __ Lsr(temp, object, Operand::From(gc::accounting::CardTable::kCardShift)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7066 | __ Strb(card, MemOperand(card, temp)); |
| 7067 | if (can_be_null) { |
| 7068 | __ Bind(&is_null); |
| 7069 | } |
| 7070 | } |
| 7071 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7072 | void LocationsBuilderARMVIXL::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 7073 | LOG(FATAL) << "Unreachable"; |
| 7074 | } |
| 7075 | |
| 7076 | void InstructionCodeGeneratorARMVIXL::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 7077 | if (instruction->GetNext()->IsSuspendCheck() && |
| 7078 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 7079 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 7080 | // The back edge will generate the suspend check. |
| 7081 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 7082 | } |
| 7083 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7084 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 7085 | } |
| 7086 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7087 | void LocationsBuilderARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7088 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7089 | instruction, LocationSummary::kCallOnSlowPath); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7090 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7091 | } |
| 7092 | |
| 7093 | void InstructionCodeGeneratorARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 7094 | HBasicBlock* block = instruction->GetBlock(); |
| 7095 | if (block->GetLoopInformation() != nullptr) { |
| 7096 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 7097 | // The back edge will generate the suspend check. |
| 7098 | return; |
| 7099 | } |
| 7100 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 7101 | // The goto will generate the suspend check. |
| 7102 | return; |
| 7103 | } |
| 7104 | GenerateSuspendCheck(instruction, nullptr); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 7105 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 12); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7106 | } |
| 7107 | |
| 7108 | void InstructionCodeGeneratorARMVIXL::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 7109 | HBasicBlock* successor) { |
| 7110 | SuspendCheckSlowPathARMVIXL* slow_path = |
| 7111 | down_cast<SuspendCheckSlowPathARMVIXL*>(instruction->GetSlowPath()); |
| 7112 | if (slow_path == nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7113 | slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7114 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathARMVIXL(instruction, successor); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7115 | instruction->SetSlowPath(slow_path); |
| 7116 | codegen_->AddSlowPath(slow_path); |
| 7117 | if (successor != nullptr) { |
| 7118 | DCHECK(successor->IsLoopHeader()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7119 | } |
| 7120 | } else { |
| 7121 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 7122 | } |
| 7123 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7124 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7125 | vixl32::Register temp = temps.Acquire(); |
| 7126 | GetAssembler()->LoadFromOffset( |
| 7127 | kLoadUnsignedHalfword, temp, tr, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
| 7128 | if (successor == nullptr) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7129 | __ CompareAndBranchIfNonZero(temp, slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7130 | __ Bind(slow_path->GetReturnLabel()); |
| 7131 | } else { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7132 | __ CompareAndBranchIfZero(temp, codegen_->GetLabelOf(successor)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7133 | __ B(slow_path->GetEntryLabel()); |
| 7134 | } |
| 7135 | } |
| 7136 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7137 | ArmVIXLAssembler* ParallelMoveResolverARMVIXL::GetAssembler() const { |
| 7138 | return codegen_->GetAssembler(); |
| 7139 | } |
| 7140 | |
| 7141 | void ParallelMoveResolverARMVIXL::EmitMove(size_t index) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7142 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7143 | MoveOperands* move = moves_[index]; |
| 7144 | Location source = move->GetSource(); |
| 7145 | Location destination = move->GetDestination(); |
| 7146 | |
| 7147 | if (source.IsRegister()) { |
| 7148 | if (destination.IsRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7149 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7150 | } else if (destination.IsFpuRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7151 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7152 | } else { |
| 7153 | DCHECK(destination.IsStackSlot()); |
| 7154 | GetAssembler()->StoreToOffset(kStoreWord, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7155 | RegisterFrom(source), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7156 | sp, |
| 7157 | destination.GetStackIndex()); |
| 7158 | } |
| 7159 | } else if (source.IsStackSlot()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7160 | if (destination.IsRegister()) { |
| 7161 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 7162 | RegisterFrom(destination), |
| 7163 | sp, |
| 7164 | source.GetStackIndex()); |
| 7165 | } else if (destination.IsFpuRegister()) { |
| 7166 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 7167 | } else { |
| 7168 | DCHECK(destination.IsStackSlot()); |
| 7169 | vixl32::Register temp = temps.Acquire(); |
| 7170 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 7171 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 7172 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7173 | } else if (source.IsFpuRegister()) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7174 | if (destination.IsRegister()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7175 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7176 | } else if (destination.IsFpuRegister()) { |
| 7177 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 7178 | } else { |
| 7179 | DCHECK(destination.IsStackSlot()); |
| 7180 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 7181 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7182 | } else if (source.IsDoubleStackSlot()) { |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7183 | if (destination.IsDoubleStackSlot()) { |
| 7184 | vixl32::DRegister temp = temps.AcquireD(); |
| 7185 | GetAssembler()->LoadDFromOffset(temp, sp, source.GetStackIndex()); |
| 7186 | GetAssembler()->StoreDToOffset(temp, sp, destination.GetStackIndex()); |
| 7187 | } else if (destination.IsRegisterPair()) { |
| 7188 | DCHECK(ExpectedPairLayout(destination)); |
| 7189 | GetAssembler()->LoadFromOffset( |
| 7190 | kLoadWordPair, LowRegisterFrom(destination), sp, source.GetStackIndex()); |
| 7191 | } else { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7192 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 7193 | GetAssembler()->LoadDFromOffset(DRegisterFrom(destination), sp, source.GetStackIndex()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7194 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7195 | } else if (source.IsRegisterPair()) { |
| 7196 | if (destination.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7197 | __ Mov(LowRegisterFrom(destination), LowRegisterFrom(source)); |
| 7198 | __ Mov(HighRegisterFrom(destination), HighRegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7199 | } else if (destination.IsFpuRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7200 | __ Vmov(DRegisterFrom(destination), LowRegisterFrom(source), HighRegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7201 | } else { |
| 7202 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 7203 | DCHECK(ExpectedPairLayout(source)); |
| 7204 | GetAssembler()->StoreToOffset(kStoreWordPair, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7205 | LowRegisterFrom(source), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7206 | sp, |
| 7207 | destination.GetStackIndex()); |
| 7208 | } |
| 7209 | } else if (source.IsFpuRegisterPair()) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7210 | if (destination.IsRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7211 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), DRegisterFrom(source)); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7212 | } else if (destination.IsFpuRegisterPair()) { |
| 7213 | __ Vmov(DRegisterFrom(destination), DRegisterFrom(source)); |
| 7214 | } else { |
| 7215 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 7216 | GetAssembler()->StoreDToOffset(DRegisterFrom(source), sp, destination.GetStackIndex()); |
| 7217 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7218 | } else { |
| 7219 | DCHECK(source.IsConstant()) << source; |
| 7220 | HConstant* constant = source.GetConstant(); |
| 7221 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 7222 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
| 7223 | if (destination.IsRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7224 | __ Mov(RegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7225 | } else { |
| 7226 | DCHECK(destination.IsStackSlot()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7227 | vixl32::Register temp = temps.Acquire(); |
| 7228 | __ Mov(temp, value); |
| 7229 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 7230 | } |
| 7231 | } else if (constant->IsLongConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 7232 | int64_t value = Int64ConstantFrom(source); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7233 | if (destination.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7234 | __ Mov(LowRegisterFrom(destination), Low32Bits(value)); |
| 7235 | __ Mov(HighRegisterFrom(destination), High32Bits(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7236 | } else { |
| 7237 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7238 | vixl32::Register temp = temps.Acquire(); |
| 7239 | __ Mov(temp, Low32Bits(value)); |
| 7240 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 7241 | __ Mov(temp, High32Bits(value)); |
| 7242 | GetAssembler()->StoreToOffset(kStoreWord, |
| 7243 | temp, |
| 7244 | sp, |
| 7245 | destination.GetHighStackIndex(kArmWordSize)); |
| 7246 | } |
| 7247 | } else if (constant->IsDoubleConstant()) { |
| 7248 | double value = constant->AsDoubleConstant()->GetValue(); |
| 7249 | if (destination.IsFpuRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7250 | __ Vmov(DRegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7251 | } else { |
| 7252 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 7253 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7254 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7255 | __ Mov(temp, Low32Bits(int_value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7256 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7257 | __ Mov(temp, High32Bits(int_value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7258 | GetAssembler()->StoreToOffset(kStoreWord, |
| 7259 | temp, |
| 7260 | sp, |
| 7261 | destination.GetHighStackIndex(kArmWordSize)); |
| 7262 | } |
| 7263 | } else { |
| 7264 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
| 7265 | float value = constant->AsFloatConstant()->GetValue(); |
| 7266 | if (destination.IsFpuRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7267 | __ Vmov(SRegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7268 | } else { |
| 7269 | DCHECK(destination.IsStackSlot()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7270 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7271 | __ Mov(temp, bit_cast<int32_t, float>(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7272 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 7273 | } |
| 7274 | } |
| 7275 | } |
| 7276 | } |
| 7277 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7278 | void ParallelMoveResolverARMVIXL::Exchange(vixl32::Register reg, int mem) { |
| 7279 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 7280 | vixl32::Register temp = temps.Acquire(); |
| 7281 | __ Mov(temp, reg); |
| 7282 | GetAssembler()->LoadFromOffset(kLoadWord, reg, sp, mem); |
| 7283 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7284 | } |
| 7285 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7286 | void ParallelMoveResolverARMVIXL::Exchange(int mem1, int mem2) { |
| 7287 | // TODO(VIXL32): Double check the performance of this implementation. |
| 7288 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7289 | vixl32::Register temp1 = temps.Acquire(); |
| 7290 | ScratchRegisterScope ensure_scratch( |
| 7291 | this, temp1.GetCode(), r0.GetCode(), codegen_->GetNumberOfCoreRegisters()); |
| 7292 | vixl32::Register temp2(ensure_scratch.GetRegister()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7293 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7294 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 7295 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, sp, mem1 + stack_offset); |
| 7296 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, sp, mem2 + stack_offset); |
| 7297 | GetAssembler()->StoreToOffset(kStoreWord, temp1, sp, mem2 + stack_offset); |
| 7298 | GetAssembler()->StoreToOffset(kStoreWord, temp2, sp, mem1 + stack_offset); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7299 | } |
| 7300 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7301 | void ParallelMoveResolverARMVIXL::EmitSwap(size_t index) { |
| 7302 | MoveOperands* move = moves_[index]; |
| 7303 | Location source = move->GetSource(); |
| 7304 | Location destination = move->GetDestination(); |
| 7305 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 7306 | |
| 7307 | if (source.IsRegister() && destination.IsRegister()) { |
| 7308 | vixl32::Register temp = temps.Acquire(); |
| 7309 | DCHECK(!RegisterFrom(source).Is(temp)); |
| 7310 | DCHECK(!RegisterFrom(destination).Is(temp)); |
| 7311 | __ Mov(temp, RegisterFrom(destination)); |
| 7312 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 7313 | __ Mov(RegisterFrom(source), temp); |
| 7314 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| 7315 | Exchange(RegisterFrom(source), destination.GetStackIndex()); |
| 7316 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| 7317 | Exchange(RegisterFrom(destination), source.GetStackIndex()); |
| 7318 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7319 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7320 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7321 | vixl32::Register temp = temps.Acquire(); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7322 | __ Vmov(temp, SRegisterFrom(source)); |
| 7323 | __ Vmov(SRegisterFrom(source), SRegisterFrom(destination)); |
| 7324 | __ Vmov(SRegisterFrom(destination), temp); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7325 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
| 7326 | vixl32::DRegister temp = temps.AcquireD(); |
| 7327 | __ Vmov(temp, LowRegisterFrom(source), HighRegisterFrom(source)); |
| 7328 | __ Mov(LowRegisterFrom(source), LowRegisterFrom(destination)); |
| 7329 | __ Mov(HighRegisterFrom(source), HighRegisterFrom(destination)); |
| 7330 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), temp); |
| 7331 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
| 7332 | vixl32::Register low_reg = LowRegisterFrom(source.IsRegisterPair() ? source : destination); |
| 7333 | int mem = source.IsRegisterPair() ? destination.GetStackIndex() : source.GetStackIndex(); |
| 7334 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
| 7335 | vixl32::DRegister temp = temps.AcquireD(); |
| 7336 | __ Vmov(temp, low_reg, vixl32::Register(low_reg.GetCode() + 1)); |
| 7337 | GetAssembler()->LoadFromOffset(kLoadWordPair, low_reg, sp, mem); |
| 7338 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
| 7339 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7340 | vixl32::DRegister first = DRegisterFrom(source); |
| 7341 | vixl32::DRegister second = DRegisterFrom(destination); |
| 7342 | vixl32::DRegister temp = temps.AcquireD(); |
| 7343 | __ Vmov(temp, first); |
| 7344 | __ Vmov(first, second); |
| 7345 | __ Vmov(second, temp); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7346 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7347 | vixl32::DRegister reg = source.IsFpuRegisterPair() |
| 7348 | ? DRegisterFrom(source) |
| 7349 | : DRegisterFrom(destination); |
| 7350 | int mem = source.IsFpuRegisterPair() |
| 7351 | ? destination.GetStackIndex() |
| 7352 | : source.GetStackIndex(); |
| 7353 | vixl32::DRegister temp = temps.AcquireD(); |
| 7354 | __ Vmov(temp, reg); |
| 7355 | GetAssembler()->LoadDFromOffset(reg, sp, mem); |
| 7356 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7357 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7358 | vixl32::SRegister reg = source.IsFpuRegister() |
| 7359 | ? SRegisterFrom(source) |
| 7360 | : SRegisterFrom(destination); |
| 7361 | int mem = source.IsFpuRegister() |
| 7362 | ? destination.GetStackIndex() |
| 7363 | : source.GetStackIndex(); |
| 7364 | vixl32::Register temp = temps.Acquire(); |
| 7365 | __ Vmov(temp, reg); |
| 7366 | GetAssembler()->LoadSFromOffset(reg, sp, mem); |
| 7367 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7368 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 7369 | vixl32::DRegister temp1 = temps.AcquireD(); |
| 7370 | vixl32::DRegister temp2 = temps.AcquireD(); |
| 7371 | __ Vldr(temp1, MemOperand(sp, source.GetStackIndex())); |
| 7372 | __ Vldr(temp2, MemOperand(sp, destination.GetStackIndex())); |
| 7373 | __ Vstr(temp1, MemOperand(sp, destination.GetStackIndex())); |
| 7374 | __ Vstr(temp2, MemOperand(sp, source.GetStackIndex())); |
| 7375 | } else { |
| 7376 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
| 7377 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7378 | } |
| 7379 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7380 | void ParallelMoveResolverARMVIXL::SpillScratch(int reg) { |
| 7381 | __ Push(vixl32::Register(reg)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7382 | } |
| 7383 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7384 | void ParallelMoveResolverARMVIXL::RestoreScratch(int reg) { |
| 7385 | __ Pop(vixl32::Register(reg)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7386 | } |
| 7387 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7388 | HLoadClass::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadClassKind( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7389 | HLoadClass::LoadKind desired_class_load_kind) { |
| 7390 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7391 | case HLoadClass::LoadKind::kInvalid: |
| 7392 | LOG(FATAL) << "UNREACHABLE"; |
| 7393 | UNREACHABLE(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7394 | case HLoadClass::LoadKind::kReferrersClass: |
| 7395 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7396 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7397 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7398 | case HLoadClass::LoadKind::kBssEntry: |
| 7399 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 7400 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7401 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7402 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7403 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 7404 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7405 | case HLoadClass::LoadKind::kRuntimeCall: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7406 | break; |
| 7407 | } |
| 7408 | return desired_class_load_kind; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7409 | } |
| 7410 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7411 | void LocationsBuilderARMVIXL::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7412 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7413 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7414 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7415 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7416 | cls, |
| 7417 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7418 | LocationFrom(r0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7419 | DCHECK(calling_convention.GetRegisterAt(0).Is(r0)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7420 | return; |
| 7421 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7422 | DCHECK(!cls->NeedsAccessCheck()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7423 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7424 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 7425 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7426 | ? LocationSummary::kCallOnSlowPath |
| 7427 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7428 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7429 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7430 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7431 | } |
| 7432 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7433 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7434 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7435 | } |
| 7436 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7437 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 7438 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 7439 | // Rely on the type resolution or initialization and marking to save everything we need. |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7440 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 7441 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7442 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7443 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 7444 | // that the the kPrimNot result register is the same as the first argument register. |
| 7445 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 7446 | } else { |
| 7447 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7448 | } |
| 7449 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 7450 | if (kUseBakerReadBarrier && kBakerReadBarrierLinkTimeThunksEnableForGcRoots) { |
| 7451 | if (load_kind == HLoadClass::LoadKind::kBssEntry || |
| 7452 | (load_kind == HLoadClass::LoadKind::kReferrersClass && |
| 7453 | !Runtime::Current()->UseJitCompilation())) { |
| 7454 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 7455 | } |
| 7456 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7457 | } |
| 7458 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7459 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7460 | // move. |
| 7461 | void InstructionCodeGeneratorARMVIXL::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7462 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7463 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7464 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 7465 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 13); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7466 | return; |
| 7467 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7468 | DCHECK(!cls->NeedsAccessCheck()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7469 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7470 | LocationSummary* locations = cls->GetLocations(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7471 | Location out_loc = locations->Out(); |
| 7472 | vixl32::Register out = OutputRegister(cls); |
| 7473 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7474 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 7475 | ? kWithoutReadBarrier |
| 7476 | : kCompilerReadBarrierOption; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7477 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7478 | switch (load_kind) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7479 | case HLoadClass::LoadKind::kReferrersClass: { |
| 7480 | DCHECK(!cls->CanCallRuntime()); |
| 7481 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 7482 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 7483 | vixl32::Register current_method = InputRegisterAt(cls, 0); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7484 | codegen_->GenerateGcRootFieldLoad(cls, |
| 7485 | out_loc, |
| 7486 | current_method, |
| 7487 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 7488 | read_barrier_option); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7489 | break; |
| 7490 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7491 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7492 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7493 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 7494 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7495 | codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7496 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 7497 | break; |
| 7498 | } |
| 7499 | case HLoadClass::LoadKind::kBootImageAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7500 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7501 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 7502 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 7503 | DCHECK_NE(address, 0u); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7504 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7505 | break; |
| 7506 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7507 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7508 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7509 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7510 | codegen_->NewBootImageRelRoPatch(codegen_->GetBootImageOffset(cls)); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7511 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 7512 | __ Ldr(out, MemOperand(out, /* offset */ 0)); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7513 | break; |
| 7514 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7515 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7516 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7517 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 7518 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7519 | codegen_->GenerateGcRootFieldLoad(cls, out_loc, out, /* offset */ 0, read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7520 | generate_null_check = true; |
| 7521 | break; |
| 7522 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7523 | case HLoadClass::LoadKind::kJitTableAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7524 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 7525 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7526 | cls->GetClass())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7527 | // /* GcRoot<mirror::Class> */ out = *out |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7528 | codegen_->GenerateGcRootFieldLoad(cls, out_loc, out, /* offset */ 0, read_barrier_option); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7529 | break; |
| 7530 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7531 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7532 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7533 | LOG(FATAL) << "UNREACHABLE"; |
| 7534 | UNREACHABLE(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7535 | } |
| 7536 | |
| 7537 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 7538 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7539 | LoadClassSlowPathARMVIXL* slow_path = |
| 7540 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARMVIXL( |
| 7541 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7542 | codegen_->AddSlowPath(slow_path); |
| 7543 | if (generate_null_check) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7544 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7545 | } |
| 7546 | if (cls->MustGenerateClinitCheck()) { |
| 7547 | GenerateClassInitializationCheck(slow_path, out); |
| 7548 | } else { |
| 7549 | __ Bind(slow_path->GetExitLabel()); |
| 7550 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 7551 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 14); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7552 | } |
| 7553 | } |
| 7554 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7555 | void LocationsBuilderARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 7556 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7557 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7558 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7559 | if (check->HasUses()) { |
| 7560 | locations->SetOut(Location::SameAsFirstInput()); |
| 7561 | } |
| 7562 | } |
| 7563 | |
| 7564 | void InstructionCodeGeneratorARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 7565 | // We assume the class is not null. |
| 7566 | LoadClassSlowPathARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7567 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARMVIXL(check->GetLoadClass(), |
| 7568 | check, |
| 7569 | check->GetDexPc(), |
| 7570 | /* do_clinit */ true); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7571 | codegen_->AddSlowPath(slow_path); |
| 7572 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 7573 | } |
| 7574 | |
| 7575 | void InstructionCodeGeneratorARMVIXL::GenerateClassInitializationCheck( |
| 7576 | LoadClassSlowPathARMVIXL* slow_path, vixl32::Register class_reg) { |
| 7577 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 7578 | vixl32::Register temp = temps.Acquire(); |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 7579 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 7580 | const size_t status_byte_offset = |
| 7581 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 7582 | constexpr uint32_t shifted_initialized_value = |
| 7583 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
| 7584 | |
| 7585 | GetAssembler()->LoadFromOffset(kLoadUnsignedByte, temp, class_reg, status_byte_offset); |
| 7586 | __ Cmp(temp, shifted_initialized_value); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 7587 | __ B(lo, slow_path->GetEntryLabel()); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7588 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 7589 | // properly. Therefore, we do a memory fence. |
| 7590 | __ Dmb(ISH); |
| 7591 | __ Bind(slow_path->GetExitLabel()); |
| 7592 | } |
| 7593 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7594 | void InstructionCodeGeneratorARMVIXL::GenerateBitstringTypeCheckCompare( |
| 7595 | HTypeCheckInstruction* check, |
| 7596 | vixl32::Register temp, |
| 7597 | vixl32::FlagsUpdate flags_update) { |
| 7598 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 7599 | uint32_t mask = check->GetBitstringMask(); |
| 7600 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 7601 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 7602 | |
| 7603 | // Note that HInstanceOf shall check for zero value in `temp` but HCheckCast needs |
| 7604 | // the Z flag for BNE. This is indicated by the `flags_update` parameter. |
| 7605 | if (mask_bits == 16u) { |
| 7606 | // Load only the bitstring part of the status word. |
| 7607 | __ Ldrh(temp, MemOperand(temp, mirror::Class::StatusOffset().Int32Value())); |
| 7608 | // Check if the bitstring bits are equal to `path_to_root`. |
| 7609 | if (flags_update == SetFlags) { |
| 7610 | __ Cmp(temp, path_to_root); |
| 7611 | } else { |
| 7612 | __ Sub(temp, temp, path_to_root); |
| 7613 | } |
| 7614 | } else { |
| 7615 | // /* uint32_t */ temp = temp->status_ |
| 7616 | __ Ldr(temp, MemOperand(temp, mirror::Class::StatusOffset().Int32Value())); |
| 7617 | if (GetAssembler()->ShifterOperandCanHold(SUB, path_to_root)) { |
| 7618 | // Compare the bitstring bits using SUB. |
| 7619 | __ Sub(temp, temp, path_to_root); |
| 7620 | // Shift out bits that do not contribute to the comparison. |
| 7621 | __ Lsl(flags_update, temp, temp, dchecked_integral_cast<uint32_t>(32u - mask_bits)); |
| 7622 | } else if (IsUint<16>(path_to_root)) { |
| 7623 | if (temp.IsLow()) { |
| 7624 | // Note: Optimized for size but contains one more dependent instruction than necessary. |
| 7625 | // MOVW+SUB(register) would be 8 bytes unless we find a low-reg temporary but the |
| 7626 | // macro assembler would use the high reg IP for the constant by default. |
| 7627 | // Compare the bitstring bits using SUB. |
| 7628 | __ Sub(temp, temp, path_to_root & 0x00ffu); // 16-bit SUB (immediate) T2 |
| 7629 | __ Sub(temp, temp, path_to_root & 0xff00u); // 32-bit SUB (immediate) T3 |
| 7630 | // Shift out bits that do not contribute to the comparison. |
| 7631 | __ Lsl(flags_update, temp, temp, dchecked_integral_cast<uint32_t>(32u - mask_bits)); |
| 7632 | } else { |
| 7633 | // Extract the bitstring bits. |
| 7634 | __ Ubfx(temp, temp, 0, mask_bits); |
| 7635 | // Check if the bitstring bits are equal to `path_to_root`. |
| 7636 | if (flags_update == SetFlags) { |
| 7637 | __ Cmp(temp, path_to_root); |
| 7638 | } else { |
| 7639 | __ Sub(temp, temp, path_to_root); |
| 7640 | } |
| 7641 | } |
| 7642 | } else { |
| 7643 | // Shift out bits that do not contribute to the comparison. |
| 7644 | __ Lsl(temp, temp, dchecked_integral_cast<uint32_t>(32u - mask_bits)); |
| 7645 | // Check if the shifted bitstring bits are equal to `path_to_root << (32u - mask_bits)`. |
| 7646 | if (flags_update == SetFlags) { |
| 7647 | __ Cmp(temp, path_to_root << (32u - mask_bits)); |
| 7648 | } else { |
| 7649 | __ Sub(temp, temp, path_to_root << (32u - mask_bits)); |
| 7650 | } |
| 7651 | } |
| 7652 | } |
| 7653 | } |
| 7654 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7655 | HLoadString::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadStringKind( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7656 | HLoadString::LoadKind desired_string_load_kind) { |
| 7657 | switch (desired_string_load_kind) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7658 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7659 | case HLoadString::LoadKind::kBootImageRelRo: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7660 | case HLoadString::LoadKind::kBssEntry: |
| 7661 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 7662 | break; |
| 7663 | case HLoadString::LoadKind::kJitTableAddress: |
| 7664 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7665 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 7666 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7667 | case HLoadString::LoadKind::kRuntimeCall: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7668 | break; |
| 7669 | } |
| 7670 | return desired_string_load_kind; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7671 | } |
| 7672 | |
| 7673 | void LocationsBuilderARMVIXL::VisitLoadString(HLoadString* load) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7674 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7675 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7676 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7677 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7678 | locations->SetOut(LocationFrom(r0)); |
| 7679 | } else { |
| 7680 | locations->SetOut(Location::RequiresRegister()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7681 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 7682 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7683 | // Rely on the pResolveString and marking to save everything we need, including temps. |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7684 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 7685 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7686 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7687 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 7688 | // that the the kPrimNot result register is the same as the first argument register. |
| 7689 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 7690 | if (kUseBakerReadBarrier && kBakerReadBarrierLinkTimeThunksEnableForGcRoots) { |
| 7691 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 7692 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7693 | } else { |
| 7694 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7695 | } |
| 7696 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7697 | } |
| 7698 | } |
| 7699 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7700 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7701 | // move. |
| 7702 | void InstructionCodeGeneratorARMVIXL::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7703 | LocationSummary* locations = load->GetLocations(); |
| 7704 | Location out_loc = locations->Out(); |
| 7705 | vixl32::Register out = OutputRegister(load); |
| 7706 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 7707 | |
| 7708 | switch (load_kind) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7709 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 7710 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| 7711 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7712 | codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7713 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7714 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7715 | } |
| 7716 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7717 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 7718 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 7719 | DCHECK_NE(address, 0u); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7720 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7721 | return; |
| 7722 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7723 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7724 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7725 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7726 | codegen_->NewBootImageRelRoPatch(codegen_->GetBootImageOffset(load)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7727 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 7728 | __ Ldr(out, MemOperand(out, /* offset */ 0)); |
| 7729 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7730 | } |
| 7731 | case HLoadString::LoadKind::kBssEntry: { |
| 7732 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7733 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7734 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 7735 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7736 | codegen_->GenerateGcRootFieldLoad( |
| 7737 | load, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7738 | LoadStringSlowPathARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7739 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathARMVIXL(load); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7740 | codegen_->AddSlowPath(slow_path); |
| 7741 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 7742 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 7743 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 15); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7744 | return; |
| 7745 | } |
| 7746 | case HLoadString::LoadKind::kJitTableAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7747 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7748 | load->GetStringIndex(), |
| 7749 | load->GetString())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7750 | // /* GcRoot<mirror::String> */ out = *out |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7751 | codegen_->GenerateGcRootFieldLoad( |
| 7752 | load, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7753 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7754 | } |
| 7755 | default: |
| 7756 | break; |
| 7757 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7758 | |
| 7759 | // 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] | 7760 | DCHECK_EQ(load->GetLoadKind(), HLoadString::LoadKind::kRuntimeCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7761 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7762 | __ Mov(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7763 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 7764 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 7765 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 16); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7766 | } |
| 7767 | |
| 7768 | static int32_t GetExceptionTlsOffset() { |
| 7769 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
| 7770 | } |
| 7771 | |
| 7772 | void LocationsBuilderARMVIXL::VisitLoadException(HLoadException* load) { |
| 7773 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7774 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7775 | locations->SetOut(Location::RequiresRegister()); |
| 7776 | } |
| 7777 | |
| 7778 | void InstructionCodeGeneratorARMVIXL::VisitLoadException(HLoadException* load) { |
| 7779 | vixl32::Register out = OutputRegister(load); |
| 7780 | GetAssembler()->LoadFromOffset(kLoadWord, out, tr, GetExceptionTlsOffset()); |
| 7781 | } |
| 7782 | |
| 7783 | |
| 7784 | void LocationsBuilderARMVIXL::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7785 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7786 | } |
| 7787 | |
| 7788 | void InstructionCodeGeneratorARMVIXL::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 7789 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 7790 | vixl32::Register temp = temps.Acquire(); |
| 7791 | __ Mov(temp, 0); |
| 7792 | GetAssembler()->StoreToOffset(kStoreWord, temp, tr, GetExceptionTlsOffset()); |
| 7793 | } |
| 7794 | |
| 7795 | void LocationsBuilderARMVIXL::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7796 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7797 | instruction, LocationSummary::kCallOnMainOnly); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7798 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7799 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7800 | } |
| 7801 | |
| 7802 | void InstructionCodeGeneratorARMVIXL::VisitThrow(HThrow* instruction) { |
| 7803 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| 7804 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 7805 | } |
| 7806 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7807 | // Temp is used for read barrier. |
| 7808 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 7809 | if (kEmitCompilerReadBarrier && |
| 7810 | (kUseBakerReadBarrier || |
| 7811 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7812 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7813 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 7814 | return 1; |
| 7815 | } |
| 7816 | return 0; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7817 | } |
| 7818 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7819 | // Interface case has 3 temps, one for holding the number of interfaces, one for the current |
| 7820 | // interface pointer, one for loading the current interface. |
| 7821 | // The other checks have one temp for loading the object's class. |
| 7822 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 7823 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7824 | return 3; |
| 7825 | } |
| 7826 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 7827 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7828 | |
| 7829 | void LocationsBuilderARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 7830 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7831 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7832 | bool baker_read_barrier_slow_path = false; |
| 7833 | switch (type_check_kind) { |
| 7834 | case TypeCheckKind::kExactCheck: |
| 7835 | case TypeCheckKind::kAbstractClassCheck: |
| 7836 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7837 | case TypeCheckKind::kArrayObjectCheck: { |
| 7838 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 7839 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 7840 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7841 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7842 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7843 | case TypeCheckKind::kArrayCheck: |
| 7844 | case TypeCheckKind::kUnresolvedCheck: |
| 7845 | case TypeCheckKind::kInterfaceCheck: |
| 7846 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7847 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7848 | case TypeCheckKind::kBitstringCheck: |
| 7849 | break; |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7850 | } |
| 7851 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7852 | LocationSummary* locations = |
| 7853 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7854 | if (baker_read_barrier_slow_path) { |
| 7855 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 7856 | } |
| 7857 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7858 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7859 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7860 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7861 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 7862 | } else { |
| 7863 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7864 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7865 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 7866 | // Note that TypeCheckSlowPathARM uses this register too. |
| 7867 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7868 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 7869 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 7870 | codegen_->MaybeAddBakerCcEntrypointTempForFields(locations); |
| 7871 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7872 | } |
| 7873 | |
| 7874 | void InstructionCodeGeneratorARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 7875 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7876 | LocationSummary* locations = instruction->GetLocations(); |
| 7877 | Location obj_loc = locations->InAt(0); |
| 7878 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7879 | vixl32::Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 7880 | ? vixl32::Register() |
| 7881 | : InputRegisterAt(instruction, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7882 | Location out_loc = locations->Out(); |
| 7883 | vixl32::Register out = OutputRegister(instruction); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7884 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7885 | DCHECK_LE(num_temps, 1u); |
| 7886 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7887 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7888 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7889 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7890 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7891 | vixl32::Label done; |
| 7892 | vixl32::Label* const final_label = codegen_->GetFinalLabel(instruction, &done); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7893 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 7894 | |
| 7895 | // Return 0 if `obj` is null. |
| 7896 | // avoid null check if we know obj is not null. |
| 7897 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7898 | DCHECK(!out.Is(obj)); |
| 7899 | __ Mov(out, 0); |
| 7900 | __ CompareAndBranchIfZero(obj, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7901 | } |
| 7902 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7903 | switch (type_check_kind) { |
| 7904 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7905 | ReadBarrierOption read_barrier_option = |
| 7906 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7907 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7908 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7909 | out_loc, |
| 7910 | obj_loc, |
| 7911 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7912 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7913 | read_barrier_option); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7914 | // Classes must be equal for the instanceof to succeed. |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7915 | __ Cmp(out, cls); |
| 7916 | // We speculatively set the result to false without changing the condition |
| 7917 | // flags, which allows us to avoid some branching later. |
| 7918 | __ Mov(LeaveFlags, out, 0); |
| 7919 | |
| 7920 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7921 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7922 | // encoding can be used. |
| 7923 | if (out.IsLow()) { |
| 7924 | // We use the scope because of the IT block that follows. |
| 7925 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7926 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7927 | CodeBufferCheckScope::kExactSize); |
| 7928 | |
| 7929 | __ it(eq); |
| 7930 | __ mov(eq, out, 1); |
| 7931 | } else { |
| 7932 | __ B(ne, final_label, /* far_target */ false); |
| 7933 | __ Mov(out, 1); |
| 7934 | } |
| 7935 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7936 | break; |
| 7937 | } |
| 7938 | |
| 7939 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7940 | ReadBarrierOption read_barrier_option = |
| 7941 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7942 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7943 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7944 | out_loc, |
| 7945 | obj_loc, |
| 7946 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7947 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7948 | read_barrier_option); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7949 | // If the class is abstract, we eagerly fetch the super class of the |
| 7950 | // object to avoid doing a comparison we know will fail. |
| 7951 | vixl32::Label loop; |
| 7952 | __ Bind(&loop); |
| 7953 | // /* HeapReference<Class> */ out = out->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7954 | GenerateReferenceLoadOneRegister(instruction, |
| 7955 | out_loc, |
| 7956 | super_offset, |
| 7957 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7958 | read_barrier_option); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7959 | // 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] | 7960 | __ CompareAndBranchIfZero(out, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7961 | __ Cmp(out, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7962 | __ B(ne, &loop, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7963 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7964 | break; |
| 7965 | } |
| 7966 | |
| 7967 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7968 | ReadBarrierOption read_barrier_option = |
| 7969 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7970 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7971 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7972 | out_loc, |
| 7973 | obj_loc, |
| 7974 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7975 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7976 | read_barrier_option); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7977 | // Walk over the class hierarchy to find a match. |
| 7978 | vixl32::Label loop, success; |
| 7979 | __ Bind(&loop); |
| 7980 | __ Cmp(out, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7981 | __ B(eq, &success, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7982 | // /* HeapReference<Class> */ out = out->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7983 | GenerateReferenceLoadOneRegister(instruction, |
| 7984 | out_loc, |
| 7985 | super_offset, |
| 7986 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7987 | read_barrier_option); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7988 | // This is essentially a null check, but it sets the condition flags to the |
| 7989 | // proper value for the code that follows the loop, i.e. not `eq`. |
| 7990 | __ Cmp(out, 1); |
| 7991 | __ B(hs, &loop, /* far_target */ false); |
| 7992 | |
| 7993 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7994 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7995 | // encoding can be used. |
| 7996 | if (out.IsLow()) { |
| 7997 | // If `out` is null, we use it for the result, and the condition flags |
| 7998 | // have already been set to `ne`, so the IT block that comes afterwards |
| 7999 | // (and which handles the successful case) turns into a NOP (instead of |
| 8000 | // overwriting `out`). |
| 8001 | __ Bind(&success); |
| 8002 | |
| 8003 | // We use the scope because of the IT block that follows. |
| 8004 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 8005 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 8006 | CodeBufferCheckScope::kExactSize); |
| 8007 | |
| 8008 | // There is only one branch to the `success` label (which is bound to this |
| 8009 | // IT block), and it has the same condition, `eq`, so in that case the MOV |
| 8010 | // is executed. |
| 8011 | __ it(eq); |
| 8012 | __ mov(eq, out, 1); |
| 8013 | } else { |
| 8014 | // 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] | 8015 | __ B(final_label); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 8016 | __ Bind(&success); |
| 8017 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8018 | } |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 8019 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8020 | break; |
| 8021 | } |
| 8022 | |
| 8023 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 8024 | ReadBarrierOption read_barrier_option = |
| 8025 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 8026 | // /* HeapReference<Class> */ out = obj->klass_ |
| 8027 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8028 | out_loc, |
| 8029 | obj_loc, |
| 8030 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8031 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 8032 | read_barrier_option); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8033 | // Do an exact check. |
| 8034 | vixl32::Label exact_check; |
| 8035 | __ Cmp(out, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 8036 | __ B(eq, &exact_check, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8037 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 8038 | // /* HeapReference<Class> */ out = out->component_type_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8039 | GenerateReferenceLoadOneRegister(instruction, |
| 8040 | out_loc, |
| 8041 | component_offset, |
| 8042 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 8043 | read_barrier_option); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 8044 | // 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] | 8045 | __ CompareAndBranchIfZero(out, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8046 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 8047 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 8048 | __ Cmp(out, 0); |
| 8049 | // We speculatively set the result to false without changing the condition |
| 8050 | // flags, which allows us to avoid some branching later. |
| 8051 | __ Mov(LeaveFlags, out, 0); |
| 8052 | |
| 8053 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 8054 | // we check that the output is in a low register, so that a 16-bit MOV |
| 8055 | // encoding can be used. |
| 8056 | if (out.IsLow()) { |
| 8057 | __ Bind(&exact_check); |
| 8058 | |
| 8059 | // We use the scope because of the IT block that follows. |
| 8060 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 8061 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 8062 | CodeBufferCheckScope::kExactSize); |
| 8063 | |
| 8064 | __ it(eq); |
| 8065 | __ mov(eq, out, 1); |
| 8066 | } else { |
| 8067 | __ B(ne, final_label, /* far_target */ false); |
| 8068 | __ Bind(&exact_check); |
| 8069 | __ Mov(out, 1); |
| 8070 | } |
| 8071 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8072 | break; |
| 8073 | } |
| 8074 | |
| 8075 | case TypeCheckKind::kArrayCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8076 | // No read barrier since the slow path will retry upon failure. |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 8077 | // /* HeapReference<Class> */ out = obj->klass_ |
| 8078 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8079 | out_loc, |
| 8080 | obj_loc, |
| 8081 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8082 | maybe_temp_loc, |
| 8083 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8084 | __ Cmp(out, cls); |
| 8085 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8086 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
| 8087 | instruction, /* is_fatal */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8088 | codegen_->AddSlowPath(slow_path); |
| 8089 | __ B(ne, slow_path->GetEntryLabel()); |
| 8090 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8091 | break; |
| 8092 | } |
| 8093 | |
| 8094 | case TypeCheckKind::kUnresolvedCheck: |
| 8095 | case TypeCheckKind::kInterfaceCheck: { |
| 8096 | // Note that we indeed only call on slow path, but we always go |
| 8097 | // into the slow path for the unresolved and interface check |
| 8098 | // cases. |
| 8099 | // |
| 8100 | // We cannot directly call the InstanceofNonTrivial runtime |
| 8101 | // entry point without resorting to a type checking slow path |
| 8102 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 8103 | // require to assign fixed registers for the inputs of this |
| 8104 | // HInstanceOf instruction (following the runtime calling |
| 8105 | // convention), which might be cluttered by the potential first |
| 8106 | // read barrier emission at the beginning of this method. |
| 8107 | // |
| 8108 | // TODO: Introduce a new runtime entry point taking the object |
| 8109 | // to test (instead of its class) as argument, and let it deal |
| 8110 | // with the read barrier issues. This will let us refactor this |
| 8111 | // case of the `switch` code as it was previously (with a direct |
| 8112 | // call to the runtime not using a type checking slow path). |
| 8113 | // This should also be beneficial for the other cases above. |
| 8114 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8115 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
| 8116 | instruction, /* is_fatal */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8117 | codegen_->AddSlowPath(slow_path); |
| 8118 | __ B(slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8119 | break; |
| 8120 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 8121 | |
| 8122 | case TypeCheckKind::kBitstringCheck: { |
| 8123 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8124 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8125 | out_loc, |
| 8126 | obj_loc, |
| 8127 | class_offset, |
| 8128 | maybe_temp_loc, |
| 8129 | kWithoutReadBarrier); |
| 8130 | |
| 8131 | GenerateBitstringTypeCheckCompare(instruction, out, DontCare); |
| 8132 | // If `out` is a low reg and we would have another low reg temp, we could |
| 8133 | // optimize this as RSBS+ADC, see GenerateConditionWithZero(). |
| 8134 | // |
| 8135 | // Also, in some cases when `out` is a low reg and we're loading a constant to IP |
| 8136 | // it would make sense to use CMP+MOV+IT+MOV instead of SUB+CLZ+LSR as the code size |
| 8137 | // would be the same and we would have fewer direct data dependencies. |
| 8138 | codegen_->GenerateConditionWithZero(kCondEQ, out, out); // CLZ+LSR |
| 8139 | break; |
| 8140 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8141 | } |
| 8142 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8143 | if (done.IsReferenced()) { |
| 8144 | __ Bind(&done); |
| 8145 | } |
| 8146 | |
| 8147 | if (slow_path != nullptr) { |
| 8148 | __ Bind(slow_path->GetExitLabel()); |
| 8149 | } |
| 8150 | } |
| 8151 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8152 | void LocationsBuilderARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8153 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 8154 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8155 | LocationSummary* locations = |
| 8156 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8157 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 8158 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 8159 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 8160 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 8161 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 8162 | } else { |
| 8163 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8164 | } |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8165 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8166 | } |
| 8167 | |
| 8168 | void InstructionCodeGeneratorARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
| 8169 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 8170 | LocationSummary* locations = instruction->GetLocations(); |
| 8171 | Location obj_loc = locations->InAt(0); |
| 8172 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 8173 | vixl32::Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 8174 | ? vixl32::Register() |
| 8175 | : InputRegisterAt(instruction, 1); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8176 | Location temp_loc = locations->GetTemp(0); |
| 8177 | vixl32::Register temp = RegisterFrom(temp_loc); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8178 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 8179 | DCHECK_LE(num_temps, 3u); |
| 8180 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 8181 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 8182 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 8183 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 8184 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 8185 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 8186 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 8187 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 8188 | const uint32_t object_array_data_offset = |
| 8189 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8190 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 8191 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8192 | SlowPathCodeARMVIXL* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8193 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
| 8194 | instruction, is_type_check_slow_path_fatal); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8195 | codegen_->AddSlowPath(type_check_slow_path); |
| 8196 | |
| 8197 | vixl32::Label done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 8198 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8199 | // Avoid null check if we know obj is not null. |
| 8200 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 8201 | __ CompareAndBranchIfZero(obj, final_label, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8202 | } |
| 8203 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8204 | switch (type_check_kind) { |
| 8205 | case TypeCheckKind::kExactCheck: |
| 8206 | case TypeCheckKind::kArrayCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8207 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8208 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8209 | temp_loc, |
| 8210 | obj_loc, |
| 8211 | class_offset, |
| 8212 | maybe_temp2_loc, |
| 8213 | kWithoutReadBarrier); |
| 8214 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8215 | __ Cmp(temp, cls); |
| 8216 | // Jump to slow path for throwing the exception or doing a |
| 8217 | // more involved array check. |
| 8218 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 8219 | break; |
| 8220 | } |
| 8221 | |
| 8222 | case TypeCheckKind::kAbstractClassCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8223 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8224 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8225 | temp_loc, |
| 8226 | obj_loc, |
| 8227 | class_offset, |
| 8228 | maybe_temp2_loc, |
| 8229 | kWithoutReadBarrier); |
| 8230 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8231 | // If the class is abstract, we eagerly fetch the super class of the |
| 8232 | // object to avoid doing a comparison we know will fail. |
| 8233 | vixl32::Label loop; |
| 8234 | __ Bind(&loop); |
| 8235 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8236 | GenerateReferenceLoadOneRegister(instruction, |
| 8237 | temp_loc, |
| 8238 | super_offset, |
| 8239 | maybe_temp2_loc, |
| 8240 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8241 | |
| 8242 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 8243 | // exception. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 8244 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8245 | |
| 8246 | // Otherwise, compare the classes. |
| 8247 | __ Cmp(temp, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 8248 | __ B(ne, &loop, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8249 | break; |
| 8250 | } |
| 8251 | |
| 8252 | case TypeCheckKind::kClassHierarchyCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8253 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8254 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8255 | temp_loc, |
| 8256 | obj_loc, |
| 8257 | class_offset, |
| 8258 | maybe_temp2_loc, |
| 8259 | kWithoutReadBarrier); |
| 8260 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8261 | // Walk over the class hierarchy to find a match. |
| 8262 | vixl32::Label loop; |
| 8263 | __ Bind(&loop); |
| 8264 | __ Cmp(temp, cls); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 8265 | __ B(eq, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8266 | |
| 8267 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8268 | GenerateReferenceLoadOneRegister(instruction, |
| 8269 | temp_loc, |
| 8270 | super_offset, |
| 8271 | maybe_temp2_loc, |
| 8272 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8273 | |
| 8274 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 8275 | // exception. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 8276 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8277 | // Otherwise, jump to the beginning of the loop. |
| 8278 | __ B(&loop); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8279 | break; |
| 8280 | } |
| 8281 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8282 | case TypeCheckKind::kArrayObjectCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8283 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8284 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8285 | temp_loc, |
| 8286 | obj_loc, |
| 8287 | class_offset, |
| 8288 | maybe_temp2_loc, |
| 8289 | kWithoutReadBarrier); |
| 8290 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8291 | // Do an exact check. |
| 8292 | __ Cmp(temp, cls); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 8293 | __ B(eq, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8294 | |
| 8295 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 8296 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8297 | GenerateReferenceLoadOneRegister(instruction, |
| 8298 | temp_loc, |
| 8299 | component_offset, |
| 8300 | maybe_temp2_loc, |
| 8301 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8302 | // 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] | 8303 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8304 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 8305 | // to further check that this component type is not a primitive type. |
| 8306 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8307 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 8308 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8309 | break; |
| 8310 | } |
| 8311 | |
| 8312 | case TypeCheckKind::kUnresolvedCheck: |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8313 | // 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] | 8314 | // We cannot directly call the CheckCast runtime entry point |
| 8315 | // without resorting to a type checking slow path here (i.e. by |
| 8316 | // calling InvokeRuntime directly), as it would require to |
| 8317 | // assign fixed registers for the inputs of this HInstanceOf |
| 8318 | // instruction (following the runtime calling convention), which |
| 8319 | // might be cluttered by the potential first read barrier |
| 8320 | // emission at the beginning of this method. |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8321 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8322 | __ B(type_check_slow_path->GetEntryLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8323 | break; |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8324 | |
| 8325 | case TypeCheckKind::kInterfaceCheck: { |
| 8326 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 8327 | // positives by doing this. |
| 8328 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8329 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8330 | temp_loc, |
| 8331 | obj_loc, |
| 8332 | class_offset, |
| 8333 | maybe_temp2_loc, |
| 8334 | kWithoutReadBarrier); |
| 8335 | |
| 8336 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 8337 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8338 | temp_loc, |
| 8339 | temp_loc, |
| 8340 | iftable_offset, |
| 8341 | maybe_temp2_loc, |
| 8342 | kWithoutReadBarrier); |
| 8343 | // Iftable is never null. |
| 8344 | __ Ldr(RegisterFrom(maybe_temp2_loc), MemOperand(temp, array_length_offset)); |
| 8345 | // Loop through the iftable and check if any class matches. |
| 8346 | vixl32::Label start_loop; |
| 8347 | __ Bind(&start_loop); |
| 8348 | __ CompareAndBranchIfZero(RegisterFrom(maybe_temp2_loc), |
| 8349 | type_check_slow_path->GetEntryLabel()); |
| 8350 | __ Ldr(RegisterFrom(maybe_temp3_loc), MemOperand(temp, object_array_data_offset)); |
| 8351 | GetAssembler()->MaybeUnpoisonHeapReference(RegisterFrom(maybe_temp3_loc)); |
| 8352 | // Go to next interface. |
| 8353 | __ Add(temp, temp, Operand::From(2 * kHeapReferenceSize)); |
| 8354 | __ Sub(RegisterFrom(maybe_temp2_loc), RegisterFrom(maybe_temp2_loc), 2); |
| 8355 | // Compare the classes and continue the loop if they do not match. |
| 8356 | __ Cmp(cls, RegisterFrom(maybe_temp3_loc)); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 8357 | __ B(ne, &start_loop, /* far_target */ false); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8358 | break; |
| 8359 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 8360 | |
| 8361 | case TypeCheckKind::kBitstringCheck: { |
| 8362 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8363 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8364 | temp_loc, |
| 8365 | obj_loc, |
| 8366 | class_offset, |
| 8367 | maybe_temp2_loc, |
| 8368 | kWithoutReadBarrier); |
| 8369 | |
| 8370 | GenerateBitstringTypeCheckCompare(instruction, temp, SetFlags); |
| 8371 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 8372 | break; |
| 8373 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8374 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 8375 | if (done.IsReferenced()) { |
| 8376 | __ Bind(&done); |
| 8377 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8378 | |
| 8379 | __ Bind(type_check_slow_path->GetExitLabel()); |
| 8380 | } |
| 8381 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8382 | void LocationsBuilderARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8383 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8384 | instruction, LocationSummary::kCallOnMainOnly); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8385 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 8386 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 8387 | } |
| 8388 | |
| 8389 | void InstructionCodeGeneratorARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 8390 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 8391 | instruction, |
| 8392 | instruction->GetDexPc()); |
| 8393 | if (instruction->IsEnter()) { |
| 8394 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 8395 | } else { |
| 8396 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 8397 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8398 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ 17); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8399 | } |
| 8400 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8401 | void LocationsBuilderARMVIXL::VisitAnd(HAnd* instruction) { |
| 8402 | HandleBitwiseOperation(instruction, AND); |
| 8403 | } |
| 8404 | |
| 8405 | void LocationsBuilderARMVIXL::VisitOr(HOr* instruction) { |
| 8406 | HandleBitwiseOperation(instruction, ORR); |
| 8407 | } |
| 8408 | |
| 8409 | void LocationsBuilderARMVIXL::VisitXor(HXor* instruction) { |
| 8410 | HandleBitwiseOperation(instruction, EOR); |
| 8411 | } |
| 8412 | |
| 8413 | void LocationsBuilderARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
| 8414 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8415 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8416 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 8417 | || instruction->GetResultType() == DataType::Type::kInt64); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8418 | // Note: GVN reorders commutative operations to have the constant on the right hand side. |
| 8419 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8420 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
| 8421 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8422 | } |
| 8423 | |
| 8424 | void InstructionCodeGeneratorARMVIXL::VisitAnd(HAnd* instruction) { |
| 8425 | HandleBitwiseOperation(instruction); |
| 8426 | } |
| 8427 | |
| 8428 | void InstructionCodeGeneratorARMVIXL::VisitOr(HOr* instruction) { |
| 8429 | HandleBitwiseOperation(instruction); |
| 8430 | } |
| 8431 | |
| 8432 | void InstructionCodeGeneratorARMVIXL::VisitXor(HXor* instruction) { |
| 8433 | HandleBitwiseOperation(instruction); |
| 8434 | } |
| 8435 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8436 | void LocationsBuilderARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 8437 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8438 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8439 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 8440 | || instruction->GetResultType() == DataType::Type::kInt64); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8441 | |
| 8442 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8443 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8444 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8445 | } |
| 8446 | |
| 8447 | void InstructionCodeGeneratorARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 8448 | LocationSummary* locations = instruction->GetLocations(); |
| 8449 | Location first = locations->InAt(0); |
| 8450 | Location second = locations->InAt(1); |
| 8451 | Location out = locations->Out(); |
| 8452 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8453 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8454 | vixl32::Register first_reg = RegisterFrom(first); |
| 8455 | vixl32::Register second_reg = RegisterFrom(second); |
| 8456 | vixl32::Register out_reg = RegisterFrom(out); |
| 8457 | |
| 8458 | switch (instruction->GetOpKind()) { |
| 8459 | case HInstruction::kAnd: |
| 8460 | __ Bic(out_reg, first_reg, second_reg); |
| 8461 | break; |
| 8462 | case HInstruction::kOr: |
| 8463 | __ Orn(out_reg, first_reg, second_reg); |
| 8464 | break; |
| 8465 | // There is no EON on arm. |
| 8466 | case HInstruction::kXor: |
| 8467 | default: |
| 8468 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 8469 | UNREACHABLE(); |
| 8470 | } |
| 8471 | return; |
| 8472 | |
| 8473 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8474 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8475 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8476 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8477 | vixl32::Register second_low = LowRegisterFrom(second); |
| 8478 | vixl32::Register second_high = HighRegisterFrom(second); |
| 8479 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8480 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8481 | |
| 8482 | switch (instruction->GetOpKind()) { |
| 8483 | case HInstruction::kAnd: |
| 8484 | __ Bic(out_low, first_low, second_low); |
| 8485 | __ Bic(out_high, first_high, second_high); |
| 8486 | break; |
| 8487 | case HInstruction::kOr: |
| 8488 | __ Orn(out_low, first_low, second_low); |
| 8489 | __ Orn(out_high, first_high, second_high); |
| 8490 | break; |
| 8491 | // There is no EON on arm. |
| 8492 | case HInstruction::kXor: |
| 8493 | default: |
| 8494 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 8495 | UNREACHABLE(); |
| 8496 | } |
| 8497 | } |
| 8498 | } |
| 8499 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8500 | void LocationsBuilderARMVIXL::VisitDataProcWithShifterOp( |
| 8501 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8502 | DCHECK(instruction->GetType() == DataType::Type::kInt32 || |
| 8503 | instruction->GetType() == DataType::Type::kInt64); |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8504 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8505 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8506 | const bool overlap = instruction->GetType() == DataType::Type::kInt64 && |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8507 | HDataProcWithShifterOp::IsExtensionOp(instruction->GetOpKind()); |
| 8508 | |
| 8509 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8510 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8511 | locations->SetOut(Location::RequiresRegister(), |
| 8512 | overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 8513 | } |
| 8514 | |
| 8515 | void InstructionCodeGeneratorARMVIXL::VisitDataProcWithShifterOp( |
| 8516 | HDataProcWithShifterOp* instruction) { |
| 8517 | const LocationSummary* const locations = instruction->GetLocations(); |
| 8518 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 8519 | const HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 8520 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8521 | if (instruction->GetType() == DataType::Type::kInt32) { |
Anton Kirilov | 420ee30 | 2017-02-21 18:10:26 +0000 | [diff] [blame] | 8522 | const vixl32::Register first = InputRegisterAt(instruction, 0); |
| 8523 | const vixl32::Register output = OutputRegister(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8524 | const vixl32::Register second = instruction->InputAt(1)->GetType() == DataType::Type::kInt64 |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8525 | ? LowRegisterFrom(locations->InAt(1)) |
| 8526 | : InputRegisterAt(instruction, 1); |
| 8527 | |
Anton Kirilov | 420ee30 | 2017-02-21 18:10:26 +0000 | [diff] [blame] | 8528 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 8529 | DCHECK_EQ(kind, HInstruction::kAdd); |
| 8530 | |
| 8531 | switch (op_kind) { |
| 8532 | case HDataProcWithShifterOp::kUXTB: |
| 8533 | __ Uxtab(output, first, second); |
| 8534 | break; |
| 8535 | case HDataProcWithShifterOp::kUXTH: |
| 8536 | __ Uxtah(output, first, second); |
| 8537 | break; |
| 8538 | case HDataProcWithShifterOp::kSXTB: |
| 8539 | __ Sxtab(output, first, second); |
| 8540 | break; |
| 8541 | case HDataProcWithShifterOp::kSXTH: |
| 8542 | __ Sxtah(output, first, second); |
| 8543 | break; |
| 8544 | default: |
| 8545 | LOG(FATAL) << "Unexpected operation kind: " << op_kind; |
| 8546 | UNREACHABLE(); |
| 8547 | } |
| 8548 | } else { |
| 8549 | GenerateDataProcInstruction(kind, |
| 8550 | output, |
| 8551 | first, |
| 8552 | Operand(second, |
| 8553 | ShiftFromOpKind(op_kind), |
| 8554 | instruction->GetShiftAmount()), |
| 8555 | codegen_); |
| 8556 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8557 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8558 | DCHECK_EQ(instruction->GetType(), DataType::Type::kInt64); |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8559 | |
| 8560 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 8561 | const vixl32::Register second = InputRegisterAt(instruction, 1); |
| 8562 | |
| 8563 | DCHECK(!LowRegisterFrom(locations->Out()).Is(second)); |
| 8564 | GenerateDataProc(kind, |
| 8565 | locations->Out(), |
| 8566 | locations->InAt(0), |
| 8567 | second, |
| 8568 | Operand(second, ShiftType::ASR, 31), |
| 8569 | codegen_); |
| 8570 | } else { |
| 8571 | GenerateLongDataProc(instruction, codegen_); |
| 8572 | } |
| 8573 | } |
| 8574 | } |
| 8575 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8576 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8577 | void InstructionCodeGeneratorARMVIXL::GenerateAndConst(vixl32::Register out, |
| 8578 | vixl32::Register first, |
| 8579 | uint32_t value) { |
| 8580 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 8581 | if (value == 0xffffffffu) { |
| 8582 | if (!out.Is(first)) { |
| 8583 | __ Mov(out, first); |
| 8584 | } |
| 8585 | return; |
| 8586 | } |
| 8587 | if (value == 0u) { |
| 8588 | __ Mov(out, 0); |
| 8589 | return; |
| 8590 | } |
| 8591 | if (GetAssembler()->ShifterOperandCanHold(AND, value)) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 8592 | __ And(out, first, value); |
| 8593 | } else if (GetAssembler()->ShifterOperandCanHold(BIC, ~value)) { |
| 8594 | __ Bic(out, first, ~value); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8595 | } else { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 8596 | DCHECK(IsPowerOfTwo(value + 1)); |
| 8597 | __ Ubfx(out, first, 0, WhichPowerOf2(value + 1)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8598 | } |
| 8599 | } |
| 8600 | |
| 8601 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8602 | void InstructionCodeGeneratorARMVIXL::GenerateOrrConst(vixl32::Register out, |
| 8603 | vixl32::Register first, |
| 8604 | uint32_t value) { |
| 8605 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 8606 | if (value == 0u) { |
| 8607 | if (!out.Is(first)) { |
| 8608 | __ Mov(out, first); |
| 8609 | } |
| 8610 | return; |
| 8611 | } |
| 8612 | if (value == 0xffffffffu) { |
| 8613 | __ Mvn(out, 0); |
| 8614 | return; |
| 8615 | } |
| 8616 | if (GetAssembler()->ShifterOperandCanHold(ORR, value)) { |
| 8617 | __ Orr(out, first, value); |
| 8618 | } else { |
| 8619 | DCHECK(GetAssembler()->ShifterOperandCanHold(ORN, ~value)); |
| 8620 | __ Orn(out, first, ~value); |
| 8621 | } |
| 8622 | } |
| 8623 | |
| 8624 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8625 | void InstructionCodeGeneratorARMVIXL::GenerateEorConst(vixl32::Register out, |
| 8626 | vixl32::Register first, |
| 8627 | uint32_t value) { |
| 8628 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 8629 | if (value == 0u) { |
| 8630 | if (!out.Is(first)) { |
| 8631 | __ Mov(out, first); |
| 8632 | } |
| 8633 | return; |
| 8634 | } |
| 8635 | __ Eor(out, first, value); |
| 8636 | } |
| 8637 | |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8638 | void InstructionCodeGeneratorARMVIXL::GenerateAddLongConst(Location out, |
| 8639 | Location first, |
| 8640 | uint64_t value) { |
| 8641 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8642 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8643 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8644 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8645 | uint32_t value_low = Low32Bits(value); |
| 8646 | uint32_t value_high = High32Bits(value); |
| 8647 | if (value_low == 0u) { |
| 8648 | if (!out_low.Is(first_low)) { |
| 8649 | __ Mov(out_low, first_low); |
| 8650 | } |
| 8651 | __ Add(out_high, first_high, value_high); |
| 8652 | return; |
| 8653 | } |
| 8654 | __ Adds(out_low, first_low, value_low); |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 8655 | if (GetAssembler()->ShifterOperandCanHold(ADC, value_high)) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8656 | __ Adc(out_high, first_high, value_high); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8657 | } else { |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 8658 | DCHECK(GetAssembler()->ShifterOperandCanHold(SBC, ~value_high)); |
| 8659 | __ Sbc(out_high, first_high, ~value_high); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8660 | } |
| 8661 | } |
| 8662 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8663 | void InstructionCodeGeneratorARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 8664 | LocationSummary* locations = instruction->GetLocations(); |
| 8665 | Location first = locations->InAt(0); |
| 8666 | Location second = locations->InAt(1); |
| 8667 | Location out = locations->Out(); |
| 8668 | |
| 8669 | if (second.IsConstant()) { |
| 8670 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 8671 | uint32_t value_low = Low32Bits(value); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8672 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8673 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 8674 | vixl32::Register out_reg = OutputRegister(instruction); |
| 8675 | if (instruction->IsAnd()) { |
| 8676 | GenerateAndConst(out_reg, first_reg, value_low); |
| 8677 | } else if (instruction->IsOr()) { |
| 8678 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 8679 | } else { |
| 8680 | DCHECK(instruction->IsXor()); |
| 8681 | GenerateEorConst(out_reg, first_reg, value_low); |
| 8682 | } |
| 8683 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8684 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8685 | uint32_t value_high = High32Bits(value); |
| 8686 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8687 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8688 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8689 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8690 | if (instruction->IsAnd()) { |
| 8691 | GenerateAndConst(out_low, first_low, value_low); |
| 8692 | GenerateAndConst(out_high, first_high, value_high); |
| 8693 | } else if (instruction->IsOr()) { |
| 8694 | GenerateOrrConst(out_low, first_low, value_low); |
| 8695 | GenerateOrrConst(out_high, first_high, value_high); |
| 8696 | } else { |
| 8697 | DCHECK(instruction->IsXor()); |
| 8698 | GenerateEorConst(out_low, first_low, value_low); |
| 8699 | GenerateEorConst(out_high, first_high, value_high); |
| 8700 | } |
| 8701 | } |
| 8702 | return; |
| 8703 | } |
| 8704 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8705 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8706 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 8707 | vixl32::Register second_reg = InputRegisterAt(instruction, 1); |
| 8708 | vixl32::Register out_reg = OutputRegister(instruction); |
| 8709 | if (instruction->IsAnd()) { |
| 8710 | __ And(out_reg, first_reg, second_reg); |
| 8711 | } else if (instruction->IsOr()) { |
| 8712 | __ Orr(out_reg, first_reg, second_reg); |
| 8713 | } else { |
| 8714 | DCHECK(instruction->IsXor()); |
| 8715 | __ Eor(out_reg, first_reg, second_reg); |
| 8716 | } |
| 8717 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8718 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8719 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8720 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8721 | vixl32::Register second_low = LowRegisterFrom(second); |
| 8722 | vixl32::Register second_high = HighRegisterFrom(second); |
| 8723 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8724 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8725 | if (instruction->IsAnd()) { |
| 8726 | __ And(out_low, first_low, second_low); |
| 8727 | __ And(out_high, first_high, second_high); |
| 8728 | } else if (instruction->IsOr()) { |
| 8729 | __ Orr(out_low, first_low, second_low); |
| 8730 | __ Orr(out_high, first_high, second_high); |
| 8731 | } else { |
| 8732 | DCHECK(instruction->IsXor()); |
| 8733 | __ Eor(out_low, first_low, second_low); |
| 8734 | __ Eor(out_high, first_high, second_high); |
| 8735 | } |
| 8736 | } |
| 8737 | } |
| 8738 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8739 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadOneRegister( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8740 | HInstruction* instruction, |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8741 | Location out, |
| 8742 | uint32_t offset, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8743 | Location maybe_temp, |
| 8744 | ReadBarrierOption read_barrier_option) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8745 | vixl32::Register out_reg = RegisterFrom(out); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8746 | if (read_barrier_option == kWithReadBarrier) { |
| 8747 | CHECK(kEmitCompilerReadBarrier); |
| 8748 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 8749 | if (kUseBakerReadBarrier) { |
| 8750 | // Load with fast path based Baker's read barrier. |
| 8751 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8752 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 8753 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
| 8754 | } else { |
| 8755 | // Load with slow path based read barrier. |
| 8756 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 8757 | // in the following move operation, as we will need it for the |
| 8758 | // read barrier below. |
| 8759 | __ Mov(RegisterFrom(maybe_temp), out_reg); |
| 8760 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8761 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 8762 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 8763 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8764 | } else { |
| 8765 | // Plain load with no read barrier. |
| 8766 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8767 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 8768 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 8769 | } |
| 8770 | } |
| 8771 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8772 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadTwoRegisters( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8773 | HInstruction* instruction, |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8774 | Location out, |
| 8775 | Location obj, |
| 8776 | uint32_t offset, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8777 | Location maybe_temp, |
| 8778 | ReadBarrierOption read_barrier_option) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8779 | vixl32::Register out_reg = RegisterFrom(out); |
| 8780 | vixl32::Register obj_reg = RegisterFrom(obj); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8781 | if (read_barrier_option == kWithReadBarrier) { |
| 8782 | CHECK(kEmitCompilerReadBarrier); |
| 8783 | if (kUseBakerReadBarrier) { |
| 8784 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 8785 | // Load with fast path based Baker's read barrier. |
| 8786 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8787 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 8788 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
| 8789 | } else { |
| 8790 | // Load with slow path based read barrier. |
| 8791 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8792 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8793 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 8794 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8795 | } else { |
| 8796 | // Plain load with no read barrier. |
| 8797 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8798 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8799 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 8800 | } |
| 8801 | } |
| 8802 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 8803 | void CodeGeneratorARMVIXL::GenerateGcRootFieldLoad( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8804 | HInstruction* instruction, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8805 | Location root, |
| 8806 | vixl32::Register obj, |
| 8807 | uint32_t offset, |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8808 | ReadBarrierOption read_barrier_option) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8809 | vixl32::Register root_reg = RegisterFrom(root); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8810 | if (read_barrier_option == kWithReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8811 | DCHECK(kEmitCompilerReadBarrier); |
| 8812 | if (kUseBakerReadBarrier) { |
| 8813 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8814 | // Baker's read barrier are used. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8815 | if (kBakerReadBarrierLinkTimeThunksEnableForGcRoots && |
| 8816 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8817 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 8818 | // the Marking Register) to decide whether we need to enter |
| 8819 | // the slow path to mark the GC root. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8820 | // |
| 8821 | // We use link-time generated thunks for the slow path. That thunk |
| 8822 | // checks the reference and jumps to the entrypoint if needed. |
| 8823 | // |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8824 | // lr = &return_address; |
| 8825 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8826 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8827 | // goto gc_root_thunk<root_reg>(lr) |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8828 | // } |
| 8829 | // return_address: |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8830 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8831 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8832 | ExcludeIPAndBakerCcEntrypointRegister(&temps, instruction); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8833 | bool narrow = CanEmitNarrowLdr(root_reg, obj, offset); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 8834 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(root_reg.GetCode(), narrow); |
| 8835 | vixl32::Label* bne_label = NewBakerReadBarrierPatch(custom_data); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8836 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8837 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), 4 * vixl32::kMaxInstructionSizeInBytes); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8838 | vixl32::Label return_address; |
| 8839 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8840 | __ cmp(mr, Operand(0)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8841 | // Currently the offset is always within range. If that changes, |
| 8842 | // we shall have to split the load the same way as for fields. |
| 8843 | DCHECK_LT(offset, kReferenceLoadMinFarOffset); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8844 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8845 | __ ldr(EncodingSize(narrow ? Narrow : Wide), root_reg, MemOperand(obj, offset)); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 8846 | EmitPlaceholderBne(this, bne_label); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8847 | __ Bind(&return_address); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8848 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8849 | narrow ? BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_OFFSET |
| 8850 | : BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8851 | } else { |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8852 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 8853 | // the Marking Register) to decide whether we need to enter |
| 8854 | // the slow path to mark the GC root. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8855 | // |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8856 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8857 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8858 | // // Slow path. |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8859 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8860 | // root = entrypoint(root); // root = ReadBarrier::Mark(root); // Entry point call. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8861 | // } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8862 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8863 | // Slow path marking the GC root `root`. The entrypoint will |
| 8864 | // be loaded by the slow path code. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8865 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 8866 | new (GetScopedAllocator()) ReadBarrierMarkSlowPathARMVIXL(instruction, root); |
| 8867 | AddSlowPath(slow_path); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8868 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8869 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8870 | GetAssembler()->LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8871 | static_assert( |
| 8872 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 8873 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 8874 | "have different sizes."); |
| 8875 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 8876 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 8877 | "have different sizes."); |
| 8878 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8879 | __ CompareAndBranchIfNonZero(mr, slow_path->GetEntryLabel()); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8880 | __ Bind(slow_path->GetExitLabel()); |
| 8881 | } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8882 | } else { |
| 8883 | // GC root loaded through a slow path for read barriers other |
| 8884 | // than Baker's. |
| 8885 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 8886 | __ Add(root_reg, obj, offset); |
| 8887 | // /* mirror::Object* */ root = root->Read() |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 8888 | GenerateReadBarrierForRootSlow(instruction, root, root); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8889 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8890 | } else { |
| 8891 | // Plain GC root load with no read barrier. |
| 8892 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8893 | GetAssembler()->LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8894 | // Note that GC roots are not affected by heap poisoning, thus we |
| 8895 | // do not have to unpoison `root_reg` here. |
| 8896 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 8897 | MaybeGenerateMarkingRegisterCheck(/* code */ 18); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8898 | } |
| 8899 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8900 | void CodeGeneratorARMVIXL::MaybeAddBakerCcEntrypointTempForFields(LocationSummary* locations) { |
| 8901 | DCHECK(kEmitCompilerReadBarrier); |
| 8902 | DCHECK(kUseBakerReadBarrier); |
| 8903 | if (kBakerReadBarrierLinkTimeThunksEnableForFields) { |
| 8904 | if (!Runtime::Current()->UseJitCompilation()) { |
| 8905 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 8906 | } |
| 8907 | } |
| 8908 | } |
| 8909 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8910 | void CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8911 | Location ref, |
| 8912 | vixl32::Register obj, |
| 8913 | uint32_t offset, |
| 8914 | Location temp, |
| 8915 | bool needs_null_check) { |
| 8916 | DCHECK(kEmitCompilerReadBarrier); |
| 8917 | DCHECK(kUseBakerReadBarrier); |
| 8918 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8919 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 8920 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8921 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 8922 | // Marking Register) to decide whether we need to enter the slow |
| 8923 | // path to mark the reference. Then, in the slow path, check the |
| 8924 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 8925 | // decide whether to mark `ref` or not. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8926 | // |
| 8927 | // We use link-time generated thunks for the slow path. That thunk checks |
| 8928 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 8929 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 8930 | // |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8931 | // lr = &gray_return_address; |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 8932 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8933 | // goto field_thunk<holder_reg, base_reg>(lr) |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8934 | // } |
| 8935 | // not_gray_return_address: |
| 8936 | // // Original reference load. If the offset is too large to fit |
| 8937 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8938 | // HeapReference<mirror::Object> reference = *(obj+offset); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8939 | // gray_return_address: |
| 8940 | |
| 8941 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8942 | vixl32::Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8943 | bool narrow = CanEmitNarrowLdr(ref_reg, obj, offset); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8944 | vixl32::Register base = obj; |
| 8945 | if (offset >= kReferenceLoadMinFarOffset) { |
| 8946 | base = RegisterFrom(temp); |
| 8947 | DCHECK(!base.Is(kBakerCcEntrypointRegister)); |
| 8948 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 8949 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 8950 | offset &= (kReferenceLoadMinFarOffset - 1u); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8951 | // Use narrow LDR only for small offsets. Generating narrow encoding LDR for the large |
| 8952 | // offsets with `(offset & (kReferenceLoadMinFarOffset - 1u)) < 32u` would most likely |
| 8953 | // increase the overall code size when taking the generated thunks into account. |
| 8954 | DCHECK(!narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8955 | } |
| 8956 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8957 | ExcludeIPAndBakerCcEntrypointRegister(&temps, instruction); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 8958 | uint32_t custom_data = EncodeBakerReadBarrierFieldData(base.GetCode(), obj.GetCode(), narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8959 | vixl32::Label* bne_label = NewBakerReadBarrierPatch(custom_data); |
| 8960 | |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8961 | { |
| 8962 | vixl::EmissionCheckScope guard( |
| 8963 | GetVIXLAssembler(), |
| 8964 | (kPoisonHeapReferences ? 5u : 4u) * vixl32::kMaxInstructionSizeInBytes); |
| 8965 | vixl32::Label return_address; |
| 8966 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8967 | __ cmp(mr, Operand(0)); |
| 8968 | EmitPlaceholderBne(this, bne_label); |
| 8969 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8970 | __ ldr(EncodingSize(narrow ? Narrow : Wide), ref_reg, MemOperand(base, offset)); |
| 8971 | if (needs_null_check) { |
| 8972 | MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8973 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8974 | // Note: We need a specific width for the unpoisoning NEG. |
| 8975 | if (kPoisonHeapReferences) { |
| 8976 | if (narrow) { |
| 8977 | // The only 16-bit encoding is T1 which sets flags outside IT block (i.e. RSBS, not RSB). |
| 8978 | __ rsbs(EncodingSize(Narrow), ref_reg, ref_reg, Operand(0)); |
| 8979 | } else { |
| 8980 | __ rsb(EncodingSize(Wide), ref_reg, ref_reg, Operand(0)); |
| 8981 | } |
| 8982 | } |
| 8983 | __ Bind(&return_address); |
| 8984 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8985 | narrow ? BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_OFFSET |
| 8986 | : BAKER_MARK_INTROSPECTION_FIELD_LDR_WIDE_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8987 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8988 | MaybeGenerateMarkingRegisterCheck(/* code */ 19, /* temp_loc */ LocationFrom(ip)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8989 | return; |
| 8990 | } |
| 8991 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8992 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 8993 | Location no_index = Location::NoLocation(); |
| 8994 | ScaleFactor no_scale_factor = TIMES_1; |
| 8995 | GenerateReferenceLoadWithBakerReadBarrier( |
| 8996 | 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] | 8997 | } |
| 8998 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8999 | void CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 9000 | Location ref, |
| 9001 | vixl32::Register obj, |
| 9002 | uint32_t data_offset, |
| 9003 | Location index, |
| 9004 | Location temp, |
| 9005 | bool needs_null_check) { |
| 9006 | DCHECK(kEmitCompilerReadBarrier); |
| 9007 | DCHECK(kUseBakerReadBarrier); |
| 9008 | |
| 9009 | static_assert( |
| 9010 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 9011 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9012 | ScaleFactor scale_factor = TIMES_4; |
| 9013 | |
| 9014 | if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 9015 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 9016 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 9017 | // Marking Register) to decide whether we need to enter the slow |
| 9018 | // path to mark the reference. Then, in the slow path, check the |
| 9019 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 9020 | // decide whether to mark `ref` or not. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9021 | // |
| 9022 | // We use link-time generated thunks for the slow path. That thunk checks |
| 9023 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 9024 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 9025 | // |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9026 | // lr = &gray_return_address; |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 9027 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 9028 | // goto array_thunk<base_reg>(lr) |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9029 | // } |
| 9030 | // not_gray_return_address: |
| 9031 | // // Original reference load. If the offset is too large to fit |
| 9032 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 9033 | // HeapReference<mirror::Object> reference = data[index]; |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9034 | // gray_return_address: |
| 9035 | |
| 9036 | DCHECK(index.IsValid()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9037 | vixl32::Register index_reg = RegisterFrom(index, DataType::Type::kInt32); |
| 9038 | vixl32::Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
| 9039 | vixl32::Register data_reg = RegisterFrom(temp, DataType::Type::kInt32); // Raw pointer. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9040 | DCHECK(!data_reg.Is(kBakerCcEntrypointRegister)); |
| 9041 | |
| 9042 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 9043 | ExcludeIPAndBakerCcEntrypointRegister(&temps, instruction); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9044 | uint32_t custom_data = EncodeBakerReadBarrierArrayData(data_reg.GetCode()); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9045 | vixl32::Label* bne_label = NewBakerReadBarrierPatch(custom_data); |
| 9046 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9047 | __ Add(data_reg, obj, Operand(data_offset)); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 9048 | { |
| 9049 | vixl::EmissionCheckScope guard( |
| 9050 | GetVIXLAssembler(), |
| 9051 | (kPoisonHeapReferences ? 5u : 4u) * vixl32::kMaxInstructionSizeInBytes); |
| 9052 | vixl32::Label return_address; |
| 9053 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 9054 | __ cmp(mr, Operand(0)); |
| 9055 | EmitPlaceholderBne(this, bne_label); |
| 9056 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 9057 | __ ldr(ref_reg, MemOperand(data_reg, index_reg, vixl32::LSL, scale_factor)); |
| 9058 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 9059 | // Note: We need a Wide NEG for the unpoisoning. |
| 9060 | if (kPoisonHeapReferences) { |
| 9061 | __ rsb(EncodingSize(Wide), ref_reg, ref_reg, Operand(0)); |
| 9062 | } |
| 9063 | __ Bind(&return_address); |
| 9064 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 9065 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9066 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 9067 | MaybeGenerateMarkingRegisterCheck(/* code */ 20, /* temp_loc */ LocationFrom(ip)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9068 | return; |
| 9069 | } |
| 9070 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9071 | // /* HeapReference<Object> */ ref = |
| 9072 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9073 | GenerateReferenceLoadWithBakerReadBarrier( |
| 9074 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | 6070e88 | 2016-11-03 17:51:58 +0000 | [diff] [blame] | 9075 | } |
| 9076 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9077 | void CodeGeneratorARMVIXL::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 9078 | Location ref, |
| 9079 | vixl32::Register obj, |
| 9080 | uint32_t offset, |
| 9081 | Location index, |
| 9082 | ScaleFactor scale_factor, |
| 9083 | Location temp, |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 9084 | bool needs_null_check) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9085 | DCHECK(kEmitCompilerReadBarrier); |
| 9086 | DCHECK(kUseBakerReadBarrier); |
| 9087 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 9088 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 9089 | // Marking Register) to decide whether we need to enter the slow |
| 9090 | // path to mark the reference. Then, in the slow path, check the |
| 9091 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 9092 | // decide whether to mark `ref` or not. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9093 | // |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 9094 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 9095 | // // Slow path. |
| 9096 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 9097 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 9098 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 9099 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 9100 | // if (is_gray) { |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 9101 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 9102 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 9103 | // } |
| 9104 | // } else { |
| 9105 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 9106 | // } |
| 9107 | |
| 9108 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 9109 | |
| 9110 | // Slow path marking the object `ref` when the GC is marking. The |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 9111 | // entrypoint will be loaded by the slow path code. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 9112 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9113 | new (GetScopedAllocator()) LoadReferenceWithBakerReadBarrierSlowPathARMVIXL( |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 9114 | instruction, ref, obj, offset, index, scale_factor, needs_null_check, temp_reg); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 9115 | AddSlowPath(slow_path); |
| 9116 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 9117 | __ CompareAndBranchIfNonZero(mr, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 9118 | // Fast path: the GC is not marking: just load the reference. |
| 9119 | GenerateRawReferenceLoad(instruction, ref, obj, offset, index, scale_factor, needs_null_check); |
| 9120 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 9121 | MaybeGenerateMarkingRegisterCheck(/* code */ 21); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 9122 | } |
| 9123 | |
| 9124 | void CodeGeneratorARMVIXL::UpdateReferenceFieldWithBakerReadBarrier(HInstruction* instruction, |
| 9125 | Location ref, |
| 9126 | vixl32::Register obj, |
| 9127 | Location field_offset, |
| 9128 | Location temp, |
| 9129 | bool needs_null_check, |
| 9130 | vixl32::Register temp2) { |
| 9131 | DCHECK(kEmitCompilerReadBarrier); |
| 9132 | DCHECK(kUseBakerReadBarrier); |
| 9133 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 9134 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 9135 | // Marking Register) to decide whether we need to enter the slow |
| 9136 | // path to update the reference field within `obj`. Then, in the |
| 9137 | // slow path, check the gray bit in the lock word of the reference's |
| 9138 | // holder (`obj`) to decide whether to mark `ref` and update the |
| 9139 | // field or not. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 9140 | // |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 9141 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 9142 | // // Slow path. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 9143 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 9144 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 9145 | // HeapReference<mirror::Object> ref = *(obj + field_offset); // Reference load. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 9146 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 9147 | // if (is_gray) { |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 9148 | // old_ref = ref; |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 9149 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 9150 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 9151 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 9152 | // } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9153 | // } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9154 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9155 | vixl32::Register temp_reg = RegisterFrom(temp); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9156 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 9157 | // Slow path updating the object reference at address `obj + field_offset` |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 9158 | // when the GC is marking. The entrypoint will be loaded by the slow path code. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9159 | SlowPathCodeARMVIXL* slow_path = |
| 9160 | new (GetScopedAllocator()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL( |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 9161 | instruction, |
| 9162 | ref, |
| 9163 | obj, |
| 9164 | /* offset */ 0u, |
| 9165 | /* index */ field_offset, |
| 9166 | /* scale_factor */ ScaleFactor::TIMES_1, |
| 9167 | needs_null_check, |
| 9168 | temp_reg, |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 9169 | temp2); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9170 | AddSlowPath(slow_path); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9171 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 9172 | __ CompareAndBranchIfNonZero(mr, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 9173 | // Fast path: the GC is not marking: nothing to do (the field is |
| 9174 | // up-to-date, and we don't need to load the reference). |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9175 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 9176 | MaybeGenerateMarkingRegisterCheck(/* code */ 22); |
Roland Levillain | 844e653 | 2016-11-03 16:09:47 +0000 | [diff] [blame] | 9177 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9178 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 9179 | void CodeGeneratorARMVIXL::GenerateRawReferenceLoad(HInstruction* instruction, |
| 9180 | Location ref, |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9181 | vixl32::Register obj, |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 9182 | uint32_t offset, |
| 9183 | Location index, |
| 9184 | ScaleFactor scale_factor, |
| 9185 | bool needs_null_check) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9186 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 9187 | vixl32::Register ref_reg = RegisterFrom(ref, type); |
| 9188 | |
| 9189 | // If needed, vixl::EmissionCheckScope guards are used to ensure |
| 9190 | // that no pools are emitted between the load (macro) instruction |
| 9191 | // and MaybeRecordImplicitNullCheck. |
| 9192 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9193 | if (index.IsValid()) { |
| 9194 | // Load types involving an "index": ArrayGet, |
| 9195 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 9196 | // intrinsics. |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 9197 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9198 | if (index.IsConstant()) { |
| 9199 | size_t computed_offset = |
| 9200 | (Int32ConstantFrom(index) << scale_factor) + offset; |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 9201 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9202 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 9203 | if (needs_null_check) { |
| 9204 | MaybeRecordImplicitNullCheck(instruction); |
| 9205 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9206 | } else { |
| 9207 | // Handle the special case of the |
| 9208 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 9209 | // intrinsics, which use a register pair as index ("long |
| 9210 | // offset"), of which only the low part contains data. |
| 9211 | vixl32::Register index_reg = index.IsRegisterPair() |
| 9212 | ? LowRegisterFrom(index) |
| 9213 | : RegisterFrom(index); |
| 9214 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 9215 | vixl32::Register temp = temps.Acquire(); |
| 9216 | __ Add(temp, obj, Operand(index_reg, ShiftType::LSL, scale_factor)); |
| 9217 | { |
| 9218 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 9219 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, temp, offset); |
| 9220 | if (needs_null_check) { |
| 9221 | MaybeRecordImplicitNullCheck(instruction); |
| 9222 | } |
| 9223 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9224 | } |
| 9225 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 9226 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
| 9227 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9228 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 9229 | if (needs_null_check) { |
| 9230 | MaybeRecordImplicitNullCheck(instruction); |
| 9231 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9232 | } |
| 9233 | |
Roland Levillain | 844e653 | 2016-11-03 16:09:47 +0000 | [diff] [blame] | 9234 | // Object* ref = ref_addr->AsMirrorPtr() |
| 9235 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | 844e653 | 2016-11-03 16:09:47 +0000 | [diff] [blame] | 9236 | } |
| 9237 | |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 9238 | void CodeGeneratorARMVIXL::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 9239 | // The following condition is a compile-time one, so it does not have a run-time cost. |
| 9240 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && kIsDebugBuild) { |
| 9241 | // The following condition is a run-time one; it is executed after the |
| 9242 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 9243 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 9244 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 9245 | vixl32::Register temp = temp_loc.IsValid() ? RegisterFrom(temp_loc) : temps.Acquire(); |
| 9246 | GetAssembler()->GenerateMarkingRegisterCheck(temp, |
| 9247 | kMarkingRegisterCheckBreakCodeBaseCode + code); |
| 9248 | } |
| 9249 | } |
| 9250 | } |
| 9251 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9252 | void CodeGeneratorARMVIXL::GenerateReadBarrierSlow(HInstruction* instruction, |
| 9253 | Location out, |
| 9254 | Location ref, |
| 9255 | Location obj, |
| 9256 | uint32_t offset, |
| 9257 | Location index) { |
| 9258 | DCHECK(kEmitCompilerReadBarrier); |
| 9259 | |
| 9260 | // Insert a slow path based read barrier *after* the reference load. |
| 9261 | // |
| 9262 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 9263 | // reference will be carried out by the runtime within the slow |
| 9264 | // path. |
| 9265 | // |
| 9266 | // Note that `ref` currently does not get unpoisoned (when heap |
| 9267 | // poisoning is enabled), which is alright as the `ref` argument is |
| 9268 | // not used by the artReadBarrierSlow entry point. |
| 9269 | // |
| 9270 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9271 | SlowPathCodeARMVIXL* slow_path = new (GetScopedAllocator()) |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9272 | ReadBarrierForHeapReferenceSlowPathARMVIXL(instruction, out, ref, obj, offset, index); |
| 9273 | AddSlowPath(slow_path); |
| 9274 | |
| 9275 | __ B(slow_path->GetEntryLabel()); |
| 9276 | __ Bind(slow_path->GetExitLabel()); |
| 9277 | } |
| 9278 | |
| 9279 | void CodeGeneratorARMVIXL::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9280 | Location out, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9281 | Location ref, |
| 9282 | Location obj, |
| 9283 | uint32_t offset, |
| 9284 | Location index) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9285 | if (kEmitCompilerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9286 | // Baker's read barriers shall be handled by the fast path |
Roland Levillain | 9983e30 | 2017-07-14 14:34:22 +0100 | [diff] [blame] | 9287 | // (CodeGeneratorARMVIXL::GenerateReferenceLoadWithBakerReadBarrier). |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9288 | DCHECK(!kUseBakerReadBarrier); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9289 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 9290 | // by the runtime within the slow path. |
| 9291 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9292 | } else if (kPoisonHeapReferences) { |
| 9293 | GetAssembler()->UnpoisonHeapReference(RegisterFrom(out)); |
| 9294 | } |
| 9295 | } |
| 9296 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9297 | void CodeGeneratorARMVIXL::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 9298 | Location out, |
| 9299 | Location root) { |
| 9300 | DCHECK(kEmitCompilerReadBarrier); |
| 9301 | |
| 9302 | // Insert a slow path based read barrier *after* the GC root load. |
| 9303 | // |
| 9304 | // Note that GC roots are not affected by heap poisoning, so we do |
| 9305 | // not need to do anything special for this here. |
| 9306 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9307 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathARMVIXL(instruction, out, root); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9308 | AddSlowPath(slow_path); |
| 9309 | |
| 9310 | __ B(slow_path->GetEntryLabel()); |
| 9311 | __ Bind(slow_path->GetExitLabel()); |
| 9312 | } |
| 9313 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9314 | // Check if the desired_dispatch_info is supported. If it is, return it, |
| 9315 | // otherwise return a fall-back info that should be used instead. |
| 9316 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARMVIXL::GetSupportedInvokeStaticOrDirectDispatch( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9317 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 9318 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e807ff7 | 2017-01-23 09:03:12 +0000 | [diff] [blame] | 9319 | return desired_dispatch_info; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9320 | } |
| 9321 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9322 | vixl32::Register CodeGeneratorARMVIXL::GetInvokeStaticOrDirectExtraParameter( |
| 9323 | HInvokeStaticOrDirect* invoke, vixl32::Register temp) { |
| 9324 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 9325 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 9326 | if (!invoke->GetLocations()->Intrinsified()) { |
| 9327 | return RegisterFrom(location); |
| 9328 | } |
| 9329 | // For intrinsics we allow any location, so it may be on the stack. |
| 9330 | if (!location.IsRegister()) { |
| 9331 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, location.GetStackIndex()); |
| 9332 | return temp; |
| 9333 | } |
| 9334 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 9335 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 9336 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 9337 | // simple and more robust approach rather that trying to determine if that's the case. |
| 9338 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Scott Wakeling | d5cd497 | 2017-02-03 11:38:35 +0000 | [diff] [blame] | 9339 | if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(RegisterFrom(location).GetCode())) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9340 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(RegisterFrom(location).GetCode()); |
| 9341 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, stack_offset); |
| 9342 | return temp; |
| 9343 | } |
| 9344 | return RegisterFrom(location); |
| 9345 | } |
| 9346 | |
Vladimir Marko | d254f5c | 2017-06-02 15:18:36 +0000 | [diff] [blame] | 9347 | void CodeGeneratorARMVIXL::GenerateStaticOrDirectCall( |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9348 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9349 | 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] | 9350 | switch (invoke->GetMethodLoadKind()) { |
| 9351 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 9352 | uint32_t offset = |
| 9353 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 9354 | // temp = thread->string_init_entrypoint |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9355 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp), tr, offset); |
| 9356 | break; |
| 9357 | } |
| 9358 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 9359 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 9360 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9361 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 9362 | DCHECK(GetCompilerOptions().IsBootImage()); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9363 | PcRelativePatchInfo* labels = NewBootImageMethodPatch(invoke->GetTargetMethod()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9364 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 9365 | EmitMovwMovtPlaceholder(labels, temp_reg); |
| 9366 | break; |
| 9367 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9368 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 9369 | __ Mov(RegisterFrom(temp), Operand::From(invoke->GetMethodAddress())); |
| 9370 | break; |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 9371 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 9372 | uint32_t boot_image_offset = GetBootImageOffset(invoke); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 9373 | PcRelativePatchInfo* labels = NewBootImageRelRoPatch(boot_image_offset); |
| 9374 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 9375 | EmitMovwMovtPlaceholder(labels, temp_reg); |
| 9376 | GetAssembler()->LoadFromOffset(kLoadWord, temp_reg, temp_reg, /* offset*/ 0); |
| 9377 | break; |
| 9378 | } |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9379 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
| 9380 | PcRelativePatchInfo* labels = NewMethodBssEntryPatch( |
| 9381 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex())); |
| 9382 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 9383 | EmitMovwMovtPlaceholder(labels, temp_reg); |
| 9384 | GetAssembler()->LoadFromOffset(kLoadWord, temp_reg, temp_reg, /* offset*/ 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9385 | break; |
| 9386 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9387 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 9388 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 9389 | return; // No code pointer retrieval; the runtime performs the call directly. |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9390 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9391 | } |
| 9392 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9393 | switch (invoke->GetCodePtrLocation()) { |
| 9394 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9395 | { |
| 9396 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 9397 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9398 | vixl32::k32BitT32InstructionSizeInBytes, |
| 9399 | CodeBufferCheckScope::kMaximumSize); |
| 9400 | __ bl(GetFrameEntryLabel()); |
| 9401 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 9402 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9403 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9404 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 9405 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 9406 | GetAssembler()->LoadFromOffset( |
| 9407 | kLoadWord, |
| 9408 | lr, |
| 9409 | RegisterFrom(callee_method), |
| 9410 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9411 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9412 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9413 | // 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] | 9414 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9415 | vixl32::k16BitT32InstructionSizeInBytes, |
| 9416 | CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9417 | // LR() |
| 9418 | __ blx(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9419 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9420 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9421 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9422 | } |
| 9423 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9424 | DCHECK(!IsLeafMethod()); |
| 9425 | } |
| 9426 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9427 | void CodeGeneratorARMVIXL::GenerateVirtualCall( |
| 9428 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9429 | vixl32::Register temp = RegisterFrom(temp_location); |
| 9430 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 9431 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
| 9432 | |
| 9433 | // Use the calling convention instead of the location of the receiver, as |
| 9434 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 9435 | // slow path, the arguments have been moved to the right place, so here we are |
| 9436 | // guaranteed that the receiver is the first register of the calling convention. |
| 9437 | InvokeDexCallingConventionARMVIXL calling_convention; |
| 9438 | vixl32::Register receiver = calling_convention.GetRegisterAt(0); |
| 9439 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9440 | { |
| 9441 | // Make sure the pc is recorded immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 9442 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9443 | vixl32::kMaxInstructionSizeInBytes, |
| 9444 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9445 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 9446 | __ ldr(temp, MemOperand(receiver, class_offset)); |
| 9447 | MaybeRecordImplicitNullCheck(invoke); |
| 9448 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9449 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 9450 | // emit a read barrier for the previous class reference load. |
| 9451 | // However this is not required in practice, as this is an |
| 9452 | // intermediate/temporary reference and because the current |
| 9453 | // concurrent copying collector keeps the from-space memory |
| 9454 | // intact/accessible until the end of the marking phase (the |
| 9455 | // concurrent copying collector may not in the future). |
| 9456 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 9457 | |
| 9458 | // temp = temp->GetMethodAt(method_offset); |
| 9459 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 9460 | kArmPointerSize).Int32Value(); |
| 9461 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 9462 | // LR = temp->GetEntryPoint(); |
| 9463 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9464 | { |
| 9465 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 9466 | // blx in T32 has only 16bit encoding that's why a stricter check for the scope is used. |
| 9467 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9468 | vixl32::k16BitT32InstructionSizeInBytes, |
| 9469 | CodeBufferCheckScope::kExactSize); |
| 9470 | // LR(); |
| 9471 | __ blx(lr); |
| 9472 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 9473 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9474 | } |
| 9475 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 9476 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageRelRoPatch( |
| 9477 | uint32_t boot_image_offset) { |
| 9478 | return NewPcRelativePatch(/* dex_file */ nullptr, |
| 9479 | boot_image_offset, |
| 9480 | &boot_image_method_patches_); |
| 9481 | } |
| 9482 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9483 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageMethodPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9484 | MethodReference target_method) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9485 | return NewPcRelativePatch( |
| 9486 | target_method.dex_file, target_method.index, &boot_image_method_patches_); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9487 | } |
| 9488 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9489 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewMethodBssEntryPatch( |
| 9490 | MethodReference target_method) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9491 | return NewPcRelativePatch( |
| 9492 | target_method.dex_file, target_method.index, &method_bss_entry_patches_); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9493 | } |
| 9494 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9495 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageTypePatch( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9496 | const DexFile& dex_file, dex::TypeIndex type_index) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9497 | return NewPcRelativePatch(&dex_file, type_index.index_, &boot_image_type_patches_); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9498 | } |
| 9499 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9500 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewTypeBssEntryPatch( |
| 9501 | const DexFile& dex_file, dex::TypeIndex type_index) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9502 | return NewPcRelativePatch(&dex_file, type_index.index_, &type_bss_entry_patches_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9503 | } |
| 9504 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9505 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageStringPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9506 | const DexFile& dex_file, dex::StringIndex string_index) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9507 | return NewPcRelativePatch(&dex_file, string_index.index_, &boot_image_string_patches_); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9508 | } |
| 9509 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 9510 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewStringBssEntryPatch( |
| 9511 | const DexFile& dex_file, dex::StringIndex string_index) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9512 | return NewPcRelativePatch(&dex_file, string_index.index_, &string_bss_entry_patches_); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 9513 | } |
| 9514 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9515 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativePatch( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9516 | const DexFile* dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9517 | patches->emplace_back(dex_file, offset_or_index); |
| 9518 | return &patches->back(); |
| 9519 | } |
| 9520 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9521 | vixl32::Label* CodeGeneratorARMVIXL::NewBakerReadBarrierPatch(uint32_t custom_data) { |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9522 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 9523 | return &baker_read_barrier_patches_.back().label; |
| 9524 | } |
| 9525 | |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9526 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateBootImageAddressLiteral(uint32_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 9527 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9528 | } |
| 9529 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 9530 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitStringLiteral( |
| 9531 | const DexFile& dex_file, |
| 9532 | dex::StringIndex string_index, |
| 9533 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9534 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9535 | return jit_string_patches_.GetOrCreate( |
| 9536 | StringReference(&dex_file, string_index), |
| 9537 | [this]() { |
| 9538 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 9539 | }); |
| 9540 | } |
| 9541 | |
| 9542 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 9543 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 9544 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9545 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9546 | return jit_class_patches_.GetOrCreate( |
| 9547 | TypeReference(&dex_file, type_index), |
| 9548 | [this]() { |
| 9549 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 9550 | }); |
| 9551 | } |
| 9552 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9553 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9554 | inline void CodeGeneratorARMVIXL::EmitPcRelativeLinkerPatches( |
| 9555 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9556 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9557 | for (const PcRelativePatchInfo& info : infos) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9558 | const DexFile* dex_file = info.target_dex_file; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9559 | size_t offset_or_index = info.offset_or_index; |
| 9560 | DCHECK(info.add_pc_label.IsBound()); |
| 9561 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.GetLocation()); |
| 9562 | // Add MOVW patch. |
| 9563 | DCHECK(info.movw_label.IsBound()); |
| 9564 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.GetLocation()); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9565 | linker_patches->push_back(Factory(movw_offset, dex_file, add_pc_offset, offset_or_index)); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9566 | // Add MOVT patch. |
| 9567 | DCHECK(info.movt_label.IsBound()); |
| 9568 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.GetLocation()); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9569 | linker_patches->push_back(Factory(movt_offset, dex_file, add_pc_offset, offset_or_index)); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9570 | } |
| 9571 | } |
| 9572 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 9573 | linker::LinkerPatch DataBimgRelRoPatchAdapter(size_t literal_offset, |
| 9574 | const DexFile* target_dex_file, |
| 9575 | uint32_t pc_insn_offset, |
| 9576 | uint32_t boot_image_offset) { |
| 9577 | DCHECK(target_dex_file == nullptr); // Unused for DataBimgRelRoPatch(), should be null. |
| 9578 | return linker::LinkerPatch::DataBimgRelRoPatch(literal_offset, pc_insn_offset, boot_image_offset); |
| 9579 | } |
| 9580 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9581 | void CodeGeneratorARMVIXL::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9582 | DCHECK(linker_patches->empty()); |
| 9583 | size_t size = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9584 | /* MOVW+MOVT for each entry */ 2u * boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9585 | /* MOVW+MOVT for each entry */ 2u * method_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9586 | /* MOVW+MOVT for each entry */ 2u * boot_image_type_patches_.size() + |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9587 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9588 | /* MOVW+MOVT for each entry */ 2u * boot_image_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 9589 | /* MOVW+MOVT for each entry */ 2u * string_bss_entry_patches_.size() + |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9590 | baker_read_barrier_patches_.size(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9591 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9592 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9593 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9594 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9595 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9596 | boot_image_type_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9597 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9598 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9599 | } else { |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 9600 | EmitPcRelativeLinkerPatches<DataBimgRelRoPatchAdapter>( |
| 9601 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 9602 | DCHECK(boot_image_type_patches_.empty()); |
| 9603 | DCHECK(boot_image_string_patches_.empty()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9604 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9605 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 9606 | method_bss_entry_patches_, linker_patches); |
| 9607 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 9608 | type_bss_entry_patches_, linker_patches); |
| 9609 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 9610 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9611 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9612 | linker_patches->push_back(linker::LinkerPatch::BakerReadBarrierBranchPatch( |
| 9613 | info.label.GetLocation(), info.custom_data)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9614 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9615 | DCHECK_EQ(size, linker_patches->size()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9616 | } |
| 9617 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9618 | bool CodeGeneratorARMVIXL::NeedsThunkCode(const linker::LinkerPatch& patch) const { |
| 9619 | return patch.GetType() == linker::LinkerPatch::Type::kBakerReadBarrierBranch || |
| 9620 | patch.GetType() == linker::LinkerPatch::Type::kCallRelative; |
| 9621 | } |
| 9622 | |
| 9623 | void CodeGeneratorARMVIXL::EmitThunkCode(const linker::LinkerPatch& patch, |
| 9624 | /*out*/ ArenaVector<uint8_t>* code, |
| 9625 | /*out*/ std::string* debug_name) { |
| 9626 | arm::ArmVIXLAssembler assembler(GetGraph()->GetAllocator()); |
| 9627 | switch (patch.GetType()) { |
| 9628 | case linker::LinkerPatch::Type::kCallRelative: |
| 9629 | // The thunk just uses the entry point in the ArtMethod. This works even for calls |
| 9630 | // to the generic JNI and interpreter trampolines. |
| 9631 | assembler.LoadFromOffset( |
| 9632 | arm::kLoadWord, |
| 9633 | vixl32::pc, |
| 9634 | vixl32::r0, |
| 9635 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
| 9636 | assembler.GetVIXLAssembler()->Bkpt(0); |
| 9637 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 9638 | *debug_name = "MethodCallThunk"; |
| 9639 | } |
| 9640 | break; |
| 9641 | case linker::LinkerPatch::Type::kBakerReadBarrierBranch: |
| 9642 | DCHECK_EQ(patch.GetBakerCustomValue2(), 0u); |
| 9643 | CompileBakerReadBarrierThunk(assembler, patch.GetBakerCustomValue1(), debug_name); |
| 9644 | break; |
| 9645 | default: |
| 9646 | LOG(FATAL) << "Unexpected patch type " << patch.GetType(); |
| 9647 | UNREACHABLE(); |
| 9648 | } |
| 9649 | |
| 9650 | // Ensure we emit the literal pool if any. |
| 9651 | assembler.FinalizeCode(); |
| 9652 | code->resize(assembler.CodeSize()); |
| 9653 | MemoryRegion code_region(code->data(), code->size()); |
| 9654 | assembler.FinalizeInstructions(code_region); |
| 9655 | } |
| 9656 | |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9657 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateUint32Literal( |
| 9658 | uint32_t value, |
| 9659 | Uint32ToLiteralMap* map) { |
| 9660 | return map->GetOrCreate( |
| 9661 | value, |
| 9662 | [this, value]() { |
| 9663 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ value); |
| 9664 | }); |
| 9665 | } |
| 9666 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 9667 | void LocationsBuilderARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 9668 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9669 | new (GetGraph()->GetAllocator()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 9670 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 9671 | Location::RequiresRegister()); |
| 9672 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 9673 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 9674 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 9675 | } |
| 9676 | |
| 9677 | void InstructionCodeGeneratorARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 9678 | vixl32::Register res = OutputRegister(instr); |
| 9679 | vixl32::Register accumulator = |
| 9680 | InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 9681 | vixl32::Register mul_left = |
| 9682 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 9683 | vixl32::Register mul_right = |
| 9684 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
| 9685 | |
| 9686 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 9687 | __ Mla(res, mul_left, mul_right, accumulator); |
| 9688 | } else { |
| 9689 | __ Mls(res, mul_left, mul_right, accumulator); |
| 9690 | } |
| 9691 | } |
| 9692 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9693 | void LocationsBuilderARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9694 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9695 | LOG(FATAL) << "Unreachable"; |
| 9696 | } |
| 9697 | |
| 9698 | void InstructionCodeGeneratorARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9699 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9700 | LOG(FATAL) << "Unreachable"; |
| 9701 | } |
| 9702 | |
| 9703 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 9704 | void LocationsBuilderARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9705 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9706 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9707 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9708 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
| 9709 | codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 9710 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 9711 | if (switch_instr->GetStartValue() != 0) { |
| 9712 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 9713 | } |
| 9714 | } |
| 9715 | } |
| 9716 | |
| 9717 | // TODO(VIXL): Investigate and reach the parity with old arm codegen. |
| 9718 | void InstructionCodeGeneratorARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9719 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 9720 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9721 | LocationSummary* locations = switch_instr->GetLocations(); |
| 9722 | vixl32::Register value_reg = InputRegisterAt(switch_instr, 0); |
| 9723 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 9724 | |
| 9725 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
| 9726 | !codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 9727 | // Create a series of compare/jumps. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9728 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9729 | vixl32::Register temp_reg = temps.Acquire(); |
| 9730 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 9731 | // the immediate, because IP is used as the destination register. For the other |
| 9732 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 9733 | // and they can be encoded in the instruction without making use of IP register. |
| 9734 | __ Adds(temp_reg, value_reg, -lower_bound); |
| 9735 | |
| 9736 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 9737 | // Jump to successors[0] if value == lower_bound. |
| 9738 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 9739 | int32_t last_index = 0; |
| 9740 | for (; num_entries - last_index > 2; last_index += 2) { |
| 9741 | __ Adds(temp_reg, temp_reg, -2); |
| 9742 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 9743 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9744 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 9745 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 9746 | } |
| 9747 | if (num_entries - last_index == 2) { |
| 9748 | // The last missing case_value. |
| 9749 | __ Cmp(temp_reg, 1); |
| 9750 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9751 | } |
| 9752 | |
| 9753 | // And the default for any other value. |
| 9754 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 9755 | __ B(codegen_->GetLabelOf(default_block)); |
| 9756 | } |
| 9757 | } else { |
| 9758 | // Create a table lookup. |
| 9759 | vixl32::Register table_base = RegisterFrom(locations->GetTemp(0)); |
| 9760 | |
| 9761 | JumpTableARMVIXL* jump_table = codegen_->CreateJumpTable(switch_instr); |
| 9762 | |
| 9763 | // Remove the bias. |
| 9764 | vixl32::Register key_reg; |
| 9765 | if (lower_bound != 0) { |
| 9766 | key_reg = RegisterFrom(locations->GetTemp(1)); |
| 9767 | __ Sub(key_reg, value_reg, lower_bound); |
| 9768 | } else { |
| 9769 | key_reg = value_reg; |
| 9770 | } |
| 9771 | |
| 9772 | // Check whether the value is in the table, jump to default block if not. |
| 9773 | __ Cmp(key_reg, num_entries - 1); |
| 9774 | __ B(hi, codegen_->GetLabelOf(default_block)); |
| 9775 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9776 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9777 | vixl32::Register jump_offset = temps.Acquire(); |
| 9778 | |
| 9779 | // Load jump offset from the table. |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9780 | { |
| 9781 | const size_t jump_size = switch_instr->GetNumEntries() * sizeof(int32_t); |
| 9782 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9783 | (vixl32::kMaxInstructionSizeInBytes * 4) + jump_size, |
| 9784 | CodeBufferCheckScope::kMaximumSize); |
| 9785 | __ adr(table_base, jump_table->GetTableStartLabel()); |
| 9786 | __ ldr(jump_offset, MemOperand(table_base, key_reg, vixl32::LSL, 2)); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9787 | |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9788 | // Jump to target block by branching to table_base(pc related) + offset. |
| 9789 | vixl32::Register target_address = table_base; |
| 9790 | __ add(target_address, table_base, jump_offset); |
| 9791 | __ bx(target_address); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 9792 | |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9793 | jump_table->EmitTable(codegen_); |
| 9794 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9795 | } |
| 9796 | } |
| 9797 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9798 | // Copy the result of a call into the given target. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9799 | void CodeGeneratorARMVIXL::MoveFromReturnRegister(Location trg, DataType::Type type) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9800 | if (!trg.IsValid()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9801 | DCHECK_EQ(type, DataType::Type::kVoid); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9802 | return; |
| 9803 | } |
| 9804 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9805 | DCHECK_NE(type, DataType::Type::kVoid); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9806 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9807 | Location return_loc = InvokeDexCallingConventionVisitorARMVIXL().GetReturnLocation(type); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9808 | if (return_loc.Equals(trg)) { |
| 9809 | return; |
| 9810 | } |
| 9811 | |
| 9812 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 9813 | // with the last branch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9814 | if (type == DataType::Type::kInt64) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9815 | TODO_VIXL32(FATAL); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9816 | } else if (type == DataType::Type::kFloat64) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9817 | TODO_VIXL32(FATAL); |
| 9818 | } else { |
| 9819 | // Let the parallel move resolver take care of all of this. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9820 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9821 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 9822 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 9823 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9824 | } |
| 9825 | |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9826 | void LocationsBuilderARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 9827 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9828 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9829 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9830 | locations->SetOut(Location::RequiresRegister()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9831 | } |
| 9832 | |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9833 | void InstructionCodeGeneratorARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 9834 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| 9835 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 9836 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
| 9837 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9838 | OutputRegister(instruction), |
| 9839 | InputRegisterAt(instruction, 0), |
| 9840 | method_offset); |
| 9841 | } else { |
| 9842 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 9843 | instruction->GetIndex(), kArmPointerSize)); |
| 9844 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9845 | OutputRegister(instruction), |
| 9846 | InputRegisterAt(instruction, 0), |
| 9847 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 9848 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9849 | OutputRegister(instruction), |
| 9850 | OutputRegister(instruction), |
| 9851 | method_offset); |
| 9852 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9853 | } |
| 9854 | |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9855 | static void PatchJitRootUse(uint8_t* code, |
| 9856 | const uint8_t* roots_data, |
| 9857 | VIXLUInt32Literal* literal, |
| 9858 | uint64_t index_in_table) { |
| 9859 | DCHECK(literal->IsBound()); |
| 9860 | uint32_t literal_offset = literal->GetLocation(); |
| 9861 | uintptr_t address = |
| 9862 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 9863 | uint8_t* data = code + literal_offset; |
| 9864 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 9865 | } |
| 9866 | |
| 9867 | void CodeGeneratorARMVIXL::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 9868 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9869 | const StringReference& string_reference = entry.first; |
| 9870 | VIXLUInt32Literal* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9871 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9872 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9873 | } |
| 9874 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9875 | const TypeReference& type_reference = entry.first; |
| 9876 | VIXLUInt32Literal* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9877 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9878 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9879 | } |
| 9880 | } |
| 9881 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9882 | void CodeGeneratorARMVIXL::EmitMovwMovtPlaceholder( |
| 9883 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels, |
| 9884 | vixl32::Register out) { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 9885 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9886 | 3 * vixl32::kMaxInstructionSizeInBytes, |
| 9887 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9888 | // TODO(VIXL): Think about using mov instead of movw. |
| 9889 | __ bind(&labels->movw_label); |
| 9890 | __ movw(out, /* placeholder */ 0u); |
| 9891 | __ bind(&labels->movt_label); |
| 9892 | __ movt(out, /* placeholder */ 0u); |
| 9893 | __ bind(&labels->add_pc_label); |
| 9894 | __ add(out, out, pc); |
| 9895 | } |
| 9896 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9897 | #undef __ |
| 9898 | #undef QUICK_ENTRY_POINT |
| 9899 | #undef TODO_VIXL32 |
| 9900 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9901 | #define __ assembler.GetVIXLAssembler()-> |
| 9902 | |
| 9903 | static void EmitGrayCheckAndFastPath(ArmVIXLAssembler& assembler, |
| 9904 | vixl32::Register base_reg, |
| 9905 | vixl32::MemOperand& lock_word, |
| 9906 | vixl32::Label* slow_path, |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9907 | int32_t raw_ldr_offset, |
| 9908 | vixl32::Label* throw_npe = nullptr) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9909 | // Load the lock word containing the rb_state. |
| 9910 | __ Ldr(ip, lock_word); |
| 9911 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 9912 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 9913 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 9914 | __ Tst(ip, Operand(LockWord::kReadBarrierStateMaskShifted)); |
| 9915 | __ B(ne, slow_path, /* is_far_target */ false); |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9916 | // To throw NPE, we return to the fast path; the artificial dependence below does not matter. |
| 9917 | if (throw_npe != nullptr) { |
| 9918 | __ Bind(throw_npe); |
| 9919 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9920 | __ Add(lr, lr, raw_ldr_offset); |
| 9921 | // Introduce a dependency on the lock_word including rb_state, |
| 9922 | // to prevent load-load reordering, and without using |
| 9923 | // a memory barrier (which would be more expensive). |
| 9924 | __ Add(base_reg, base_reg, Operand(ip, LSR, 32)); |
| 9925 | __ Bx(lr); // And return back to the function. |
| 9926 | // Note: The fake dependency is unnecessary for the slow path. |
| 9927 | } |
| 9928 | |
| 9929 | // Load the read barrier introspection entrypoint in register `entrypoint` |
| 9930 | static void LoadReadBarrierMarkIntrospectionEntrypoint(ArmVIXLAssembler& assembler, |
| 9931 | vixl32::Register entrypoint) { |
| 9932 | // The register where the read barrier introspection entrypoint is loaded |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9933 | // is fixed: `kBakerCcEntrypointRegister` (R4). |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9934 | DCHECK(entrypoint.Is(kBakerCcEntrypointRegister)); |
| 9935 | // entrypoint = Thread::Current()->pReadBarrierMarkReg12, i.e. pReadBarrierMarkIntrospection. |
| 9936 | DCHECK_EQ(ip.GetCode(), 12u); |
| 9937 | const int32_t entry_point_offset = |
| 9938 | Thread::ReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ip.GetCode()); |
| 9939 | __ Ldr(entrypoint, MemOperand(tr, entry_point_offset)); |
| 9940 | } |
| 9941 | |
| 9942 | void CodeGeneratorARMVIXL::CompileBakerReadBarrierThunk(ArmVIXLAssembler& assembler, |
| 9943 | uint32_t encoded_data, |
| 9944 | /*out*/ std::string* debug_name) { |
| 9945 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 9946 | switch (kind) { |
| 9947 | case BakerReadBarrierKind::kField: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9948 | vixl32::Register base_reg(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 9949 | CheckValidReg(base_reg.GetCode()); |
| 9950 | vixl32::Register holder_reg(BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 9951 | CheckValidReg(holder_reg.GetCode()); |
| 9952 | BakerReadBarrierWidth width = BakerReadBarrierWidthField::Decode(encoded_data); |
| 9953 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 9954 | temps.Exclude(ip); |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9955 | // If base_reg differs from holder_reg, the offset was too large and we must have emitted |
| 9956 | // an explicit null check before the load. Otherwise, for implicit null checks, we need to |
| 9957 | // null-check the holder as we do not necessarily do that check before going to the thunk. |
| 9958 | vixl32::Label throw_npe_label; |
| 9959 | vixl32::Label* throw_npe = nullptr; |
| 9960 | if (GetCompilerOptions().GetImplicitNullChecks() && holder_reg.Is(base_reg)) { |
| 9961 | throw_npe = &throw_npe_label; |
| 9962 | __ CompareAndBranchIfZero(holder_reg, throw_npe, /* is_far_target */ false); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9963 | } |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9964 | // Check if the holder is gray and, if not, add fake dependency to the base register |
| 9965 | // and return to the LDR instruction to load the reference. Otherwise, use introspection |
| 9966 | // to load the reference and call the entrypoint that performs further checks on the |
| 9967 | // reference and marks it if needed. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9968 | vixl32::Label slow_path; |
| 9969 | MemOperand lock_word(holder_reg, mirror::Object::MonitorOffset().Int32Value()); |
| 9970 | const int32_t raw_ldr_offset = (width == BakerReadBarrierWidth::kWide) |
| 9971 | ? BAKER_MARK_INTROSPECTION_FIELD_LDR_WIDE_OFFSET |
| 9972 | : BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_OFFSET; |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9973 | EmitGrayCheckAndFastPath( |
| 9974 | assembler, base_reg, lock_word, &slow_path, raw_ldr_offset, throw_npe); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9975 | __ Bind(&slow_path); |
| 9976 | const int32_t ldr_offset = /* Thumb state adjustment (LR contains Thumb state). */ -1 + |
| 9977 | raw_ldr_offset; |
| 9978 | vixl32::Register ep_reg(kBakerCcEntrypointRegister); |
| 9979 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ep_reg); |
| 9980 | if (width == BakerReadBarrierWidth::kWide) { |
| 9981 | MemOperand ldr_half_address(lr, ldr_offset + 2); |
| 9982 | __ Ldrh(ip, ldr_half_address); // Load the LDR immediate half-word with "Rt | imm12". |
| 9983 | __ Ubfx(ip, ip, 0, 12); // Extract the offset imm12. |
| 9984 | __ Ldr(ip, MemOperand(base_reg, ip)); // Load the reference. |
| 9985 | } else { |
| 9986 | MemOperand ldr_address(lr, ldr_offset); |
| 9987 | __ Ldrh(ip, ldr_address); // Load the LDR immediate, encoding T1. |
| 9988 | __ Add(ep_reg, // Adjust the entrypoint address to the entrypoint |
| 9989 | ep_reg, // for narrow LDR. |
| 9990 | Operand(BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_ENTRYPOINT_OFFSET)); |
| 9991 | __ Ubfx(ip, ip, 6, 5); // Extract the imm5, i.e. offset / 4. |
| 9992 | __ Ldr(ip, MemOperand(base_reg, ip, LSL, 2)); // Load the reference. |
| 9993 | } |
| 9994 | // Do not unpoison. With heap poisoning enabled, the entrypoint expects a poisoned reference. |
| 9995 | __ Bx(ep_reg); // Jump to the entrypoint. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9996 | break; |
| 9997 | } |
| 9998 | case BakerReadBarrierKind::kArray: { |
| 9999 | vixl32::Register base_reg(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 10000 | CheckValidReg(base_reg.GetCode()); |
| 10001 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 10002 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 10003 | DCHECK(BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide); |
| 10004 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 10005 | temps.Exclude(ip); |
| 10006 | vixl32::Label slow_path; |
| 10007 | int32_t data_offset = |
| 10008 | mirror::Array::DataOffset(Primitive::ComponentSize(Primitive::kPrimNot)).Int32Value(); |
| 10009 | MemOperand lock_word(base_reg, mirror::Object::MonitorOffset().Int32Value() - data_offset); |
| 10010 | DCHECK_LT(lock_word.GetOffsetImmediate(), 0); |
| 10011 | const int32_t raw_ldr_offset = BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET; |
| 10012 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path, raw_ldr_offset); |
| 10013 | __ Bind(&slow_path); |
| 10014 | const int32_t ldr_offset = /* Thumb state adjustment (LR contains Thumb state). */ -1 + |
| 10015 | raw_ldr_offset; |
| 10016 | MemOperand ldr_address(lr, ldr_offset + 2); |
| 10017 | __ Ldrb(ip, ldr_address); // Load the LDR (register) byte with "00 | imm2 | Rm", |
| 10018 | // i.e. Rm+32 because the scale in imm2 is 2. |
| 10019 | vixl32::Register ep_reg(kBakerCcEntrypointRegister); |
| 10020 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ep_reg); |
| 10021 | __ Bfi(ep_reg, ip, 3, 6); // Insert ip to the entrypoint address to create |
| 10022 | // a switch case target based on the index register. |
| 10023 | __ Mov(ip, base_reg); // Move the base register to ip0. |
| 10024 | __ Bx(ep_reg); // Jump to the entrypoint's array switch case. |
| 10025 | break; |
| 10026 | } |
| 10027 | case BakerReadBarrierKind::kGcRoot: { |
| 10028 | // Check if the reference needs to be marked and if so (i.e. not null, not marked yet |
| 10029 | // and it does not have a forwarding address), call the correct introspection entrypoint; |
| 10030 | // otherwise return the reference (or the extracted forwarding address). |
| 10031 | // There is no gray bit check for GC roots. |
| 10032 | vixl32::Register root_reg(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 10033 | CheckValidReg(root_reg.GetCode()); |
| 10034 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 10035 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 10036 | BakerReadBarrierWidth width = BakerReadBarrierWidthField::Decode(encoded_data); |
| 10037 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 10038 | temps.Exclude(ip); |
| 10039 | vixl32::Label return_label, not_marked, forwarding_address; |
| 10040 | __ CompareAndBranchIfZero(root_reg, &return_label, /* is_far_target */ false); |
| 10041 | MemOperand lock_word(root_reg, mirror::Object::MonitorOffset().Int32Value()); |
| 10042 | __ Ldr(ip, lock_word); |
| 10043 | __ Tst(ip, LockWord::kMarkBitStateMaskShifted); |
| 10044 | __ B(eq, ¬_marked); |
| 10045 | __ Bind(&return_label); |
| 10046 | __ Bx(lr); |
| 10047 | __ Bind(¬_marked); |
| 10048 | static_assert(LockWord::kStateShift == 30 && LockWord::kStateForwardingAddress == 3, |
| 10049 | "To use 'CMP ip, #modified-immediate; BHS', we need the lock word state in " |
| 10050 | " the highest bits and the 'forwarding address' state to have all bits set"); |
| 10051 | __ Cmp(ip, Operand(0xc0000000)); |
| 10052 | __ B(hs, &forwarding_address); |
| 10053 | vixl32::Register ep_reg(kBakerCcEntrypointRegister); |
| 10054 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ep_reg); |
| 10055 | // Adjust the art_quick_read_barrier_mark_introspection address in kBakerCcEntrypointRegister |
| 10056 | // to art_quick_read_barrier_mark_introspection_gc_roots. |
| 10057 | int32_t entrypoint_offset = (width == BakerReadBarrierWidth::kWide) |
| 10058 | ? BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_ENTRYPOINT_OFFSET |
| 10059 | : BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_ENTRYPOINT_OFFSET; |
| 10060 | __ Add(ep_reg, ep_reg, Operand(entrypoint_offset)); |
| 10061 | __ Mov(ip, root_reg); |
| 10062 | __ Bx(ep_reg); |
| 10063 | __ Bind(&forwarding_address); |
| 10064 | __ Lsl(root_reg, ip, LockWord::kForwardingAddressShift); |
| 10065 | __ Bx(lr); |
| 10066 | break; |
| 10067 | } |
| 10068 | default: |
| 10069 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 10070 | UNREACHABLE(); |
| 10071 | } |
| 10072 | |
| 10073 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 10074 | std::ostringstream oss; |
| 10075 | oss << "BakerReadBarrierThunk"; |
| 10076 | switch (kind) { |
| 10077 | case BakerReadBarrierKind::kField: |
| 10078 | oss << "Field"; |
| 10079 | if (BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide) { |
| 10080 | oss << "Wide"; |
| 10081 | } |
| 10082 | oss << "_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 10083 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 10084 | break; |
| 10085 | case BakerReadBarrierKind::kArray: |
| 10086 | oss << "Array_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 10087 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 10088 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 10089 | DCHECK(BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide); |
| 10090 | break; |
| 10091 | case BakerReadBarrierKind::kGcRoot: |
| 10092 | oss << "GcRoot"; |
| 10093 | if (BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide) { |
| 10094 | oss << "Wide"; |
| 10095 | } |
| 10096 | oss << "_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 10097 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 10098 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 10099 | break; |
| 10100 | } |
| 10101 | *debug_name = oss.str(); |
| 10102 | } |
| 10103 | } |
| 10104 | |
| 10105 | #undef __ |
| 10106 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 10107 | } // namespace arm |
| 10108 | } // namespace art |