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" |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 24 | #include "code_generator_utils.h" |
| 25 | #include "common_arm.h" |
| 26 | #include "compiled_method.h" |
| 27 | #include "entrypoints/quick/quick_entrypoints.h" |
| 28 | #include "gc/accounting/card_table.h" |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 29 | #include "intrinsics_arm_vixl.h" |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 30 | #include "linker/arm/relative_patcher_thumb2.h" |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 31 | #include "mirror/array-inl.h" |
| 32 | #include "mirror/class-inl.h" |
| 33 | #include "thread.h" |
| 34 | #include "utils/arm/assembler_arm_vixl.h" |
| 35 | #include "utils/arm/managed_register_arm.h" |
| 36 | #include "utils/assembler.h" |
| 37 | #include "utils/stack_checks.h" |
| 38 | |
| 39 | namespace art { |
| 40 | namespace arm { |
| 41 | |
| 42 | namespace vixl32 = vixl::aarch32; |
| 43 | using namespace vixl32; // NOLINT(build/namespaces) |
| 44 | |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 45 | using helpers::DRegisterFrom; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 46 | using helpers::DWARFReg; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 47 | using helpers::HighDRegisterFrom; |
| 48 | using helpers::HighRegisterFrom; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 49 | using helpers::InputDRegisterAt; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 50 | using helpers::InputOperandAt; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 51 | using helpers::InputRegister; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 52 | using helpers::InputRegisterAt; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 53 | using helpers::InputSRegisterAt; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 54 | using helpers::InputVRegister; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 55 | using helpers::InputVRegisterAt; |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 56 | using helpers::Int32ConstantFrom; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 57 | using helpers::Int64ConstantFrom; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 58 | using helpers::LocationFrom; |
| 59 | using helpers::LowRegisterFrom; |
| 60 | using helpers::LowSRegisterFrom; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 61 | using helpers::OperandFrom; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 62 | using helpers::OutputRegister; |
| 63 | using helpers::OutputSRegister; |
| 64 | using helpers::OutputVRegister; |
| 65 | using helpers::RegisterFrom; |
| 66 | using helpers::SRegisterFrom; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 67 | using helpers::Uint64ConstantFrom; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 68 | |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 69 | using vixl::ExactAssemblyScope; |
| 70 | using vixl::CodeBufferCheckScope; |
| 71 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 72 | using RegisterList = vixl32::RegisterList; |
| 73 | |
| 74 | static bool ExpectedPairLayout(Location location) { |
| 75 | // We expected this for both core and fpu register pairs. |
| 76 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 77 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 78 | // Use a local definition to prevent copying mistakes. |
| 79 | static constexpr size_t kArmWordSize = static_cast<size_t>(kArmPointerSize); |
| 80 | static constexpr size_t kArmBitsPerWord = kArmWordSize * kBitsPerByte; |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 81 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 82 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 83 | // Reference load (except object array loads) is using LDR Rt, [Rn, #offset] which can handle |
| 84 | // offset < 4KiB. For offsets >= 4KiB, the load shall be emitted as two or more instructions. |
| 85 | // For the Baker read barrier implementation using link-generated thunks we need to split |
| 86 | // the offset explicitly. |
| 87 | constexpr uint32_t kReferenceLoadMinFarOffset = 4 * KB; |
| 88 | |
| 89 | // Flags controlling the use of link-time generated thunks for Baker read barriers. |
| 90 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForFields = true; |
| 91 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForArrays = true; |
| 92 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForGcRoots = true; |
| 93 | |
| 94 | // The reserved entrypoint register for link-time generated thunks. |
| 95 | const vixl32::Register kBakerCcEntrypointRegister = r4; |
| 96 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 97 | #ifdef __ |
| 98 | #error "ARM Codegen VIXL macro-assembler macro already defined." |
| 99 | #endif |
| 100 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 101 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 102 | #define __ down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()-> // NOLINT |
| 103 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, x).Int32Value() |
| 104 | |
| 105 | // Marker that code is yet to be, and must, be implemented. |
| 106 | #define TODO_VIXL32(level) LOG(level) << __PRETTY_FUNCTION__ << " unimplemented " |
| 107 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 108 | static inline void ExcludeIPAndBakerCcEntrypointRegister(UseScratchRegisterScope* temps, |
| 109 | HInstruction* instruction) { |
| 110 | DCHECK(temps->IsAvailable(ip)); |
| 111 | temps->Exclude(ip); |
| 112 | DCHECK(!temps->IsAvailable(kBakerCcEntrypointRegister)); |
| 113 | DCHECK_EQ(kBakerCcEntrypointRegister.GetCode(), |
| 114 | linker::Thumb2RelativePatcher::kBakerCcEntrypointRegister); |
| 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 | |
| 279 | void SlowPathCodeARMVIXL::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 280 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 281 | size_t orig_offset = stack_offset; |
| 282 | |
| 283 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 284 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 285 | // If the register holds an object, update the stack mask. |
| 286 | if (locations->RegisterContainsObject(i)) { |
| 287 | locations->SetStackBit(stack_offset / kVRegSize); |
| 288 | } |
| 289 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 290 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 291 | saved_core_stack_offsets_[i] = stack_offset; |
| 292 | stack_offset += kArmWordSize; |
| 293 | } |
| 294 | |
| 295 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 296 | arm_codegen->GetAssembler()->StoreRegisterList(core_spills, orig_offset); |
| 297 | |
| 298 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 299 | orig_offset = stack_offset; |
| 300 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 301 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 302 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 303 | stack_offset += kArmWordSize; |
| 304 | } |
| 305 | |
| 306 | stack_offset = orig_offset; |
| 307 | while (fp_spills != 0u) { |
| 308 | uint32_t begin = CTZ(fp_spills); |
| 309 | uint32_t tmp = fp_spills + (1u << begin); |
| 310 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 311 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 312 | stack_offset = SaveContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 313 | } |
| 314 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 315 | } |
| 316 | |
| 317 | void SlowPathCodeARMVIXL::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 318 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 319 | size_t orig_offset = stack_offset; |
| 320 | |
| 321 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 322 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 323 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 324 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 325 | stack_offset += kArmWordSize; |
| 326 | } |
| 327 | |
| 328 | // TODO(VIXL): Check the coherency of stack_offset after this with a test. |
| 329 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 330 | arm_codegen->GetAssembler()->LoadRegisterList(core_spills, orig_offset); |
| 331 | |
| 332 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 333 | while (fp_spills != 0u) { |
| 334 | uint32_t begin = CTZ(fp_spills); |
| 335 | uint32_t tmp = fp_spills + (1u << begin); |
| 336 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 337 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 338 | stack_offset = RestoreContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 339 | } |
| 340 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 341 | } |
| 342 | |
| 343 | class NullCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 344 | public: |
| 345 | explicit NullCheckSlowPathARMVIXL(HNullCheck* instruction) : SlowPathCodeARMVIXL(instruction) {} |
| 346 | |
| 347 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 348 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 349 | __ Bind(GetEntryLabel()); |
| 350 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 351 | // Live registers will be restored in the catch block if caught. |
| 352 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 353 | } |
| 354 | arm_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 355 | instruction_, |
| 356 | instruction_->GetDexPc(), |
| 357 | this); |
| 358 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| 359 | } |
| 360 | |
| 361 | bool IsFatal() const OVERRIDE { return true; } |
| 362 | |
| 363 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARMVIXL"; } |
| 364 | |
| 365 | private: |
| 366 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARMVIXL); |
| 367 | }; |
| 368 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 369 | class DivZeroCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 370 | public: |
| 371 | explicit DivZeroCheckSlowPathARMVIXL(HDivZeroCheck* instruction) |
| 372 | : SlowPathCodeARMVIXL(instruction) {} |
| 373 | |
| 374 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 375 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 376 | __ Bind(GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 377 | arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 378 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| 379 | } |
| 380 | |
| 381 | bool IsFatal() const OVERRIDE { return true; } |
| 382 | |
| 383 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARMVIXL"; } |
| 384 | |
| 385 | private: |
| 386 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARMVIXL); |
| 387 | }; |
| 388 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 389 | class SuspendCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 390 | public: |
| 391 | SuspendCheckSlowPathARMVIXL(HSuspendCheck* instruction, HBasicBlock* successor) |
| 392 | : SlowPathCodeARMVIXL(instruction), successor_(successor) {} |
| 393 | |
| 394 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 395 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 396 | __ Bind(GetEntryLabel()); |
| 397 | arm_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
| 398 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
| 399 | if (successor_ == nullptr) { |
| 400 | __ B(GetReturnLabel()); |
| 401 | } else { |
| 402 | __ B(arm_codegen->GetLabelOf(successor_)); |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | vixl32::Label* GetReturnLabel() { |
| 407 | DCHECK(successor_ == nullptr); |
| 408 | return &return_label_; |
| 409 | } |
| 410 | |
| 411 | HBasicBlock* GetSuccessor() const { |
| 412 | return successor_; |
| 413 | } |
| 414 | |
| 415 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARMVIXL"; } |
| 416 | |
| 417 | private: |
| 418 | // If not null, the block to branch to after the suspend check. |
| 419 | HBasicBlock* const successor_; |
| 420 | |
| 421 | // If `successor_` is null, the label to branch to after the suspend check. |
| 422 | vixl32::Label return_label_; |
| 423 | |
| 424 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARMVIXL); |
| 425 | }; |
| 426 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 427 | class BoundsCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 428 | public: |
| 429 | explicit BoundsCheckSlowPathARMVIXL(HBoundsCheck* instruction) |
| 430 | : SlowPathCodeARMVIXL(instruction) {} |
| 431 | |
| 432 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 433 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 434 | LocationSummary* locations = instruction_->GetLocations(); |
| 435 | |
| 436 | __ Bind(GetEntryLabel()); |
| 437 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 438 | // Live registers will be restored in the catch block if caught. |
| 439 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 440 | } |
| 441 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 442 | // move resolver. |
| 443 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 444 | codegen->EmitParallelMoves( |
| 445 | locations->InAt(0), |
| 446 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 447 | Primitive::kPrimInt, |
| 448 | locations->InAt(1), |
| 449 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 450 | Primitive::kPrimInt); |
| 451 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 452 | ? kQuickThrowStringBounds |
| 453 | : kQuickThrowArrayBounds; |
| 454 | arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
| 455 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
| 456 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| 457 | } |
| 458 | |
| 459 | bool IsFatal() const OVERRIDE { return true; } |
| 460 | |
| 461 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARMVIXL"; } |
| 462 | |
| 463 | private: |
| 464 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARMVIXL); |
| 465 | }; |
| 466 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 467 | class LoadClassSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 468 | public: |
| 469 | LoadClassSlowPathARMVIXL(HLoadClass* cls, HInstruction* at, uint32_t dex_pc, bool do_clinit) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 470 | : SlowPathCodeARMVIXL(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 471 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 472 | } |
| 473 | |
| 474 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 475 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 476 | Location out = locations->Out(); |
| 477 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 478 | |
| 479 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 480 | __ Bind(GetEntryLabel()); |
| 481 | SaveLiveRegisters(codegen, locations); |
| 482 | |
| 483 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 484 | // For HLoadClass/kBssEntry/kSaveEverything, make sure we preserve the address of the entry. |
| 485 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 486 | bool is_load_class_bss_entry = |
| 487 | (cls_ == instruction_) && (cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry); |
| 488 | vixl32::Register entry_address; |
| 489 | if (is_load_class_bss_entry && call_saves_everything_except_r0) { |
| 490 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 491 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
| 492 | // the kSaveEverything call. |
| 493 | bool temp_is_r0 = temp.Is(calling_convention.GetRegisterAt(0)); |
| 494 | entry_address = temp_is_r0 ? RegisterFrom(out) : temp; |
| 495 | DCHECK(!entry_address.Is(calling_convention.GetRegisterAt(0))); |
| 496 | if (temp_is_r0) { |
| 497 | __ Mov(entry_address, temp); |
| 498 | } |
| 499 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 500 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 501 | __ Mov(calling_convention.GetRegisterAt(0), type_index.index_); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 502 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 503 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 504 | arm_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 505 | if (do_clinit_) { |
| 506 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 507 | } else { |
| 508 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 509 | } |
| 510 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 511 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
| 512 | if (is_load_class_bss_entry) { |
| 513 | if (call_saves_everything_except_r0) { |
| 514 | // The class entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 515 | __ Str(r0, MemOperand(entry_address)); |
| 516 | } else { |
| 517 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
| 518 | UseScratchRegisterScope temps( |
| 519 | down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 520 | vixl32::Register temp = temps.Acquire(); |
| 521 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 522 | arm_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index); |
| 523 | arm_codegen->EmitMovwMovtPlaceholder(labels, temp); |
| 524 | __ Str(r0, MemOperand(temp)); |
| 525 | } |
| 526 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 527 | // Move the class to the desired location. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 528 | if (out.IsValid()) { |
| 529 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 530 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
| 531 | } |
| 532 | RestoreLiveRegisters(codegen, locations); |
| 533 | __ B(GetExitLabel()); |
| 534 | } |
| 535 | |
| 536 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARMVIXL"; } |
| 537 | |
| 538 | private: |
| 539 | // The class this slow path will load. |
| 540 | HLoadClass* const cls_; |
| 541 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 542 | // The dex PC of `at_`. |
| 543 | const uint32_t dex_pc_; |
| 544 | |
| 545 | // Whether to initialize the class. |
| 546 | const bool do_clinit_; |
| 547 | |
| 548 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARMVIXL); |
| 549 | }; |
| 550 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 551 | class LoadStringSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 552 | public: |
| 553 | explicit LoadStringSlowPathARMVIXL(HLoadString* instruction) |
| 554 | : SlowPathCodeARMVIXL(instruction) {} |
| 555 | |
| 556 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 557 | DCHECK(instruction_->IsLoadString()); |
| 558 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 559 | LocationSummary* locations = instruction_->GetLocations(); |
| 560 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 561 | HLoadString* load = instruction_->AsLoadString(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 562 | const dex::StringIndex string_index = load->GetStringIndex(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 563 | vixl32::Register out = OutputRegister(load); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 564 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
| 565 | |
| 566 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 567 | __ Bind(GetEntryLabel()); |
| 568 | SaveLiveRegisters(codegen, locations); |
| 569 | |
| 570 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 571 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 572 | // the kSaveEverything call. |
| 573 | vixl32::Register entry_address; |
| 574 | if (call_saves_everything_except_r0) { |
| 575 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 576 | bool temp_is_r0 = (temp.Is(calling_convention.GetRegisterAt(0))); |
| 577 | entry_address = temp_is_r0 ? out : temp; |
| 578 | DCHECK(!entry_address.Is(calling_convention.GetRegisterAt(0))); |
| 579 | if (temp_is_r0) { |
| 580 | __ Mov(entry_address, temp); |
| 581 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 582 | } |
| 583 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 584 | __ Mov(calling_convention.GetRegisterAt(0), string_index.index_); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 585 | arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 586 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 587 | |
| 588 | // Store the resolved String to the .bss entry. |
| 589 | if (call_saves_everything_except_r0) { |
| 590 | // The string entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 591 | __ Str(r0, MemOperand(entry_address)); |
| 592 | } else { |
| 593 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 594 | UseScratchRegisterScope temps( |
| 595 | down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 596 | vixl32::Register temp = temps.Acquire(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 597 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 598 | arm_codegen->NewPcRelativeStringPatch(load->GetDexFile(), string_index); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 599 | arm_codegen->EmitMovwMovtPlaceholder(labels, temp); |
| 600 | __ Str(r0, MemOperand(temp)); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
| 604 | RestoreLiveRegisters(codegen, locations); |
| 605 | |
| 606 | __ B(GetExitLabel()); |
| 607 | } |
| 608 | |
| 609 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARMVIXL"; } |
| 610 | |
| 611 | private: |
| 612 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARMVIXL); |
| 613 | }; |
| 614 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 615 | class TypeCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 616 | public: |
| 617 | TypeCheckSlowPathARMVIXL(HInstruction* instruction, bool is_fatal) |
| 618 | : SlowPathCodeARMVIXL(instruction), is_fatal_(is_fatal) {} |
| 619 | |
| 620 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 621 | LocationSummary* locations = instruction_->GetLocations(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 622 | DCHECK(instruction_->IsCheckCast() |
| 623 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 624 | |
| 625 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 626 | __ Bind(GetEntryLabel()); |
| 627 | |
| 628 | if (!is_fatal_) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 629 | SaveLiveRegisters(codegen, locations); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 633 | // move resolver. |
| 634 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 635 | |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 636 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 637 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 638 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 639 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 640 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 641 | Primitive::kPrimNot); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 642 | if (instruction_->IsInstanceOf()) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 643 | arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
| 644 | instruction_, |
| 645 | instruction_->GetDexPc(), |
| 646 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 647 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 648 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 649 | } else { |
| 650 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 651 | arm_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 652 | instruction_, |
| 653 | instruction_->GetDexPc(), |
| 654 | this); |
| 655 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | if (!is_fatal_) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 659 | RestoreLiveRegisters(codegen, locations); |
| 660 | __ B(GetExitLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 661 | } |
| 662 | } |
| 663 | |
| 664 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARMVIXL"; } |
| 665 | |
| 666 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 667 | |
| 668 | private: |
| 669 | const bool is_fatal_; |
| 670 | |
| 671 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARMVIXL); |
| 672 | }; |
| 673 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 674 | class DeoptimizationSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 675 | public: |
| 676 | explicit DeoptimizationSlowPathARMVIXL(HDeoptimize* instruction) |
| 677 | : SlowPathCodeARMVIXL(instruction) {} |
| 678 | |
| 679 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 680 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 681 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 682 | LocationSummary* locations = instruction_->GetLocations(); |
| 683 | SaveLiveRegisters(codegen, locations); |
| 684 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 685 | __ Mov(calling_convention.GetRegisterAt(0), |
| 686 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
| 687 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 688 | arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 689 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARMVIXL"; } |
| 693 | |
| 694 | private: |
| 695 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARMVIXL); |
| 696 | }; |
| 697 | |
| 698 | class ArraySetSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 699 | public: |
| 700 | explicit ArraySetSlowPathARMVIXL(HInstruction* instruction) : SlowPathCodeARMVIXL(instruction) {} |
| 701 | |
| 702 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 703 | LocationSummary* locations = instruction_->GetLocations(); |
| 704 | __ Bind(GetEntryLabel()); |
| 705 | SaveLiveRegisters(codegen, locations); |
| 706 | |
| 707 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 708 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 709 | parallel_move.AddMove( |
| 710 | locations->InAt(0), |
| 711 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 712 | Primitive::kPrimNot, |
| 713 | nullptr); |
| 714 | parallel_move.AddMove( |
| 715 | locations->InAt(1), |
| 716 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 717 | Primitive::kPrimInt, |
| 718 | nullptr); |
| 719 | parallel_move.AddMove( |
| 720 | locations->InAt(2), |
| 721 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 722 | Primitive::kPrimNot, |
| 723 | nullptr); |
| 724 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 725 | |
| 726 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 727 | arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| 728 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 729 | RestoreLiveRegisters(codegen, locations); |
| 730 | __ B(GetExitLabel()); |
| 731 | } |
| 732 | |
| 733 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARMVIXL"; } |
| 734 | |
| 735 | private: |
| 736 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARMVIXL); |
| 737 | }; |
| 738 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 739 | // Abstract base class for read barrier slow paths marking a reference |
| 740 | // `ref`. |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 741 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 742 | // Argument `entrypoint` must be a register location holding the read |
| 743 | // barrier marking runtime entry point to be invoked. |
| 744 | class ReadBarrierMarkSlowPathBaseARMVIXL : public SlowPathCodeARMVIXL { |
| 745 | protected: |
| 746 | ReadBarrierMarkSlowPathBaseARMVIXL(HInstruction* instruction, Location ref, Location entrypoint) |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 747 | : SlowPathCodeARMVIXL(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 748 | DCHECK(kEmitCompilerReadBarrier); |
| 749 | } |
| 750 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 751 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathBaseARMVIXL"; } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 752 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 753 | // Generate assembly code calling the read barrier marking runtime |
| 754 | // entry point (ReadBarrierMarkRegX). |
| 755 | void GenerateReadBarrierMarkRuntimeCall(CodeGenerator* codegen) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 756 | vixl32::Register ref_reg = RegisterFrom(ref_); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 757 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 758 | // No need to save live registers; it's taken care of by the |
| 759 | // entrypoint. Also, there is no need to update the stack mask, |
| 760 | // as this runtime call will not trigger a garbage collection. |
| 761 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 762 | DCHECK(!ref_reg.Is(sp)); |
| 763 | DCHECK(!ref_reg.Is(lr)); |
| 764 | DCHECK(!ref_reg.Is(pc)); |
| 765 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 766 | // as a temporary, it cannot be the entry point's input/output. |
| 767 | DCHECK(!ref_reg.Is(ip)); |
| 768 | DCHECK(ref_reg.IsRegister()) << ref_reg; |
| 769 | // "Compact" slow path, saving two moves. |
| 770 | // |
| 771 | // Instead of using the standard runtime calling convention (input |
| 772 | // and output in R0): |
| 773 | // |
| 774 | // R0 <- ref |
| 775 | // R0 <- ReadBarrierMark(R0) |
| 776 | // ref <- R0 |
| 777 | // |
| 778 | // we just use rX (the register containing `ref`) as input and output |
| 779 | // of a dedicated entrypoint: |
| 780 | // |
| 781 | // rX <- ReadBarrierMarkRegX(rX) |
| 782 | // |
| 783 | if (entrypoint_.IsValid()) { |
| 784 | arm_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 785 | __ Blx(RegisterFrom(entrypoint_)); |
| 786 | } else { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 787 | // Entrypoint is not already loaded, load from the thread. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 788 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 789 | Thread::ReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg.GetCode()); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 790 | // This runtime call does not require a stack map. |
| 791 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 792 | } |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 793 | } |
| 794 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 795 | // The location (register) of the marked object reference. |
| 796 | const Location ref_; |
| 797 | |
| 798 | // The location of the entrypoint if already loaded. |
| 799 | const Location entrypoint_; |
| 800 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 801 | private: |
| 802 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathBaseARMVIXL); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 803 | }; |
| 804 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 805 | // Slow path marking an object reference `ref` during a read |
| 806 | // barrier. The field `obj.field` in the object `obj` holding this |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 807 | // reference does not get updated by this slow path after marking. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 808 | // |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 809 | // This means that after the execution of this slow path, `ref` will |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 810 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 811 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 812 | // probably still be a from-space reference (unless it gets updated by |
| 813 | // another thread, or if another thread installed another object |
| 814 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 815 | // |
| 816 | // If `entrypoint` is a valid location it is assumed to already be |
| 817 | // holding the entrypoint. The case where the entrypoint is passed in |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 818 | // is when the decision to mark is based on whether the GC is marking. |
| 819 | class ReadBarrierMarkSlowPathARMVIXL : public ReadBarrierMarkSlowPathBaseARMVIXL { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 820 | public: |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 821 | ReadBarrierMarkSlowPathARMVIXL(HInstruction* instruction, |
| 822 | Location ref, |
| 823 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 824 | : ReadBarrierMarkSlowPathBaseARMVIXL(instruction, ref, entrypoint) { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 825 | DCHECK(kEmitCompilerReadBarrier); |
| 826 | } |
| 827 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 828 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARMVIXL"; } |
| 829 | |
| 830 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 831 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 832 | DCHECK(locations->CanCall()); |
| 833 | DCHECK(ref_.IsRegister()) << ref_; |
| 834 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
| 835 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 836 | << "Unexpected instruction in read barrier marking slow path: " |
| 837 | << instruction_->DebugName(); |
| 838 | |
| 839 | __ Bind(GetEntryLabel()); |
| 840 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 841 | __ B(GetExitLabel()); |
| 842 | } |
| 843 | |
| 844 | private: |
| 845 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARMVIXL); |
| 846 | }; |
| 847 | |
| 848 | // Slow path loading `obj`'s lock word, loading a reference from |
| 849 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 850 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 851 | // read barrier). The field `obj.field` in the object `obj` holding |
| 852 | // this reference does not get updated by this slow path after marking |
| 853 | // (see LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL |
| 854 | // below for that). |
| 855 | // |
| 856 | // This means that after the execution of this slow path, `ref` will |
| 857 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 858 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 859 | // probably still be a from-space reference (unless it gets updated by |
| 860 | // another thread, or if another thread installed another object |
| 861 | // reference (different from `ref`) in `obj.field`). |
| 862 | // |
| 863 | // Argument `entrypoint` must be a register location holding the read |
| 864 | // barrier marking runtime entry point to be invoked. |
| 865 | class LoadReferenceWithBakerReadBarrierSlowPathARMVIXL : public ReadBarrierMarkSlowPathBaseARMVIXL { |
| 866 | public: |
| 867 | LoadReferenceWithBakerReadBarrierSlowPathARMVIXL(HInstruction* instruction, |
| 868 | Location ref, |
| 869 | vixl32::Register obj, |
| 870 | uint32_t offset, |
| 871 | Location index, |
| 872 | ScaleFactor scale_factor, |
| 873 | bool needs_null_check, |
| 874 | vixl32::Register temp, |
| 875 | Location entrypoint) |
| 876 | : ReadBarrierMarkSlowPathBaseARMVIXL(instruction, ref, entrypoint), |
| 877 | obj_(obj), |
| 878 | offset_(offset), |
| 879 | index_(index), |
| 880 | scale_factor_(scale_factor), |
| 881 | needs_null_check_(needs_null_check), |
| 882 | temp_(temp) { |
| 883 | DCHECK(kEmitCompilerReadBarrier); |
| 884 | DCHECK(kUseBakerReadBarrier); |
| 885 | } |
| 886 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 887 | const char* GetDescription() const OVERRIDE { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 888 | return "LoadReferenceWithBakerReadBarrierSlowPathARMVIXL"; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 892 | LocationSummary* locations = instruction_->GetLocations(); |
| 893 | vixl32::Register ref_reg = RegisterFrom(ref_); |
| 894 | DCHECK(locations->CanCall()); |
| 895 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg.GetCode())) << ref_reg; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 896 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 897 | instruction_->IsStaticFieldGet() || |
| 898 | instruction_->IsArrayGet() || |
| 899 | instruction_->IsArraySet() || |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 900 | instruction_->IsInstanceOf() || |
| 901 | instruction_->IsCheckCast() || |
| 902 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 903 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 904 | << "Unexpected instruction in read barrier marking slow path: " |
| 905 | << instruction_->DebugName(); |
| 906 | // The read barrier instrumentation of object ArrayGet |
| 907 | // instructions does not support the HIntermediateAddress |
| 908 | // instruction. |
| 909 | DCHECK(!(instruction_->IsArrayGet() && |
| 910 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 911 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 912 | // Temporary register `temp_`, used to store the lock word, must |
| 913 | // not be IP, as we may use it to emit the reference load (in the |
| 914 | // call to GenerateRawReferenceLoad below), and we need the lock |
| 915 | // word to still be in `temp_` after the reference load. |
| 916 | DCHECK(!temp_.Is(ip)); |
| 917 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 918 | __ Bind(GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 919 | |
| 920 | // When using MaybeGenerateReadBarrierSlow, the read barrier call is |
| 921 | // inserted after the original load. However, in fast path based |
| 922 | // Baker's read barriers, we need to perform the load of |
| 923 | // mirror::Object::monitor_ *before* the original reference load. |
| 924 | // This load-load ordering is required by the read barrier. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 925 | // The slow path (for Baker's algorithm) should look like: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 926 | // |
| 927 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 928 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 929 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 930 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 931 | // if (is_gray) { |
| 932 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 933 | // } |
| 934 | // |
| 935 | // Note: the original implementation in ReadBarrier::Barrier is |
| 936 | // slightly more complex as it performs additional checks that we do |
| 937 | // not do here for performance reasons. |
| 938 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 939 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 940 | |
| 941 | // /* int32_t */ monitor = obj->monitor_ |
| 942 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 943 | arm_codegen->GetAssembler()->LoadFromOffset(kLoadWord, temp_, obj_, monitor_offset); |
| 944 | if (needs_null_check_) { |
| 945 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 946 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 947 | // /* LockWord */ lock_word = LockWord(monitor) |
| 948 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 949 | "art::LockWord and int32_t have different sizes."); |
| 950 | |
| 951 | // Introduce a dependency on the lock_word including the rb_state, |
| 952 | // which shall prevent load-load reordering without using |
| 953 | // a memory barrier (which would be more expensive). |
| 954 | // `obj` is unchanged by this operation, but its value now depends |
| 955 | // on `temp`. |
| 956 | __ Add(obj_, obj_, Operand(temp_, ShiftType::LSR, 32)); |
| 957 | |
| 958 | // The actual reference load. |
| 959 | // A possible implicit null check has already been handled above. |
| 960 | arm_codegen->GenerateRawReferenceLoad( |
| 961 | instruction_, ref_, obj_, offset_, index_, scale_factor_, /* needs_null_check */ false); |
| 962 | |
| 963 | // Mark the object `ref` when `obj` is gray. |
| 964 | // |
| 965 | // if (rb_state == ReadBarrier::GrayState()) |
| 966 | // ref = ReadBarrier::Mark(ref); |
| 967 | // |
| 968 | // Given the numeric representation, it's enough to check the low bit of the |
| 969 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 970 | // which can be a 16-bit instruction unlike the TST immediate. |
| 971 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 972 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 973 | __ Lsrs(temp_, temp_, LockWord::kReadBarrierStateShift + 1); |
| 974 | __ B(cc, GetExitLabel()); // Carry flag is the last bit shifted out by LSRS. |
| 975 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 976 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 977 | __ B(GetExitLabel()); |
| 978 | } |
| 979 | |
| 980 | private: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 981 | // The register containing the object holding the marked object reference field. |
| 982 | vixl32::Register obj_; |
| 983 | // The offset, index and scale factor to access the reference in `obj_`. |
| 984 | uint32_t offset_; |
| 985 | Location index_; |
| 986 | ScaleFactor scale_factor_; |
| 987 | // Is a null check required? |
| 988 | bool needs_null_check_; |
| 989 | // A temporary register used to hold the lock word of `obj_`. |
| 990 | vixl32::Register temp_; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 991 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 992 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierSlowPathARMVIXL); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 993 | }; |
| 994 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 995 | // Slow path loading `obj`'s lock word, loading a reference from |
| 996 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 997 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 998 | // read barrier). If needed, this slow path also atomically updates |
| 999 | // the field `obj.field` in the object `obj` holding this reference |
| 1000 | // after marking (contrary to |
| 1001 | // LoadReferenceWithBakerReadBarrierSlowPathARMVIXL above, which never |
| 1002 | // tries to update `obj.field`). |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1003 | // |
| 1004 | // This means that after the execution of this slow path, both `ref` |
| 1005 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 1006 | // hold the same to-space reference (unless another thread installed |
| 1007 | // another object reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 1008 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1009 | // |
| 1010 | // Argument `entrypoint` must be a register location holding the read |
| 1011 | // barrier marking runtime entry point to be invoked. |
| 1012 | class LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL |
| 1013 | : public ReadBarrierMarkSlowPathBaseARMVIXL { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1014 | public: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1015 | LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL(HInstruction* instruction, |
| 1016 | Location ref, |
| 1017 | vixl32::Register obj, |
| 1018 | uint32_t offset, |
| 1019 | Location index, |
| 1020 | ScaleFactor scale_factor, |
| 1021 | bool needs_null_check, |
| 1022 | vixl32::Register temp1, |
| 1023 | vixl32::Register temp2, |
| 1024 | Location entrypoint) |
| 1025 | : ReadBarrierMarkSlowPathBaseARMVIXL(instruction, ref, entrypoint), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1026 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1027 | offset_(offset), |
| 1028 | index_(index), |
| 1029 | scale_factor_(scale_factor), |
| 1030 | needs_null_check_(needs_null_check), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1031 | temp1_(temp1), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1032 | temp2_(temp2) { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1033 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1034 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | const char* GetDescription() const OVERRIDE { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1038 | return "LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL"; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1042 | LocationSummary* locations = instruction_->GetLocations(); |
| 1043 | vixl32::Register ref_reg = RegisterFrom(ref_); |
| 1044 | DCHECK(locations->CanCall()); |
| 1045 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg.GetCode())) << ref_reg; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1046 | DCHECK_NE(ref_.reg(), LocationFrom(temp1_).reg()); |
| 1047 | |
| 1048 | // 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] | 1049 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 1050 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 1051 | << instruction_->DebugName(); |
| 1052 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1053 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1054 | DCHECK_EQ(offset_, 0u); |
| 1055 | DCHECK_EQ(scale_factor_, ScaleFactor::TIMES_1); |
| 1056 | Location field_offset = index_; |
| 1057 | DCHECK(field_offset.IsRegisterPair()) << field_offset; |
| 1058 | |
| 1059 | // Temporary register `temp1_`, used to store the lock word, must |
| 1060 | // not be IP, as we may use it to emit the reference load (in the |
| 1061 | // call to GenerateRawReferenceLoad below), and we need the lock |
| 1062 | // word to still be in `temp1_` after the reference load. |
| 1063 | DCHECK(!temp1_.Is(ip)); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1064 | |
| 1065 | __ Bind(GetEntryLabel()); |
| 1066 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 1067 | // The implementation is similar to LoadReferenceWithBakerReadBarrierSlowPathARMVIXL's: |
| 1068 | // |
| 1069 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 1070 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 1071 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 1072 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 1073 | // if (is_gray) { |
| 1074 | // old_ref = ref; |
| 1075 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 1076 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 1077 | // } |
| 1078 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1079 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 1080 | |
| 1081 | // /* int32_t */ monitor = obj->monitor_ |
| 1082 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 1083 | arm_codegen->GetAssembler()->LoadFromOffset(kLoadWord, temp1_, obj_, monitor_offset); |
| 1084 | if (needs_null_check_) { |
| 1085 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| 1086 | } |
| 1087 | // /* LockWord */ lock_word = LockWord(monitor) |
| 1088 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 1089 | "art::LockWord and int32_t have different sizes."); |
| 1090 | |
| 1091 | // Introduce a dependency on the lock_word including the rb_state, |
| 1092 | // which shall prevent load-load reordering without using |
| 1093 | // a memory barrier (which would be more expensive). |
| 1094 | // `obj` is unchanged by this operation, but its value now depends |
| 1095 | // on `temp`. |
| 1096 | __ Add(obj_, obj_, Operand(temp1_, ShiftType::LSR, 32)); |
| 1097 | |
| 1098 | // The actual reference load. |
| 1099 | // A possible implicit null check has already been handled above. |
| 1100 | arm_codegen->GenerateRawReferenceLoad( |
| 1101 | instruction_, ref_, obj_, offset_, index_, scale_factor_, /* needs_null_check */ false); |
| 1102 | |
| 1103 | // Mark the object `ref` when `obj` is gray. |
| 1104 | // |
| 1105 | // if (rb_state == ReadBarrier::GrayState()) |
| 1106 | // ref = ReadBarrier::Mark(ref); |
| 1107 | // |
| 1108 | // Given the numeric representation, it's enough to check the low bit of the |
| 1109 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 1110 | // which can be a 16-bit instruction unlike the TST immediate. |
| 1111 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 1112 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 1113 | __ Lsrs(temp1_, temp1_, LockWord::kReadBarrierStateShift + 1); |
| 1114 | __ B(cc, GetExitLabel()); // Carry flag is the last bit shifted out by LSRS. |
| 1115 | |
| 1116 | // Save the old value of the reference before marking it. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1117 | // Note that we cannot use IP to save the old reference, as IP is |
| 1118 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 1119 | // need the old reference after the call to that entry point. |
| 1120 | DCHECK(!temp1_.Is(ip)); |
| 1121 | __ Mov(temp1_, ref_reg); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 1122 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1123 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1124 | |
| 1125 | // If the new reference is different from the old reference, |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1126 | // update the field in the holder (`*(obj_ + field_offset)`). |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1127 | // |
| 1128 | // Note that this field could also hold a different object, if |
| 1129 | // another thread had concurrently changed it. In that case, the |
| 1130 | // LDREX/SUBS/ITNE sequence of instructions in the compare-and-set |
| 1131 | // (CAS) operation below would abort the CAS, leaving the field |
| 1132 | // as-is. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1133 | __ Cmp(temp1_, ref_reg); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1134 | __ B(eq, GetExitLabel()); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1135 | |
| 1136 | // Update the the holder's field atomically. This may fail if |
| 1137 | // mutator updates before us, but it's OK. This is achieved |
| 1138 | // using a strong compare-and-set (CAS) operation with relaxed |
| 1139 | // memory synchronization ordering, where the expected value is |
| 1140 | // the old reference and the desired value is the new reference. |
| 1141 | |
| 1142 | UseScratchRegisterScope temps(arm_codegen->GetVIXLAssembler()); |
| 1143 | // Convenience aliases. |
| 1144 | vixl32::Register base = obj_; |
| 1145 | // The UnsafeCASObject intrinsic uses a register pair as field |
| 1146 | // offset ("long offset"), of which only the low part contains |
| 1147 | // data. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1148 | vixl32::Register offset = LowRegisterFrom(field_offset); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1149 | vixl32::Register expected = temp1_; |
| 1150 | vixl32::Register value = ref_reg; |
| 1151 | vixl32::Register tmp_ptr = temps.Acquire(); // Pointer to actual memory. |
| 1152 | vixl32::Register tmp = temp2_; // Value in memory. |
| 1153 | |
| 1154 | __ Add(tmp_ptr, base, offset); |
| 1155 | |
| 1156 | if (kPoisonHeapReferences) { |
| 1157 | arm_codegen->GetAssembler()->PoisonHeapReference(expected); |
| 1158 | if (value.Is(expected)) { |
| 1159 | // Do not poison `value`, as it is the same register as |
| 1160 | // `expected`, which has just been poisoned. |
| 1161 | } else { |
| 1162 | arm_codegen->GetAssembler()->PoisonHeapReference(value); |
| 1163 | } |
| 1164 | } |
| 1165 | |
| 1166 | // do { |
| 1167 | // tmp = [r_ptr] - expected; |
| 1168 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 1169 | |
| 1170 | vixl32::Label loop_head, exit_loop; |
| 1171 | __ Bind(&loop_head); |
| 1172 | |
| 1173 | __ Ldrex(tmp, MemOperand(tmp_ptr)); |
| 1174 | |
| 1175 | __ Subs(tmp, tmp, expected); |
| 1176 | |
| 1177 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 1178 | ExactAssemblyScope aas(arm_codegen->GetVIXLAssembler(), |
| 1179 | 2 * kMaxInstructionSizeInBytes, |
| 1180 | CodeBufferCheckScope::kMaximumSize); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1181 | |
| 1182 | __ it(ne); |
| 1183 | __ clrex(ne); |
| 1184 | } |
| 1185 | |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 1186 | __ B(ne, &exit_loop, /* far_target */ false); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1187 | |
| 1188 | __ Strex(tmp, value, MemOperand(tmp_ptr)); |
| 1189 | __ Cmp(tmp, 1); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 1190 | __ B(eq, &loop_head, /* far_target */ false); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1191 | |
| 1192 | __ Bind(&exit_loop); |
| 1193 | |
| 1194 | if (kPoisonHeapReferences) { |
| 1195 | arm_codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 1196 | if (value.Is(expected)) { |
| 1197 | // Do not unpoison `value`, as it is the same register as |
| 1198 | // `expected`, which has just been unpoisoned. |
| 1199 | } else { |
| 1200 | arm_codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 1201 | } |
| 1202 | } |
| 1203 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1204 | __ B(GetExitLabel()); |
| 1205 | } |
| 1206 | |
| 1207 | private: |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1208 | // The register containing the object holding the marked object reference field. |
| 1209 | const vixl32::Register obj_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1210 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1211 | uint32_t offset_; |
| 1212 | Location index_; |
| 1213 | ScaleFactor scale_factor_; |
| 1214 | // Is a null check required? |
| 1215 | bool needs_null_check_; |
| 1216 | // A temporary register used to hold the lock word of `obj_`; and |
| 1217 | // also to hold the original reference value, when the reference is |
| 1218 | // marked. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1219 | const vixl32::Register temp1_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1220 | // A temporary register used in the implementation of the CAS, to |
| 1221 | // update the object's reference field. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1222 | const vixl32::Register temp2_; |
| 1223 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1224 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1225 | }; |
| 1226 | |
| 1227 | // Slow path generating a read barrier for a heap reference. |
| 1228 | class ReadBarrierForHeapReferenceSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 1229 | public: |
| 1230 | ReadBarrierForHeapReferenceSlowPathARMVIXL(HInstruction* instruction, |
| 1231 | Location out, |
| 1232 | Location ref, |
| 1233 | Location obj, |
| 1234 | uint32_t offset, |
| 1235 | Location index) |
| 1236 | : SlowPathCodeARMVIXL(instruction), |
| 1237 | out_(out), |
| 1238 | ref_(ref), |
| 1239 | obj_(obj), |
| 1240 | offset_(offset), |
| 1241 | index_(index) { |
| 1242 | DCHECK(kEmitCompilerReadBarrier); |
| 1243 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 1244 | // has been overwritten by (or after) the heap object reference load |
| 1245 | // to be instrumented, e.g.: |
| 1246 | // |
| 1247 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
| 1248 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| 1249 | // |
| 1250 | // In that case, we have lost the information about the original |
| 1251 | // object, and the emitted read barrier cannot work properly. |
| 1252 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 1253 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 1254 | } |
| 1255 | |
| 1256 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1257 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 1258 | LocationSummary* locations = instruction_->GetLocations(); |
| 1259 | vixl32::Register reg_out = RegisterFrom(out_); |
| 1260 | DCHECK(locations->CanCall()); |
| 1261 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.GetCode())); |
| 1262 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 1263 | instruction_->IsStaticFieldGet() || |
| 1264 | instruction_->IsArrayGet() || |
| 1265 | instruction_->IsInstanceOf() || |
| 1266 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 1267 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1268 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 1269 | << instruction_->DebugName(); |
| 1270 | // The read barrier instrumentation of object ArrayGet |
| 1271 | // instructions does not support the HIntermediateAddress |
| 1272 | // instruction. |
| 1273 | DCHECK(!(instruction_->IsArrayGet() && |
| 1274 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 1275 | |
| 1276 | __ Bind(GetEntryLabel()); |
| 1277 | SaveLiveRegisters(codegen, locations); |
| 1278 | |
| 1279 | // We may have to change the index's value, but as `index_` is a |
| 1280 | // constant member (like other "inputs" of this slow path), |
| 1281 | // introduce a copy of it, `index`. |
| 1282 | Location index = index_; |
| 1283 | if (index_.IsValid()) { |
| 1284 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 1285 | if (instruction_->IsArrayGet()) { |
| 1286 | // Compute the actual memory offset and store it in `index`. |
| 1287 | vixl32::Register index_reg = RegisterFrom(index_); |
| 1288 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg.GetCode())); |
| 1289 | if (codegen->IsCoreCalleeSaveRegister(index_reg.GetCode())) { |
| 1290 | // We are about to change the value of `index_reg` (see the |
| 1291 | // calls to art::arm::Thumb2Assembler::Lsl and |
| 1292 | // art::arm::Thumb2Assembler::AddConstant below), but it has |
| 1293 | // not been saved by the previous call to |
| 1294 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1295 | // callee-save register -- |
| 1296 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1297 | // callee-save registers, as it has been designed with the |
| 1298 | // assumption that callee-save registers are supposed to be |
| 1299 | // handled by the called function. So, as a callee-save |
| 1300 | // register, `index_reg` _would_ eventually be saved onto |
| 1301 | // the stack, but it would be too late: we would have |
| 1302 | // changed its value earlier. Therefore, we manually save |
| 1303 | // it here into another freely available register, |
| 1304 | // `free_reg`, chosen of course among the caller-save |
| 1305 | // registers (as a callee-save `free_reg` register would |
| 1306 | // exhibit the same problem). |
| 1307 | // |
| 1308 | // Note we could have requested a temporary register from |
| 1309 | // the register allocator instead; but we prefer not to, as |
| 1310 | // this is a slow path, and we know we can find a |
| 1311 | // caller-save register that is available. |
| 1312 | vixl32::Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1313 | __ Mov(free_reg, index_reg); |
| 1314 | index_reg = free_reg; |
| 1315 | index = LocationFrom(index_reg); |
| 1316 | } else { |
| 1317 | // The initial register stored in `index_` has already been |
| 1318 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1319 | // (as it is not a callee-save register), so we can freely |
| 1320 | // use it. |
| 1321 | } |
| 1322 | // Shifting the index value contained in `index_reg` by the scale |
| 1323 | // factor (2) cannot overflow in practice, as the runtime is |
| 1324 | // unable to allocate object arrays with a size larger than |
| 1325 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 1326 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 1327 | static_assert( |
| 1328 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1329 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1330 | __ Add(index_reg, index_reg, offset_); |
| 1331 | } else { |
| 1332 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1333 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1334 | // (as in the case of ArrayGet), as it is actually an offset |
| 1335 | // to an object field within an object. |
| 1336 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| 1337 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1338 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1339 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1340 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 1341 | DCHECK_EQ(offset_, 0U); |
| 1342 | DCHECK(index_.IsRegisterPair()); |
| 1343 | // UnsafeGet's offset location is a register pair, the low |
| 1344 | // part contains the correct offset. |
| 1345 | index = index_.ToLow(); |
| 1346 | } |
| 1347 | } |
| 1348 | |
| 1349 | // We're moving two or three locations to locations that could |
| 1350 | // overlap, so we need a parallel move resolver. |
| 1351 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 1352 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 1353 | parallel_move.AddMove(ref_, |
| 1354 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1355 | Primitive::kPrimNot, |
| 1356 | nullptr); |
| 1357 | parallel_move.AddMove(obj_, |
| 1358 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 1359 | Primitive::kPrimNot, |
| 1360 | nullptr); |
| 1361 | if (index.IsValid()) { |
| 1362 | parallel_move.AddMove(index, |
| 1363 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 1364 | Primitive::kPrimInt, |
| 1365 | nullptr); |
| 1366 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1367 | } else { |
| 1368 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1369 | __ Mov(calling_convention.GetRegisterAt(2), offset_); |
| 1370 | } |
| 1371 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
| 1372 | CheckEntrypointTypes< |
| 1373 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1374 | arm_codegen->Move32(out_, LocationFrom(r0)); |
| 1375 | |
| 1376 | RestoreLiveRegisters(codegen, locations); |
| 1377 | __ B(GetExitLabel()); |
| 1378 | } |
| 1379 | |
| 1380 | const char* GetDescription() const OVERRIDE { |
| 1381 | return "ReadBarrierForHeapReferenceSlowPathARMVIXL"; |
| 1382 | } |
| 1383 | |
| 1384 | private: |
| 1385 | vixl32::Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 1386 | uint32_t ref = RegisterFrom(ref_).GetCode(); |
| 1387 | uint32_t obj = RegisterFrom(obj_).GetCode(); |
| 1388 | for (uint32_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1389 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1390 | return vixl32::Register(i); |
| 1391 | } |
| 1392 | } |
| 1393 | // We shall never fail to find a free caller-save register, as |
| 1394 | // there are more than two core caller-save registers on ARM |
| 1395 | // (meaning it is possible to find one which is different from |
| 1396 | // `ref` and `obj`). |
| 1397 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1398 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 1399 | UNREACHABLE(); |
| 1400 | } |
| 1401 | |
| 1402 | const Location out_; |
| 1403 | const Location ref_; |
| 1404 | const Location obj_; |
| 1405 | const uint32_t offset_; |
| 1406 | // An additional location containing an index to an array. |
| 1407 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1408 | // UnsafeGetObjectVolatile intrinsics. |
| 1409 | const Location index_; |
| 1410 | |
| 1411 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARMVIXL); |
| 1412 | }; |
| 1413 | |
| 1414 | // Slow path generating a read barrier for a GC root. |
| 1415 | class ReadBarrierForRootSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 1416 | public: |
| 1417 | ReadBarrierForRootSlowPathARMVIXL(HInstruction* instruction, Location out, Location root) |
| 1418 | : SlowPathCodeARMVIXL(instruction), out_(out), root_(root) { |
| 1419 | DCHECK(kEmitCompilerReadBarrier); |
| 1420 | } |
| 1421 | |
| 1422 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1423 | LocationSummary* locations = instruction_->GetLocations(); |
| 1424 | vixl32::Register reg_out = RegisterFrom(out_); |
| 1425 | DCHECK(locations->CanCall()); |
| 1426 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.GetCode())); |
| 1427 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1428 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1429 | << instruction_->DebugName(); |
| 1430 | |
| 1431 | __ Bind(GetEntryLabel()); |
| 1432 | SaveLiveRegisters(codegen, locations); |
| 1433 | |
| 1434 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 1435 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 1436 | arm_codegen->Move32(LocationFrom(calling_convention.GetRegisterAt(0)), root_); |
| 1437 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| 1438 | instruction_, |
| 1439 | instruction_->GetDexPc(), |
| 1440 | this); |
| 1441 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1442 | arm_codegen->Move32(out_, LocationFrom(r0)); |
| 1443 | |
| 1444 | RestoreLiveRegisters(codegen, locations); |
| 1445 | __ B(GetExitLabel()); |
| 1446 | } |
| 1447 | |
| 1448 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARMVIXL"; } |
| 1449 | |
| 1450 | private: |
| 1451 | const Location out_; |
| 1452 | const Location root_; |
| 1453 | |
| 1454 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARMVIXL); |
| 1455 | }; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 1456 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1457 | inline vixl32::Condition ARMCondition(IfCondition cond) { |
| 1458 | switch (cond) { |
| 1459 | case kCondEQ: return eq; |
| 1460 | case kCondNE: return ne; |
| 1461 | case kCondLT: return lt; |
| 1462 | case kCondLE: return le; |
| 1463 | case kCondGT: return gt; |
| 1464 | case kCondGE: return ge; |
| 1465 | case kCondB: return lo; |
| 1466 | case kCondBE: return ls; |
| 1467 | case kCondA: return hi; |
| 1468 | case kCondAE: return hs; |
| 1469 | } |
| 1470 | LOG(FATAL) << "Unreachable"; |
| 1471 | UNREACHABLE(); |
| 1472 | } |
| 1473 | |
| 1474 | // Maps signed condition to unsigned condition. |
| 1475 | inline vixl32::Condition ARMUnsignedCondition(IfCondition cond) { |
| 1476 | switch (cond) { |
| 1477 | case kCondEQ: return eq; |
| 1478 | case kCondNE: return ne; |
| 1479 | // Signed to unsigned. |
| 1480 | case kCondLT: return lo; |
| 1481 | case kCondLE: return ls; |
| 1482 | case kCondGT: return hi; |
| 1483 | case kCondGE: return hs; |
| 1484 | // Unsigned remain unchanged. |
| 1485 | case kCondB: return lo; |
| 1486 | case kCondBE: return ls; |
| 1487 | case kCondA: return hi; |
| 1488 | case kCondAE: return hs; |
| 1489 | } |
| 1490 | LOG(FATAL) << "Unreachable"; |
| 1491 | UNREACHABLE(); |
| 1492 | } |
| 1493 | |
| 1494 | inline vixl32::Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 1495 | // The ARM condition codes can express all the necessary branches, see the |
| 1496 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 1497 | // There is no dex instruction or HIR that would need the missing conditions |
| 1498 | // "equal or unordered" or "not equal". |
| 1499 | switch (cond) { |
| 1500 | case kCondEQ: return eq; |
| 1501 | case kCondNE: return ne /* unordered */; |
| 1502 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 1503 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 1504 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 1505 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 1506 | default: |
| 1507 | LOG(FATAL) << "UNREACHABLE"; |
| 1508 | UNREACHABLE(); |
| 1509 | } |
| 1510 | } |
| 1511 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1512 | inline ShiftType ShiftFromOpKind(HDataProcWithShifterOp::OpKind op_kind) { |
| 1513 | switch (op_kind) { |
| 1514 | case HDataProcWithShifterOp::kASR: return ShiftType::ASR; |
| 1515 | case HDataProcWithShifterOp::kLSL: return ShiftType::LSL; |
| 1516 | case HDataProcWithShifterOp::kLSR: return ShiftType::LSR; |
| 1517 | default: |
| 1518 | LOG(FATAL) << "Unexpected op kind " << op_kind; |
| 1519 | UNREACHABLE(); |
| 1520 | } |
| 1521 | } |
| 1522 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1523 | void CodeGeneratorARMVIXL::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 1524 | stream << vixl32::Register(reg); |
| 1525 | } |
| 1526 | |
| 1527 | void CodeGeneratorARMVIXL::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| 1528 | stream << vixl32::SRegister(reg); |
| 1529 | } |
| 1530 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1531 | static uint32_t ComputeSRegisterListMask(const SRegisterList& regs) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1532 | uint32_t mask = 0; |
| 1533 | for (uint32_t i = regs.GetFirstSRegister().GetCode(); |
| 1534 | i <= regs.GetLastSRegister().GetCode(); |
| 1535 | ++i) { |
| 1536 | mask |= (1 << i); |
| 1537 | } |
| 1538 | return mask; |
| 1539 | } |
| 1540 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1541 | // Saves the register in the stack. Returns the size taken on stack. |
| 1542 | size_t CodeGeneratorARMVIXL::SaveCoreRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1543 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1544 | TODO_VIXL32(FATAL); |
| 1545 | return 0; |
| 1546 | } |
| 1547 | |
| 1548 | // Restores the register from the stack. Returns the size taken on stack. |
| 1549 | size_t CodeGeneratorARMVIXL::RestoreCoreRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1550 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1551 | TODO_VIXL32(FATAL); |
| 1552 | return 0; |
| 1553 | } |
| 1554 | |
| 1555 | size_t CodeGeneratorARMVIXL::SaveFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1556 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1557 | TODO_VIXL32(FATAL); |
| 1558 | return 0; |
| 1559 | } |
| 1560 | |
| 1561 | size_t CodeGeneratorARMVIXL::RestoreFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1562 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1563 | TODO_VIXL32(FATAL); |
| 1564 | return 0; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 1565 | } |
| 1566 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1567 | static void GenerateDataProcInstruction(HInstruction::InstructionKind kind, |
| 1568 | vixl32::Register out, |
| 1569 | vixl32::Register first, |
| 1570 | const Operand& second, |
| 1571 | CodeGeneratorARMVIXL* codegen) { |
| 1572 | if (second.IsImmediate() && second.GetImmediate() == 0) { |
| 1573 | const Operand in = kind == HInstruction::kAnd |
| 1574 | ? Operand(0) |
| 1575 | : Operand(first); |
| 1576 | |
| 1577 | __ Mov(out, in); |
| 1578 | } else { |
| 1579 | switch (kind) { |
| 1580 | case HInstruction::kAdd: |
| 1581 | __ Add(out, first, second); |
| 1582 | break; |
| 1583 | case HInstruction::kAnd: |
| 1584 | __ And(out, first, second); |
| 1585 | break; |
| 1586 | case HInstruction::kOr: |
| 1587 | __ Orr(out, first, second); |
| 1588 | break; |
| 1589 | case HInstruction::kSub: |
| 1590 | __ Sub(out, first, second); |
| 1591 | break; |
| 1592 | case HInstruction::kXor: |
| 1593 | __ Eor(out, first, second); |
| 1594 | break; |
| 1595 | default: |
| 1596 | LOG(FATAL) << "Unexpected instruction kind: " << kind; |
| 1597 | UNREACHABLE(); |
| 1598 | } |
| 1599 | } |
| 1600 | } |
| 1601 | |
| 1602 | static void GenerateDataProc(HInstruction::InstructionKind kind, |
| 1603 | const Location& out, |
| 1604 | const Location& first, |
| 1605 | const Operand& second_lo, |
| 1606 | const Operand& second_hi, |
| 1607 | CodeGeneratorARMVIXL* codegen) { |
| 1608 | const vixl32::Register first_hi = HighRegisterFrom(first); |
| 1609 | const vixl32::Register first_lo = LowRegisterFrom(first); |
| 1610 | const vixl32::Register out_hi = HighRegisterFrom(out); |
| 1611 | const vixl32::Register out_lo = LowRegisterFrom(out); |
| 1612 | |
| 1613 | if (kind == HInstruction::kAdd) { |
| 1614 | __ Adds(out_lo, first_lo, second_lo); |
| 1615 | __ Adc(out_hi, first_hi, second_hi); |
| 1616 | } else if (kind == HInstruction::kSub) { |
| 1617 | __ Subs(out_lo, first_lo, second_lo); |
| 1618 | __ Sbc(out_hi, first_hi, second_hi); |
| 1619 | } else { |
| 1620 | GenerateDataProcInstruction(kind, out_lo, first_lo, second_lo, codegen); |
| 1621 | GenerateDataProcInstruction(kind, out_hi, first_hi, second_hi, codegen); |
| 1622 | } |
| 1623 | } |
| 1624 | |
| 1625 | static Operand GetShifterOperand(vixl32::Register rm, ShiftType shift, uint32_t shift_imm) { |
| 1626 | return shift_imm == 0 ? Operand(rm) : Operand(rm, shift, shift_imm); |
| 1627 | } |
| 1628 | |
| 1629 | static void GenerateLongDataProc(HDataProcWithShifterOp* instruction, |
| 1630 | CodeGeneratorARMVIXL* codegen) { |
| 1631 | DCHECK_EQ(instruction->GetType(), Primitive::kPrimLong); |
| 1632 | DCHECK(HDataProcWithShifterOp::IsShiftOp(instruction->GetOpKind())); |
| 1633 | |
| 1634 | const LocationSummary* const locations = instruction->GetLocations(); |
| 1635 | const uint32_t shift_value = instruction->GetShiftAmount(); |
| 1636 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 1637 | const Location first = locations->InAt(0); |
| 1638 | const Location second = locations->InAt(1); |
| 1639 | const Location out = locations->Out(); |
| 1640 | const vixl32::Register first_hi = HighRegisterFrom(first); |
| 1641 | const vixl32::Register first_lo = LowRegisterFrom(first); |
| 1642 | const vixl32::Register out_hi = HighRegisterFrom(out); |
| 1643 | const vixl32::Register out_lo = LowRegisterFrom(out); |
| 1644 | const vixl32::Register second_hi = HighRegisterFrom(second); |
| 1645 | const vixl32::Register second_lo = LowRegisterFrom(second); |
| 1646 | const ShiftType shift = ShiftFromOpKind(instruction->GetOpKind()); |
| 1647 | |
| 1648 | if (shift_value >= 32) { |
| 1649 | if (shift == ShiftType::LSL) { |
| 1650 | GenerateDataProcInstruction(kind, |
| 1651 | out_hi, |
| 1652 | first_hi, |
| 1653 | Operand(second_lo, ShiftType::LSL, shift_value - 32), |
| 1654 | codegen); |
| 1655 | GenerateDataProcInstruction(kind, out_lo, first_lo, 0, codegen); |
| 1656 | } else if (shift == ShiftType::ASR) { |
| 1657 | GenerateDataProc(kind, |
| 1658 | out, |
| 1659 | first, |
| 1660 | GetShifterOperand(second_hi, ShiftType::ASR, shift_value - 32), |
| 1661 | Operand(second_hi, ShiftType::ASR, 31), |
| 1662 | codegen); |
| 1663 | } else { |
| 1664 | DCHECK_EQ(shift, ShiftType::LSR); |
| 1665 | GenerateDataProc(kind, |
| 1666 | out, |
| 1667 | first, |
| 1668 | GetShifterOperand(second_hi, ShiftType::LSR, shift_value - 32), |
| 1669 | 0, |
| 1670 | codegen); |
| 1671 | } |
| 1672 | } else { |
| 1673 | DCHECK_GT(shift_value, 1U); |
| 1674 | DCHECK_LT(shift_value, 32U); |
| 1675 | |
| 1676 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1677 | |
| 1678 | if (shift == ShiftType::LSL) { |
| 1679 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1680 | // Location::kOutputOverlap; not applicable to other cases. |
| 1681 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1682 | GenerateDataProcInstruction(kind, |
| 1683 | out_hi, |
| 1684 | first_hi, |
| 1685 | Operand(second_hi, ShiftType::LSL, shift_value), |
| 1686 | codegen); |
| 1687 | GenerateDataProcInstruction(kind, |
| 1688 | out_hi, |
| 1689 | out_hi, |
| 1690 | Operand(second_lo, ShiftType::LSR, 32 - shift_value), |
| 1691 | codegen); |
| 1692 | GenerateDataProcInstruction(kind, |
| 1693 | out_lo, |
| 1694 | first_lo, |
| 1695 | Operand(second_lo, ShiftType::LSL, shift_value), |
| 1696 | codegen); |
| 1697 | } else { |
| 1698 | const vixl32::Register temp = temps.Acquire(); |
| 1699 | |
| 1700 | __ Lsl(temp, second_hi, shift_value); |
| 1701 | __ Orr(temp, temp, Operand(second_lo, ShiftType::LSR, 32 - shift_value)); |
| 1702 | GenerateDataProc(kind, |
| 1703 | out, |
| 1704 | first, |
| 1705 | Operand(second_lo, ShiftType::LSL, shift_value), |
| 1706 | temp, |
| 1707 | codegen); |
| 1708 | } |
| 1709 | } else { |
| 1710 | DCHECK(shift == ShiftType::ASR || shift == ShiftType::LSR); |
| 1711 | |
| 1712 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1713 | // Location::kOutputOverlap; not applicable to other cases. |
| 1714 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1715 | GenerateDataProcInstruction(kind, |
| 1716 | out_lo, |
| 1717 | first_lo, |
| 1718 | Operand(second_lo, ShiftType::LSR, shift_value), |
| 1719 | codegen); |
| 1720 | GenerateDataProcInstruction(kind, |
| 1721 | out_lo, |
| 1722 | out_lo, |
| 1723 | Operand(second_hi, ShiftType::LSL, 32 - shift_value), |
| 1724 | codegen); |
| 1725 | GenerateDataProcInstruction(kind, |
| 1726 | out_hi, |
| 1727 | first_hi, |
| 1728 | Operand(second_hi, shift, shift_value), |
| 1729 | codegen); |
| 1730 | } else { |
| 1731 | const vixl32::Register temp = temps.Acquire(); |
| 1732 | |
| 1733 | __ Lsr(temp, second_lo, shift_value); |
| 1734 | __ Orr(temp, temp, Operand(second_hi, ShiftType::LSL, 32 - shift_value)); |
| 1735 | GenerateDataProc(kind, |
| 1736 | out, |
| 1737 | first, |
| 1738 | temp, |
| 1739 | Operand(second_hi, shift, shift_value), |
| 1740 | codegen); |
| 1741 | } |
| 1742 | } |
| 1743 | } |
| 1744 | } |
| 1745 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1746 | static void GenerateVcmp(HInstruction* instruction, CodeGeneratorARMVIXL* codegen) { |
| 1747 | const Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1748 | if (rhs_loc.IsConstant()) { |
| 1749 | // 0.0 is the only immediate that can be encoded directly in |
| 1750 | // a VCMP instruction. |
| 1751 | // |
| 1752 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1753 | // specify that in a floating-point comparison, positive zero |
| 1754 | // and negative zero are considered equal, so we can use the |
| 1755 | // literal 0.0 for both cases here. |
| 1756 | // |
| 1757 | // Note however that some methods (Float.equal, Float.compare, |
| 1758 | // Float.compareTo, Double.equal, Double.compare, |
| 1759 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1760 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1761 | // -0.0. So if we ever translate calls to these methods into a |
| 1762 | // HCompare instruction, we must handle the -0.0 case with |
| 1763 | // care here. |
| 1764 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1765 | |
| 1766 | const Primitive::Type type = instruction->InputAt(0)->GetType(); |
| 1767 | |
| 1768 | if (type == Primitive::kPrimFloat) { |
| 1769 | __ Vcmp(F32, InputSRegisterAt(instruction, 0), 0.0); |
| 1770 | } else { |
| 1771 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1772 | __ Vcmp(F64, InputDRegisterAt(instruction, 0), 0.0); |
| 1773 | } |
| 1774 | } else { |
| 1775 | __ Vcmp(InputVRegisterAt(instruction, 0), InputVRegisterAt(instruction, 1)); |
| 1776 | } |
| 1777 | } |
| 1778 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1779 | static int64_t AdjustConstantForCondition(int64_t value, |
| 1780 | IfCondition* condition, |
| 1781 | IfCondition* opposite) { |
| 1782 | if (value == 1) { |
| 1783 | if (*condition == kCondB) { |
| 1784 | value = 0; |
| 1785 | *condition = kCondEQ; |
| 1786 | *opposite = kCondNE; |
| 1787 | } else if (*condition == kCondAE) { |
| 1788 | value = 0; |
| 1789 | *condition = kCondNE; |
| 1790 | *opposite = kCondEQ; |
| 1791 | } |
| 1792 | } else if (value == -1) { |
| 1793 | if (*condition == kCondGT) { |
| 1794 | value = 0; |
| 1795 | *condition = kCondGE; |
| 1796 | *opposite = kCondLT; |
| 1797 | } else if (*condition == kCondLE) { |
| 1798 | value = 0; |
| 1799 | *condition = kCondLT; |
| 1800 | *opposite = kCondGE; |
| 1801 | } |
| 1802 | } |
| 1803 | |
| 1804 | return value; |
| 1805 | } |
| 1806 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1807 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateLongTestConstant( |
| 1808 | HCondition* condition, |
| 1809 | bool invert, |
| 1810 | CodeGeneratorARMVIXL* codegen) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1811 | DCHECK_EQ(condition->GetLeft()->GetType(), Primitive::kPrimLong); |
| 1812 | |
| 1813 | const LocationSummary* const locations = condition->GetLocations(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1814 | IfCondition cond = condition->GetCondition(); |
| 1815 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1816 | |
| 1817 | if (invert) { |
| 1818 | std::swap(cond, opposite); |
| 1819 | } |
| 1820 | |
| 1821 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1822 | const Location left = locations->InAt(0); |
| 1823 | const Location right = locations->InAt(1); |
| 1824 | |
| 1825 | DCHECK(right.IsConstant()); |
| 1826 | |
| 1827 | const vixl32::Register left_high = HighRegisterFrom(left); |
| 1828 | const vixl32::Register left_low = LowRegisterFrom(left); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1829 | int64_t value = AdjustConstantForCondition(Int64ConstantFrom(right), &cond, &opposite); |
| 1830 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1831 | |
| 1832 | // Comparisons against 0 are common enough to deserve special attention. |
| 1833 | if (value == 0) { |
| 1834 | switch (cond) { |
| 1835 | case kCondNE: |
| 1836 | // x > 0 iff x != 0 when the comparison is unsigned. |
| 1837 | case kCondA: |
| 1838 | ret = std::make_pair(ne, eq); |
| 1839 | FALLTHROUGH_INTENDED; |
| 1840 | case kCondEQ: |
| 1841 | // x <= 0 iff x == 0 when the comparison is unsigned. |
| 1842 | case kCondBE: |
| 1843 | __ Orrs(temps.Acquire(), left_low, left_high); |
| 1844 | return ret; |
| 1845 | case kCondLT: |
| 1846 | case kCondGE: |
| 1847 | __ Cmp(left_high, 0); |
| 1848 | return std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
| 1849 | // Trivially true or false. |
| 1850 | case kCondB: |
| 1851 | ret = std::make_pair(ne, eq); |
| 1852 | FALLTHROUGH_INTENDED; |
| 1853 | case kCondAE: |
| 1854 | __ Cmp(left_low, left_low); |
| 1855 | return ret; |
| 1856 | default: |
| 1857 | break; |
| 1858 | } |
| 1859 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1860 | |
| 1861 | switch (cond) { |
| 1862 | case kCondEQ: |
| 1863 | case kCondNE: |
| 1864 | case kCondB: |
| 1865 | case kCondBE: |
| 1866 | case kCondA: |
| 1867 | case kCondAE: { |
| 1868 | __ Cmp(left_high, High32Bits(value)); |
| 1869 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1870 | // We use the scope because of the IT block that follows. |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1871 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1872 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1873 | CodeBufferCheckScope::kExactSize); |
| 1874 | |
| 1875 | __ it(eq); |
| 1876 | __ cmp(eq, left_low, Low32Bits(value)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1877 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1878 | break; |
| 1879 | } |
| 1880 | case kCondLE: |
| 1881 | case kCondGT: |
| 1882 | // Trivially true or false. |
| 1883 | if (value == std::numeric_limits<int64_t>::max()) { |
| 1884 | __ Cmp(left_low, left_low); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1885 | ret = cond == kCondLE ? std::make_pair(eq, ne) : std::make_pair(ne, eq); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1886 | break; |
| 1887 | } |
| 1888 | |
| 1889 | if (cond == kCondLE) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1890 | DCHECK_EQ(opposite, kCondGT); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1891 | cond = kCondLT; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1892 | opposite = kCondGE; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1893 | } else { |
| 1894 | DCHECK_EQ(cond, kCondGT); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1895 | DCHECK_EQ(opposite, kCondLE); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1896 | cond = kCondGE; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1897 | opposite = kCondLT; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | value++; |
| 1901 | FALLTHROUGH_INTENDED; |
| 1902 | case kCondGE: |
| 1903 | case kCondLT: { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1904 | __ Cmp(left_low, Low32Bits(value)); |
| 1905 | __ Sbcs(temps.Acquire(), left_high, High32Bits(value)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1906 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1907 | break; |
| 1908 | } |
| 1909 | default: |
| 1910 | LOG(FATAL) << "Unreachable"; |
| 1911 | UNREACHABLE(); |
| 1912 | } |
| 1913 | |
| 1914 | return ret; |
| 1915 | } |
| 1916 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1917 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateLongTest( |
| 1918 | HCondition* condition, |
| 1919 | bool invert, |
| 1920 | CodeGeneratorARMVIXL* codegen) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1921 | DCHECK_EQ(condition->GetLeft()->GetType(), Primitive::kPrimLong); |
| 1922 | |
| 1923 | const LocationSummary* const locations = condition->GetLocations(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1924 | IfCondition cond = condition->GetCondition(); |
| 1925 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1926 | |
| 1927 | if (invert) { |
| 1928 | std::swap(cond, opposite); |
| 1929 | } |
| 1930 | |
| 1931 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1932 | Location left = locations->InAt(0); |
| 1933 | Location right = locations->InAt(1); |
| 1934 | |
| 1935 | DCHECK(right.IsRegisterPair()); |
| 1936 | |
| 1937 | switch (cond) { |
| 1938 | case kCondEQ: |
| 1939 | case kCondNE: |
| 1940 | case kCondB: |
| 1941 | case kCondBE: |
| 1942 | case kCondA: |
| 1943 | case kCondAE: { |
| 1944 | __ Cmp(HighRegisterFrom(left), HighRegisterFrom(right)); |
| 1945 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1946 | // We use the scope because of the IT block that follows. |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1947 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1948 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1949 | CodeBufferCheckScope::kExactSize); |
| 1950 | |
| 1951 | __ it(eq); |
| 1952 | __ cmp(eq, LowRegisterFrom(left), LowRegisterFrom(right)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1953 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1954 | break; |
| 1955 | } |
| 1956 | case kCondLE: |
| 1957 | case kCondGT: |
| 1958 | if (cond == kCondLE) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1959 | DCHECK_EQ(opposite, kCondGT); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1960 | cond = kCondGE; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1961 | opposite = kCondLT; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1962 | } else { |
| 1963 | DCHECK_EQ(cond, kCondGT); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1964 | DCHECK_EQ(opposite, kCondLE); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1965 | cond = kCondLT; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1966 | opposite = kCondGE; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | std::swap(left, right); |
| 1970 | FALLTHROUGH_INTENDED; |
| 1971 | case kCondGE: |
| 1972 | case kCondLT: { |
| 1973 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1974 | |
| 1975 | __ Cmp(LowRegisterFrom(left), LowRegisterFrom(right)); |
| 1976 | __ Sbcs(temps.Acquire(), HighRegisterFrom(left), HighRegisterFrom(right)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1977 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1978 | break; |
| 1979 | } |
| 1980 | default: |
| 1981 | LOG(FATAL) << "Unreachable"; |
| 1982 | UNREACHABLE(); |
| 1983 | } |
| 1984 | |
| 1985 | return ret; |
| 1986 | } |
| 1987 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1988 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateTest(HCondition* condition, |
| 1989 | bool invert, |
| 1990 | CodeGeneratorARMVIXL* codegen) { |
| 1991 | const Primitive::Type type = condition->GetLeft()->GetType(); |
| 1992 | IfCondition cond = condition->GetCondition(); |
| 1993 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1994 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1995 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1996 | if (invert) { |
| 1997 | std::swap(cond, opposite); |
| 1998 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1999 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2000 | if (type == Primitive::kPrimLong) { |
| 2001 | ret = condition->GetLocations()->InAt(1).IsConstant() |
| 2002 | ? GenerateLongTestConstant(condition, invert, codegen) |
| 2003 | : GenerateLongTest(condition, invert, codegen); |
| 2004 | } else if (Primitive::IsFloatingPointType(type)) { |
| 2005 | GenerateVcmp(condition, codegen); |
| 2006 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 2007 | ret = std::make_pair(ARMFPCondition(cond, condition->IsGtBias()), |
| 2008 | ARMFPCondition(opposite, condition->IsGtBias())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2009 | } else { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2010 | DCHECK(Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) << type; |
| 2011 | __ Cmp(InputRegisterAt(condition, 0), InputOperandAt(condition, 1)); |
| 2012 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | return ret; |
| 2016 | } |
| 2017 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2018 | static bool CanGenerateTest(HCondition* condition, ArmVIXLAssembler* assembler) { |
| 2019 | if (condition->GetLeft()->GetType() == Primitive::kPrimLong) { |
| 2020 | const LocationSummary* const locations = condition->GetLocations(); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2021 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2022 | if (locations->InAt(1).IsConstant()) { |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2023 | IfCondition c = condition->GetCondition(); |
| 2024 | IfCondition opposite = condition->GetOppositeCondition(); |
| 2025 | const int64_t value = |
| 2026 | AdjustConstantForCondition(Int64ConstantFrom(locations->InAt(1)), &c, &opposite); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2027 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2028 | if (c < kCondLT || c > kCondGE) { |
| 2029 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 2030 | // we check that the least significant half of the first input to be compared |
| 2031 | // is in a low register (the other half is read outside an IT block), and |
| 2032 | // the constant fits in an 8-bit unsigned integer, so that a 16-bit CMP |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2033 | // encoding can be used; 0 is always handled, no matter what registers are |
| 2034 | // used by the first input. |
| 2035 | if (value != 0 && |
| 2036 | (!LowRegisterFrom(locations->InAt(0)).IsLow() || !IsUint<8>(Low32Bits(value)))) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2037 | return false; |
| 2038 | } |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2039 | // TODO(VIXL): The rest of the checks are there to keep the backend in sync with |
| 2040 | // the previous one, but are not strictly necessary. |
| 2041 | } else if (c == kCondLE || c == kCondGT) { |
| 2042 | if (value < std::numeric_limits<int64_t>::max() && |
| 2043 | !assembler->ShifterOperandCanHold(SBC, High32Bits(value + 1), kCcSet)) { |
| 2044 | return false; |
| 2045 | } |
| 2046 | } else if (!assembler->ShifterOperandCanHold(SBC, High32Bits(value), kCcSet)) { |
| 2047 | return false; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2048 | } |
| 2049 | } |
| 2050 | } |
| 2051 | |
| 2052 | return true; |
| 2053 | } |
| 2054 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2055 | static void GenerateConditionGeneric(HCondition* cond, CodeGeneratorARMVIXL* codegen) { |
| 2056 | DCHECK(CanGenerateTest(cond, codegen->GetAssembler())); |
| 2057 | |
| 2058 | const vixl32::Register out = OutputRegister(cond); |
| 2059 | const auto condition = GenerateTest(cond, false, codegen); |
| 2060 | |
| 2061 | __ Mov(LeaveFlags, out, 0); |
| 2062 | |
| 2063 | if (out.IsLow()) { |
| 2064 | // We use the scope because of the IT block that follows. |
| 2065 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 2066 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 2067 | CodeBufferCheckScope::kExactSize); |
| 2068 | |
| 2069 | __ it(condition.first); |
| 2070 | __ mov(condition.first, out, 1); |
| 2071 | } else { |
| 2072 | vixl32::Label done_label; |
| 2073 | vixl32::Label* const final_label = codegen->GetFinalLabel(cond, &done_label); |
| 2074 | |
| 2075 | __ B(condition.second, final_label, /* far_target */ false); |
| 2076 | __ Mov(out, 1); |
| 2077 | |
| 2078 | if (done_label.IsReferenced()) { |
| 2079 | __ Bind(&done_label); |
| 2080 | } |
| 2081 | } |
| 2082 | } |
| 2083 | |
| 2084 | static void GenerateEqualLong(HCondition* cond, CodeGeneratorARMVIXL* codegen) { |
| 2085 | DCHECK_EQ(cond->GetLeft()->GetType(), Primitive::kPrimLong); |
| 2086 | |
| 2087 | const LocationSummary* const locations = cond->GetLocations(); |
| 2088 | IfCondition condition = cond->GetCondition(); |
| 2089 | const vixl32::Register out = OutputRegister(cond); |
| 2090 | const Location left = locations->InAt(0); |
| 2091 | const Location right = locations->InAt(1); |
| 2092 | vixl32::Register left_high = HighRegisterFrom(left); |
| 2093 | vixl32::Register left_low = LowRegisterFrom(left); |
| 2094 | vixl32::Register temp; |
| 2095 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 2096 | |
| 2097 | if (right.IsConstant()) { |
| 2098 | IfCondition opposite = cond->GetOppositeCondition(); |
| 2099 | const int64_t value = AdjustConstantForCondition(Int64ConstantFrom(right), |
| 2100 | &condition, |
| 2101 | &opposite); |
| 2102 | Operand right_high = High32Bits(value); |
| 2103 | Operand right_low = Low32Bits(value); |
| 2104 | |
| 2105 | // The output uses Location::kNoOutputOverlap. |
| 2106 | if (out.Is(left_high)) { |
| 2107 | std::swap(left_low, left_high); |
| 2108 | std::swap(right_low, right_high); |
| 2109 | } |
| 2110 | |
| 2111 | __ Sub(out, left_low, right_low); |
| 2112 | temp = temps.Acquire(); |
| 2113 | __ Sub(temp, left_high, right_high); |
| 2114 | } else { |
| 2115 | DCHECK(right.IsRegisterPair()); |
| 2116 | temp = temps.Acquire(); |
| 2117 | __ Sub(temp, left_high, HighRegisterFrom(right)); |
| 2118 | __ Sub(out, left_low, LowRegisterFrom(right)); |
| 2119 | } |
| 2120 | |
| 2121 | // Need to check after calling AdjustConstantForCondition(). |
| 2122 | DCHECK(condition == kCondEQ || condition == kCondNE) << condition; |
| 2123 | |
| 2124 | if (condition == kCondNE && out.IsLow()) { |
| 2125 | __ Orrs(out, out, temp); |
| 2126 | |
| 2127 | // We use the scope because of the IT block that follows. |
| 2128 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 2129 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 2130 | CodeBufferCheckScope::kExactSize); |
| 2131 | |
| 2132 | __ it(ne); |
| 2133 | __ mov(ne, out, 1); |
| 2134 | } else { |
| 2135 | __ Orr(out, out, temp); |
| 2136 | codegen->GenerateConditionWithZero(condition, out, out, temp); |
| 2137 | } |
| 2138 | } |
| 2139 | |
| 2140 | static void GenerateLongComparesAndJumps(HCondition* cond, |
| 2141 | vixl32::Label* true_label, |
| 2142 | vixl32::Label* false_label, |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2143 | CodeGeneratorARMVIXL* codegen, |
| 2144 | bool is_far_target = true) { |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2145 | LocationSummary* locations = cond->GetLocations(); |
| 2146 | Location left = locations->InAt(0); |
| 2147 | Location right = locations->InAt(1); |
| 2148 | IfCondition if_cond = cond->GetCondition(); |
| 2149 | |
| 2150 | vixl32::Register left_high = HighRegisterFrom(left); |
| 2151 | vixl32::Register left_low = LowRegisterFrom(left); |
| 2152 | IfCondition true_high_cond = if_cond; |
| 2153 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
| 2154 | vixl32::Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
| 2155 | |
| 2156 | // Set the conditions for the test, remembering that == needs to be |
| 2157 | // decided using the low words. |
| 2158 | switch (if_cond) { |
| 2159 | case kCondEQ: |
| 2160 | case kCondNE: |
| 2161 | // Nothing to do. |
| 2162 | break; |
| 2163 | case kCondLT: |
| 2164 | false_high_cond = kCondGT; |
| 2165 | break; |
| 2166 | case kCondLE: |
| 2167 | true_high_cond = kCondLT; |
| 2168 | break; |
| 2169 | case kCondGT: |
| 2170 | false_high_cond = kCondLT; |
| 2171 | break; |
| 2172 | case kCondGE: |
| 2173 | true_high_cond = kCondGT; |
| 2174 | break; |
| 2175 | case kCondB: |
| 2176 | false_high_cond = kCondA; |
| 2177 | break; |
| 2178 | case kCondBE: |
| 2179 | true_high_cond = kCondB; |
| 2180 | break; |
| 2181 | case kCondA: |
| 2182 | false_high_cond = kCondB; |
| 2183 | break; |
| 2184 | case kCondAE: |
| 2185 | true_high_cond = kCondA; |
| 2186 | break; |
| 2187 | } |
| 2188 | if (right.IsConstant()) { |
| 2189 | int64_t value = Int64ConstantFrom(right); |
| 2190 | int32_t val_low = Low32Bits(value); |
| 2191 | int32_t val_high = High32Bits(value); |
| 2192 | |
| 2193 | __ Cmp(left_high, val_high); |
| 2194 | if (if_cond == kCondNE) { |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2195 | __ B(ARMCondition(true_high_cond), true_label, is_far_target); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2196 | } else if (if_cond == kCondEQ) { |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2197 | __ B(ARMCondition(false_high_cond), false_label, is_far_target); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2198 | } else { |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2199 | __ B(ARMCondition(true_high_cond), true_label, is_far_target); |
| 2200 | __ B(ARMCondition(false_high_cond), false_label, is_far_target); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2201 | } |
| 2202 | // Must be equal high, so compare the lows. |
| 2203 | __ Cmp(left_low, val_low); |
| 2204 | } else { |
| 2205 | vixl32::Register right_high = HighRegisterFrom(right); |
| 2206 | vixl32::Register right_low = LowRegisterFrom(right); |
| 2207 | |
| 2208 | __ Cmp(left_high, right_high); |
| 2209 | if (if_cond == kCondNE) { |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2210 | __ B(ARMCondition(true_high_cond), true_label, is_far_target); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2211 | } else if (if_cond == kCondEQ) { |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2212 | __ B(ARMCondition(false_high_cond), false_label, is_far_target); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2213 | } else { |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2214 | __ B(ARMCondition(true_high_cond), true_label, is_far_target); |
| 2215 | __ B(ARMCondition(false_high_cond), false_label, is_far_target); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2216 | } |
| 2217 | // Must be equal high, so compare the lows. |
| 2218 | __ Cmp(left_low, right_low); |
| 2219 | } |
| 2220 | // The last comparison might be unsigned. |
| 2221 | // TODO: optimize cases where this is always true/false |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2222 | __ B(final_condition, true_label, is_far_target); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2223 | } |
| 2224 | |
| 2225 | static void GenerateConditionLong(HCondition* cond, CodeGeneratorARMVIXL* codegen) { |
| 2226 | DCHECK_EQ(cond->GetLeft()->GetType(), Primitive::kPrimLong); |
| 2227 | |
| 2228 | const LocationSummary* const locations = cond->GetLocations(); |
| 2229 | IfCondition condition = cond->GetCondition(); |
| 2230 | const vixl32::Register out = OutputRegister(cond); |
| 2231 | const Location left = locations->InAt(0); |
| 2232 | const Location right = locations->InAt(1); |
| 2233 | |
| 2234 | if (right.IsConstant()) { |
| 2235 | IfCondition opposite = cond->GetOppositeCondition(); |
| 2236 | |
| 2237 | // Comparisons against 0 are common enough to deserve special attention. |
| 2238 | if (AdjustConstantForCondition(Int64ConstantFrom(right), &condition, &opposite) == 0) { |
| 2239 | switch (condition) { |
| 2240 | case kCondNE: |
| 2241 | case kCondA: |
| 2242 | if (out.IsLow()) { |
| 2243 | // We only care if both input registers are 0 or not. |
| 2244 | __ Orrs(out, LowRegisterFrom(left), HighRegisterFrom(left)); |
| 2245 | |
| 2246 | // We use the scope because of the IT block that follows. |
| 2247 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 2248 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 2249 | CodeBufferCheckScope::kExactSize); |
| 2250 | |
| 2251 | __ it(ne); |
| 2252 | __ mov(ne, out, 1); |
| 2253 | return; |
| 2254 | } |
| 2255 | |
| 2256 | FALLTHROUGH_INTENDED; |
| 2257 | case kCondEQ: |
| 2258 | case kCondBE: |
| 2259 | // We only care if both input registers are 0 or not. |
| 2260 | __ Orr(out, LowRegisterFrom(left), HighRegisterFrom(left)); |
| 2261 | codegen->GenerateConditionWithZero(condition, out, out); |
| 2262 | return; |
| 2263 | case kCondLT: |
| 2264 | case kCondGE: |
| 2265 | // We only care about the sign bit. |
| 2266 | FALLTHROUGH_INTENDED; |
| 2267 | case kCondAE: |
| 2268 | case kCondB: |
| 2269 | codegen->GenerateConditionWithZero(condition, out, HighRegisterFrom(left)); |
| 2270 | return; |
| 2271 | case kCondLE: |
| 2272 | case kCondGT: |
| 2273 | default: |
| 2274 | break; |
| 2275 | } |
| 2276 | } |
| 2277 | } |
| 2278 | |
| 2279 | if ((condition == kCondEQ || condition == kCondNE) && |
| 2280 | // If `out` is a low register, then the GenerateConditionGeneric() |
| 2281 | // function generates a shorter code sequence that is still branchless. |
| 2282 | (!out.IsLow() || !CanGenerateTest(cond, codegen->GetAssembler()))) { |
| 2283 | GenerateEqualLong(cond, codegen); |
| 2284 | return; |
| 2285 | } |
| 2286 | |
| 2287 | if (CanGenerateTest(cond, codegen->GetAssembler())) { |
| 2288 | GenerateConditionGeneric(cond, codegen); |
| 2289 | return; |
| 2290 | } |
| 2291 | |
| 2292 | // Convert the jumps into the result. |
| 2293 | vixl32::Label done_label; |
| 2294 | vixl32::Label* const final_label = codegen->GetFinalLabel(cond, &done_label); |
| 2295 | vixl32::Label true_label, false_label; |
| 2296 | |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2297 | GenerateLongComparesAndJumps(cond, &true_label, &false_label, codegen, /* is_far_target */ false); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2298 | |
| 2299 | // False case: result = 0. |
| 2300 | __ Bind(&false_label); |
| 2301 | __ Mov(out, 0); |
| 2302 | __ B(final_label); |
| 2303 | |
| 2304 | // True case: result = 1. |
| 2305 | __ Bind(&true_label); |
| 2306 | __ Mov(out, 1); |
| 2307 | |
| 2308 | if (done_label.IsReferenced()) { |
| 2309 | __ Bind(&done_label); |
| 2310 | } |
| 2311 | } |
| 2312 | |
| 2313 | static void GenerateConditionIntegralOrNonPrimitive(HCondition* cond, CodeGeneratorARMVIXL* codegen) { |
| 2314 | const Primitive::Type type = cond->GetLeft()->GetType(); |
| 2315 | |
| 2316 | DCHECK(Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) << type; |
| 2317 | |
| 2318 | if (type == Primitive::kPrimLong) { |
| 2319 | GenerateConditionLong(cond, codegen); |
| 2320 | return; |
| 2321 | } |
| 2322 | |
| 2323 | IfCondition condition = cond->GetCondition(); |
| 2324 | vixl32::Register in = InputRegisterAt(cond, 0); |
| 2325 | const vixl32::Register out = OutputRegister(cond); |
| 2326 | const Location right = cond->GetLocations()->InAt(1); |
| 2327 | int64_t value; |
| 2328 | |
| 2329 | if (right.IsConstant()) { |
| 2330 | IfCondition opposite = cond->GetOppositeCondition(); |
| 2331 | |
| 2332 | value = AdjustConstantForCondition(Int64ConstantFrom(right), &condition, &opposite); |
| 2333 | |
| 2334 | // Comparisons against 0 are common enough to deserve special attention. |
| 2335 | if (value == 0) { |
| 2336 | switch (condition) { |
| 2337 | case kCondNE: |
| 2338 | case kCondA: |
| 2339 | if (out.IsLow() && out.Is(in)) { |
| 2340 | __ Cmp(out, 0); |
| 2341 | |
| 2342 | // We use the scope because of the IT block that follows. |
| 2343 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 2344 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 2345 | CodeBufferCheckScope::kExactSize); |
| 2346 | |
| 2347 | __ it(ne); |
| 2348 | __ mov(ne, out, 1); |
| 2349 | return; |
| 2350 | } |
| 2351 | |
| 2352 | FALLTHROUGH_INTENDED; |
| 2353 | case kCondEQ: |
| 2354 | case kCondBE: |
| 2355 | case kCondLT: |
| 2356 | case kCondGE: |
| 2357 | case kCondAE: |
| 2358 | case kCondB: |
| 2359 | codegen->GenerateConditionWithZero(condition, out, in); |
| 2360 | return; |
| 2361 | case kCondLE: |
| 2362 | case kCondGT: |
| 2363 | default: |
| 2364 | break; |
| 2365 | } |
| 2366 | } |
| 2367 | } |
| 2368 | |
| 2369 | if (condition == kCondEQ || condition == kCondNE) { |
| 2370 | Operand operand(0); |
| 2371 | |
| 2372 | if (right.IsConstant()) { |
| 2373 | operand = Operand::From(value); |
| 2374 | } else if (out.Is(RegisterFrom(right))) { |
| 2375 | // Avoid 32-bit instructions if possible. |
| 2376 | operand = InputOperandAt(cond, 0); |
| 2377 | in = RegisterFrom(right); |
| 2378 | } else { |
| 2379 | operand = InputOperandAt(cond, 1); |
| 2380 | } |
| 2381 | |
| 2382 | if (condition == kCondNE && out.IsLow()) { |
| 2383 | __ Subs(out, in, operand); |
| 2384 | |
| 2385 | // We use the scope because of the IT block that follows. |
| 2386 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 2387 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 2388 | CodeBufferCheckScope::kExactSize); |
| 2389 | |
| 2390 | __ it(ne); |
| 2391 | __ mov(ne, out, 1); |
| 2392 | } else { |
| 2393 | __ Sub(out, in, operand); |
| 2394 | codegen->GenerateConditionWithZero(condition, out, out); |
| 2395 | } |
| 2396 | |
| 2397 | return; |
| 2398 | } |
| 2399 | |
| 2400 | GenerateConditionGeneric(cond, codegen); |
| 2401 | } |
| 2402 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2403 | static bool CanEncodeConstantAs8BitImmediate(HConstant* constant) { |
| 2404 | const Primitive::Type type = constant->GetType(); |
| 2405 | bool ret = false; |
| 2406 | |
| 2407 | DCHECK(Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) << type; |
| 2408 | |
| 2409 | if (type == Primitive::kPrimLong) { |
| 2410 | const uint64_t value = Uint64ConstantFrom(constant); |
| 2411 | |
| 2412 | ret = IsUint<8>(Low32Bits(value)) && IsUint<8>(High32Bits(value)); |
| 2413 | } else { |
| 2414 | ret = IsUint<8>(Int32ConstantFrom(constant)); |
| 2415 | } |
| 2416 | |
| 2417 | return ret; |
| 2418 | } |
| 2419 | |
| 2420 | static Location Arm8BitEncodableConstantOrRegister(HInstruction* constant) { |
| 2421 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 2422 | |
| 2423 | if (constant->IsConstant() && CanEncodeConstantAs8BitImmediate(constant->AsConstant())) { |
| 2424 | return Location::ConstantLocation(constant->AsConstant()); |
| 2425 | } |
| 2426 | |
| 2427 | return Location::RequiresRegister(); |
| 2428 | } |
| 2429 | |
| 2430 | static bool CanGenerateConditionalMove(const Location& out, const Location& src) { |
| 2431 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 2432 | // we check that we are not dealing with floating-point output (there is no |
| 2433 | // 16-bit VMOV encoding). |
| 2434 | if (!out.IsRegister() && !out.IsRegisterPair()) { |
| 2435 | return false; |
| 2436 | } |
| 2437 | |
| 2438 | // For constants, we also check that the output is in one or two low registers, |
| 2439 | // and that the constants fit in an 8-bit unsigned integer, so that a 16-bit |
| 2440 | // MOV encoding can be used. |
| 2441 | if (src.IsConstant()) { |
| 2442 | if (!CanEncodeConstantAs8BitImmediate(src.GetConstant())) { |
| 2443 | return false; |
| 2444 | } |
| 2445 | |
| 2446 | if (out.IsRegister()) { |
| 2447 | if (!RegisterFrom(out).IsLow()) { |
| 2448 | return false; |
| 2449 | } |
| 2450 | } else { |
| 2451 | DCHECK(out.IsRegisterPair()); |
| 2452 | |
| 2453 | if (!HighRegisterFrom(out).IsLow()) { |
| 2454 | return false; |
| 2455 | } |
| 2456 | } |
| 2457 | } |
| 2458 | |
| 2459 | return true; |
| 2460 | } |
| 2461 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2462 | #undef __ |
| 2463 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2464 | vixl32::Label* CodeGeneratorARMVIXL::GetFinalLabel(HInstruction* instruction, |
| 2465 | vixl32::Label* final_label) { |
| 2466 | DCHECK(!instruction->IsControlFlow() && !instruction->IsSuspendCheck()); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 2467 | DCHECK(!instruction->IsInvoke() || !instruction->GetLocations()->CanCall()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2468 | |
| 2469 | const HBasicBlock* const block = instruction->GetBlock(); |
| 2470 | const HLoopInformation* const info = block->GetLoopInformation(); |
| 2471 | HInstruction* const next = instruction->GetNext(); |
| 2472 | |
| 2473 | // Avoid a branch to a branch. |
| 2474 | if (next->IsGoto() && (info == nullptr || |
| 2475 | !info->IsBackEdge(*block) || |
| 2476 | !info->HasSuspendCheck())) { |
| 2477 | final_label = GetLabelOf(next->AsGoto()->GetSuccessor()); |
| 2478 | } |
| 2479 | |
| 2480 | return final_label; |
| 2481 | } |
| 2482 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2483 | CodeGeneratorARMVIXL::CodeGeneratorARMVIXL(HGraph* graph, |
| 2484 | const ArmInstructionSetFeatures& isa_features, |
| 2485 | const CompilerOptions& compiler_options, |
| 2486 | OptimizingCompilerStats* stats) |
| 2487 | : CodeGenerator(graph, |
| 2488 | kNumberOfCoreRegisters, |
| 2489 | kNumberOfSRegisters, |
| 2490 | kNumberOfRegisterPairs, |
| 2491 | kCoreCalleeSaves.GetList(), |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2492 | ComputeSRegisterListMask(kFpuCalleeSaves), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2493 | compiler_options, |
| 2494 | stats), |
| 2495 | block_labels_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2496 | jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2497 | location_builder_(graph, this), |
| 2498 | instruction_visitor_(graph, this), |
| 2499 | move_resolver_(graph->GetArena(), this), |
| 2500 | assembler_(graph->GetArena()), |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2501 | isa_features_(isa_features), |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 2502 | uint32_literals_(std::less<uint32_t>(), |
| 2503 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 2504 | pc_relative_method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 2505 | method_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 2506 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 2507 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 2508 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 2509 | baker_read_barrier_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 2510 | jit_string_patches_(StringReferenceValueComparator(), |
| 2511 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 2512 | jit_class_patches_(TypeReferenceValueComparator(), |
| 2513 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2514 | // Always save the LR register to mimic Quick. |
| 2515 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 2516 | // Give D30 and D31 as scratch register to VIXL. The register allocator only works on |
| 2517 | // S0-S31, which alias to D0-D15. |
| 2518 | GetVIXLAssembler()->GetScratchVRegisterList()->Combine(d31); |
| 2519 | GetVIXLAssembler()->GetScratchVRegisterList()->Combine(d30); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2520 | } |
| 2521 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2522 | void JumpTableARMVIXL::EmitTable(CodeGeneratorARMVIXL* codegen) { |
| 2523 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| 2524 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| 2525 | |
| 2526 | // 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] | 2527 | // underlying code buffer and we have generated a jump table of the right size, using |
| 2528 | // codegen->GetVIXLAssembler()->GetBuffer().Align(); |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 2529 | ExactAssemblyScope aas(codegen->GetVIXLAssembler(), |
| 2530 | num_entries * sizeof(int32_t), |
| 2531 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2532 | // TODO(VIXL): Check that using lower case bind is fine here. |
| 2533 | codegen->GetVIXLAssembler()->bind(&table_start_); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2534 | for (uint32_t i = 0; i < num_entries; i++) { |
| 2535 | codegen->GetVIXLAssembler()->place(bb_addresses_[i].get()); |
| 2536 | } |
| 2537 | } |
| 2538 | |
| 2539 | void JumpTableARMVIXL::FixTable(CodeGeneratorARMVIXL* codegen) { |
| 2540 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| 2541 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| 2542 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2543 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 2544 | for (uint32_t i = 0; i < num_entries; i++) { |
| 2545 | vixl32::Label* target_label = codegen->GetLabelOf(successors[i]); |
| 2546 | DCHECK(target_label->IsBound()); |
| 2547 | int32_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
| 2548 | // When doing BX to address we need to have lower bit set to 1 in T32. |
| 2549 | if (codegen->GetVIXLAssembler()->IsUsingT32()) { |
| 2550 | jump_offset++; |
| 2551 | } |
| 2552 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 2553 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2554 | |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 2555 | bb_addresses_[i].get()->UpdateValue(jump_offset, codegen->GetVIXLAssembler()->GetBuffer()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2556 | } |
| 2557 | } |
| 2558 | |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2559 | void CodeGeneratorARMVIXL::FixJumpTables() { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2560 | for (auto&& jump_table : jump_tables_) { |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2561 | jump_table->FixTable(this); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2562 | } |
| 2563 | } |
| 2564 | |
Andreas Gampe | ca620d7 | 2016-11-08 08:09:33 -0800 | [diff] [blame] | 2565 | #define __ reinterpret_cast<ArmVIXLAssembler*>(GetAssembler())->GetVIXLAssembler()-> // NOLINT |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2566 | |
| 2567 | void CodeGeneratorARMVIXL::Finalize(CodeAllocator* allocator) { |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2568 | FixJumpTables(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2569 | GetAssembler()->FinalizeCode(); |
| 2570 | CodeGenerator::Finalize(allocator); |
| 2571 | } |
| 2572 | |
| 2573 | void CodeGeneratorARMVIXL::SetupBlockedRegisters() const { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2574 | // Stack register, LR and PC are always reserved. |
| 2575 | blocked_core_registers_[SP] = true; |
| 2576 | blocked_core_registers_[LR] = true; |
| 2577 | blocked_core_registers_[PC] = true; |
| 2578 | |
| 2579 | // Reserve thread register. |
| 2580 | blocked_core_registers_[TR] = true; |
| 2581 | |
| 2582 | // Reserve temp register. |
| 2583 | blocked_core_registers_[IP] = true; |
| 2584 | |
| 2585 | if (GetGraph()->IsDebuggable()) { |
| 2586 | // Stubs do not save callee-save floating point registers. If the graph |
| 2587 | // is debuggable, we need to deal with these registers differently. For |
| 2588 | // now, just block them. |
| 2589 | for (uint32_t i = kFpuCalleeSaves.GetFirstSRegister().GetCode(); |
| 2590 | i <= kFpuCalleeSaves.GetLastSRegister().GetCode(); |
| 2591 | ++i) { |
| 2592 | blocked_fpu_registers_[i] = true; |
| 2593 | } |
| 2594 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2595 | } |
| 2596 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2597 | InstructionCodeGeneratorARMVIXL::InstructionCodeGeneratorARMVIXL(HGraph* graph, |
| 2598 | CodeGeneratorARMVIXL* codegen) |
| 2599 | : InstructionCodeGenerator(graph, codegen), |
| 2600 | assembler_(codegen->GetAssembler()), |
| 2601 | codegen_(codegen) {} |
| 2602 | |
| 2603 | void CodeGeneratorARMVIXL::ComputeSpillMask() { |
| 2604 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 2605 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
| 2606 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 2607 | // restore another arbitrary register. |
| 2608 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister.GetCode()); |
| 2609 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 2610 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 2611 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 2612 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 2613 | // but in the range. |
| 2614 | if (fpu_spill_mask_ != 0) { |
| 2615 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 2616 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 2617 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 2618 | fpu_spill_mask_ |= (1 << i); |
| 2619 | } |
| 2620 | } |
| 2621 | } |
| 2622 | |
| 2623 | void CodeGeneratorARMVIXL::GenerateFrameEntry() { |
| 2624 | bool skip_overflow_check = |
| 2625 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
| 2626 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
| 2627 | __ Bind(&frame_entry_label_); |
| 2628 | |
| 2629 | if (HasEmptyFrame()) { |
| 2630 | return; |
| 2631 | } |
| 2632 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2633 | if (!skip_overflow_check) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2634 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2635 | vixl32::Register temp = temps.Acquire(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 2636 | __ Sub(temp, sp, Operand::From(GetStackOverflowReservedBytes(kArm))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2637 | // The load must immediately precede RecordPcInfo. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 2638 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2639 | vixl32::kMaxInstructionSizeInBytes, |
| 2640 | CodeBufferCheckScope::kMaximumSize); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2641 | __ ldr(temp, MemOperand(temp)); |
| 2642 | RecordPcInfo(nullptr, 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2643 | } |
| 2644 | |
| 2645 | __ Push(RegisterList(core_spill_mask_)); |
| 2646 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 2647 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(kMethodRegister), |
| 2648 | 0, |
| 2649 | core_spill_mask_, |
| 2650 | kArmWordSize); |
| 2651 | if (fpu_spill_mask_ != 0) { |
| 2652 | uint32_t first = LeastSignificantBit(fpu_spill_mask_); |
| 2653 | |
| 2654 | // Check that list is contiguous. |
| 2655 | DCHECK_EQ(fpu_spill_mask_ >> CTZ(fpu_spill_mask_), ~0u >> (32 - POPCOUNT(fpu_spill_mask_))); |
| 2656 | |
| 2657 | __ Vpush(SRegisterList(vixl32::SRegister(first), POPCOUNT(fpu_spill_mask_))); |
| 2658 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2659 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(s0), 0, fpu_spill_mask_, kArmWordSize); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2660 | } |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 2661 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2662 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 2663 | __ Sub(sp, sp, adjust); |
| 2664 | GetAssembler()->cfi().AdjustCFAOffset(adjust); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 2665 | |
| 2666 | // Save the current method if we need it. Note that we do not |
| 2667 | // do this in HCurrentMethod, as the instruction might have been removed |
| 2668 | // in the SSA graph. |
| 2669 | if (RequiresCurrentMethod()) { |
| 2670 | GetAssembler()->StoreToOffset(kStoreWord, kMethodRegister, sp, 0); |
| 2671 | } |
Nicolas Geoffray | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 2672 | |
| 2673 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 2674 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2675 | vixl32::Register temp = temps.Acquire(); |
| 2676 | // Initialize should_deoptimize flag to 0. |
| 2677 | __ Mov(temp, 0); |
| 2678 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, GetStackOffsetOfShouldDeoptimizeFlag()); |
| 2679 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2680 | } |
| 2681 | |
| 2682 | void CodeGeneratorARMVIXL::GenerateFrameExit() { |
| 2683 | if (HasEmptyFrame()) { |
| 2684 | __ Bx(lr); |
| 2685 | return; |
| 2686 | } |
| 2687 | GetAssembler()->cfi().RememberState(); |
| 2688 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 2689 | __ Add(sp, sp, adjust); |
| 2690 | GetAssembler()->cfi().AdjustCFAOffset(-adjust); |
| 2691 | if (fpu_spill_mask_ != 0) { |
| 2692 | uint32_t first = LeastSignificantBit(fpu_spill_mask_); |
| 2693 | |
| 2694 | // Check that list is contiguous. |
| 2695 | DCHECK_EQ(fpu_spill_mask_ >> CTZ(fpu_spill_mask_), ~0u >> (32 - POPCOUNT(fpu_spill_mask_))); |
| 2696 | |
| 2697 | __ Vpop(SRegisterList(vixl32::SRegister(first), POPCOUNT(fpu_spill_mask_))); |
| 2698 | GetAssembler()->cfi().AdjustCFAOffset( |
| 2699 | -static_cast<int>(kArmWordSize) * POPCOUNT(fpu_spill_mask_)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2700 | GetAssembler()->cfi().RestoreMany(DWARFReg(vixl32::SRegister(0)), fpu_spill_mask_); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2701 | } |
| 2702 | // Pop LR into PC to return. |
| 2703 | DCHECK_NE(core_spill_mask_ & (1 << kLrCode), 0U); |
| 2704 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << kLrCode))) | 1 << kPcCode; |
| 2705 | __ Pop(RegisterList(pop_mask)); |
| 2706 | GetAssembler()->cfi().RestoreState(); |
| 2707 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
| 2708 | } |
| 2709 | |
| 2710 | void CodeGeneratorARMVIXL::Bind(HBasicBlock* block) { |
| 2711 | __ Bind(GetLabelOf(block)); |
| 2712 | } |
| 2713 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2714 | Location InvokeDexCallingConventionVisitorARMVIXL::GetNextLocation(Primitive::Type type) { |
| 2715 | switch (type) { |
| 2716 | case Primitive::kPrimBoolean: |
| 2717 | case Primitive::kPrimByte: |
| 2718 | case Primitive::kPrimChar: |
| 2719 | case Primitive::kPrimShort: |
| 2720 | case Primitive::kPrimInt: |
| 2721 | case Primitive::kPrimNot: { |
| 2722 | uint32_t index = gp_index_++; |
| 2723 | uint32_t stack_index = stack_index_++; |
| 2724 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2725 | return LocationFrom(calling_convention.GetRegisterAt(index)); |
| 2726 | } else { |
| 2727 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2728 | } |
| 2729 | } |
| 2730 | |
| 2731 | case Primitive::kPrimLong: { |
| 2732 | uint32_t index = gp_index_; |
| 2733 | uint32_t stack_index = stack_index_; |
| 2734 | gp_index_ += 2; |
| 2735 | stack_index_ += 2; |
| 2736 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2737 | if (calling_convention.GetRegisterAt(index).Is(r1)) { |
| 2738 | // Skip R1, and use R2_R3 instead. |
| 2739 | gp_index_++; |
| 2740 | index++; |
| 2741 | } |
| 2742 | } |
| 2743 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2744 | DCHECK_EQ(calling_convention.GetRegisterAt(index).GetCode() + 1, |
| 2745 | calling_convention.GetRegisterAt(index + 1).GetCode()); |
| 2746 | |
| 2747 | return LocationFrom(calling_convention.GetRegisterAt(index), |
| 2748 | calling_convention.GetRegisterAt(index + 1)); |
| 2749 | } else { |
| 2750 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2751 | } |
| 2752 | } |
| 2753 | |
| 2754 | case Primitive::kPrimFloat: { |
| 2755 | uint32_t stack_index = stack_index_++; |
| 2756 | if (float_index_ % 2 == 0) { |
| 2757 | float_index_ = std::max(double_index_, float_index_); |
| 2758 | } |
| 2759 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 2760 | return LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 2761 | } else { |
| 2762 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2763 | } |
| 2764 | } |
| 2765 | |
| 2766 | case Primitive::kPrimDouble: { |
| 2767 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 2768 | uint32_t stack_index = stack_index_; |
| 2769 | stack_index_ += 2; |
| 2770 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 2771 | uint32_t index = double_index_; |
| 2772 | double_index_ += 2; |
| 2773 | Location result = LocationFrom( |
| 2774 | calling_convention.GetFpuRegisterAt(index), |
| 2775 | calling_convention.GetFpuRegisterAt(index + 1)); |
| 2776 | DCHECK(ExpectedPairLayout(result)); |
| 2777 | return result; |
| 2778 | } else { |
| 2779 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2780 | } |
| 2781 | } |
| 2782 | |
| 2783 | case Primitive::kPrimVoid: |
| 2784 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2785 | break; |
| 2786 | } |
| 2787 | return Location::NoLocation(); |
| 2788 | } |
| 2789 | |
| 2790 | Location InvokeDexCallingConventionVisitorARMVIXL::GetReturnLocation(Primitive::Type type) const { |
| 2791 | switch (type) { |
| 2792 | case Primitive::kPrimBoolean: |
| 2793 | case Primitive::kPrimByte: |
| 2794 | case Primitive::kPrimChar: |
| 2795 | case Primitive::kPrimShort: |
| 2796 | case Primitive::kPrimInt: |
| 2797 | case Primitive::kPrimNot: { |
| 2798 | return LocationFrom(r0); |
| 2799 | } |
| 2800 | |
| 2801 | case Primitive::kPrimFloat: { |
| 2802 | return LocationFrom(s0); |
| 2803 | } |
| 2804 | |
| 2805 | case Primitive::kPrimLong: { |
| 2806 | return LocationFrom(r0, r1); |
| 2807 | } |
| 2808 | |
| 2809 | case Primitive::kPrimDouble: { |
| 2810 | return LocationFrom(s0, s1); |
| 2811 | } |
| 2812 | |
| 2813 | case Primitive::kPrimVoid: |
| 2814 | return Location::NoLocation(); |
| 2815 | } |
| 2816 | |
| 2817 | UNREACHABLE(); |
| 2818 | } |
| 2819 | |
| 2820 | Location InvokeDexCallingConventionVisitorARMVIXL::GetMethodLocation() const { |
| 2821 | return LocationFrom(kMethodRegister); |
| 2822 | } |
| 2823 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2824 | void CodeGeneratorARMVIXL::Move32(Location destination, Location source) { |
| 2825 | if (source.Equals(destination)) { |
| 2826 | return; |
| 2827 | } |
| 2828 | if (destination.IsRegister()) { |
| 2829 | if (source.IsRegister()) { |
| 2830 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 2831 | } else if (source.IsFpuRegister()) { |
| 2832 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
| 2833 | } else { |
| 2834 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 2835 | RegisterFrom(destination), |
| 2836 | sp, |
| 2837 | source.GetStackIndex()); |
| 2838 | } |
| 2839 | } else if (destination.IsFpuRegister()) { |
| 2840 | if (source.IsRegister()) { |
| 2841 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
| 2842 | } else if (source.IsFpuRegister()) { |
| 2843 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 2844 | } else { |
| 2845 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 2846 | } |
| 2847 | } else { |
| 2848 | DCHECK(destination.IsStackSlot()) << destination; |
| 2849 | if (source.IsRegister()) { |
| 2850 | GetAssembler()->StoreToOffset(kStoreWord, |
| 2851 | RegisterFrom(source), |
| 2852 | sp, |
| 2853 | destination.GetStackIndex()); |
| 2854 | } else if (source.IsFpuRegister()) { |
| 2855 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 2856 | } else { |
| 2857 | DCHECK(source.IsStackSlot()) << source; |
| 2858 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2859 | vixl32::Register temp = temps.Acquire(); |
| 2860 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 2861 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 2862 | } |
| 2863 | } |
| 2864 | } |
| 2865 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2866 | void CodeGeneratorARMVIXL::MoveConstant(Location location, int32_t value) { |
| 2867 | DCHECK(location.IsRegister()); |
| 2868 | __ Mov(RegisterFrom(location), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2869 | } |
| 2870 | |
| 2871 | void CodeGeneratorARMVIXL::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2872 | // TODO(VIXL): Maybe refactor to have the 'move' implementation here and use it in |
| 2873 | // `ParallelMoveResolverARMVIXL::EmitMove`, as is done in the `arm64` backend. |
| 2874 | HParallelMove move(GetGraph()->GetArena()); |
| 2875 | move.AddMove(src, dst, dst_type, nullptr); |
| 2876 | GetMoveResolver()->EmitNativeCode(&move); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2877 | } |
| 2878 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2879 | void CodeGeneratorARMVIXL::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 2880 | if (location.IsRegister()) { |
| 2881 | locations->AddTemp(location); |
| 2882 | } else if (location.IsRegisterPair()) { |
| 2883 | locations->AddTemp(LocationFrom(LowRegisterFrom(location))); |
| 2884 | locations->AddTemp(LocationFrom(HighRegisterFrom(location))); |
| 2885 | } else { |
| 2886 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 2887 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2888 | } |
| 2889 | |
| 2890 | void CodeGeneratorARMVIXL::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2891 | HInstruction* instruction, |
| 2892 | uint32_t dex_pc, |
| 2893 | SlowPathCode* slow_path) { |
| 2894 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2895 | __ Ldr(lr, MemOperand(tr, GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value())); |
| 2896 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 2897 | // 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] | 2898 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2899 | vixl32::k16BitT32InstructionSizeInBytes, |
| 2900 | CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2901 | __ blx(lr); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2902 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2903 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2904 | } |
| 2905 | } |
| 2906 | |
| 2907 | void CodeGeneratorARMVIXL::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2908 | HInstruction* instruction, |
| 2909 | SlowPathCode* slow_path) { |
| 2910 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2911 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2912 | __ Blx(lr); |
| 2913 | } |
| 2914 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2915 | void InstructionCodeGeneratorARMVIXL::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| 2916 | DCHECK(!successor->IsExitBlock()); |
| 2917 | HBasicBlock* block = got->GetBlock(); |
| 2918 | HInstruction* previous = got->GetPrevious(); |
| 2919 | HLoopInformation* info = block->GetLoopInformation(); |
| 2920 | |
| 2921 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| 2922 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 2923 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2924 | return; |
| 2925 | } |
| 2926 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2927 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 2928 | } |
| 2929 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 2930 | __ B(codegen_->GetLabelOf(successor)); |
| 2931 | } |
| 2932 | } |
| 2933 | |
| 2934 | void LocationsBuilderARMVIXL::VisitGoto(HGoto* got) { |
| 2935 | got->SetLocations(nullptr); |
| 2936 | } |
| 2937 | |
| 2938 | void InstructionCodeGeneratorARMVIXL::VisitGoto(HGoto* got) { |
| 2939 | HandleGoto(got, got->GetSuccessor()); |
| 2940 | } |
| 2941 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2942 | void LocationsBuilderARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2943 | try_boundary->SetLocations(nullptr); |
| 2944 | } |
| 2945 | |
| 2946 | void InstructionCodeGeneratorARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2947 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2948 | if (!successor->IsExitBlock()) { |
| 2949 | HandleGoto(try_boundary, successor); |
| 2950 | } |
| 2951 | } |
| 2952 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2953 | void LocationsBuilderARMVIXL::VisitExit(HExit* exit) { |
| 2954 | exit->SetLocations(nullptr); |
| 2955 | } |
| 2956 | |
| 2957 | void InstructionCodeGeneratorARMVIXL::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 2958 | } |
| 2959 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2960 | void InstructionCodeGeneratorARMVIXL::GenerateCompareTestAndBranch(HCondition* condition, |
| 2961 | vixl32::Label* true_target_in, |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2962 | vixl32::Label* false_target_in, |
| 2963 | bool is_far_target) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2964 | if (CanGenerateTest(condition, codegen_->GetAssembler())) { |
| 2965 | vixl32::Label* non_fallthrough_target; |
| 2966 | bool invert; |
Nicolas Geoffray | 6fda427 | 2017-06-26 09:12:45 +0100 | [diff] [blame] | 2967 | bool emit_both_branches; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2968 | |
| 2969 | if (true_target_in == nullptr) { |
Nicolas Geoffray | 6fda427 | 2017-06-26 09:12:45 +0100 | [diff] [blame] | 2970 | // The true target is fallthrough. |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2971 | DCHECK(false_target_in != nullptr); |
| 2972 | non_fallthrough_target = false_target_in; |
| 2973 | invert = true; |
Nicolas Geoffray | 6fda427 | 2017-06-26 09:12:45 +0100 | [diff] [blame] | 2974 | emit_both_branches = false; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2975 | } else { |
| 2976 | non_fallthrough_target = true_target_in; |
| 2977 | invert = false; |
Nicolas Geoffray | 6fda427 | 2017-06-26 09:12:45 +0100 | [diff] [blame] | 2978 | // Either the false target is fallthrough, or there is no fallthrough |
| 2979 | // and both branches must be emitted. |
| 2980 | emit_both_branches = (false_target_in != nullptr); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2981 | } |
| 2982 | |
| 2983 | const auto cond = GenerateTest(condition, invert, codegen_); |
| 2984 | |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2985 | __ B(cond.first, non_fallthrough_target, is_far_target); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2986 | |
Nicolas Geoffray | 6fda427 | 2017-06-26 09:12:45 +0100 | [diff] [blame] | 2987 | if (emit_both_branches) { |
| 2988 | // No target falls through, we need to branch. |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2989 | __ B(false_target_in); |
| 2990 | } |
| 2991 | |
| 2992 | return; |
| 2993 | } |
| 2994 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2995 | // Generated branching requires both targets to be explicit. If either of the |
| 2996 | // targets is nullptr (fallthrough) use and bind `fallthrough` instead. |
| 2997 | vixl32::Label fallthrough; |
| 2998 | vixl32::Label* true_target = (true_target_in == nullptr) ? &fallthrough : true_target_in; |
| 2999 | vixl32::Label* false_target = (false_target_in == nullptr) ? &fallthrough : false_target_in; |
| 3000 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3001 | DCHECK_EQ(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 3002 | GenerateLongComparesAndJumps(condition, true_target, false_target, codegen_, is_far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3003 | |
| 3004 | if (false_target != &fallthrough) { |
| 3005 | __ B(false_target); |
| 3006 | } |
| 3007 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3008 | if (fallthrough.IsReferenced()) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3009 | __ Bind(&fallthrough); |
| 3010 | } |
| 3011 | } |
| 3012 | |
| 3013 | void InstructionCodeGeneratorARMVIXL::GenerateTestAndBranch(HInstruction* instruction, |
| 3014 | size_t condition_input_index, |
| 3015 | vixl32::Label* true_target, |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 3016 | vixl32::Label* false_target, |
| 3017 | bool far_target) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3018 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 3019 | |
| 3020 | if (true_target == nullptr && false_target == nullptr) { |
| 3021 | // Nothing to do. The code always falls through. |
| 3022 | return; |
| 3023 | } else if (cond->IsIntConstant()) { |
| 3024 | // Constant condition, statically compared against "true" (integer value 1). |
| 3025 | if (cond->AsIntConstant()->IsTrue()) { |
| 3026 | if (true_target != nullptr) { |
| 3027 | __ B(true_target); |
| 3028 | } |
| 3029 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 3030 | DCHECK(cond->AsIntConstant()->IsFalse()) << Int32ConstantFrom(cond); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3031 | if (false_target != nullptr) { |
| 3032 | __ B(false_target); |
| 3033 | } |
| 3034 | } |
| 3035 | return; |
| 3036 | } |
| 3037 | |
| 3038 | // The following code generates these patterns: |
| 3039 | // (1) true_target == nullptr && false_target != nullptr |
| 3040 | // - opposite condition true => branch to false_target |
| 3041 | // (2) true_target != nullptr && false_target == nullptr |
| 3042 | // - condition true => branch to true_target |
| 3043 | // (3) true_target != nullptr && false_target != nullptr |
| 3044 | // - condition true => branch to true_target |
| 3045 | // - branch to false_target |
| 3046 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3047 | // Condition has been materialized, compare the output to 0. |
| 3048 | if (kIsDebugBuild) { |
| 3049 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 3050 | DCHECK(cond_val.IsRegister()); |
| 3051 | } |
| 3052 | if (true_target == nullptr) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 3053 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, condition_input_index), |
| 3054 | false_target, |
| 3055 | far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3056 | } else { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 3057 | __ CompareAndBranchIfNonZero(InputRegisterAt(instruction, condition_input_index), |
| 3058 | true_target, |
| 3059 | far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3060 | } |
| 3061 | } else { |
| 3062 | // Condition has not been materialized. Use its inputs as the comparison and |
| 3063 | // its condition as the branch condition. |
| 3064 | HCondition* condition = cond->AsCondition(); |
| 3065 | |
| 3066 | // If this is a long or FP comparison that has been folded into |
| 3067 | // the HCondition, generate the comparison directly. |
| 3068 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 3069 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 3070 | GenerateCompareTestAndBranch(condition, true_target, false_target, far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3071 | return; |
| 3072 | } |
| 3073 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3074 | vixl32::Label* non_fallthrough_target; |
| 3075 | vixl32::Condition arm_cond = vixl32::Condition::None(); |
| 3076 | const vixl32::Register left = InputRegisterAt(cond, 0); |
| 3077 | const Operand right = InputOperandAt(cond, 1); |
| 3078 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3079 | if (true_target == nullptr) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3080 | arm_cond = ARMCondition(condition->GetOppositeCondition()); |
| 3081 | non_fallthrough_target = false_target; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3082 | } else { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3083 | arm_cond = ARMCondition(condition->GetCondition()); |
| 3084 | non_fallthrough_target = true_target; |
| 3085 | } |
| 3086 | |
| 3087 | if (right.IsImmediate() && right.GetImmediate() == 0 && (arm_cond.Is(ne) || arm_cond.Is(eq))) { |
| 3088 | if (arm_cond.Is(eq)) { |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 3089 | __ CompareAndBranchIfZero(left, non_fallthrough_target, far_target); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3090 | } else { |
| 3091 | DCHECK(arm_cond.Is(ne)); |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 3092 | __ CompareAndBranchIfNonZero(left, non_fallthrough_target, far_target); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3093 | } |
| 3094 | } else { |
| 3095 | __ Cmp(left, right); |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 3096 | __ B(arm_cond, non_fallthrough_target, far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3097 | } |
| 3098 | } |
| 3099 | |
| 3100 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3101 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3102 | if (true_target != nullptr && false_target != nullptr) { |
| 3103 | __ B(false_target); |
| 3104 | } |
| 3105 | } |
| 3106 | |
| 3107 | void LocationsBuilderARMVIXL::VisitIf(HIf* if_instr) { |
| 3108 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 3109 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| 3110 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3111 | } |
| 3112 | } |
| 3113 | |
| 3114 | void InstructionCodeGeneratorARMVIXL::VisitIf(HIf* if_instr) { |
| 3115 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3116 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3117 | vixl32::Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 3118 | nullptr : codegen_->GetLabelOf(true_successor); |
| 3119 | vixl32::Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 3120 | nullptr : codegen_->GetLabelOf(false_successor); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3121 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
| 3122 | } |
| 3123 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3124 | void LocationsBuilderARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 3125 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3126 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3127 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3128 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3129 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 3130 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3131 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| 3132 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3133 | } |
| 3134 | } |
| 3135 | |
| 3136 | void InstructionCodeGeneratorARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 3137 | SlowPathCodeARMVIXL* slow_path = |
| 3138 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARMVIXL>(deoptimize); |
| 3139 | GenerateTestAndBranch(deoptimize, |
| 3140 | /* condition_input_index */ 0, |
| 3141 | slow_path->GetEntryLabel(), |
| 3142 | /* false_target */ nullptr); |
| 3143 | } |
| 3144 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3145 | void LocationsBuilderARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3146 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3147 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3148 | locations->SetOut(Location::RequiresRegister()); |
| 3149 | } |
| 3150 | |
| 3151 | void InstructionCodeGeneratorARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3152 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3153 | OutputRegister(flag), |
| 3154 | sp, |
| 3155 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 3156 | } |
| 3157 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3158 | void LocationsBuilderARMVIXL::VisitSelect(HSelect* select) { |
| 3159 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3160 | const bool is_floating_point = Primitive::IsFloatingPointType(select->GetType()); |
| 3161 | |
| 3162 | if (is_floating_point) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3163 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3164 | locations->SetInAt(1, Location::FpuRegisterOrConstant(select->GetTrueValue())); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3165 | } else { |
| 3166 | locations->SetInAt(0, Location::RequiresRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3167 | locations->SetInAt(1, Arm8BitEncodableConstantOrRegister(select->GetTrueValue())); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3168 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3169 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3170 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3171 | locations->SetInAt(2, Location::RegisterOrConstant(select->GetCondition())); |
| 3172 | // The code generator handles overlap with the values, but not with the condition. |
| 3173 | locations->SetOut(Location::SameAsFirstInput()); |
| 3174 | } else if (is_floating_point) { |
| 3175 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3176 | } else { |
| 3177 | if (!locations->InAt(1).IsConstant()) { |
| 3178 | locations->SetInAt(0, Arm8BitEncodableConstantOrRegister(select->GetFalseValue())); |
| 3179 | } |
| 3180 | |
| 3181 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3182 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3183 | } |
| 3184 | |
| 3185 | void InstructionCodeGeneratorARMVIXL::VisitSelect(HSelect* select) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3186 | HInstruction* const condition = select->GetCondition(); |
| 3187 | const LocationSummary* const locations = select->GetLocations(); |
| 3188 | const Primitive::Type type = select->GetType(); |
| 3189 | const Location first = locations->InAt(0); |
| 3190 | const Location out = locations->Out(); |
| 3191 | const Location second = locations->InAt(1); |
| 3192 | Location src; |
| 3193 | |
| 3194 | if (condition->IsIntConstant()) { |
| 3195 | if (condition->AsIntConstant()->IsFalse()) { |
| 3196 | src = first; |
| 3197 | } else { |
| 3198 | src = second; |
| 3199 | } |
| 3200 | |
| 3201 | codegen_->MoveLocation(out, src, type); |
| 3202 | return; |
| 3203 | } |
| 3204 | |
| 3205 | if (!Primitive::IsFloatingPointType(type) && |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3206 | (IsBooleanValueOrMaterializedCondition(condition) || |
| 3207 | CanGenerateTest(condition->AsCondition(), codegen_->GetAssembler()))) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3208 | bool invert = false; |
| 3209 | |
| 3210 | if (out.Equals(second)) { |
| 3211 | src = first; |
| 3212 | invert = true; |
| 3213 | } else if (out.Equals(first)) { |
| 3214 | src = second; |
| 3215 | } else if (second.IsConstant()) { |
| 3216 | DCHECK(CanEncodeConstantAs8BitImmediate(second.GetConstant())); |
| 3217 | src = second; |
| 3218 | } else if (first.IsConstant()) { |
| 3219 | DCHECK(CanEncodeConstantAs8BitImmediate(first.GetConstant())); |
| 3220 | src = first; |
| 3221 | invert = true; |
| 3222 | } else { |
| 3223 | src = second; |
| 3224 | } |
| 3225 | |
| 3226 | if (CanGenerateConditionalMove(out, src)) { |
| 3227 | if (!out.Equals(first) && !out.Equals(second)) { |
| 3228 | codegen_->MoveLocation(out, src.Equals(first) ? second : first, type); |
| 3229 | } |
| 3230 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3231 | std::pair<vixl32::Condition, vixl32::Condition> cond(eq, ne); |
| 3232 | |
| 3233 | if (IsBooleanValueOrMaterializedCondition(condition)) { |
| 3234 | __ Cmp(InputRegisterAt(select, 2), 0); |
| 3235 | cond = invert ? std::make_pair(eq, ne) : std::make_pair(ne, eq); |
| 3236 | } else { |
| 3237 | cond = GenerateTest(condition->AsCondition(), invert, codegen_); |
| 3238 | } |
| 3239 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3240 | const size_t instr_count = out.IsRegisterPair() ? 4 : 2; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3241 | // We use the scope because of the IT block that follows. |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3242 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 3243 | instr_count * vixl32::k16BitT32InstructionSizeInBytes, |
| 3244 | CodeBufferCheckScope::kExactSize); |
| 3245 | |
| 3246 | if (out.IsRegister()) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3247 | __ it(cond.first); |
| 3248 | __ mov(cond.first, RegisterFrom(out), OperandFrom(src, type)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3249 | } else { |
| 3250 | DCHECK(out.IsRegisterPair()); |
| 3251 | |
| 3252 | Operand operand_high(0); |
| 3253 | Operand operand_low(0); |
| 3254 | |
| 3255 | if (src.IsConstant()) { |
| 3256 | const int64_t value = Int64ConstantFrom(src); |
| 3257 | |
| 3258 | operand_high = High32Bits(value); |
| 3259 | operand_low = Low32Bits(value); |
| 3260 | } else { |
| 3261 | DCHECK(src.IsRegisterPair()); |
| 3262 | operand_high = HighRegisterFrom(src); |
| 3263 | operand_low = LowRegisterFrom(src); |
| 3264 | } |
| 3265 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3266 | __ it(cond.first); |
| 3267 | __ mov(cond.first, LowRegisterFrom(out), operand_low); |
| 3268 | __ it(cond.first); |
| 3269 | __ mov(cond.first, HighRegisterFrom(out), operand_high); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3270 | } |
| 3271 | |
| 3272 | return; |
| 3273 | } |
| 3274 | } |
| 3275 | |
| 3276 | vixl32::Label* false_target = nullptr; |
| 3277 | vixl32::Label* true_target = nullptr; |
| 3278 | vixl32::Label select_end; |
| 3279 | vixl32::Label* const target = codegen_->GetFinalLabel(select, &select_end); |
| 3280 | |
| 3281 | if (out.Equals(second)) { |
| 3282 | true_target = target; |
| 3283 | src = first; |
| 3284 | } else { |
| 3285 | false_target = target; |
| 3286 | src = second; |
| 3287 | |
| 3288 | if (!out.Equals(first)) { |
| 3289 | codegen_->MoveLocation(out, first, type); |
| 3290 | } |
| 3291 | } |
| 3292 | |
| 3293 | GenerateTestAndBranch(select, 2, true_target, false_target, /* far_target */ false); |
| 3294 | codegen_->MoveLocation(out, src, type); |
| 3295 | |
| 3296 | if (select_end.IsReferenced()) { |
| 3297 | __ Bind(&select_end); |
| 3298 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3299 | } |
| 3300 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 3301 | void LocationsBuilderARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 3302 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 3303 | } |
| 3304 | |
| 3305 | void InstructionCodeGeneratorARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3306 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| 3307 | } |
| 3308 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3309 | void CodeGeneratorARMVIXL::GenerateNop() { |
| 3310 | __ Nop(); |
| 3311 | } |
| 3312 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3313 | // `temp` is an extra temporary register that is used for some conditions; |
| 3314 | // callers may not specify it, in which case the method will use a scratch |
| 3315 | // register instead. |
| 3316 | void CodeGeneratorARMVIXL::GenerateConditionWithZero(IfCondition condition, |
| 3317 | vixl32::Register out, |
| 3318 | vixl32::Register in, |
| 3319 | vixl32::Register temp) { |
| 3320 | switch (condition) { |
| 3321 | case kCondEQ: |
| 3322 | // x <= 0 iff x == 0 when the comparison is unsigned. |
| 3323 | case kCondBE: |
| 3324 | if (!temp.IsValid() || (out.IsLow() && !out.Is(in))) { |
| 3325 | temp = out; |
| 3326 | } |
| 3327 | |
| 3328 | // Avoid 32-bit instructions if possible; note that `in` and `temp` must be |
| 3329 | // different as well. |
| 3330 | if (in.IsLow() && temp.IsLow() && !in.Is(temp)) { |
| 3331 | // temp = - in; only 0 sets the carry flag. |
| 3332 | __ Rsbs(temp, in, 0); |
| 3333 | |
| 3334 | if (out.Is(in)) { |
| 3335 | std::swap(in, temp); |
| 3336 | } |
| 3337 | |
| 3338 | // out = - in + in + carry = carry |
| 3339 | __ Adc(out, temp, in); |
| 3340 | } else { |
| 3341 | // If `in` is 0, then it has 32 leading zeros, and less than that otherwise. |
| 3342 | __ Clz(out, in); |
| 3343 | // Any number less than 32 logically shifted right by 5 bits results in 0; |
| 3344 | // the same operation on 32 yields 1. |
| 3345 | __ Lsr(out, out, 5); |
| 3346 | } |
| 3347 | |
| 3348 | break; |
| 3349 | case kCondNE: |
| 3350 | // x > 0 iff x != 0 when the comparison is unsigned. |
| 3351 | case kCondA: { |
| 3352 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3353 | |
| 3354 | if (out.Is(in)) { |
| 3355 | if (!temp.IsValid() || in.Is(temp)) { |
| 3356 | temp = temps.Acquire(); |
| 3357 | } |
| 3358 | } else if (!temp.IsValid() || !temp.IsLow()) { |
| 3359 | temp = out; |
| 3360 | } |
| 3361 | |
| 3362 | // temp = in - 1; only 0 does not set the carry flag. |
| 3363 | __ Subs(temp, in, 1); |
| 3364 | // out = in + ~temp + carry = in + (-(in - 1) - 1) + carry = in - in + 1 - 1 + carry = carry |
| 3365 | __ Sbc(out, in, temp); |
| 3366 | break; |
| 3367 | } |
| 3368 | case kCondGE: |
| 3369 | __ Mvn(out, in); |
| 3370 | in = out; |
| 3371 | FALLTHROUGH_INTENDED; |
| 3372 | case kCondLT: |
| 3373 | // We only care about the sign bit. |
| 3374 | __ Lsr(out, in, 31); |
| 3375 | break; |
| 3376 | case kCondAE: |
| 3377 | // Trivially true. |
| 3378 | __ Mov(out, 1); |
| 3379 | break; |
| 3380 | case kCondB: |
| 3381 | // Trivially false. |
| 3382 | __ Mov(out, 0); |
| 3383 | break; |
| 3384 | default: |
| 3385 | LOG(FATAL) << "Unexpected condition " << condition; |
| 3386 | UNREACHABLE(); |
| 3387 | } |
| 3388 | } |
| 3389 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3390 | void LocationsBuilderARMVIXL::HandleCondition(HCondition* cond) { |
| 3391 | LocationSummary* locations = |
| 3392 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
| 3393 | // Handle the long/FP comparisons made in instruction simplification. |
| 3394 | switch (cond->InputAt(0)->GetType()) { |
| 3395 | case Primitive::kPrimLong: |
| 3396 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3397 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 3398 | if (!cond->IsEmittedAtUseSite()) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3399 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3400 | } |
| 3401 | break; |
| 3402 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3403 | case Primitive::kPrimFloat: |
| 3404 | case Primitive::kPrimDouble: |
| 3405 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 3406 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3407 | if (!cond->IsEmittedAtUseSite()) { |
| 3408 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3409 | } |
| 3410 | break; |
| 3411 | |
| 3412 | default: |
| 3413 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3414 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 3415 | if (!cond->IsEmittedAtUseSite()) { |
| 3416 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3417 | } |
| 3418 | } |
| 3419 | } |
| 3420 | |
| 3421 | void InstructionCodeGeneratorARMVIXL::HandleCondition(HCondition* cond) { |
| 3422 | if (cond->IsEmittedAtUseSite()) { |
| 3423 | return; |
| 3424 | } |
| 3425 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3426 | const Primitive::Type type = cond->GetLeft()->GetType(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3427 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3428 | if (Primitive::IsFloatingPointType(type)) { |
| 3429 | GenerateConditionGeneric(cond, codegen_); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3430 | return; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3431 | } |
| 3432 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3433 | DCHECK(Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) << type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3434 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3435 | const IfCondition condition = cond->GetCondition(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3436 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3437 | // A condition with only one boolean input, or two boolean inputs without being equality or |
| 3438 | // inequality results from transformations done by the instruction simplifier, and is handled |
| 3439 | // as a regular condition with integral inputs. |
| 3440 | if (type == Primitive::kPrimBoolean && |
| 3441 | cond->GetRight()->GetType() == Primitive::kPrimBoolean && |
| 3442 | (condition == kCondEQ || condition == kCondNE)) { |
| 3443 | vixl32::Register left = InputRegisterAt(cond, 0); |
| 3444 | const vixl32::Register out = OutputRegister(cond); |
| 3445 | const Location right_loc = cond->GetLocations()->InAt(1); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3446 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3447 | // The constant case is handled by the instruction simplifier. |
| 3448 | DCHECK(!right_loc.IsConstant()); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3449 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3450 | vixl32::Register right = RegisterFrom(right_loc); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3451 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3452 | // Avoid 32-bit instructions if possible. |
| 3453 | if (out.Is(right)) { |
| 3454 | std::swap(left, right); |
| 3455 | } |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3456 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3457 | __ Eor(out, left, right); |
| 3458 | |
| 3459 | if (condition == kCondEQ) { |
| 3460 | __ Eor(out, out, 1); |
| 3461 | } |
| 3462 | |
| 3463 | return; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3464 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 3465 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3466 | GenerateConditionIntegralOrNonPrimitive(cond, codegen_); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3467 | } |
| 3468 | |
| 3469 | void LocationsBuilderARMVIXL::VisitEqual(HEqual* comp) { |
| 3470 | HandleCondition(comp); |
| 3471 | } |
| 3472 | |
| 3473 | void InstructionCodeGeneratorARMVIXL::VisitEqual(HEqual* comp) { |
| 3474 | HandleCondition(comp); |
| 3475 | } |
| 3476 | |
| 3477 | void LocationsBuilderARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 3478 | HandleCondition(comp); |
| 3479 | } |
| 3480 | |
| 3481 | void InstructionCodeGeneratorARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 3482 | HandleCondition(comp); |
| 3483 | } |
| 3484 | |
| 3485 | void LocationsBuilderARMVIXL::VisitLessThan(HLessThan* comp) { |
| 3486 | HandleCondition(comp); |
| 3487 | } |
| 3488 | |
| 3489 | void InstructionCodeGeneratorARMVIXL::VisitLessThan(HLessThan* comp) { |
| 3490 | HandleCondition(comp); |
| 3491 | } |
| 3492 | |
| 3493 | void LocationsBuilderARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 3494 | HandleCondition(comp); |
| 3495 | } |
| 3496 | |
| 3497 | void InstructionCodeGeneratorARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 3498 | HandleCondition(comp); |
| 3499 | } |
| 3500 | |
| 3501 | void LocationsBuilderARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 3502 | HandleCondition(comp); |
| 3503 | } |
| 3504 | |
| 3505 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 3506 | HandleCondition(comp); |
| 3507 | } |
| 3508 | |
| 3509 | void LocationsBuilderARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 3510 | HandleCondition(comp); |
| 3511 | } |
| 3512 | |
| 3513 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 3514 | HandleCondition(comp); |
| 3515 | } |
| 3516 | |
| 3517 | void LocationsBuilderARMVIXL::VisitBelow(HBelow* comp) { |
| 3518 | HandleCondition(comp); |
| 3519 | } |
| 3520 | |
| 3521 | void InstructionCodeGeneratorARMVIXL::VisitBelow(HBelow* comp) { |
| 3522 | HandleCondition(comp); |
| 3523 | } |
| 3524 | |
| 3525 | void LocationsBuilderARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 3526 | HandleCondition(comp); |
| 3527 | } |
| 3528 | |
| 3529 | void InstructionCodeGeneratorARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 3530 | HandleCondition(comp); |
| 3531 | } |
| 3532 | |
| 3533 | void LocationsBuilderARMVIXL::VisitAbove(HAbove* comp) { |
| 3534 | HandleCondition(comp); |
| 3535 | } |
| 3536 | |
| 3537 | void InstructionCodeGeneratorARMVIXL::VisitAbove(HAbove* comp) { |
| 3538 | HandleCondition(comp); |
| 3539 | } |
| 3540 | |
| 3541 | void LocationsBuilderARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 3542 | HandleCondition(comp); |
| 3543 | } |
| 3544 | |
| 3545 | void InstructionCodeGeneratorARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 3546 | HandleCondition(comp); |
| 3547 | } |
| 3548 | |
| 3549 | void LocationsBuilderARMVIXL::VisitIntConstant(HIntConstant* constant) { |
| 3550 | LocationSummary* locations = |
| 3551 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3552 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3553 | } |
| 3554 | |
| 3555 | void InstructionCodeGeneratorARMVIXL::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 3556 | // Will be generated at use site. |
| 3557 | } |
| 3558 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3559 | void LocationsBuilderARMVIXL::VisitNullConstant(HNullConstant* constant) { |
| 3560 | LocationSummary* locations = |
| 3561 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3562 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3563 | } |
| 3564 | |
| 3565 | void InstructionCodeGeneratorARMVIXL::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 3566 | // Will be generated at use site. |
| 3567 | } |
| 3568 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3569 | void LocationsBuilderARMVIXL::VisitLongConstant(HLongConstant* constant) { |
| 3570 | LocationSummary* locations = |
| 3571 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3572 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3573 | } |
| 3574 | |
| 3575 | void InstructionCodeGeneratorARMVIXL::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 3576 | // Will be generated at use site. |
| 3577 | } |
| 3578 | |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3579 | void LocationsBuilderARMVIXL::VisitFloatConstant(HFloatConstant* constant) { |
| 3580 | LocationSummary* locations = |
| 3581 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3582 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3583 | } |
| 3584 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3585 | void InstructionCodeGeneratorARMVIXL::VisitFloatConstant( |
| 3586 | HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3587 | // Will be generated at use site. |
| 3588 | } |
| 3589 | |
| 3590 | void LocationsBuilderARMVIXL::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3591 | LocationSummary* locations = |
| 3592 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3593 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3594 | } |
| 3595 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3596 | void InstructionCodeGeneratorARMVIXL::VisitDoubleConstant( |
| 3597 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3598 | // Will be generated at use site. |
| 3599 | } |
| 3600 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 3601 | void LocationsBuilderARMVIXL::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 3602 | constructor_fence->SetLocations(nullptr); |
| 3603 | } |
| 3604 | |
| 3605 | void InstructionCodeGeneratorARMVIXL::VisitConstructorFence( |
| 3606 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 3607 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 3608 | } |
| 3609 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3610 | void LocationsBuilderARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3611 | memory_barrier->SetLocations(nullptr); |
| 3612 | } |
| 3613 | |
| 3614 | void InstructionCodeGeneratorARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3615 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 3616 | } |
| 3617 | |
| 3618 | void LocationsBuilderARMVIXL::VisitReturnVoid(HReturnVoid* ret) { |
| 3619 | ret->SetLocations(nullptr); |
| 3620 | } |
| 3621 | |
| 3622 | void InstructionCodeGeneratorARMVIXL::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 3623 | codegen_->GenerateFrameExit(); |
| 3624 | } |
| 3625 | |
| 3626 | void LocationsBuilderARMVIXL::VisitReturn(HReturn* ret) { |
| 3627 | LocationSummary* locations = |
| 3628 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
| 3629 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
| 3630 | } |
| 3631 | |
| 3632 | void InstructionCodeGeneratorARMVIXL::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 3633 | codegen_->GenerateFrameExit(); |
| 3634 | } |
| 3635 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3636 | void LocationsBuilderARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3637 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3638 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3639 | // the method_idx. |
| 3640 | HandleInvoke(invoke); |
| 3641 | } |
| 3642 | |
| 3643 | void InstructionCodeGeneratorARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3644 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 3645 | } |
| 3646 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3647 | void LocationsBuilderARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3648 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3649 | // art::PrepareForRegisterAllocation. |
| 3650 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 3651 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3652 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3653 | if (intrinsic.TryDispatch(invoke)) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3654 | return; |
| 3655 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3656 | |
| 3657 | HandleInvoke(invoke); |
| 3658 | } |
| 3659 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3660 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARMVIXL* codegen) { |
| 3661 | if (invoke->GetLocations()->Intrinsified()) { |
| 3662 | IntrinsicCodeGeneratorARMVIXL intrinsic(codegen); |
| 3663 | intrinsic.Dispatch(invoke); |
| 3664 | return true; |
| 3665 | } |
| 3666 | return false; |
| 3667 | } |
| 3668 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3669 | void InstructionCodeGeneratorARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3670 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3671 | // art::PrepareForRegisterAllocation. |
| 3672 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 3673 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3674 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3675 | return; |
| 3676 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3677 | |
| 3678 | LocationSummary* locations = invoke->GetLocations(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3679 | codegen_->GenerateStaticOrDirectCall( |
| 3680 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3681 | } |
| 3682 | |
| 3683 | void LocationsBuilderARMVIXL::HandleInvoke(HInvoke* invoke) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3684 | InvokeDexCallingConventionVisitorARMVIXL calling_convention_visitor; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3685 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 3686 | } |
| 3687 | |
| 3688 | void LocationsBuilderARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3689 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3690 | if (intrinsic.TryDispatch(invoke)) { |
| 3691 | return; |
| 3692 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3693 | |
| 3694 | HandleInvoke(invoke); |
| 3695 | } |
| 3696 | |
| 3697 | void InstructionCodeGeneratorARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3698 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3699 | return; |
| 3700 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3701 | |
| 3702 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3703 | DCHECK(!codegen_->IsLeafMethod()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3704 | } |
| 3705 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3706 | void LocationsBuilderARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3707 | HandleInvoke(invoke); |
| 3708 | // Add the hidden argument. |
| 3709 | invoke->GetLocations()->AddTemp(LocationFrom(r12)); |
| 3710 | } |
| 3711 | |
| 3712 | void InstructionCodeGeneratorARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3713 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 3714 | LocationSummary* locations = invoke->GetLocations(); |
| 3715 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 3716 | vixl32::Register hidden_reg = RegisterFrom(locations->GetTemp(1)); |
| 3717 | Location receiver = locations->InAt(0); |
| 3718 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3719 | |
| 3720 | DCHECK(!receiver.IsStackSlot()); |
| 3721 | |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3722 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
| 3723 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 3724 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 3725 | vixl32::kMaxInstructionSizeInBytes, |
| 3726 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3727 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 3728 | __ ldr(temp, MemOperand(RegisterFrom(receiver), class_offset)); |
| 3729 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 3730 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3731 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3732 | // emit a read barrier for the previous class reference load. |
| 3733 | // However this is not required in practice, as this is an |
| 3734 | // intermediate/temporary reference and because the current |
| 3735 | // concurrent copying collector keeps the from-space memory |
| 3736 | // intact/accessible until the end of the marking phase (the |
| 3737 | // concurrent copying collector may not in the future). |
| 3738 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 3739 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3740 | temp, |
| 3741 | temp, |
| 3742 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 3743 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 3744 | invoke->GetImtIndex(), kArmPointerSize)); |
| 3745 | // temp = temp->GetImtEntryAt(method_offset); |
| 3746 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 3747 | uint32_t entry_point = |
| 3748 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
| 3749 | // LR = temp->GetEntryPoint(); |
| 3750 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
| 3751 | |
| 3752 | // Set the hidden (in r12) argument. It is done here, right before a BLX to prevent other |
| 3753 | // instruction from clobbering it as they might use r12 as a scratch register. |
| 3754 | DCHECK(hidden_reg.Is(r12)); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3755 | |
| 3756 | { |
| 3757 | // The VIXL macro assembler may clobber any of the scratch registers that are available to it, |
| 3758 | // so it checks if the application is using them (by passing them to the macro assembler |
| 3759 | // methods). The following application of UseScratchRegisterScope corrects VIXL's notion of |
| 3760 | // what is available, and is the opposite of the standard usage: Instead of requesting a |
| 3761 | // temporary location, it imposes an external constraint (i.e. a specific register is reserved |
| 3762 | // for the hidden argument). Note that this works even if VIXL needs a scratch register itself |
| 3763 | // (to materialize the constant), since the destination register becomes available for such use |
| 3764 | // internally for the duration of the macro instruction. |
| 3765 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3766 | temps.Exclude(hidden_reg); |
| 3767 | __ Mov(hidden_reg, invoke->GetDexMethodIndex()); |
| 3768 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3769 | { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3770 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 3771 | // 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] | 3772 | ExactAssemblyScope aas(GetVIXLAssembler(), |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3773 | vixl32::k16BitT32InstructionSizeInBytes, |
| 3774 | CodeBufferCheckScope::kExactSize); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3775 | // LR(); |
| 3776 | __ blx(lr); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3777 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3778 | DCHECK(!codegen_->IsLeafMethod()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3779 | } |
| 3780 | } |
| 3781 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3782 | void LocationsBuilderARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3783 | HandleInvoke(invoke); |
| 3784 | } |
| 3785 | |
| 3786 | void InstructionCodeGeneratorARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3787 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 3788 | } |
| 3789 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3790 | void LocationsBuilderARMVIXL::VisitNeg(HNeg* neg) { |
| 3791 | LocationSummary* locations = |
| 3792 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 3793 | switch (neg->GetResultType()) { |
| 3794 | case Primitive::kPrimInt: { |
| 3795 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3796 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3797 | break; |
| 3798 | } |
| 3799 | case Primitive::kPrimLong: { |
| 3800 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3801 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3802 | break; |
| 3803 | } |
| 3804 | |
| 3805 | case Primitive::kPrimFloat: |
| 3806 | case Primitive::kPrimDouble: |
| 3807 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3808 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3809 | break; |
| 3810 | |
| 3811 | default: |
| 3812 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3813 | } |
| 3814 | } |
| 3815 | |
| 3816 | void InstructionCodeGeneratorARMVIXL::VisitNeg(HNeg* neg) { |
| 3817 | LocationSummary* locations = neg->GetLocations(); |
| 3818 | Location out = locations->Out(); |
| 3819 | Location in = locations->InAt(0); |
| 3820 | switch (neg->GetResultType()) { |
| 3821 | case Primitive::kPrimInt: |
| 3822 | __ Rsb(OutputRegister(neg), InputRegisterAt(neg, 0), 0); |
| 3823 | break; |
| 3824 | |
| 3825 | case Primitive::kPrimLong: |
| 3826 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 3827 | __ Rsbs(LowRegisterFrom(out), LowRegisterFrom(in), 0); |
| 3828 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 3829 | // instruction here, as it does not exist in the Thumb-2 |
| 3830 | // instruction set. We use the following approach |
| 3831 | // using SBC and SUB instead. |
| 3832 | // |
| 3833 | // out.hi = -C |
| 3834 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(out)); |
| 3835 | // out.hi = out.hi - in.hi |
| 3836 | __ Sub(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(in)); |
| 3837 | break; |
| 3838 | |
| 3839 | case Primitive::kPrimFloat: |
| 3840 | case Primitive::kPrimDouble: |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 3841 | __ Vneg(OutputVRegister(neg), InputVRegister(neg)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3842 | break; |
| 3843 | |
| 3844 | default: |
| 3845 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3846 | } |
| 3847 | } |
| 3848 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3849 | void LocationsBuilderARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
| 3850 | Primitive::Type result_type = conversion->GetResultType(); |
| 3851 | Primitive::Type input_type = conversion->GetInputType(); |
| 3852 | DCHECK_NE(result_type, input_type); |
| 3853 | |
| 3854 | // The float-to-long, double-to-long and long-to-float type conversions |
| 3855 | // rely on a call to the runtime. |
| 3856 | LocationSummary::CallKind call_kind = |
| 3857 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 3858 | && result_type == Primitive::kPrimLong) |
| 3859 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
| 3860 | ? LocationSummary::kCallOnMainOnly |
| 3861 | : LocationSummary::kNoCall; |
| 3862 | LocationSummary* locations = |
| 3863 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 3864 | |
| 3865 | // The Java language does not allow treating boolean as an integral type but |
| 3866 | // our bit representation makes it safe. |
| 3867 | |
| 3868 | switch (result_type) { |
| 3869 | case Primitive::kPrimByte: |
| 3870 | switch (input_type) { |
| 3871 | case Primitive::kPrimLong: |
| 3872 | // Type conversion from long to byte is a result of code transformations. |
| 3873 | case Primitive::kPrimBoolean: |
| 3874 | // Boolean input is a result of code transformations. |
| 3875 | case Primitive::kPrimShort: |
| 3876 | case Primitive::kPrimInt: |
| 3877 | case Primitive::kPrimChar: |
| 3878 | // Processing a Dex `int-to-byte' instruction. |
| 3879 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3880 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3881 | break; |
| 3882 | |
| 3883 | default: |
| 3884 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3885 | << " to " << result_type; |
| 3886 | } |
| 3887 | break; |
| 3888 | |
| 3889 | case Primitive::kPrimShort: |
| 3890 | switch (input_type) { |
| 3891 | case Primitive::kPrimLong: |
| 3892 | // Type conversion from long to short is a result of code transformations. |
| 3893 | case Primitive::kPrimBoolean: |
| 3894 | // Boolean input is a result of code transformations. |
| 3895 | case Primitive::kPrimByte: |
| 3896 | case Primitive::kPrimInt: |
| 3897 | case Primitive::kPrimChar: |
| 3898 | // Processing a Dex `int-to-short' instruction. |
| 3899 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3900 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3901 | break; |
| 3902 | |
| 3903 | default: |
| 3904 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3905 | << " to " << result_type; |
| 3906 | } |
| 3907 | break; |
| 3908 | |
| 3909 | case Primitive::kPrimInt: |
| 3910 | switch (input_type) { |
| 3911 | case Primitive::kPrimLong: |
| 3912 | // Processing a Dex `long-to-int' instruction. |
| 3913 | locations->SetInAt(0, Location::Any()); |
| 3914 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3915 | break; |
| 3916 | |
| 3917 | case Primitive::kPrimFloat: |
| 3918 | // Processing a Dex `float-to-int' instruction. |
| 3919 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3920 | locations->SetOut(Location::RequiresRegister()); |
| 3921 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3922 | break; |
| 3923 | |
| 3924 | case Primitive::kPrimDouble: |
| 3925 | // Processing a Dex `double-to-int' instruction. |
| 3926 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3927 | locations->SetOut(Location::RequiresRegister()); |
| 3928 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3929 | break; |
| 3930 | |
| 3931 | default: |
| 3932 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3933 | << " to " << result_type; |
| 3934 | } |
| 3935 | break; |
| 3936 | |
| 3937 | case Primitive::kPrimLong: |
| 3938 | switch (input_type) { |
| 3939 | case Primitive::kPrimBoolean: |
| 3940 | // Boolean input is a result of code transformations. |
| 3941 | case Primitive::kPrimByte: |
| 3942 | case Primitive::kPrimShort: |
| 3943 | case Primitive::kPrimInt: |
| 3944 | case Primitive::kPrimChar: |
| 3945 | // Processing a Dex `int-to-long' instruction. |
| 3946 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3947 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3948 | break; |
| 3949 | |
| 3950 | case Primitive::kPrimFloat: { |
| 3951 | // Processing a Dex `float-to-long' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3952 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3953 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 3954 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3955 | break; |
| 3956 | } |
| 3957 | |
| 3958 | case Primitive::kPrimDouble: { |
| 3959 | // Processing a Dex `double-to-long' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3960 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3961 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0), |
| 3962 | calling_convention.GetFpuRegisterAt(1))); |
| 3963 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3964 | break; |
| 3965 | } |
| 3966 | |
| 3967 | default: |
| 3968 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3969 | << " to " << result_type; |
| 3970 | } |
| 3971 | break; |
| 3972 | |
| 3973 | case Primitive::kPrimChar: |
| 3974 | switch (input_type) { |
| 3975 | case Primitive::kPrimLong: |
| 3976 | // Type conversion from long to char is a result of code transformations. |
| 3977 | case Primitive::kPrimBoolean: |
| 3978 | // Boolean input is a result of code transformations. |
| 3979 | case Primitive::kPrimByte: |
| 3980 | case Primitive::kPrimShort: |
| 3981 | case Primitive::kPrimInt: |
| 3982 | // Processing a Dex `int-to-char' instruction. |
| 3983 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3984 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3985 | break; |
| 3986 | |
| 3987 | default: |
| 3988 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3989 | << " to " << result_type; |
| 3990 | } |
| 3991 | break; |
| 3992 | |
| 3993 | case Primitive::kPrimFloat: |
| 3994 | switch (input_type) { |
| 3995 | case Primitive::kPrimBoolean: |
| 3996 | // Boolean input is a result of code transformations. |
| 3997 | case Primitive::kPrimByte: |
| 3998 | case Primitive::kPrimShort: |
| 3999 | case Primitive::kPrimInt: |
| 4000 | case Primitive::kPrimChar: |
| 4001 | // Processing a Dex `int-to-float' instruction. |
| 4002 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4003 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4004 | break; |
| 4005 | |
| 4006 | case Primitive::kPrimLong: { |
| 4007 | // Processing a Dex `long-to-float' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4008 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4009 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0), |
| 4010 | calling_convention.GetRegisterAt(1))); |
| 4011 | locations->SetOut(LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4012 | break; |
| 4013 | } |
| 4014 | |
| 4015 | case Primitive::kPrimDouble: |
| 4016 | // Processing a Dex `double-to-float' instruction. |
| 4017 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4018 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4019 | break; |
| 4020 | |
| 4021 | default: |
| 4022 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4023 | << " to " << result_type; |
| 4024 | }; |
| 4025 | break; |
| 4026 | |
| 4027 | case Primitive::kPrimDouble: |
| 4028 | switch (input_type) { |
| 4029 | case Primitive::kPrimBoolean: |
| 4030 | // Boolean input is a result of code transformations. |
| 4031 | case Primitive::kPrimByte: |
| 4032 | case Primitive::kPrimShort: |
| 4033 | case Primitive::kPrimInt: |
| 4034 | case Primitive::kPrimChar: |
| 4035 | // Processing a Dex `int-to-double' instruction. |
| 4036 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4037 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4038 | break; |
| 4039 | |
| 4040 | case Primitive::kPrimLong: |
| 4041 | // Processing a Dex `long-to-double' instruction. |
| 4042 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4043 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4044 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4045 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4046 | break; |
| 4047 | |
| 4048 | case Primitive::kPrimFloat: |
| 4049 | // Processing a Dex `float-to-double' instruction. |
| 4050 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4051 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4052 | break; |
| 4053 | |
| 4054 | default: |
| 4055 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4056 | << " to " << result_type; |
| 4057 | }; |
| 4058 | break; |
| 4059 | |
| 4060 | default: |
| 4061 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4062 | << " to " << result_type; |
| 4063 | } |
| 4064 | } |
| 4065 | |
| 4066 | void InstructionCodeGeneratorARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
| 4067 | LocationSummary* locations = conversion->GetLocations(); |
| 4068 | Location out = locations->Out(); |
| 4069 | Location in = locations->InAt(0); |
| 4070 | Primitive::Type result_type = conversion->GetResultType(); |
| 4071 | Primitive::Type input_type = conversion->GetInputType(); |
| 4072 | DCHECK_NE(result_type, input_type); |
| 4073 | switch (result_type) { |
| 4074 | case Primitive::kPrimByte: |
| 4075 | switch (input_type) { |
| 4076 | case Primitive::kPrimLong: |
| 4077 | // Type conversion from long to byte is a result of code transformations. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4078 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 8); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4079 | break; |
| 4080 | case Primitive::kPrimBoolean: |
| 4081 | // Boolean input is a result of code transformations. |
| 4082 | case Primitive::kPrimShort: |
| 4083 | case Primitive::kPrimInt: |
| 4084 | case Primitive::kPrimChar: |
| 4085 | // Processing a Dex `int-to-byte' instruction. |
| 4086 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 8); |
| 4087 | break; |
| 4088 | |
| 4089 | default: |
| 4090 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4091 | << " to " << result_type; |
| 4092 | } |
| 4093 | break; |
| 4094 | |
| 4095 | case Primitive::kPrimShort: |
| 4096 | switch (input_type) { |
| 4097 | case Primitive::kPrimLong: |
| 4098 | // Type conversion from long to short is a result of code transformations. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4099 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4100 | break; |
| 4101 | case Primitive::kPrimBoolean: |
| 4102 | // Boolean input is a result of code transformations. |
| 4103 | case Primitive::kPrimByte: |
| 4104 | case Primitive::kPrimInt: |
| 4105 | case Primitive::kPrimChar: |
| 4106 | // Processing a Dex `int-to-short' instruction. |
| 4107 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 4108 | break; |
| 4109 | |
| 4110 | default: |
| 4111 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4112 | << " to " << result_type; |
| 4113 | } |
| 4114 | break; |
| 4115 | |
| 4116 | case Primitive::kPrimInt: |
| 4117 | switch (input_type) { |
| 4118 | case Primitive::kPrimLong: |
| 4119 | // Processing a Dex `long-to-int' instruction. |
| 4120 | DCHECK(out.IsRegister()); |
| 4121 | if (in.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4122 | __ Mov(OutputRegister(conversion), LowRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4123 | } else if (in.IsDoubleStackSlot()) { |
| 4124 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 4125 | OutputRegister(conversion), |
| 4126 | sp, |
| 4127 | in.GetStackIndex()); |
| 4128 | } else { |
| 4129 | DCHECK(in.IsConstant()); |
| 4130 | DCHECK(in.GetConstant()->IsLongConstant()); |
Vladimir Marko | ba1a48e | 2017-04-13 11:50:14 +0100 | [diff] [blame] | 4131 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 4132 | __ Mov(OutputRegister(conversion), static_cast<int32_t>(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4133 | } |
| 4134 | break; |
| 4135 | |
| 4136 | case Primitive::kPrimFloat: { |
| 4137 | // Processing a Dex `float-to-int' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4138 | vixl32::SRegister temp = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4139 | __ Vcvt(S32, F32, temp, InputSRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4140 | __ Vmov(OutputRegister(conversion), temp); |
| 4141 | break; |
| 4142 | } |
| 4143 | |
| 4144 | case Primitive::kPrimDouble: { |
| 4145 | // Processing a Dex `double-to-int' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4146 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4147 | __ Vcvt(S32, F64, temp_s, DRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4148 | __ Vmov(OutputRegister(conversion), temp_s); |
| 4149 | break; |
| 4150 | } |
| 4151 | |
| 4152 | default: |
| 4153 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4154 | << " to " << result_type; |
| 4155 | } |
| 4156 | break; |
| 4157 | |
| 4158 | case Primitive::kPrimLong: |
| 4159 | switch (input_type) { |
| 4160 | case Primitive::kPrimBoolean: |
| 4161 | // Boolean input is a result of code transformations. |
| 4162 | case Primitive::kPrimByte: |
| 4163 | case Primitive::kPrimShort: |
| 4164 | case Primitive::kPrimInt: |
| 4165 | case Primitive::kPrimChar: |
| 4166 | // Processing a Dex `int-to-long' instruction. |
| 4167 | DCHECK(out.IsRegisterPair()); |
| 4168 | DCHECK(in.IsRegister()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4169 | __ Mov(LowRegisterFrom(out), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4170 | // Sign extension. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4171 | __ Asr(HighRegisterFrom(out), LowRegisterFrom(out), 31); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4172 | break; |
| 4173 | |
| 4174 | case Primitive::kPrimFloat: |
| 4175 | // Processing a Dex `float-to-long' instruction. |
| 4176 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
| 4177 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 4178 | break; |
| 4179 | |
| 4180 | case Primitive::kPrimDouble: |
| 4181 | // Processing a Dex `double-to-long' instruction. |
| 4182 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
| 4183 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 4184 | break; |
| 4185 | |
| 4186 | default: |
| 4187 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4188 | << " to " << result_type; |
| 4189 | } |
| 4190 | break; |
| 4191 | |
| 4192 | case Primitive::kPrimChar: |
| 4193 | switch (input_type) { |
| 4194 | case Primitive::kPrimLong: |
| 4195 | // Type conversion from long to char is a result of code transformations. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4196 | __ Ubfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4197 | break; |
| 4198 | case Primitive::kPrimBoolean: |
| 4199 | // Boolean input is a result of code transformations. |
| 4200 | case Primitive::kPrimByte: |
| 4201 | case Primitive::kPrimShort: |
| 4202 | case Primitive::kPrimInt: |
| 4203 | // Processing a Dex `int-to-char' instruction. |
| 4204 | __ Ubfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 4205 | break; |
| 4206 | |
| 4207 | default: |
| 4208 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4209 | << " to " << result_type; |
| 4210 | } |
| 4211 | break; |
| 4212 | |
| 4213 | case Primitive::kPrimFloat: |
| 4214 | switch (input_type) { |
| 4215 | case Primitive::kPrimBoolean: |
| 4216 | // Boolean input is a result of code transformations. |
| 4217 | case Primitive::kPrimByte: |
| 4218 | case Primitive::kPrimShort: |
| 4219 | case Primitive::kPrimInt: |
| 4220 | case Primitive::kPrimChar: { |
| 4221 | // Processing a Dex `int-to-float' instruction. |
| 4222 | __ Vmov(OutputSRegister(conversion), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4223 | __ Vcvt(F32, S32, OutputSRegister(conversion), OutputSRegister(conversion)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4224 | break; |
| 4225 | } |
| 4226 | |
| 4227 | case Primitive::kPrimLong: |
| 4228 | // Processing a Dex `long-to-float' instruction. |
| 4229 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
| 4230 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 4231 | break; |
| 4232 | |
| 4233 | case Primitive::kPrimDouble: |
| 4234 | // Processing a Dex `double-to-float' instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4235 | __ Vcvt(F32, F64, OutputSRegister(conversion), DRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4236 | break; |
| 4237 | |
| 4238 | default: |
| 4239 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4240 | << " to " << result_type; |
| 4241 | }; |
| 4242 | break; |
| 4243 | |
| 4244 | case Primitive::kPrimDouble: |
| 4245 | switch (input_type) { |
| 4246 | case Primitive::kPrimBoolean: |
| 4247 | // Boolean input is a result of code transformations. |
| 4248 | case Primitive::kPrimByte: |
| 4249 | case Primitive::kPrimShort: |
| 4250 | case Primitive::kPrimInt: |
| 4251 | case Primitive::kPrimChar: { |
| 4252 | // Processing a Dex `int-to-double' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4253 | __ Vmov(LowSRegisterFrom(out), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4254 | __ Vcvt(F64, S32, DRegisterFrom(out), LowSRegisterFrom(out)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4255 | break; |
| 4256 | } |
| 4257 | |
| 4258 | case Primitive::kPrimLong: { |
| 4259 | // Processing a Dex `long-to-double' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4260 | vixl32::Register low = LowRegisterFrom(in); |
| 4261 | vixl32::Register high = HighRegisterFrom(in); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4262 | vixl32::SRegister out_s = LowSRegisterFrom(out); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4263 | vixl32::DRegister out_d = DRegisterFrom(out); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4264 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4265 | vixl32::DRegister temp_d = DRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4266 | vixl32::DRegister constant_d = DRegisterFrom(locations->GetTemp(1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4267 | |
| 4268 | // temp_d = int-to-double(high) |
| 4269 | __ Vmov(temp_s, high); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 4270 | __ Vcvt(F64, S32, temp_d, temp_s); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4271 | // constant_d = k2Pow32EncodingForDouble |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4272 | __ Vmov(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4273 | // out_d = unsigned-to-double(low) |
| 4274 | __ Vmov(out_s, low); |
| 4275 | __ Vcvt(F64, U32, out_d, out_s); |
| 4276 | // out_d += temp_d * constant_d |
| 4277 | __ Vmla(F64, out_d, temp_d, constant_d); |
| 4278 | break; |
| 4279 | } |
| 4280 | |
| 4281 | case Primitive::kPrimFloat: |
| 4282 | // Processing a Dex `float-to-double' instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4283 | __ Vcvt(F64, F32, DRegisterFrom(out), InputSRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4284 | break; |
| 4285 | |
| 4286 | default: |
| 4287 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4288 | << " to " << result_type; |
| 4289 | }; |
| 4290 | break; |
| 4291 | |
| 4292 | default: |
| 4293 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4294 | << " to " << result_type; |
| 4295 | } |
| 4296 | } |
| 4297 | |
| 4298 | void LocationsBuilderARMVIXL::VisitAdd(HAdd* add) { |
| 4299 | LocationSummary* locations = |
| 4300 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
| 4301 | switch (add->GetResultType()) { |
| 4302 | case Primitive::kPrimInt: { |
| 4303 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4304 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 4305 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4306 | break; |
| 4307 | } |
| 4308 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4309 | case Primitive::kPrimLong: { |
| 4310 | locations->SetInAt(0, Location::RequiresRegister()); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4311 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4312 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4313 | break; |
| 4314 | } |
| 4315 | |
| 4316 | case Primitive::kPrimFloat: |
| 4317 | case Primitive::kPrimDouble: { |
| 4318 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4319 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4320 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4321 | break; |
| 4322 | } |
| 4323 | |
| 4324 | default: |
| 4325 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 4326 | } |
| 4327 | } |
| 4328 | |
| 4329 | void InstructionCodeGeneratorARMVIXL::VisitAdd(HAdd* add) { |
| 4330 | LocationSummary* locations = add->GetLocations(); |
| 4331 | Location out = locations->Out(); |
| 4332 | Location first = locations->InAt(0); |
| 4333 | Location second = locations->InAt(1); |
| 4334 | |
| 4335 | switch (add->GetResultType()) { |
| 4336 | case Primitive::kPrimInt: { |
| 4337 | __ Add(OutputRegister(add), InputRegisterAt(add, 0), InputOperandAt(add, 1)); |
| 4338 | } |
| 4339 | break; |
| 4340 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4341 | case Primitive::kPrimLong: { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4342 | if (second.IsConstant()) { |
| 4343 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 4344 | GenerateAddLongConst(out, first, value); |
| 4345 | } else { |
| 4346 | DCHECK(second.IsRegisterPair()); |
| 4347 | __ Adds(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 4348 | __ Adc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 4349 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4350 | break; |
| 4351 | } |
| 4352 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4353 | case Primitive::kPrimFloat: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4354 | case Primitive::kPrimDouble: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4355 | __ Vadd(OutputVRegister(add), InputVRegisterAt(add, 0), InputVRegisterAt(add, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4356 | break; |
| 4357 | |
| 4358 | default: |
| 4359 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 4360 | } |
| 4361 | } |
| 4362 | |
| 4363 | void LocationsBuilderARMVIXL::VisitSub(HSub* sub) { |
| 4364 | LocationSummary* locations = |
| 4365 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
| 4366 | switch (sub->GetResultType()) { |
| 4367 | case Primitive::kPrimInt: { |
| 4368 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4369 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
| 4370 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4371 | break; |
| 4372 | } |
| 4373 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4374 | case Primitive::kPrimLong: { |
| 4375 | locations->SetInAt(0, Location::RequiresRegister()); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4376 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4377 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4378 | break; |
| 4379 | } |
| 4380 | case Primitive::kPrimFloat: |
| 4381 | case Primitive::kPrimDouble: { |
| 4382 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4383 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4384 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4385 | break; |
| 4386 | } |
| 4387 | default: |
| 4388 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 4389 | } |
| 4390 | } |
| 4391 | |
| 4392 | void InstructionCodeGeneratorARMVIXL::VisitSub(HSub* sub) { |
| 4393 | LocationSummary* locations = sub->GetLocations(); |
| 4394 | Location out = locations->Out(); |
| 4395 | Location first = locations->InAt(0); |
| 4396 | Location second = locations->InAt(1); |
| 4397 | switch (sub->GetResultType()) { |
| 4398 | case Primitive::kPrimInt: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4399 | __ Sub(OutputRegister(sub), InputRegisterAt(sub, 0), InputOperandAt(sub, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4400 | break; |
| 4401 | } |
| 4402 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4403 | case Primitive::kPrimLong: { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4404 | if (second.IsConstant()) { |
| 4405 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 4406 | GenerateAddLongConst(out, first, -value); |
| 4407 | } else { |
| 4408 | DCHECK(second.IsRegisterPair()); |
| 4409 | __ Subs(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 4410 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 4411 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4412 | break; |
| 4413 | } |
| 4414 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4415 | case Primitive::kPrimFloat: |
| 4416 | case Primitive::kPrimDouble: |
| 4417 | __ Vsub(OutputVRegister(sub), InputVRegisterAt(sub, 0), InputVRegisterAt(sub, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4418 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4419 | |
| 4420 | default: |
| 4421 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 4422 | } |
| 4423 | } |
| 4424 | |
| 4425 | void LocationsBuilderARMVIXL::VisitMul(HMul* mul) { |
| 4426 | LocationSummary* locations = |
| 4427 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 4428 | switch (mul->GetResultType()) { |
| 4429 | case Primitive::kPrimInt: |
| 4430 | case Primitive::kPrimLong: { |
| 4431 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4432 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4433 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4434 | break; |
| 4435 | } |
| 4436 | |
| 4437 | case Primitive::kPrimFloat: |
| 4438 | case Primitive::kPrimDouble: { |
| 4439 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4440 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4441 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4442 | break; |
| 4443 | } |
| 4444 | |
| 4445 | default: |
| 4446 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4447 | } |
| 4448 | } |
| 4449 | |
| 4450 | void InstructionCodeGeneratorARMVIXL::VisitMul(HMul* mul) { |
| 4451 | LocationSummary* locations = mul->GetLocations(); |
| 4452 | Location out = locations->Out(); |
| 4453 | Location first = locations->InAt(0); |
| 4454 | Location second = locations->InAt(1); |
| 4455 | switch (mul->GetResultType()) { |
| 4456 | case Primitive::kPrimInt: { |
| 4457 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 4458 | break; |
| 4459 | } |
| 4460 | case Primitive::kPrimLong: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4461 | vixl32::Register out_hi = HighRegisterFrom(out); |
| 4462 | vixl32::Register out_lo = LowRegisterFrom(out); |
| 4463 | vixl32::Register in1_hi = HighRegisterFrom(first); |
| 4464 | vixl32::Register in1_lo = LowRegisterFrom(first); |
| 4465 | vixl32::Register in2_hi = HighRegisterFrom(second); |
| 4466 | vixl32::Register in2_lo = LowRegisterFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4467 | |
| 4468 | // Extra checks to protect caused by the existence of R1_R2. |
| 4469 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 4470 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4471 | DCHECK(!out_hi.Is(in1_lo)); |
| 4472 | DCHECK(!out_hi.Is(in2_lo)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4473 | |
| 4474 | // input: in1 - 64 bits, in2 - 64 bits |
| 4475 | // output: out |
| 4476 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 4477 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 4478 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 4479 | |
| 4480 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4481 | vixl32::Register temp = temps.Acquire(); |
| 4482 | // temp <- in1.lo * in2.hi |
| 4483 | __ Mul(temp, in1_lo, in2_hi); |
| 4484 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 4485 | __ Mla(out_hi, in1_hi, in2_lo, temp); |
| 4486 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 4487 | __ Umull(out_lo, temp, in1_lo, in2_lo); |
| 4488 | // 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] | 4489 | __ Add(out_hi, out_hi, temp); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4490 | break; |
| 4491 | } |
| 4492 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4493 | case Primitive::kPrimFloat: |
| 4494 | case Primitive::kPrimDouble: |
| 4495 | __ Vmul(OutputVRegister(mul), InputVRegisterAt(mul, 0), InputVRegisterAt(mul, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4496 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4497 | |
| 4498 | default: |
| 4499 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4500 | } |
| 4501 | } |
| 4502 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4503 | void InstructionCodeGeneratorARMVIXL::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 4504 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4505 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4506 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4507 | Location second = instruction->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4508 | DCHECK(second.IsConstant()); |
| 4509 | |
| 4510 | vixl32::Register out = OutputRegister(instruction); |
| 4511 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4512 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4513 | DCHECK(imm == 1 || imm == -1); |
| 4514 | |
| 4515 | if (instruction->IsRem()) { |
| 4516 | __ Mov(out, 0); |
| 4517 | } else { |
| 4518 | if (imm == 1) { |
| 4519 | __ Mov(out, dividend); |
| 4520 | } else { |
| 4521 | __ Rsb(out, dividend, 0); |
| 4522 | } |
| 4523 | } |
| 4524 | } |
| 4525 | |
| 4526 | void InstructionCodeGeneratorARMVIXL::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 4527 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4528 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4529 | |
| 4530 | LocationSummary* locations = instruction->GetLocations(); |
| 4531 | Location second = locations->InAt(1); |
| 4532 | DCHECK(second.IsConstant()); |
| 4533 | |
| 4534 | vixl32::Register out = OutputRegister(instruction); |
| 4535 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4536 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4537 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4538 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 4539 | int ctz_imm = CTZ(abs_imm); |
| 4540 | |
| 4541 | if (ctz_imm == 1) { |
| 4542 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 4543 | } else { |
| 4544 | __ Asr(temp, dividend, 31); |
| 4545 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 4546 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4547 | __ Add(out, temp, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4548 | |
| 4549 | if (instruction->IsDiv()) { |
| 4550 | __ Asr(out, out, ctz_imm); |
| 4551 | if (imm < 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4552 | __ Rsb(out, out, 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4553 | } |
| 4554 | } else { |
| 4555 | __ Ubfx(out, out, 0, ctz_imm); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4556 | __ Sub(out, out, temp); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4557 | } |
| 4558 | } |
| 4559 | |
| 4560 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 4561 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4562 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4563 | |
| 4564 | LocationSummary* locations = instruction->GetLocations(); |
| 4565 | Location second = locations->InAt(1); |
| 4566 | DCHECK(second.IsConstant()); |
| 4567 | |
| 4568 | vixl32::Register out = OutputRegister(instruction); |
| 4569 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4570 | vixl32::Register temp1 = RegisterFrom(locations->GetTemp(0)); |
| 4571 | vixl32::Register temp2 = RegisterFrom(locations->GetTemp(1)); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4572 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4573 | |
| 4574 | int64_t magic; |
| 4575 | int shift; |
| 4576 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 4577 | |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4578 | // TODO(VIXL): Change the static cast to Operand::From() after VIXL is fixed. |
| 4579 | __ Mov(temp1, static_cast<int32_t>(magic)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4580 | __ Smull(temp2, temp1, dividend, temp1); |
| 4581 | |
| 4582 | if (imm > 0 && magic < 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4583 | __ Add(temp1, temp1, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4584 | } else if (imm < 0 && magic > 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4585 | __ Sub(temp1, temp1, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4586 | } |
| 4587 | |
| 4588 | if (shift != 0) { |
| 4589 | __ Asr(temp1, temp1, shift); |
| 4590 | } |
| 4591 | |
| 4592 | if (instruction->IsDiv()) { |
| 4593 | __ Sub(out, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 4594 | } else { |
| 4595 | __ Sub(temp1, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 4596 | // TODO: Strength reduction for mls. |
| 4597 | __ Mov(temp2, imm); |
| 4598 | __ Mls(out, temp1, temp2, dividend); |
| 4599 | } |
| 4600 | } |
| 4601 | |
| 4602 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemConstantIntegral( |
| 4603 | HBinaryOperation* instruction) { |
| 4604 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4605 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4606 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4607 | Location second = instruction->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4608 | DCHECK(second.IsConstant()); |
| 4609 | |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4610 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4611 | if (imm == 0) { |
| 4612 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4613 | } else if (imm == 1 || imm == -1) { |
| 4614 | DivRemOneOrMinusOne(instruction); |
| 4615 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 4616 | DivRemByPowerOfTwo(instruction); |
| 4617 | } else { |
| 4618 | DCHECK(imm <= -2 || imm >= 2); |
| 4619 | GenerateDivRemWithAnyConstant(instruction); |
| 4620 | } |
| 4621 | } |
| 4622 | |
| 4623 | void LocationsBuilderARMVIXL::VisitDiv(HDiv* div) { |
| 4624 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4625 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 4626 | // pLdiv runtime call. |
| 4627 | call_kind = LocationSummary::kCallOnMainOnly; |
| 4628 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 4629 | // sdiv will be replaced by other instruction sequence. |
| 4630 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 4631 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4632 | // pIdivmod runtime call. |
| 4633 | call_kind = LocationSummary::kCallOnMainOnly; |
| 4634 | } |
| 4635 | |
| 4636 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 4637 | |
| 4638 | switch (div->GetResultType()) { |
| 4639 | case Primitive::kPrimInt: { |
| 4640 | if (div->InputAt(1)->IsConstant()) { |
| 4641 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4642 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
| 4643 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4644 | int32_t value = Int32ConstantFrom(div->InputAt(1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4645 | if (value == 1 || value == 0 || value == -1) { |
| 4646 | // No temp register required. |
| 4647 | } else { |
| 4648 | locations->AddTemp(Location::RequiresRegister()); |
| 4649 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
| 4650 | locations->AddTemp(Location::RequiresRegister()); |
| 4651 | } |
| 4652 | } |
| 4653 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4654 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4655 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4656 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4657 | } else { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4658 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4659 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4660 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4661 | // 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] | 4662 | // we only need the former. |
| 4663 | locations->SetOut(LocationFrom(r0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4664 | } |
| 4665 | break; |
| 4666 | } |
| 4667 | case Primitive::kPrimLong: { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4668 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4669 | locations->SetInAt(0, LocationFrom( |
| 4670 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4671 | locations->SetInAt(1, LocationFrom( |
| 4672 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4673 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4674 | break; |
| 4675 | } |
| 4676 | case Primitive::kPrimFloat: |
| 4677 | case Primitive::kPrimDouble: { |
| 4678 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4679 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4680 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4681 | break; |
| 4682 | } |
| 4683 | |
| 4684 | default: |
| 4685 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4686 | } |
| 4687 | } |
| 4688 | |
| 4689 | void InstructionCodeGeneratorARMVIXL::VisitDiv(HDiv* div) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4690 | Location lhs = div->GetLocations()->InAt(0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4691 | Location rhs = div->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4692 | |
| 4693 | switch (div->GetResultType()) { |
| 4694 | case Primitive::kPrimInt: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4695 | if (rhs.IsConstant()) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4696 | GenerateDivRemConstantIntegral(div); |
| 4697 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4698 | __ Sdiv(OutputRegister(div), InputRegisterAt(div, 0), InputRegisterAt(div, 1)); |
| 4699 | } else { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4700 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4701 | DCHECK(calling_convention.GetRegisterAt(0).Is(RegisterFrom(lhs))); |
| 4702 | DCHECK(calling_convention.GetRegisterAt(1).Is(RegisterFrom(rhs))); |
| 4703 | DCHECK(r0.Is(OutputRegister(div))); |
| 4704 | |
| 4705 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
| 4706 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4707 | } |
| 4708 | break; |
| 4709 | } |
| 4710 | |
| 4711 | case Primitive::kPrimLong: { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4712 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4713 | DCHECK(calling_convention.GetRegisterAt(0).Is(LowRegisterFrom(lhs))); |
| 4714 | DCHECK(calling_convention.GetRegisterAt(1).Is(HighRegisterFrom(lhs))); |
| 4715 | DCHECK(calling_convention.GetRegisterAt(2).Is(LowRegisterFrom(rhs))); |
| 4716 | DCHECK(calling_convention.GetRegisterAt(3).Is(HighRegisterFrom(rhs))); |
| 4717 | DCHECK(LowRegisterFrom(div->GetLocations()->Out()).Is(r0)); |
| 4718 | DCHECK(HighRegisterFrom(div->GetLocations()->Out()).Is(r1)); |
| 4719 | |
| 4720 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
| 4721 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4722 | break; |
| 4723 | } |
| 4724 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4725 | case Primitive::kPrimFloat: |
| 4726 | case Primitive::kPrimDouble: |
| 4727 | __ Vdiv(OutputVRegister(div), InputVRegisterAt(div, 0), InputVRegisterAt(div, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4728 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4729 | |
| 4730 | default: |
| 4731 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4732 | } |
| 4733 | } |
| 4734 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4735 | void LocationsBuilderARMVIXL::VisitRem(HRem* rem) { |
| 4736 | Primitive::Type type = rem->GetResultType(); |
| 4737 | |
| 4738 | // Most remainders are implemented in the runtime. |
| 4739 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
| 4740 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 4741 | // sdiv will be replaced by other instruction sequence. |
| 4742 | call_kind = LocationSummary::kNoCall; |
| 4743 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 4744 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4745 | // Have hardware divide instruction for int, do it with three instructions. |
| 4746 | call_kind = LocationSummary::kNoCall; |
| 4747 | } |
| 4748 | |
| 4749 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 4750 | |
| 4751 | switch (type) { |
| 4752 | case Primitive::kPrimInt: { |
| 4753 | if (rem->InputAt(1)->IsConstant()) { |
| 4754 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4755 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
| 4756 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4757 | int32_t value = Int32ConstantFrom(rem->InputAt(1)); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4758 | if (value == 1 || value == 0 || value == -1) { |
| 4759 | // No temp register required. |
| 4760 | } else { |
| 4761 | locations->AddTemp(Location::RequiresRegister()); |
| 4762 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
| 4763 | locations->AddTemp(Location::RequiresRegister()); |
| 4764 | } |
| 4765 | } |
| 4766 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4767 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4768 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4769 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4770 | locations->AddTemp(Location::RequiresRegister()); |
| 4771 | } else { |
| 4772 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4773 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4774 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4775 | // 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] | 4776 | // we only need the latter. |
| 4777 | locations->SetOut(LocationFrom(r1)); |
| 4778 | } |
| 4779 | break; |
| 4780 | } |
| 4781 | case Primitive::kPrimLong: { |
| 4782 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4783 | locations->SetInAt(0, LocationFrom( |
| 4784 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4785 | locations->SetInAt(1, LocationFrom( |
| 4786 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4787 | // The runtime helper puts the output in R2,R3. |
| 4788 | locations->SetOut(LocationFrom(r2, r3)); |
| 4789 | break; |
| 4790 | } |
| 4791 | case Primitive::kPrimFloat: { |
| 4792 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4793 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 4794 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 4795 | locations->SetOut(LocationFrom(s0)); |
| 4796 | break; |
| 4797 | } |
| 4798 | |
| 4799 | case Primitive::kPrimDouble: { |
| 4800 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4801 | locations->SetInAt(0, LocationFrom( |
| 4802 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 4803 | locations->SetInAt(1, LocationFrom( |
| 4804 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 4805 | locations->SetOut(LocationFrom(s0, s1)); |
| 4806 | break; |
| 4807 | } |
| 4808 | |
| 4809 | default: |
| 4810 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4811 | } |
| 4812 | } |
| 4813 | |
| 4814 | void InstructionCodeGeneratorARMVIXL::VisitRem(HRem* rem) { |
| 4815 | LocationSummary* locations = rem->GetLocations(); |
| 4816 | Location second = locations->InAt(1); |
| 4817 | |
| 4818 | Primitive::Type type = rem->GetResultType(); |
| 4819 | switch (type) { |
| 4820 | case Primitive::kPrimInt: { |
| 4821 | vixl32::Register reg1 = InputRegisterAt(rem, 0); |
| 4822 | vixl32::Register out_reg = OutputRegister(rem); |
| 4823 | if (second.IsConstant()) { |
| 4824 | GenerateDivRemConstantIntegral(rem); |
| 4825 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4826 | vixl32::Register reg2 = RegisterFrom(second); |
| 4827 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 4828 | |
| 4829 | // temp = reg1 / reg2 (integer division) |
| 4830 | // dest = reg1 - temp * reg2 |
| 4831 | __ Sdiv(temp, reg1, reg2); |
| 4832 | __ Mls(out_reg, temp, reg2, reg1); |
| 4833 | } else { |
| 4834 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4835 | DCHECK(reg1.Is(calling_convention.GetRegisterAt(0))); |
| 4836 | DCHECK(RegisterFrom(second).Is(calling_convention.GetRegisterAt(1))); |
| 4837 | DCHECK(out_reg.Is(r1)); |
| 4838 | |
| 4839 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
| 4840 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
| 4841 | } |
| 4842 | break; |
| 4843 | } |
| 4844 | |
| 4845 | case Primitive::kPrimLong: { |
| 4846 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
| 4847 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 4848 | break; |
| 4849 | } |
| 4850 | |
| 4851 | case Primitive::kPrimFloat: { |
| 4852 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
| 4853 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 4854 | break; |
| 4855 | } |
| 4856 | |
| 4857 | case Primitive::kPrimDouble: { |
| 4858 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
| 4859 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 4860 | break; |
| 4861 | } |
| 4862 | |
| 4863 | default: |
| 4864 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4865 | } |
| 4866 | } |
| 4867 | |
| 4868 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4869 | void LocationsBuilderARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 4870 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4871 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4872 | } |
| 4873 | |
| 4874 | void InstructionCodeGeneratorARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 4875 | DivZeroCheckSlowPathARMVIXL* slow_path = |
| 4876 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARMVIXL(instruction); |
| 4877 | codegen_->AddSlowPath(slow_path); |
| 4878 | |
| 4879 | LocationSummary* locations = instruction->GetLocations(); |
| 4880 | Location value = locations->InAt(0); |
| 4881 | |
| 4882 | switch (instruction->GetType()) { |
| 4883 | case Primitive::kPrimBoolean: |
| 4884 | case Primitive::kPrimByte: |
| 4885 | case Primitive::kPrimChar: |
| 4886 | case Primitive::kPrimShort: |
| 4887 | case Primitive::kPrimInt: { |
| 4888 | if (value.IsRegister()) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 4889 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4890 | } else { |
| 4891 | DCHECK(value.IsConstant()) << value; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4892 | if (Int32ConstantFrom(value) == 0) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4893 | __ B(slow_path->GetEntryLabel()); |
| 4894 | } |
| 4895 | } |
| 4896 | break; |
| 4897 | } |
| 4898 | case Primitive::kPrimLong: { |
| 4899 | if (value.IsRegisterPair()) { |
| 4900 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4901 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4902 | __ Orrs(temp, LowRegisterFrom(value), HighRegisterFrom(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4903 | __ B(eq, slow_path->GetEntryLabel()); |
| 4904 | } else { |
| 4905 | DCHECK(value.IsConstant()) << value; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4906 | if (Int64ConstantFrom(value) == 0) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4907 | __ B(slow_path->GetEntryLabel()); |
| 4908 | } |
| 4909 | } |
| 4910 | break; |
| 4911 | } |
| 4912 | default: |
| 4913 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4914 | } |
| 4915 | } |
| 4916 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4917 | void InstructionCodeGeneratorARMVIXL::HandleIntegerRotate(HRor* ror) { |
| 4918 | LocationSummary* locations = ror->GetLocations(); |
| 4919 | vixl32::Register in = InputRegisterAt(ror, 0); |
| 4920 | Location rhs = locations->InAt(1); |
| 4921 | vixl32::Register out = OutputRegister(ror); |
| 4922 | |
| 4923 | if (rhs.IsConstant()) { |
| 4924 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 4925 | // so map all rotations to a +ve. equivalent in that range. |
| 4926 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 4927 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 4928 | if (rot) { |
| 4929 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 4930 | // (e.g. left by 2 bits == right by 30.) |
| 4931 | __ Ror(out, in, rot); |
| 4932 | } else if (!out.Is(in)) { |
| 4933 | __ Mov(out, in); |
| 4934 | } |
| 4935 | } else { |
| 4936 | __ Ror(out, in, RegisterFrom(rhs)); |
| 4937 | } |
| 4938 | } |
| 4939 | |
| 4940 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 4941 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 4942 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 4943 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 4944 | void InstructionCodeGeneratorARMVIXL::HandleLongRotate(HRor* ror) { |
| 4945 | LocationSummary* locations = ror->GetLocations(); |
| 4946 | vixl32::Register in_reg_lo = LowRegisterFrom(locations->InAt(0)); |
| 4947 | vixl32::Register in_reg_hi = HighRegisterFrom(locations->InAt(0)); |
| 4948 | Location rhs = locations->InAt(1); |
| 4949 | vixl32::Register out_reg_lo = LowRegisterFrom(locations->Out()); |
| 4950 | vixl32::Register out_reg_hi = HighRegisterFrom(locations->Out()); |
| 4951 | |
| 4952 | if (rhs.IsConstant()) { |
| 4953 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 4954 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
| 4955 | rot &= kMaxLongShiftDistance; |
| 4956 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 4957 | // logic below to a simple pair of binary orr. |
| 4958 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 4959 | if (rot >= kArmBitsPerWord) { |
| 4960 | rot -= kArmBitsPerWord; |
| 4961 | std::swap(in_reg_hi, in_reg_lo); |
| 4962 | } |
| 4963 | // Rotate, or mov to out for zero or word size rotations. |
| 4964 | if (rot != 0u) { |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4965 | __ Lsr(out_reg_hi, in_reg_hi, Operand::From(rot)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4966 | __ 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] | 4967 | __ Lsr(out_reg_lo, in_reg_lo, Operand::From(rot)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4968 | __ Orr(out_reg_lo, out_reg_lo, Operand(in_reg_hi, ShiftType::LSL, kArmBitsPerWord - rot)); |
| 4969 | } else { |
| 4970 | __ Mov(out_reg_lo, in_reg_lo); |
| 4971 | __ Mov(out_reg_hi, in_reg_hi); |
| 4972 | } |
| 4973 | } else { |
| 4974 | vixl32::Register shift_right = RegisterFrom(locations->GetTemp(0)); |
| 4975 | vixl32::Register shift_left = RegisterFrom(locations->GetTemp(1)); |
| 4976 | vixl32::Label end; |
| 4977 | vixl32::Label shift_by_32_plus_shift_right; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4978 | vixl32::Label* final_label = codegen_->GetFinalLabel(ror, &end); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4979 | |
| 4980 | __ And(shift_right, RegisterFrom(rhs), 0x1F); |
| 4981 | __ Lsrs(shift_left, RegisterFrom(rhs), 6); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 4982 | __ Rsb(LeaveFlags, shift_left, shift_right, Operand::From(kArmBitsPerWord)); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 4983 | __ B(cc, &shift_by_32_plus_shift_right, /* far_target */ false); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4984 | |
| 4985 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 4986 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 4987 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 4988 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4989 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 4990 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4991 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 4992 | __ Add(out_reg_lo, out_reg_lo, shift_left); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4993 | __ B(final_label); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4994 | |
| 4995 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 4996 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 4997 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 4998 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 4999 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 5000 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 5001 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 5002 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 5003 | __ Add(out_reg_lo, out_reg_lo, shift_right); |
| 5004 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5005 | if (end.IsReferenced()) { |
| 5006 | __ Bind(&end); |
| 5007 | } |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5008 | } |
| 5009 | } |
| 5010 | |
| 5011 | void LocationsBuilderARMVIXL::VisitRor(HRor* ror) { |
| 5012 | LocationSummary* locations = |
| 5013 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 5014 | switch (ror->GetResultType()) { |
| 5015 | case Primitive::kPrimInt: { |
| 5016 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5017 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 5018 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5019 | break; |
| 5020 | } |
| 5021 | case Primitive::kPrimLong: { |
| 5022 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5023 | if (ror->InputAt(1)->IsConstant()) { |
| 5024 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 5025 | } else { |
| 5026 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5027 | locations->AddTemp(Location::RequiresRegister()); |
| 5028 | locations->AddTemp(Location::RequiresRegister()); |
| 5029 | } |
| 5030 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5031 | break; |
| 5032 | } |
| 5033 | default: |
| 5034 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 5035 | } |
| 5036 | } |
| 5037 | |
| 5038 | void InstructionCodeGeneratorARMVIXL::VisitRor(HRor* ror) { |
| 5039 | Primitive::Type type = ror->GetResultType(); |
| 5040 | switch (type) { |
| 5041 | case Primitive::kPrimInt: { |
| 5042 | HandleIntegerRotate(ror); |
| 5043 | break; |
| 5044 | } |
| 5045 | case Primitive::kPrimLong: { |
| 5046 | HandleLongRotate(ror); |
| 5047 | break; |
| 5048 | } |
| 5049 | default: |
| 5050 | LOG(FATAL) << "Unexpected operation type " << type; |
| 5051 | UNREACHABLE(); |
| 5052 | } |
| 5053 | } |
| 5054 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5055 | void LocationsBuilderARMVIXL::HandleShift(HBinaryOperation* op) { |
| 5056 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 5057 | |
| 5058 | LocationSummary* locations = |
| 5059 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 5060 | |
| 5061 | switch (op->GetResultType()) { |
| 5062 | case Primitive::kPrimInt: { |
| 5063 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5064 | if (op->InputAt(1)->IsConstant()) { |
| 5065 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 5066 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5067 | } else { |
| 5068 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5069 | // Make the output overlap, as it will be used to hold the masked |
| 5070 | // second input. |
| 5071 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5072 | } |
| 5073 | break; |
| 5074 | } |
| 5075 | case Primitive::kPrimLong: { |
| 5076 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5077 | if (op->InputAt(1)->IsConstant()) { |
| 5078 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 5079 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 5080 | // don't clash with high registers which the register allocator currently guarantees. |
| 5081 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5082 | } else { |
| 5083 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5084 | locations->AddTemp(Location::RequiresRegister()); |
| 5085 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5086 | } |
| 5087 | break; |
| 5088 | } |
| 5089 | default: |
| 5090 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 5091 | } |
| 5092 | } |
| 5093 | |
| 5094 | void InstructionCodeGeneratorARMVIXL::HandleShift(HBinaryOperation* op) { |
| 5095 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 5096 | |
| 5097 | LocationSummary* locations = op->GetLocations(); |
| 5098 | Location out = locations->Out(); |
| 5099 | Location first = locations->InAt(0); |
| 5100 | Location second = locations->InAt(1); |
| 5101 | |
| 5102 | Primitive::Type type = op->GetResultType(); |
| 5103 | switch (type) { |
| 5104 | case Primitive::kPrimInt: { |
| 5105 | vixl32::Register out_reg = OutputRegister(op); |
| 5106 | vixl32::Register first_reg = InputRegisterAt(op, 0); |
| 5107 | if (second.IsRegister()) { |
| 5108 | vixl32::Register second_reg = RegisterFrom(second); |
| 5109 | // ARM doesn't mask the shift count so we need to do it ourselves. |
| 5110 | __ And(out_reg, second_reg, kMaxIntShiftDistance); |
| 5111 | if (op->IsShl()) { |
| 5112 | __ Lsl(out_reg, first_reg, out_reg); |
| 5113 | } else if (op->IsShr()) { |
| 5114 | __ Asr(out_reg, first_reg, out_reg); |
| 5115 | } else { |
| 5116 | __ Lsr(out_reg, first_reg, out_reg); |
| 5117 | } |
| 5118 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5119 | int32_t cst = Int32ConstantFrom(second); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5120 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
| 5121 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
| 5122 | __ Mov(out_reg, first_reg); |
| 5123 | } else if (op->IsShl()) { |
| 5124 | __ Lsl(out_reg, first_reg, shift_value); |
| 5125 | } else if (op->IsShr()) { |
| 5126 | __ Asr(out_reg, first_reg, shift_value); |
| 5127 | } else { |
| 5128 | __ Lsr(out_reg, first_reg, shift_value); |
| 5129 | } |
| 5130 | } |
| 5131 | break; |
| 5132 | } |
| 5133 | case Primitive::kPrimLong: { |
| 5134 | vixl32::Register o_h = HighRegisterFrom(out); |
| 5135 | vixl32::Register o_l = LowRegisterFrom(out); |
| 5136 | |
| 5137 | vixl32::Register high = HighRegisterFrom(first); |
| 5138 | vixl32::Register low = LowRegisterFrom(first); |
| 5139 | |
| 5140 | if (second.IsRegister()) { |
| 5141 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5142 | |
| 5143 | vixl32::Register second_reg = RegisterFrom(second); |
| 5144 | |
| 5145 | if (op->IsShl()) { |
| 5146 | __ And(o_l, second_reg, kMaxLongShiftDistance); |
| 5147 | // Shift the high part |
| 5148 | __ Lsl(o_h, high, o_l); |
| 5149 | // Shift the low part and `or` what overflew on the high part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5150 | __ Rsb(temp, o_l, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5151 | __ Lsr(temp, low, temp); |
| 5152 | __ Orr(o_h, o_h, temp); |
| 5153 | // If the shift is > 32 bits, override the high part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5154 | __ Subs(temp, o_l, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5155 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5156 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5157 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5158 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5159 | __ it(pl); |
| 5160 | __ lsl(pl, o_h, low, temp); |
| 5161 | } |
| 5162 | // Shift the low part |
| 5163 | __ Lsl(o_l, low, o_l); |
| 5164 | } else if (op->IsShr()) { |
| 5165 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 5166 | // Shift the low part |
| 5167 | __ Lsr(o_l, low, o_h); |
| 5168 | // Shift the high part and `or` what underflew on the low part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5169 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5170 | __ Lsl(temp, high, temp); |
| 5171 | __ Orr(o_l, o_l, temp); |
| 5172 | // If the shift is > 32 bits, override the low part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5173 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5174 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5175 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5176 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5177 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5178 | __ it(pl); |
| 5179 | __ asr(pl, o_l, high, temp); |
| 5180 | } |
| 5181 | // Shift the high part |
| 5182 | __ Asr(o_h, high, o_h); |
| 5183 | } else { |
| 5184 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 5185 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 5186 | __ Lsr(o_l, low, o_h); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5187 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5188 | __ Lsl(temp, high, temp); |
| 5189 | __ Orr(o_l, o_l, temp); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5190 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5191 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5192 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5193 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5194 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5195 | __ it(pl); |
| 5196 | __ lsr(pl, o_l, high, temp); |
| 5197 | } |
| 5198 | __ Lsr(o_h, high, o_h); |
| 5199 | } |
| 5200 | } else { |
| 5201 | // Register allocator doesn't create partial overlap. |
| 5202 | DCHECK(!o_l.Is(high)); |
| 5203 | DCHECK(!o_h.Is(low)); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5204 | int32_t cst = Int32ConstantFrom(second); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5205 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
| 5206 | if (shift_value > 32) { |
| 5207 | if (op->IsShl()) { |
| 5208 | __ Lsl(o_h, low, shift_value - 32); |
| 5209 | __ Mov(o_l, 0); |
| 5210 | } else if (op->IsShr()) { |
| 5211 | __ Asr(o_l, high, shift_value - 32); |
| 5212 | __ Asr(o_h, high, 31); |
| 5213 | } else { |
| 5214 | __ Lsr(o_l, high, shift_value - 32); |
| 5215 | __ Mov(o_h, 0); |
| 5216 | } |
| 5217 | } else if (shift_value == 32) { |
| 5218 | if (op->IsShl()) { |
| 5219 | __ Mov(o_h, low); |
| 5220 | __ Mov(o_l, 0); |
| 5221 | } else if (op->IsShr()) { |
| 5222 | __ Mov(o_l, high); |
| 5223 | __ Asr(o_h, high, 31); |
| 5224 | } else { |
| 5225 | __ Mov(o_l, high); |
| 5226 | __ Mov(o_h, 0); |
| 5227 | } |
| 5228 | } else if (shift_value == 1) { |
| 5229 | if (op->IsShl()) { |
| 5230 | __ Lsls(o_l, low, 1); |
| 5231 | __ Adc(o_h, high, high); |
| 5232 | } else if (op->IsShr()) { |
| 5233 | __ Asrs(o_h, high, 1); |
| 5234 | __ Rrx(o_l, low); |
| 5235 | } else { |
| 5236 | __ Lsrs(o_h, high, 1); |
| 5237 | __ Rrx(o_l, low); |
| 5238 | } |
| 5239 | } else { |
| 5240 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
| 5241 | if (op->IsShl()) { |
| 5242 | __ Lsl(o_h, high, shift_value); |
| 5243 | __ Orr(o_h, o_h, Operand(low, ShiftType::LSR, 32 - shift_value)); |
| 5244 | __ Lsl(o_l, low, shift_value); |
| 5245 | } else if (op->IsShr()) { |
| 5246 | __ Lsr(o_l, low, shift_value); |
| 5247 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 5248 | __ Asr(o_h, high, shift_value); |
| 5249 | } else { |
| 5250 | __ Lsr(o_l, low, shift_value); |
| 5251 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 5252 | __ Lsr(o_h, high, shift_value); |
| 5253 | } |
| 5254 | } |
| 5255 | } |
| 5256 | break; |
| 5257 | } |
| 5258 | default: |
| 5259 | LOG(FATAL) << "Unexpected operation type " << type; |
| 5260 | UNREACHABLE(); |
| 5261 | } |
| 5262 | } |
| 5263 | |
| 5264 | void LocationsBuilderARMVIXL::VisitShl(HShl* shl) { |
| 5265 | HandleShift(shl); |
| 5266 | } |
| 5267 | |
| 5268 | void InstructionCodeGeneratorARMVIXL::VisitShl(HShl* shl) { |
| 5269 | HandleShift(shl); |
| 5270 | } |
| 5271 | |
| 5272 | void LocationsBuilderARMVIXL::VisitShr(HShr* shr) { |
| 5273 | HandleShift(shr); |
| 5274 | } |
| 5275 | |
| 5276 | void InstructionCodeGeneratorARMVIXL::VisitShr(HShr* shr) { |
| 5277 | HandleShift(shr); |
| 5278 | } |
| 5279 | |
| 5280 | void LocationsBuilderARMVIXL::VisitUShr(HUShr* ushr) { |
| 5281 | HandleShift(ushr); |
| 5282 | } |
| 5283 | |
| 5284 | void InstructionCodeGeneratorARMVIXL::VisitUShr(HUShr* ushr) { |
| 5285 | HandleShift(ushr); |
| 5286 | } |
| 5287 | |
| 5288 | void LocationsBuilderARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
| 5289 | LocationSummary* locations = |
| 5290 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| 5291 | if (instruction->IsStringAlloc()) { |
| 5292 | locations->AddTemp(LocationFrom(kMethodRegister)); |
| 5293 | } else { |
| 5294 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 5295 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5296 | } |
| 5297 | locations->SetOut(LocationFrom(r0)); |
| 5298 | } |
| 5299 | |
| 5300 | void InstructionCodeGeneratorARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
| 5301 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5302 | // of poisoning the reference. |
| 5303 | if (instruction->IsStringAlloc()) { |
| 5304 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 5305 | vixl32::Register temp = RegisterFrom(instruction->GetLocations()->GetTemp(0)); |
| 5306 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
| 5307 | GetAssembler()->LoadFromOffset(kLoadWord, temp, tr, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 5308 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, code_offset.Int32Value()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5309 | // 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] | 5310 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5311 | vixl32::k16BitT32InstructionSizeInBytes, |
| 5312 | CodeBufferCheckScope::kExactSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5313 | __ blx(lr); |
| 5314 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5315 | } else { |
| 5316 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 5317 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5318 | } |
| 5319 | } |
| 5320 | |
| 5321 | void LocationsBuilderARMVIXL::VisitNewArray(HNewArray* instruction) { |
| 5322 | LocationSummary* locations = |
| 5323 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| 5324 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5325 | locations->SetOut(LocationFrom(r0)); |
Nicolas Geoffray | 8c7c4f1 | 2017-01-26 10:13:11 +0000 | [diff] [blame] | 5326 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5327 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5328 | } |
| 5329 | |
| 5330 | void InstructionCodeGeneratorARMVIXL::VisitNewArray(HNewArray* instruction) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5331 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5332 | // of poisoning the reference. |
Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 5333 | QuickEntrypointEnum entrypoint = |
| 5334 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 5335 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5336 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 5337 | DCHECK(!codegen_->IsLeafMethod()); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5338 | } |
| 5339 | |
| 5340 | void LocationsBuilderARMVIXL::VisitParameterValue(HParameterValue* instruction) { |
| 5341 | LocationSummary* locations = |
| 5342 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5343 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5344 | if (location.IsStackSlot()) { |
| 5345 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5346 | } else if (location.IsDoubleStackSlot()) { |
| 5347 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5348 | } |
| 5349 | locations->SetOut(location); |
| 5350 | } |
| 5351 | |
| 5352 | void InstructionCodeGeneratorARMVIXL::VisitParameterValue( |
| 5353 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 5354 | // Nothing to do, the parameter is already at its location. |
| 5355 | } |
| 5356 | |
| 5357 | void LocationsBuilderARMVIXL::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5358 | LocationSummary* locations = |
| 5359 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5360 | locations->SetOut(LocationFrom(kMethodRegister)); |
| 5361 | } |
| 5362 | |
| 5363 | void InstructionCodeGeneratorARMVIXL::VisitCurrentMethod( |
| 5364 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5365 | // Nothing to do, the method is already at its location. |
| 5366 | } |
| 5367 | |
| 5368 | void LocationsBuilderARMVIXL::VisitNot(HNot* not_) { |
| 5369 | LocationSummary* locations = |
| 5370 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
| 5371 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5372 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5373 | } |
| 5374 | |
| 5375 | void InstructionCodeGeneratorARMVIXL::VisitNot(HNot* not_) { |
| 5376 | LocationSummary* locations = not_->GetLocations(); |
| 5377 | Location out = locations->Out(); |
| 5378 | Location in = locations->InAt(0); |
| 5379 | switch (not_->GetResultType()) { |
| 5380 | case Primitive::kPrimInt: |
| 5381 | __ Mvn(OutputRegister(not_), InputRegisterAt(not_, 0)); |
| 5382 | break; |
| 5383 | |
| 5384 | case Primitive::kPrimLong: |
| 5385 | __ Mvn(LowRegisterFrom(out), LowRegisterFrom(in)); |
| 5386 | __ Mvn(HighRegisterFrom(out), HighRegisterFrom(in)); |
| 5387 | break; |
| 5388 | |
| 5389 | default: |
| 5390 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 5391 | } |
| 5392 | } |
| 5393 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5394 | void LocationsBuilderARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5395 | LocationSummary* locations = |
| 5396 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 5397 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5398 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5399 | } |
| 5400 | |
| 5401 | void InstructionCodeGeneratorARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5402 | __ Eor(OutputRegister(bool_not), InputRegister(bool_not), 1); |
| 5403 | } |
| 5404 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5405 | void LocationsBuilderARMVIXL::VisitCompare(HCompare* compare) { |
| 5406 | LocationSummary* locations = |
| 5407 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| 5408 | switch (compare->InputAt(0)->GetType()) { |
| 5409 | case Primitive::kPrimBoolean: |
| 5410 | case Primitive::kPrimByte: |
| 5411 | case Primitive::kPrimShort: |
| 5412 | case Primitive::kPrimChar: |
| 5413 | case Primitive::kPrimInt: |
| 5414 | case Primitive::kPrimLong: { |
| 5415 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5416 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5417 | // Output overlaps because it is written before doing the low comparison. |
| 5418 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5419 | break; |
| 5420 | } |
| 5421 | case Primitive::kPrimFloat: |
| 5422 | case Primitive::kPrimDouble: { |
| 5423 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5424 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
| 5425 | locations->SetOut(Location::RequiresRegister()); |
| 5426 | break; |
| 5427 | } |
| 5428 | default: |
| 5429 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 5430 | } |
| 5431 | } |
| 5432 | |
| 5433 | void InstructionCodeGeneratorARMVIXL::VisitCompare(HCompare* compare) { |
| 5434 | LocationSummary* locations = compare->GetLocations(); |
| 5435 | vixl32::Register out = OutputRegister(compare); |
| 5436 | Location left = locations->InAt(0); |
| 5437 | Location right = locations->InAt(1); |
| 5438 | |
| 5439 | vixl32::Label less, greater, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5440 | vixl32::Label* final_label = codegen_->GetFinalLabel(compare, &done); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5441 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| 5442 | vixl32::Condition less_cond = vixl32::Condition(kNone); |
| 5443 | switch (type) { |
| 5444 | case Primitive::kPrimBoolean: |
| 5445 | case Primitive::kPrimByte: |
| 5446 | case Primitive::kPrimShort: |
| 5447 | case Primitive::kPrimChar: |
| 5448 | case Primitive::kPrimInt: { |
| 5449 | // Emit move to `out` before the `Cmp`, as `Mov` might affect the status flags. |
| 5450 | __ Mov(out, 0); |
| 5451 | __ Cmp(RegisterFrom(left), RegisterFrom(right)); // Signed compare. |
| 5452 | less_cond = lt; |
| 5453 | break; |
| 5454 | } |
| 5455 | case Primitive::kPrimLong: { |
| 5456 | __ Cmp(HighRegisterFrom(left), HighRegisterFrom(right)); // Signed compare. |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 5457 | __ B(lt, &less, /* far_target */ false); |
| 5458 | __ B(gt, &greater, /* far_target */ false); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5459 | // Emit move to `out` before the last `Cmp`, as `Mov` might affect the status flags. |
| 5460 | __ Mov(out, 0); |
| 5461 | __ Cmp(LowRegisterFrom(left), LowRegisterFrom(right)); // Unsigned compare. |
| 5462 | less_cond = lo; |
| 5463 | break; |
| 5464 | } |
| 5465 | case Primitive::kPrimFloat: |
| 5466 | case Primitive::kPrimDouble: { |
| 5467 | __ Mov(out, 0); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 5468 | GenerateVcmp(compare, codegen_); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5469 | // To branch on the FP compare result we transfer FPSCR to APSR (encoded as PC in VMRS). |
| 5470 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 5471 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
| 5472 | break; |
| 5473 | } |
| 5474 | default: |
| 5475 | LOG(FATAL) << "Unexpected compare type " << type; |
| 5476 | UNREACHABLE(); |
| 5477 | } |
| 5478 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5479 | __ B(eq, final_label, /* far_target */ false); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 5480 | __ B(less_cond, &less, /* far_target */ false); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5481 | |
| 5482 | __ Bind(&greater); |
| 5483 | __ Mov(out, 1); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5484 | __ B(final_label); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5485 | |
| 5486 | __ Bind(&less); |
| 5487 | __ Mov(out, -1); |
| 5488 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5489 | if (done.IsReferenced()) { |
| 5490 | __ Bind(&done); |
| 5491 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5492 | } |
| 5493 | |
| 5494 | void LocationsBuilderARMVIXL::VisitPhi(HPhi* instruction) { |
| 5495 | LocationSummary* locations = |
| 5496 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5497 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| 5498 | locations->SetInAt(i, Location::Any()); |
| 5499 | } |
| 5500 | locations->SetOut(Location::Any()); |
| 5501 | } |
| 5502 | |
| 5503 | void InstructionCodeGeneratorARMVIXL::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 5504 | LOG(FATAL) << "Unreachable"; |
| 5505 | } |
| 5506 | |
| 5507 | void CodeGeneratorARMVIXL::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 5508 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 5509 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
| 5510 | switch (kind) { |
| 5511 | case MemBarrierKind::kAnyStore: |
| 5512 | case MemBarrierKind::kLoadAny: |
| 5513 | case MemBarrierKind::kAnyAny: { |
| 5514 | flavor = DmbOptions::ISH; |
| 5515 | break; |
| 5516 | } |
| 5517 | case MemBarrierKind::kStoreStore: { |
| 5518 | flavor = DmbOptions::ISHST; |
| 5519 | break; |
| 5520 | } |
| 5521 | default: |
| 5522 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 5523 | } |
| 5524 | __ Dmb(flavor); |
| 5525 | } |
| 5526 | |
| 5527 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicLoad(vixl32::Register addr, |
| 5528 | uint32_t offset, |
| 5529 | vixl32::Register out_lo, |
| 5530 | vixl32::Register out_hi) { |
| 5531 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5532 | if (offset != 0) { |
| 5533 | vixl32::Register temp = temps.Acquire(); |
| 5534 | __ Add(temp, addr, offset); |
| 5535 | addr = temp; |
| 5536 | } |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5537 | __ Ldrexd(out_lo, out_hi, MemOperand(addr)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5538 | } |
| 5539 | |
| 5540 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicStore(vixl32::Register addr, |
| 5541 | uint32_t offset, |
| 5542 | vixl32::Register value_lo, |
| 5543 | vixl32::Register value_hi, |
| 5544 | vixl32::Register temp1, |
| 5545 | vixl32::Register temp2, |
| 5546 | HInstruction* instruction) { |
| 5547 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5548 | vixl32::Label fail; |
| 5549 | if (offset != 0) { |
| 5550 | vixl32::Register temp = temps.Acquire(); |
| 5551 | __ Add(temp, addr, offset); |
| 5552 | addr = temp; |
| 5553 | } |
| 5554 | __ Bind(&fail); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5555 | { |
| 5556 | // Ensure the pc position is recorded immediately after the `ldrexd` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5557 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5558 | vixl32::kMaxInstructionSizeInBytes, |
| 5559 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5560 | // We need a load followed by store. (The address used in a STREX instruction must |
| 5561 | // be the same as the address in the most recently executed LDREX instruction.) |
| 5562 | __ ldrexd(temp1, temp2, MemOperand(addr)); |
| 5563 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5564 | } |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5565 | __ Strexd(temp1, value_lo, value_hi, MemOperand(addr)); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5566 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5567 | } |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5568 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5569 | void LocationsBuilderARMVIXL::HandleFieldSet( |
| 5570 | HInstruction* instruction, const FieldInfo& field_info) { |
| 5571 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5572 | |
| 5573 | LocationSummary* locations = |
| 5574 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5575 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5576 | |
| 5577 | Primitive::Type field_type = field_info.GetFieldType(); |
| 5578 | if (Primitive::IsFloatingPointType(field_type)) { |
| 5579 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5580 | } else { |
| 5581 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5582 | } |
| 5583 | |
| 5584 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
| 5585 | bool generate_volatile = field_info.IsVolatile() |
| 5586 | && is_wide |
| 5587 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5588 | bool needs_write_barrier = |
| 5589 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 5590 | // Temporary registers for the write barrier. |
| 5591 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
| 5592 | if (needs_write_barrier) { |
| 5593 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
| 5594 | locations->AddTemp(Location::RequiresRegister()); |
| 5595 | } else if (generate_volatile) { |
| 5596 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 5597 | // - registers need to be consecutive |
| 5598 | // - the first register should be even but not R14. |
| 5599 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5600 | // revisit this if we ever enable ARM encoding. |
| 5601 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5602 | |
| 5603 | locations->AddTemp(Location::RequiresRegister()); |
| 5604 | locations->AddTemp(Location::RequiresRegister()); |
| 5605 | if (field_type == Primitive::kPrimDouble) { |
| 5606 | // For doubles we need two more registers to copy the value. |
| 5607 | locations->AddTemp(LocationFrom(r2)); |
| 5608 | locations->AddTemp(LocationFrom(r3)); |
| 5609 | } |
| 5610 | } |
| 5611 | } |
| 5612 | |
| 5613 | void InstructionCodeGeneratorARMVIXL::HandleFieldSet(HInstruction* instruction, |
| 5614 | const FieldInfo& field_info, |
| 5615 | bool value_can_be_null) { |
| 5616 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5617 | |
| 5618 | LocationSummary* locations = instruction->GetLocations(); |
| 5619 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 5620 | Location value = locations->InAt(1); |
| 5621 | |
| 5622 | bool is_volatile = field_info.IsVolatile(); |
| 5623 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5624 | Primitive::Type field_type = field_info.GetFieldType(); |
| 5625 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5626 | bool needs_write_barrier = |
| 5627 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 5628 | |
| 5629 | if (is_volatile) { |
| 5630 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 5631 | } |
| 5632 | |
| 5633 | switch (field_type) { |
| 5634 | case Primitive::kPrimBoolean: |
| 5635 | case Primitive::kPrimByte: { |
| 5636 | GetAssembler()->StoreToOffset(kStoreByte, RegisterFrom(value), base, offset); |
| 5637 | break; |
| 5638 | } |
| 5639 | |
| 5640 | case Primitive::kPrimShort: |
| 5641 | case Primitive::kPrimChar: { |
| 5642 | GetAssembler()->StoreToOffset(kStoreHalfword, RegisterFrom(value), base, offset); |
| 5643 | break; |
| 5644 | } |
| 5645 | |
| 5646 | case Primitive::kPrimInt: |
| 5647 | case Primitive::kPrimNot: { |
| 5648 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5649 | // Note that in the case where `value` is a null reference, |
| 5650 | // we do not enter this block, as a null reference does not |
| 5651 | // need poisoning. |
| 5652 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 5653 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5654 | __ Mov(temp, RegisterFrom(value)); |
| 5655 | GetAssembler()->PoisonHeapReference(temp); |
| 5656 | GetAssembler()->StoreToOffset(kStoreWord, temp, base, offset); |
| 5657 | } else { |
| 5658 | GetAssembler()->StoreToOffset(kStoreWord, RegisterFrom(value), base, offset); |
| 5659 | } |
| 5660 | break; |
| 5661 | } |
| 5662 | |
| 5663 | case Primitive::kPrimLong: { |
| 5664 | if (is_volatile && !atomic_ldrd_strd) { |
| 5665 | GenerateWideAtomicStore(base, |
| 5666 | offset, |
| 5667 | LowRegisterFrom(value), |
| 5668 | HighRegisterFrom(value), |
| 5669 | RegisterFrom(locations->GetTemp(0)), |
| 5670 | RegisterFrom(locations->GetTemp(1)), |
| 5671 | instruction); |
| 5672 | } else { |
| 5673 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), base, offset); |
| 5674 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5675 | } |
| 5676 | break; |
| 5677 | } |
| 5678 | |
| 5679 | case Primitive::kPrimFloat: { |
| 5680 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), base, offset); |
| 5681 | break; |
| 5682 | } |
| 5683 | |
| 5684 | case Primitive::kPrimDouble: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5685 | vixl32::DRegister value_reg = DRegisterFrom(value); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5686 | if (is_volatile && !atomic_ldrd_strd) { |
| 5687 | vixl32::Register value_reg_lo = RegisterFrom(locations->GetTemp(0)); |
| 5688 | vixl32::Register value_reg_hi = RegisterFrom(locations->GetTemp(1)); |
| 5689 | |
| 5690 | __ Vmov(value_reg_lo, value_reg_hi, value_reg); |
| 5691 | |
| 5692 | GenerateWideAtomicStore(base, |
| 5693 | offset, |
| 5694 | value_reg_lo, |
| 5695 | value_reg_hi, |
| 5696 | RegisterFrom(locations->GetTemp(2)), |
| 5697 | RegisterFrom(locations->GetTemp(3)), |
| 5698 | instruction); |
| 5699 | } else { |
| 5700 | GetAssembler()->StoreDToOffset(value_reg, base, offset); |
| 5701 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5702 | } |
| 5703 | break; |
| 5704 | } |
| 5705 | |
| 5706 | case Primitive::kPrimVoid: |
| 5707 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5708 | UNREACHABLE(); |
| 5709 | } |
| 5710 | |
| 5711 | // Longs and doubles are handled in the switch. |
| 5712 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5713 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, we |
| 5714 | // should use a scope and the assembler to emit the store instruction to guarantee that we |
| 5715 | // record the pc at the correct position. But the `Assembler` does not automatically handle |
| 5716 | // unencodable offsets. Practically, everything is fine because the helper and VIXL, at the time |
| 5717 | // of writing, do generate the store instruction last. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5718 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5719 | } |
| 5720 | |
| 5721 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5722 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5723 | vixl32::Register card = RegisterFrom(locations->GetTemp(1)); |
| 5724 | codegen_->MarkGCCard(temp, card, base, RegisterFrom(value), value_can_be_null); |
| 5725 | } |
| 5726 | |
| 5727 | if (is_volatile) { |
| 5728 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 5729 | } |
| 5730 | } |
| 5731 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5732 | void LocationsBuilderARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 5733 | const FieldInfo& field_info) { |
| 5734 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 5735 | |
| 5736 | bool object_field_get_with_read_barrier = |
| 5737 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
| 5738 | LocationSummary* locations = |
| 5739 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5740 | object_field_get_with_read_barrier ? |
| 5741 | LocationSummary::kCallOnSlowPath : |
| 5742 | LocationSummary::kNoCall); |
| 5743 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5744 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 5745 | } |
| 5746 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5747 | |
| 5748 | bool volatile_for_double = field_info.IsVolatile() |
| 5749 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
| 5750 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5751 | // The output overlaps in case of volatile long: we don't want the |
| 5752 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 5753 | // object's location. Likewise, in the case of an object field get |
| 5754 | // with read barriers enabled, we do not want the load to overwrite |
| 5755 | // the object's location, as we need it to emit the read barrier. |
| 5756 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 5757 | object_field_get_with_read_barrier; |
| 5758 | |
| 5759 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5760 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5761 | } else { |
| 5762 | locations->SetOut(Location::RequiresRegister(), |
| 5763 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 5764 | } |
| 5765 | if (volatile_for_double) { |
| 5766 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 5767 | // - registers need to be consecutive |
| 5768 | // - the first register should be even but not R14. |
| 5769 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5770 | // revisit this if we ever enable ARM encoding. |
| 5771 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5772 | locations->AddTemp(Location::RequiresRegister()); |
| 5773 | locations->AddTemp(Location::RequiresRegister()); |
| 5774 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5775 | // We need a temporary register for the read barrier marking slow |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 5776 | // path in CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 5777 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 5778 | !Runtime::Current()->UseJitCompilation()) { |
| 5779 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 5780 | // loads we need a temporary only if the offset is too big. |
| 5781 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 5782 | locations->AddTemp(Location::RequiresRegister()); |
| 5783 | } |
| 5784 | // And we always need the reserved entrypoint register. |
| 5785 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 5786 | } else { |
| 5787 | locations->AddTemp(Location::RequiresRegister()); |
| 5788 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5789 | } |
| 5790 | } |
| 5791 | |
| 5792 | Location LocationsBuilderARMVIXL::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| 5793 | DCHECK(Primitive::IsFloatingPointType(input->GetType())) << input->GetType(); |
| 5794 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 5795 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 5796 | return Location::ConstantLocation(input->AsConstant()); |
| 5797 | } else { |
| 5798 | return Location::RequiresFpuRegister(); |
| 5799 | } |
| 5800 | } |
| 5801 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5802 | Location LocationsBuilderARMVIXL::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 5803 | Opcode opcode) { |
| 5804 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 5805 | if (constant->IsConstant() && |
| 5806 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 5807 | return Location::ConstantLocation(constant->AsConstant()); |
| 5808 | } |
| 5809 | return Location::RequiresRegister(); |
| 5810 | } |
| 5811 | |
| 5812 | bool LocationsBuilderARMVIXL::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 5813 | Opcode opcode) { |
| 5814 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 5815 | if (Primitive::Is64BitType(input_cst->GetType())) { |
| 5816 | Opcode high_opcode = opcode; |
| 5817 | SetCc low_set_cc = kCcDontCare; |
| 5818 | switch (opcode) { |
| 5819 | case SUB: |
| 5820 | // Flip the operation to an ADD. |
| 5821 | value = -value; |
| 5822 | opcode = ADD; |
| 5823 | FALLTHROUGH_INTENDED; |
| 5824 | case ADD: |
| 5825 | if (Low32Bits(value) == 0u) { |
| 5826 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 5827 | } |
| 5828 | high_opcode = ADC; |
| 5829 | low_set_cc = kCcSet; |
| 5830 | break; |
| 5831 | default: |
| 5832 | break; |
| 5833 | } |
| 5834 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 5835 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
| 5836 | } else { |
| 5837 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 5838 | } |
| 5839 | } |
| 5840 | |
| 5841 | // TODO(VIXL): Replace art::arm::SetCc` with `vixl32::FlagsUpdate after flags set optimization |
| 5842 | // enabled. |
| 5843 | bool LocationsBuilderARMVIXL::CanEncodeConstantAsImmediate(uint32_t value, |
| 5844 | Opcode opcode, |
| 5845 | SetCc set_cc) { |
| 5846 | ArmVIXLAssembler* assembler = codegen_->GetAssembler(); |
| 5847 | if (assembler->ShifterOperandCanHold(opcode, value, set_cc)) { |
| 5848 | return true; |
| 5849 | } |
| 5850 | Opcode neg_opcode = kNoOperand; |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5851 | uint32_t neg_value = 0; |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5852 | switch (opcode) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5853 | case AND: neg_opcode = BIC; neg_value = ~value; break; |
| 5854 | case ORR: neg_opcode = ORN; neg_value = ~value; break; |
| 5855 | case ADD: neg_opcode = SUB; neg_value = -value; break; |
| 5856 | case ADC: neg_opcode = SBC; neg_value = ~value; break; |
| 5857 | case SUB: neg_opcode = ADD; neg_value = -value; break; |
| 5858 | case SBC: neg_opcode = ADC; neg_value = ~value; break; |
| 5859 | case MOV: neg_opcode = MVN; neg_value = ~value; break; |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5860 | default: |
| 5861 | return false; |
| 5862 | } |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5863 | |
| 5864 | if (assembler->ShifterOperandCanHold(neg_opcode, neg_value, set_cc)) { |
| 5865 | return true; |
| 5866 | } |
| 5867 | |
| 5868 | return opcode == AND && IsPowerOfTwo(value + 1); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5869 | } |
| 5870 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5871 | void InstructionCodeGeneratorARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 5872 | const FieldInfo& field_info) { |
| 5873 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 5874 | |
| 5875 | LocationSummary* locations = instruction->GetLocations(); |
| 5876 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 5877 | Location out = locations->Out(); |
| 5878 | bool is_volatile = field_info.IsVolatile(); |
| 5879 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5880 | Primitive::Type field_type = field_info.GetFieldType(); |
| 5881 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5882 | |
| 5883 | switch (field_type) { |
| 5884 | case Primitive::kPrimBoolean: |
| 5885 | GetAssembler()->LoadFromOffset(kLoadUnsignedByte, RegisterFrom(out), base, offset); |
| 5886 | break; |
| 5887 | |
| 5888 | case Primitive::kPrimByte: |
| 5889 | GetAssembler()->LoadFromOffset(kLoadSignedByte, RegisterFrom(out), base, offset); |
| 5890 | break; |
| 5891 | |
| 5892 | case Primitive::kPrimShort: |
| 5893 | GetAssembler()->LoadFromOffset(kLoadSignedHalfword, RegisterFrom(out), base, offset); |
| 5894 | break; |
| 5895 | |
| 5896 | case Primitive::kPrimChar: |
| 5897 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, RegisterFrom(out), base, offset); |
| 5898 | break; |
| 5899 | |
| 5900 | case Primitive::kPrimInt: |
| 5901 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(out), base, offset); |
| 5902 | break; |
| 5903 | |
| 5904 | case Primitive::kPrimNot: { |
| 5905 | // /* HeapReference<Object> */ out = *(base + offset) |
| 5906 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5907 | Location temp_loc = locations->GetTemp(0); |
| 5908 | // Note that a potential implicit null check is handled in this |
| 5909 | // CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier call. |
| 5910 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 5911 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 5912 | if (is_volatile) { |
| 5913 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5914 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5915 | } else { |
| 5916 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(out), base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5917 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5918 | if (is_volatile) { |
| 5919 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5920 | } |
| 5921 | // If read barriers are enabled, emit read barriers other than |
| 5922 | // Baker's using a slow path (and also unpoison the loaded |
| 5923 | // reference, if heap poisoning is enabled). |
| 5924 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, locations->InAt(0), offset); |
| 5925 | } |
| 5926 | break; |
| 5927 | } |
| 5928 | |
| 5929 | case Primitive::kPrimLong: |
| 5930 | if (is_volatile && !atomic_ldrd_strd) { |
| 5931 | GenerateWideAtomicLoad(base, offset, LowRegisterFrom(out), HighRegisterFrom(out)); |
| 5932 | } else { |
| 5933 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out), base, offset); |
| 5934 | } |
| 5935 | break; |
| 5936 | |
| 5937 | case Primitive::kPrimFloat: |
| 5938 | GetAssembler()->LoadSFromOffset(SRegisterFrom(out), base, offset); |
| 5939 | break; |
| 5940 | |
| 5941 | case Primitive::kPrimDouble: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5942 | vixl32::DRegister out_dreg = DRegisterFrom(out); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5943 | if (is_volatile && !atomic_ldrd_strd) { |
| 5944 | vixl32::Register lo = RegisterFrom(locations->GetTemp(0)); |
| 5945 | vixl32::Register hi = RegisterFrom(locations->GetTemp(1)); |
| 5946 | GenerateWideAtomicLoad(base, offset, lo, hi); |
| 5947 | // TODO(VIXL): Do we need to be immediately after the ldrexd instruction? If so we need a |
| 5948 | // scope. |
| 5949 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5950 | __ Vmov(out_dreg, lo, hi); |
| 5951 | } else { |
| 5952 | GetAssembler()->LoadDFromOffset(out_dreg, base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5953 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5954 | } |
| 5955 | break; |
| 5956 | } |
| 5957 | |
| 5958 | case Primitive::kPrimVoid: |
| 5959 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5960 | UNREACHABLE(); |
| 5961 | } |
| 5962 | |
| 5963 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 5964 | // Potential implicit null checks, in the case of reference or |
| 5965 | // double fields, are handled in the previous switch statement. |
| 5966 | } else { |
| 5967 | // 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] | 5968 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, we |
| 5969 | // should use a scope and the assembler to emit the load instruction to guarantee that we |
| 5970 | // record the pc at the correct position. But the `Assembler` does not automatically handle |
| 5971 | // unencodable offsets. Practically, everything is fine because the helper and VIXL, at the time |
| 5972 | // of writing, do generate the store instruction last. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5973 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5974 | } |
| 5975 | |
| 5976 | if (is_volatile) { |
| 5977 | if (field_type == Primitive::kPrimNot) { |
| 5978 | // Memory barriers, in the case of references, are also handled |
| 5979 | // in the previous switch statement. |
| 5980 | } else { |
| 5981 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5982 | } |
| 5983 | } |
| 5984 | } |
| 5985 | |
| 5986 | void LocationsBuilderARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5987 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5988 | } |
| 5989 | |
| 5990 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5991 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 5992 | } |
| 5993 | |
| 5994 | void LocationsBuilderARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5995 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5996 | } |
| 5997 | |
| 5998 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5999 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6000 | } |
| 6001 | |
| 6002 | void LocationsBuilderARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6003 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6004 | } |
| 6005 | |
| 6006 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6007 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6008 | } |
| 6009 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6010 | void LocationsBuilderARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 6011 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6012 | } |
| 6013 | |
| 6014 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 6015 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 6016 | } |
| 6017 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6018 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 6019 | HUnresolvedInstanceFieldGet* instruction) { |
| 6020 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6021 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6022 | instruction, instruction->GetFieldType(), calling_convention); |
| 6023 | } |
| 6024 | |
| 6025 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 6026 | HUnresolvedInstanceFieldGet* instruction) { |
| 6027 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6028 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6029 | instruction->GetFieldType(), |
| 6030 | instruction->GetFieldIndex(), |
| 6031 | instruction->GetDexPc(), |
| 6032 | calling_convention); |
| 6033 | } |
| 6034 | |
| 6035 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 6036 | HUnresolvedInstanceFieldSet* instruction) { |
| 6037 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6038 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6039 | instruction, instruction->GetFieldType(), calling_convention); |
| 6040 | } |
| 6041 | |
| 6042 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 6043 | HUnresolvedInstanceFieldSet* instruction) { |
| 6044 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6045 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6046 | instruction->GetFieldType(), |
| 6047 | instruction->GetFieldIndex(), |
| 6048 | instruction->GetDexPc(), |
| 6049 | calling_convention); |
| 6050 | } |
| 6051 | |
| 6052 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldGet( |
| 6053 | HUnresolvedStaticFieldGet* instruction) { |
| 6054 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6055 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6056 | instruction, instruction->GetFieldType(), calling_convention); |
| 6057 | } |
| 6058 | |
| 6059 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldGet( |
| 6060 | HUnresolvedStaticFieldGet* instruction) { |
| 6061 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6062 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6063 | instruction->GetFieldType(), |
| 6064 | instruction->GetFieldIndex(), |
| 6065 | instruction->GetDexPc(), |
| 6066 | calling_convention); |
| 6067 | } |
| 6068 | |
| 6069 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldSet( |
| 6070 | HUnresolvedStaticFieldSet* instruction) { |
| 6071 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6072 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6073 | instruction, instruction->GetFieldType(), calling_convention); |
| 6074 | } |
| 6075 | |
| 6076 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldSet( |
| 6077 | HUnresolvedStaticFieldSet* instruction) { |
| 6078 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6079 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6080 | instruction->GetFieldType(), |
| 6081 | instruction->GetFieldIndex(), |
| 6082 | instruction->GetDexPc(), |
| 6083 | calling_convention); |
| 6084 | } |
| 6085 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6086 | void LocationsBuilderARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6087 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6088 | locations->SetInAt(0, Location::RequiresRegister()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6089 | } |
| 6090 | |
| 6091 | void CodeGeneratorARMVIXL::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 6092 | if (CanMoveNullCheckToUser(instruction)) { |
| 6093 | return; |
| 6094 | } |
| 6095 | |
| 6096 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6097 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6098 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6099 | vixl32::kMaxInstructionSizeInBytes, |
| 6100 | CodeBufferCheckScope::kMaximumSize); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6101 | __ ldr(temps.Acquire(), MemOperand(InputRegisterAt(instruction, 0))); |
| 6102 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 6103 | } |
| 6104 | |
| 6105 | void CodeGeneratorARMVIXL::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| 6106 | NullCheckSlowPathARMVIXL* slow_path = |
| 6107 | new (GetGraph()->GetArena()) NullCheckSlowPathARMVIXL(instruction); |
| 6108 | AddSlowPath(slow_path); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6109 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6110 | } |
| 6111 | |
| 6112 | void InstructionCodeGeneratorARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
| 6113 | codegen_->GenerateNullCheck(instruction); |
| 6114 | } |
| 6115 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6116 | static LoadOperandType GetLoadOperandType(Primitive::Type type) { |
| 6117 | switch (type) { |
| 6118 | case Primitive::kPrimNot: |
| 6119 | return kLoadWord; |
| 6120 | case Primitive::kPrimBoolean: |
| 6121 | return kLoadUnsignedByte; |
| 6122 | case Primitive::kPrimByte: |
| 6123 | return kLoadSignedByte; |
| 6124 | case Primitive::kPrimChar: |
| 6125 | return kLoadUnsignedHalfword; |
| 6126 | case Primitive::kPrimShort: |
| 6127 | return kLoadSignedHalfword; |
| 6128 | case Primitive::kPrimInt: |
| 6129 | return kLoadWord; |
| 6130 | case Primitive::kPrimLong: |
| 6131 | return kLoadWordPair; |
| 6132 | case Primitive::kPrimFloat: |
| 6133 | return kLoadSWord; |
| 6134 | case Primitive::kPrimDouble: |
| 6135 | return kLoadDWord; |
| 6136 | default: |
| 6137 | LOG(FATAL) << "Unreachable type " << type; |
| 6138 | UNREACHABLE(); |
| 6139 | } |
| 6140 | } |
| 6141 | |
| 6142 | static StoreOperandType GetStoreOperandType(Primitive::Type type) { |
| 6143 | switch (type) { |
| 6144 | case Primitive::kPrimNot: |
| 6145 | return kStoreWord; |
| 6146 | case Primitive::kPrimBoolean: |
| 6147 | case Primitive::kPrimByte: |
| 6148 | return kStoreByte; |
| 6149 | case Primitive::kPrimChar: |
| 6150 | case Primitive::kPrimShort: |
| 6151 | return kStoreHalfword; |
| 6152 | case Primitive::kPrimInt: |
| 6153 | return kStoreWord; |
| 6154 | case Primitive::kPrimLong: |
| 6155 | return kStoreWordPair; |
| 6156 | case Primitive::kPrimFloat: |
| 6157 | return kStoreSWord; |
| 6158 | case Primitive::kPrimDouble: |
| 6159 | return kStoreDWord; |
| 6160 | default: |
| 6161 | LOG(FATAL) << "Unreachable type " << type; |
| 6162 | UNREACHABLE(); |
| 6163 | } |
| 6164 | } |
| 6165 | |
| 6166 | void CodeGeneratorARMVIXL::LoadFromShiftedRegOffset(Primitive::Type type, |
| 6167 | Location out_loc, |
| 6168 | vixl32::Register base, |
| 6169 | vixl32::Register reg_index, |
| 6170 | vixl32::Condition cond) { |
| 6171 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 6172 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 6173 | |
| 6174 | switch (type) { |
| 6175 | case Primitive::kPrimByte: |
| 6176 | __ Ldrsb(cond, RegisterFrom(out_loc), mem_address); |
| 6177 | break; |
| 6178 | case Primitive::kPrimBoolean: |
| 6179 | __ Ldrb(cond, RegisterFrom(out_loc), mem_address); |
| 6180 | break; |
| 6181 | case Primitive::kPrimShort: |
| 6182 | __ Ldrsh(cond, RegisterFrom(out_loc), mem_address); |
| 6183 | break; |
| 6184 | case Primitive::kPrimChar: |
| 6185 | __ Ldrh(cond, RegisterFrom(out_loc), mem_address); |
| 6186 | break; |
| 6187 | case Primitive::kPrimNot: |
| 6188 | case Primitive::kPrimInt: |
| 6189 | __ Ldr(cond, RegisterFrom(out_loc), mem_address); |
| 6190 | break; |
| 6191 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
| 6192 | case Primitive::kPrimLong: |
| 6193 | case Primitive::kPrimFloat: |
| 6194 | case Primitive::kPrimDouble: |
| 6195 | default: |
| 6196 | LOG(FATAL) << "Unreachable type " << type; |
| 6197 | UNREACHABLE(); |
| 6198 | } |
| 6199 | } |
| 6200 | |
| 6201 | void CodeGeneratorARMVIXL::StoreToShiftedRegOffset(Primitive::Type type, |
| 6202 | Location loc, |
| 6203 | vixl32::Register base, |
| 6204 | vixl32::Register reg_index, |
| 6205 | vixl32::Condition cond) { |
| 6206 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 6207 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 6208 | |
| 6209 | switch (type) { |
| 6210 | case Primitive::kPrimByte: |
| 6211 | case Primitive::kPrimBoolean: |
| 6212 | __ Strb(cond, RegisterFrom(loc), mem_address); |
| 6213 | break; |
| 6214 | case Primitive::kPrimShort: |
| 6215 | case Primitive::kPrimChar: |
| 6216 | __ Strh(cond, RegisterFrom(loc), mem_address); |
| 6217 | break; |
| 6218 | case Primitive::kPrimNot: |
| 6219 | case Primitive::kPrimInt: |
| 6220 | __ Str(cond, RegisterFrom(loc), mem_address); |
| 6221 | break; |
| 6222 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
| 6223 | case Primitive::kPrimLong: |
| 6224 | case Primitive::kPrimFloat: |
| 6225 | case Primitive::kPrimDouble: |
| 6226 | default: |
| 6227 | LOG(FATAL) << "Unreachable type " << type; |
| 6228 | UNREACHABLE(); |
| 6229 | } |
| 6230 | } |
| 6231 | |
| 6232 | void LocationsBuilderARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
| 6233 | bool object_array_get_with_read_barrier = |
| 6234 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
| 6235 | LocationSummary* locations = |
| 6236 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 6237 | object_array_get_with_read_barrier ? |
| 6238 | LocationSummary::kCallOnSlowPath : |
| 6239 | LocationSummary::kNoCall); |
| 6240 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6241 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6242 | } |
| 6243 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6244 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 6245 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 6246 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6247 | } else { |
| 6248 | // The output overlaps in the case of an object array get with |
| 6249 | // read barriers enabled: we do not want the move to overwrite the |
| 6250 | // array's location, as we need it to emit the read barrier. |
| 6251 | locations->SetOut( |
| 6252 | Location::RequiresRegister(), |
| 6253 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 6254 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6255 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 6256 | // We need a temporary register for the read barrier marking slow |
| 6257 | // path in CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier. |
| 6258 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 6259 | !Runtime::Current()->UseJitCompilation() && |
| 6260 | instruction->GetIndex()->IsConstant()) { |
| 6261 | // Array loads with constant index are treated as field loads. |
| 6262 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 6263 | // constant index loads we need a temporary only if the offset is too big. |
| 6264 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 6265 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
| 6266 | offset += index << Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 6267 | if (offset >= kReferenceLoadMinFarOffset) { |
| 6268 | locations->AddTemp(Location::RequiresRegister()); |
| 6269 | } |
| 6270 | // And we always need the reserved entrypoint register. |
| 6271 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 6272 | } else if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 6273 | !Runtime::Current()->UseJitCompilation() && |
| 6274 | !instruction->GetIndex()->IsConstant()) { |
| 6275 | // We need a non-scratch temporary for the array data pointer. |
| 6276 | locations->AddTemp(Location::RequiresRegister()); |
| 6277 | // And we always need the reserved entrypoint register. |
| 6278 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 6279 | } else { |
| 6280 | locations->AddTemp(Location::RequiresRegister()); |
| 6281 | } |
| 6282 | } else if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 6283 | // Also need a temporary for String compression feature. |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6284 | locations->AddTemp(Location::RequiresRegister()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6285 | } |
| 6286 | } |
| 6287 | |
| 6288 | void InstructionCodeGeneratorARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6289 | LocationSummary* locations = instruction->GetLocations(); |
| 6290 | Location obj_loc = locations->InAt(0); |
| 6291 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 6292 | Location index = locations->InAt(1); |
| 6293 | Location out_loc = locations->Out(); |
| 6294 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 6295 | Primitive::Type type = instruction->GetType(); |
| 6296 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 6297 | instruction->IsStringCharAt(); |
| 6298 | HInstruction* array_instr = instruction->GetArray(); |
| 6299 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6300 | |
| 6301 | switch (type) { |
| 6302 | case Primitive::kPrimBoolean: |
| 6303 | case Primitive::kPrimByte: |
| 6304 | case Primitive::kPrimShort: |
| 6305 | case Primitive::kPrimChar: |
| 6306 | case Primitive::kPrimInt: { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6307 | vixl32::Register length; |
| 6308 | if (maybe_compressed_char_at) { |
| 6309 | length = RegisterFrom(locations->GetTemp(0)); |
| 6310 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 6311 | GetAssembler()->LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 6312 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6313 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6314 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6315 | int32_t const_index = Int32ConstantFrom(index); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6316 | if (maybe_compressed_char_at) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6317 | vixl32::Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6318 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6319 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 6320 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6321 | "Expecting 0=compressed, 1=uncompressed"); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 6322 | __ B(cs, &uncompressed_load, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6323 | GetAssembler()->LoadFromOffset(kLoadUnsignedByte, |
| 6324 | RegisterFrom(out_loc), |
| 6325 | obj, |
| 6326 | data_offset + const_index); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6327 | __ B(final_label); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6328 | __ Bind(&uncompressed_load); |
| 6329 | GetAssembler()->LoadFromOffset(GetLoadOperandType(Primitive::kPrimChar), |
| 6330 | RegisterFrom(out_loc), |
| 6331 | obj, |
| 6332 | data_offset + (const_index << 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6333 | if (done.IsReferenced()) { |
| 6334 | __ Bind(&done); |
| 6335 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6336 | } else { |
| 6337 | uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type)); |
| 6338 | |
| 6339 | LoadOperandType load_type = GetLoadOperandType(type); |
| 6340 | GetAssembler()->LoadFromOffset(load_type, RegisterFrom(out_loc), obj, full_offset); |
| 6341 | } |
| 6342 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6343 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6344 | vixl32::Register temp = temps.Acquire(); |
| 6345 | |
| 6346 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6347 | // We do not need to compute the intermediate address from the array: the |
| 6348 | // input instruction has done it already. See the comment in |
| 6349 | // `TryExtractArrayAccessAddress()`. |
| 6350 | if (kIsDebugBuild) { |
| 6351 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6352 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6353 | } |
| 6354 | temp = obj; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6355 | } else { |
| 6356 | __ Add(temp, obj, data_offset); |
| 6357 | } |
| 6358 | if (maybe_compressed_char_at) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6359 | vixl32::Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6360 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6361 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 6362 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6363 | "Expecting 0=compressed, 1=uncompressed"); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 6364 | __ B(cs, &uncompressed_load, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6365 | __ Ldrb(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 0)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6366 | __ B(final_label); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6367 | __ Bind(&uncompressed_load); |
| 6368 | __ Ldrh(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6369 | if (done.IsReferenced()) { |
| 6370 | __ Bind(&done); |
| 6371 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6372 | } else { |
| 6373 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
| 6374 | } |
| 6375 | } |
| 6376 | break; |
| 6377 | } |
| 6378 | |
| 6379 | case Primitive::kPrimNot: { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6380 | // The read barrier instrumentation of object ArrayGet |
| 6381 | // instructions does not support the HIntermediateAddress |
| 6382 | // instruction. |
| 6383 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 6384 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6385 | static_assert( |
| 6386 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6387 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 6388 | // /* HeapReference<Object> */ out = |
| 6389 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6390 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6391 | Location temp = locations->GetTemp(0); |
| 6392 | // Note that a potential implicit null check is handled in this |
| 6393 | // CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6394 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 6395 | if (index.IsConstant()) { |
| 6396 | // Array load with a constant index can be treated as a field load. |
| 6397 | data_offset += Int32ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 6398 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6399 | out_loc, |
| 6400 | obj, |
| 6401 | data_offset, |
| 6402 | locations->GetTemp(0), |
| 6403 | /* needs_null_check */ false); |
| 6404 | } else { |
| 6405 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 6406 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ false); |
| 6407 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6408 | } else { |
| 6409 | vixl32::Register out = OutputRegister(instruction); |
| 6410 | if (index.IsConstant()) { |
| 6411 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6412 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6413 | GetAssembler()->LoadFromOffset(kLoadWord, out, obj, offset); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6414 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, |
| 6415 | // we should use a scope and the assembler to emit the load instruction to guarantee that |
| 6416 | // we record the pc at the correct position. But the `Assembler` does not automatically |
| 6417 | // handle unencodable offsets. Practically, everything is fine because the helper and |
| 6418 | // VIXL, at the time of writing, do generate the store instruction last. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6419 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6420 | // If read barriers are enabled, emit read barriers other than |
| 6421 | // Baker's using a slow path (and also unpoison the loaded |
| 6422 | // reference, if heap poisoning is enabled). |
| 6423 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 6424 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6425 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6426 | vixl32::Register temp = temps.Acquire(); |
| 6427 | |
| 6428 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6429 | // We do not need to compute the intermediate address from the array: the |
| 6430 | // input instruction has done it already. See the comment in |
| 6431 | // `TryExtractArrayAccessAddress()`. |
| 6432 | if (kIsDebugBuild) { |
| 6433 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6434 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6435 | } |
| 6436 | temp = obj; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6437 | } else { |
| 6438 | __ Add(temp, obj, data_offset); |
| 6439 | } |
| 6440 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6441 | temps.Close(); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6442 | // TODO(VIXL): Use a scope to ensure that we record the pc position immediately after the |
| 6443 | // load instruction. Practically, everything is fine because the helper and VIXL, at the |
| 6444 | // time of writing, do generate the store instruction last. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6445 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6446 | // If read barriers are enabled, emit read barriers other than |
| 6447 | // Baker's using a slow path (and also unpoison the loaded |
| 6448 | // reference, if heap poisoning is enabled). |
| 6449 | codegen_->MaybeGenerateReadBarrierSlow( |
| 6450 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 6451 | } |
| 6452 | } |
| 6453 | break; |
| 6454 | } |
| 6455 | |
| 6456 | case Primitive::kPrimLong: { |
| 6457 | if (index.IsConstant()) { |
| 6458 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6459 | (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6460 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), obj, offset); |
| 6461 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6462 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6463 | vixl32::Register temp = temps.Acquire(); |
| 6464 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6465 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), temp, data_offset); |
| 6466 | } |
| 6467 | break; |
| 6468 | } |
| 6469 | |
| 6470 | case Primitive::kPrimFloat: { |
| 6471 | vixl32::SRegister out = SRegisterFrom(out_loc); |
| 6472 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6473 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6474 | GetAssembler()->LoadSFromOffset(out, obj, offset); |
| 6475 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6476 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6477 | vixl32::Register temp = temps.Acquire(); |
| 6478 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 6479 | GetAssembler()->LoadSFromOffset(out, temp, data_offset); |
| 6480 | } |
| 6481 | break; |
| 6482 | } |
| 6483 | |
| 6484 | case Primitive::kPrimDouble: { |
| 6485 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6486 | size_t offset = (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6487 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), obj, offset); |
| 6488 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6489 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6490 | vixl32::Register temp = temps.Acquire(); |
| 6491 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6492 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), temp, data_offset); |
| 6493 | } |
| 6494 | break; |
| 6495 | } |
| 6496 | |
| 6497 | case Primitive::kPrimVoid: |
| 6498 | LOG(FATAL) << "Unreachable type " << type; |
| 6499 | UNREACHABLE(); |
| 6500 | } |
| 6501 | |
| 6502 | if (type == Primitive::kPrimNot) { |
| 6503 | // Potential implicit null checks, in the case of reference |
| 6504 | // arrays, are handled in the previous switch statement. |
| 6505 | } else if (!maybe_compressed_char_at) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6506 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after |
| 6507 | // the preceding load instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6508 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6509 | } |
| 6510 | } |
| 6511 | |
| 6512 | void LocationsBuilderARMVIXL::VisitArraySet(HArraySet* instruction) { |
| 6513 | Primitive::Type value_type = instruction->GetComponentType(); |
| 6514 | |
| 6515 | bool needs_write_barrier = |
| 6516 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 6517 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 6518 | |
| 6519 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 6520 | instruction, |
| 6521 | may_need_runtime_call_for_type_check ? |
| 6522 | LocationSummary::kCallOnSlowPath : |
| 6523 | LocationSummary::kNoCall); |
| 6524 | |
| 6525 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6526 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 6527 | if (Primitive::IsFloatingPointType(value_type)) { |
| 6528 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 6529 | } else { |
| 6530 | locations->SetInAt(2, Location::RequiresRegister()); |
| 6531 | } |
| 6532 | if (needs_write_barrier) { |
| 6533 | // Temporary registers for the write barrier. |
| 6534 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 6535 | locations->AddTemp(Location::RequiresRegister()); |
| 6536 | } |
| 6537 | } |
| 6538 | |
| 6539 | void InstructionCodeGeneratorARMVIXL::VisitArraySet(HArraySet* instruction) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6540 | LocationSummary* locations = instruction->GetLocations(); |
| 6541 | vixl32::Register array = InputRegisterAt(instruction, 0); |
| 6542 | Location index = locations->InAt(1); |
| 6543 | Primitive::Type value_type = instruction->GetComponentType(); |
| 6544 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 6545 | bool needs_write_barrier = |
| 6546 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 6547 | uint32_t data_offset = |
| 6548 | mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 6549 | Location value_loc = locations->InAt(2); |
| 6550 | HInstruction* array_instr = instruction->GetArray(); |
| 6551 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6552 | |
| 6553 | switch (value_type) { |
| 6554 | case Primitive::kPrimBoolean: |
| 6555 | case Primitive::kPrimByte: |
| 6556 | case Primitive::kPrimShort: |
| 6557 | case Primitive::kPrimChar: |
| 6558 | case Primitive::kPrimInt: { |
| 6559 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6560 | int32_t const_index = Int32ConstantFrom(index); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6561 | uint32_t full_offset = |
| 6562 | data_offset + (const_index << Primitive::ComponentSizeShift(value_type)); |
| 6563 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 6564 | GetAssembler()->StoreToOffset(store_type, RegisterFrom(value_loc), array, full_offset); |
| 6565 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6566 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6567 | vixl32::Register temp = temps.Acquire(); |
| 6568 | |
| 6569 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6570 | // We do not need to compute the intermediate address from the array: the |
| 6571 | // input instruction has done it already. See the comment in |
| 6572 | // `TryExtractArrayAccessAddress()`. |
| 6573 | if (kIsDebugBuild) { |
| 6574 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6575 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6576 | } |
| 6577 | temp = array; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6578 | } else { |
| 6579 | __ Add(temp, array, data_offset); |
| 6580 | } |
| 6581 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 6582 | } |
| 6583 | break; |
| 6584 | } |
| 6585 | |
| 6586 | case Primitive::kPrimNot: { |
| 6587 | vixl32::Register value = RegisterFrom(value_loc); |
| 6588 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 6589 | // See the comment in instruction_simplifier_shared.cc. |
| 6590 | DCHECK(!has_intermediate_address); |
| 6591 | |
| 6592 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 6593 | // Just setting null. |
| 6594 | if (index.IsConstant()) { |
| 6595 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6596 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6597 | GetAssembler()->StoreToOffset(kStoreWord, value, array, offset); |
| 6598 | } else { |
| 6599 | DCHECK(index.IsRegister()) << index; |
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, array, data_offset); |
| 6603 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 6604 | } |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6605 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after the preceding |
| 6606 | // store instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6607 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6608 | DCHECK(!needs_write_barrier); |
| 6609 | DCHECK(!may_need_runtime_call_for_type_check); |
| 6610 | break; |
| 6611 | } |
| 6612 | |
| 6613 | DCHECK(needs_write_barrier); |
| 6614 | Location temp1_loc = locations->GetTemp(0); |
| 6615 | vixl32::Register temp1 = RegisterFrom(temp1_loc); |
| 6616 | Location temp2_loc = locations->GetTemp(1); |
| 6617 | vixl32::Register temp2 = RegisterFrom(temp2_loc); |
| 6618 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6619 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6620 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6621 | vixl32::Label done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6622 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6623 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 6624 | |
| 6625 | if (may_need_runtime_call_for_type_check) { |
| 6626 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARMVIXL(instruction); |
| 6627 | codegen_->AddSlowPath(slow_path); |
| 6628 | if (instruction->GetValueCanBeNull()) { |
| 6629 | vixl32::Label non_zero; |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6630 | __ CompareAndBranchIfNonZero(value, &non_zero); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6631 | if (index.IsConstant()) { |
| 6632 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6633 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6634 | GetAssembler()->StoreToOffset(kStoreWord, value, array, offset); |
| 6635 | } else { |
| 6636 | DCHECK(index.IsRegister()) << index; |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6637 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6638 | vixl32::Register temp = temps.Acquire(); |
| 6639 | __ Add(temp, array, data_offset); |
| 6640 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 6641 | } |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6642 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after the preceding |
| 6643 | // store instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6644 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6645 | __ B(final_label); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6646 | __ Bind(&non_zero); |
| 6647 | } |
| 6648 | |
| 6649 | // Note that when read barriers are enabled, the type checks |
| 6650 | // are performed without read barriers. This is fine, even in |
| 6651 | // the case where a class object is in the from-space after |
| 6652 | // the flip, as a comparison involving such a type would not |
| 6653 | // produce a false positive; it may of course produce a false |
| 6654 | // negative, in which case we would take the ArraySet slow |
| 6655 | // path. |
| 6656 | |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6657 | { |
| 6658 | // Ensure we record the pc position immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6659 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6660 | vixl32::kMaxInstructionSizeInBytes, |
| 6661 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6662 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 6663 | __ ldr(temp1, MemOperand(array, class_offset)); |
| 6664 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6665 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6666 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 6667 | |
| 6668 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 6669 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 6670 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 6671 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 6672 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 6673 | // nor `temp2`, as we are comparing two poisoned references. |
| 6674 | __ Cmp(temp1, temp2); |
| 6675 | |
| 6676 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 6677 | vixl32::Label do_put; |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 6678 | __ B(eq, &do_put, /* far_target */ false); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6679 | // If heap poisoning is enabled, the `temp1` reference has |
| 6680 | // not been unpoisoned yet; unpoison it now. |
| 6681 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 6682 | |
| 6683 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 6684 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 6685 | // If heap poisoning is enabled, no need to unpoison |
| 6686 | // `temp1`, as we are comparing against null below. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6687 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6688 | __ Bind(&do_put); |
| 6689 | } else { |
| 6690 | __ B(ne, slow_path->GetEntryLabel()); |
| 6691 | } |
| 6692 | } |
| 6693 | |
| 6694 | vixl32::Register source = value; |
| 6695 | if (kPoisonHeapReferences) { |
| 6696 | // Note that in the case where `value` is a null reference, |
| 6697 | // we do not enter this block, as a null reference does not |
| 6698 | // need poisoning. |
| 6699 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 6700 | __ Mov(temp1, value); |
| 6701 | GetAssembler()->PoisonHeapReference(temp1); |
| 6702 | source = temp1; |
| 6703 | } |
| 6704 | |
| 6705 | if (index.IsConstant()) { |
| 6706 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6707 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6708 | GetAssembler()->StoreToOffset(kStoreWord, source, array, offset); |
| 6709 | } else { |
| 6710 | DCHECK(index.IsRegister()) << index; |
| 6711 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6712 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6713 | vixl32::Register temp = temps.Acquire(); |
| 6714 | __ Add(temp, array, data_offset); |
| 6715 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6716 | LocationFrom(source), |
| 6717 | temp, |
| 6718 | RegisterFrom(index)); |
| 6719 | } |
| 6720 | |
| 6721 | if (!may_need_runtime_call_for_type_check) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6722 | // TODO(VIXL): Ensure we record the pc position immediately after the preceding store |
| 6723 | // instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6724 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6725 | } |
| 6726 | |
| 6727 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 6728 | |
| 6729 | if (done.IsReferenced()) { |
| 6730 | __ Bind(&done); |
| 6731 | } |
| 6732 | |
| 6733 | if (slow_path != nullptr) { |
| 6734 | __ Bind(slow_path->GetExitLabel()); |
| 6735 | } |
| 6736 | |
| 6737 | break; |
| 6738 | } |
| 6739 | |
| 6740 | case Primitive::kPrimLong: { |
| 6741 | Location value = locations->InAt(2); |
| 6742 | if (index.IsConstant()) { |
| 6743 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6744 | (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6745 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), array, offset); |
| 6746 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6747 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6748 | vixl32::Register temp = temps.Acquire(); |
| 6749 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6750 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), temp, data_offset); |
| 6751 | } |
| 6752 | break; |
| 6753 | } |
| 6754 | |
| 6755 | case Primitive::kPrimFloat: { |
| 6756 | Location value = locations->InAt(2); |
| 6757 | DCHECK(value.IsFpuRegister()); |
| 6758 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6759 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6760 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), array, offset); |
| 6761 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6762 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6763 | vixl32::Register temp = temps.Acquire(); |
| 6764 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 6765 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), temp, data_offset); |
| 6766 | } |
| 6767 | break; |
| 6768 | } |
| 6769 | |
| 6770 | case Primitive::kPrimDouble: { |
| 6771 | Location value = locations->InAt(2); |
| 6772 | DCHECK(value.IsFpuRegisterPair()); |
| 6773 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6774 | size_t offset = (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6775 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), array, offset); |
| 6776 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6777 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6778 | vixl32::Register temp = temps.Acquire(); |
| 6779 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6780 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), temp, data_offset); |
| 6781 | } |
| 6782 | break; |
| 6783 | } |
| 6784 | |
| 6785 | case Primitive::kPrimVoid: |
| 6786 | LOG(FATAL) << "Unreachable type " << value_type; |
| 6787 | UNREACHABLE(); |
| 6788 | } |
| 6789 | |
| 6790 | // Objects are handled in the switch. |
| 6791 | if (value_type != Primitive::kPrimNot) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6792 | // TODO(VIXL): Ensure we record the pc position immediately after the preceding store |
| 6793 | // instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6794 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6795 | } |
| 6796 | } |
| 6797 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6798 | void LocationsBuilderARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 6799 | LocationSummary* locations = |
| 6800 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6801 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6802 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6803 | } |
| 6804 | |
| 6805 | void InstructionCodeGeneratorARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 6806 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| 6807 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 6808 | vixl32::Register out = OutputRegister(instruction); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6809 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6810 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6811 | vixl32::kMaxInstructionSizeInBytes, |
| 6812 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6813 | __ ldr(out, MemOperand(obj, offset)); |
| 6814 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6815 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6816 | // Mask out compression flag from String's array length. |
| 6817 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6818 | __ Lsr(out, out, 1u); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6819 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6820 | } |
| 6821 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6822 | void LocationsBuilderARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6823 | LocationSummary* locations = |
| 6824 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6825 | |
| 6826 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6827 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 6828 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6829 | } |
| 6830 | |
| 6831 | void InstructionCodeGeneratorARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 6832 | vixl32::Register out = OutputRegister(instruction); |
| 6833 | vixl32::Register first = InputRegisterAt(instruction, 0); |
| 6834 | Location second = instruction->GetLocations()->InAt(1); |
| 6835 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6836 | if (second.IsRegister()) { |
| 6837 | __ Add(out, first, RegisterFrom(second)); |
| 6838 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6839 | __ Add(out, first, Int32ConstantFrom(second)); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6840 | } |
| 6841 | } |
| 6842 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 6843 | void LocationsBuilderARMVIXL::VisitIntermediateAddressIndex( |
| 6844 | HIntermediateAddressIndex* instruction) { |
| 6845 | LOG(FATAL) << "Unreachable " << instruction->GetId(); |
| 6846 | } |
| 6847 | |
| 6848 | void InstructionCodeGeneratorARMVIXL::VisitIntermediateAddressIndex( |
| 6849 | HIntermediateAddressIndex* instruction) { |
| 6850 | LOG(FATAL) << "Unreachable " << instruction->GetId(); |
| 6851 | } |
| 6852 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6853 | void LocationsBuilderARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 6854 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6855 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 6856 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 6857 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(1))); |
| 6858 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6859 | |
| 6860 | HInstruction* index = instruction->InputAt(0); |
| 6861 | HInstruction* length = instruction->InputAt(1); |
| 6862 | // If both index and length are constants we can statically check the bounds. But if at least one |
| 6863 | // of them is not encodable ArmEncodableConstantOrRegister will create |
| 6864 | // Location::RequiresRegister() which is not desired to happen. Instead we create constant |
| 6865 | // locations. |
| 6866 | bool both_const = index->IsConstant() && length->IsConstant(); |
| 6867 | locations->SetInAt(0, both_const |
| 6868 | ? Location::ConstantLocation(index->AsConstant()) |
| 6869 | : ArmEncodableConstantOrRegister(index, CMP)); |
| 6870 | locations->SetInAt(1, both_const |
| 6871 | ? Location::ConstantLocation(length->AsConstant()) |
| 6872 | : ArmEncodableConstantOrRegister(length, CMP)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6873 | } |
| 6874 | |
| 6875 | void InstructionCodeGeneratorARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6876 | LocationSummary* locations = instruction->GetLocations(); |
| 6877 | Location index_loc = locations->InAt(0); |
| 6878 | Location length_loc = locations->InAt(1); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6879 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6880 | if (length_loc.IsConstant()) { |
| 6881 | int32_t length = Int32ConstantFrom(length_loc); |
| 6882 | if (index_loc.IsConstant()) { |
| 6883 | // BCE will remove the bounds check if we are guaranteed to pass. |
| 6884 | int32_t index = Int32ConstantFrom(index_loc); |
| 6885 | if (index < 0 || index >= length) { |
| 6886 | SlowPathCodeARMVIXL* slow_path = |
| 6887 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARMVIXL(instruction); |
| 6888 | codegen_->AddSlowPath(slow_path); |
| 6889 | __ B(slow_path->GetEntryLabel()); |
| 6890 | } else { |
| 6891 | // Some optimization after BCE may have generated this, and we should not |
| 6892 | // generate a bounds check if it is a valid range. |
| 6893 | } |
| 6894 | return; |
| 6895 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6896 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6897 | SlowPathCodeARMVIXL* slow_path = |
| 6898 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARMVIXL(instruction); |
| 6899 | __ Cmp(RegisterFrom(index_loc), length); |
| 6900 | codegen_->AddSlowPath(slow_path); |
| 6901 | __ B(hs, slow_path->GetEntryLabel()); |
| 6902 | } else { |
| 6903 | SlowPathCodeARMVIXL* slow_path = |
| 6904 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARMVIXL(instruction); |
| 6905 | __ Cmp(RegisterFrom(length_loc), InputOperandAt(instruction, 0)); |
| 6906 | codegen_->AddSlowPath(slow_path); |
| 6907 | __ B(ls, slow_path->GetEntryLabel()); |
| 6908 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6909 | } |
| 6910 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6911 | void CodeGeneratorARMVIXL::MarkGCCard(vixl32::Register temp, |
| 6912 | vixl32::Register card, |
| 6913 | vixl32::Register object, |
| 6914 | vixl32::Register value, |
| 6915 | bool can_be_null) { |
| 6916 | vixl32::Label is_null; |
| 6917 | if (can_be_null) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6918 | __ CompareAndBranchIfZero(value, &is_null); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6919 | } |
| 6920 | GetAssembler()->LoadFromOffset( |
| 6921 | kLoadWord, card, tr, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 6922 | __ Lsr(temp, object, Operand::From(gc::accounting::CardTable::kCardShift)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6923 | __ Strb(card, MemOperand(card, temp)); |
| 6924 | if (can_be_null) { |
| 6925 | __ Bind(&is_null); |
| 6926 | } |
| 6927 | } |
| 6928 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6929 | void LocationsBuilderARMVIXL::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 6930 | LOG(FATAL) << "Unreachable"; |
| 6931 | } |
| 6932 | |
| 6933 | void InstructionCodeGeneratorARMVIXL::VisitParallelMove(HParallelMove* instruction) { |
| 6934 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6935 | } |
| 6936 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6937 | void LocationsBuilderARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6938 | LocationSummary* locations = |
| 6939 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 6940 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6941 | } |
| 6942 | |
| 6943 | void InstructionCodeGeneratorARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 6944 | HBasicBlock* block = instruction->GetBlock(); |
| 6945 | if (block->GetLoopInformation() != nullptr) { |
| 6946 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6947 | // The back edge will generate the suspend check. |
| 6948 | return; |
| 6949 | } |
| 6950 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6951 | // The goto will generate the suspend check. |
| 6952 | return; |
| 6953 | } |
| 6954 | GenerateSuspendCheck(instruction, nullptr); |
| 6955 | } |
| 6956 | |
| 6957 | void InstructionCodeGeneratorARMVIXL::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 6958 | HBasicBlock* successor) { |
| 6959 | SuspendCheckSlowPathARMVIXL* slow_path = |
| 6960 | down_cast<SuspendCheckSlowPathARMVIXL*>(instruction->GetSlowPath()); |
| 6961 | if (slow_path == nullptr) { |
| 6962 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARMVIXL(instruction, successor); |
| 6963 | instruction->SetSlowPath(slow_path); |
| 6964 | codegen_->AddSlowPath(slow_path); |
| 6965 | if (successor != nullptr) { |
| 6966 | DCHECK(successor->IsLoopHeader()); |
| 6967 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 6968 | } |
| 6969 | } else { |
| 6970 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 6971 | } |
| 6972 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6973 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6974 | vixl32::Register temp = temps.Acquire(); |
| 6975 | GetAssembler()->LoadFromOffset( |
| 6976 | kLoadUnsignedHalfword, temp, tr, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
| 6977 | if (successor == nullptr) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6978 | __ CompareAndBranchIfNonZero(temp, slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6979 | __ Bind(slow_path->GetReturnLabel()); |
| 6980 | } else { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6981 | __ CompareAndBranchIfZero(temp, codegen_->GetLabelOf(successor)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6982 | __ B(slow_path->GetEntryLabel()); |
| 6983 | } |
| 6984 | } |
| 6985 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6986 | ArmVIXLAssembler* ParallelMoveResolverARMVIXL::GetAssembler() const { |
| 6987 | return codegen_->GetAssembler(); |
| 6988 | } |
| 6989 | |
| 6990 | void ParallelMoveResolverARMVIXL::EmitMove(size_t index) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6991 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6992 | MoveOperands* move = moves_[index]; |
| 6993 | Location source = move->GetSource(); |
| 6994 | Location destination = move->GetDestination(); |
| 6995 | |
| 6996 | if (source.IsRegister()) { |
| 6997 | if (destination.IsRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6998 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6999 | } else if (destination.IsFpuRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7000 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7001 | } else { |
| 7002 | DCHECK(destination.IsStackSlot()); |
| 7003 | GetAssembler()->StoreToOffset(kStoreWord, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7004 | RegisterFrom(source), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7005 | sp, |
| 7006 | destination.GetStackIndex()); |
| 7007 | } |
| 7008 | } else if (source.IsStackSlot()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7009 | if (destination.IsRegister()) { |
| 7010 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 7011 | RegisterFrom(destination), |
| 7012 | sp, |
| 7013 | source.GetStackIndex()); |
| 7014 | } else if (destination.IsFpuRegister()) { |
| 7015 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 7016 | } else { |
| 7017 | DCHECK(destination.IsStackSlot()); |
| 7018 | vixl32::Register temp = temps.Acquire(); |
| 7019 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 7020 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 7021 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7022 | } else if (source.IsFpuRegister()) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7023 | if (destination.IsRegister()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7024 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7025 | } else if (destination.IsFpuRegister()) { |
| 7026 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 7027 | } else { |
| 7028 | DCHECK(destination.IsStackSlot()); |
| 7029 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 7030 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7031 | } else if (source.IsDoubleStackSlot()) { |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7032 | if (destination.IsDoubleStackSlot()) { |
| 7033 | vixl32::DRegister temp = temps.AcquireD(); |
| 7034 | GetAssembler()->LoadDFromOffset(temp, sp, source.GetStackIndex()); |
| 7035 | GetAssembler()->StoreDToOffset(temp, sp, destination.GetStackIndex()); |
| 7036 | } else if (destination.IsRegisterPair()) { |
| 7037 | DCHECK(ExpectedPairLayout(destination)); |
| 7038 | GetAssembler()->LoadFromOffset( |
| 7039 | kLoadWordPair, LowRegisterFrom(destination), sp, source.GetStackIndex()); |
| 7040 | } else { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7041 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 7042 | GetAssembler()->LoadDFromOffset(DRegisterFrom(destination), sp, source.GetStackIndex()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7043 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7044 | } else if (source.IsRegisterPair()) { |
| 7045 | if (destination.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7046 | __ Mov(LowRegisterFrom(destination), LowRegisterFrom(source)); |
| 7047 | __ Mov(HighRegisterFrom(destination), HighRegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7048 | } else if (destination.IsFpuRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7049 | __ Vmov(DRegisterFrom(destination), LowRegisterFrom(source), HighRegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7050 | } else { |
| 7051 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 7052 | DCHECK(ExpectedPairLayout(source)); |
| 7053 | GetAssembler()->StoreToOffset(kStoreWordPair, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7054 | LowRegisterFrom(source), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7055 | sp, |
| 7056 | destination.GetStackIndex()); |
| 7057 | } |
| 7058 | } else if (source.IsFpuRegisterPair()) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7059 | if (destination.IsRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7060 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), DRegisterFrom(source)); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7061 | } else if (destination.IsFpuRegisterPair()) { |
| 7062 | __ Vmov(DRegisterFrom(destination), DRegisterFrom(source)); |
| 7063 | } else { |
| 7064 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 7065 | GetAssembler()->StoreDToOffset(DRegisterFrom(source), sp, destination.GetStackIndex()); |
| 7066 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7067 | } else { |
| 7068 | DCHECK(source.IsConstant()) << source; |
| 7069 | HConstant* constant = source.GetConstant(); |
| 7070 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 7071 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
| 7072 | if (destination.IsRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7073 | __ Mov(RegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7074 | } else { |
| 7075 | DCHECK(destination.IsStackSlot()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7076 | vixl32::Register temp = temps.Acquire(); |
| 7077 | __ Mov(temp, value); |
| 7078 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 7079 | } |
| 7080 | } else if (constant->IsLongConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 7081 | int64_t value = Int64ConstantFrom(source); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7082 | if (destination.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7083 | __ Mov(LowRegisterFrom(destination), Low32Bits(value)); |
| 7084 | __ Mov(HighRegisterFrom(destination), High32Bits(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7085 | } else { |
| 7086 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7087 | vixl32::Register temp = temps.Acquire(); |
| 7088 | __ Mov(temp, Low32Bits(value)); |
| 7089 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 7090 | __ Mov(temp, High32Bits(value)); |
| 7091 | GetAssembler()->StoreToOffset(kStoreWord, |
| 7092 | temp, |
| 7093 | sp, |
| 7094 | destination.GetHighStackIndex(kArmWordSize)); |
| 7095 | } |
| 7096 | } else if (constant->IsDoubleConstant()) { |
| 7097 | double value = constant->AsDoubleConstant()->GetValue(); |
| 7098 | if (destination.IsFpuRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7099 | __ Vmov(DRegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7100 | } else { |
| 7101 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 7102 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7103 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7104 | __ Mov(temp, Low32Bits(int_value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7105 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7106 | __ Mov(temp, High32Bits(int_value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7107 | GetAssembler()->StoreToOffset(kStoreWord, |
| 7108 | temp, |
| 7109 | sp, |
| 7110 | destination.GetHighStackIndex(kArmWordSize)); |
| 7111 | } |
| 7112 | } else { |
| 7113 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
| 7114 | float value = constant->AsFloatConstant()->GetValue(); |
| 7115 | if (destination.IsFpuRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7116 | __ Vmov(SRegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7117 | } else { |
| 7118 | DCHECK(destination.IsStackSlot()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7119 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7120 | __ Mov(temp, bit_cast<int32_t, float>(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7121 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 7122 | } |
| 7123 | } |
| 7124 | } |
| 7125 | } |
| 7126 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7127 | void ParallelMoveResolverARMVIXL::Exchange(vixl32::Register reg, int mem) { |
| 7128 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 7129 | vixl32::Register temp = temps.Acquire(); |
| 7130 | __ Mov(temp, reg); |
| 7131 | GetAssembler()->LoadFromOffset(kLoadWord, reg, sp, mem); |
| 7132 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7133 | } |
| 7134 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7135 | void ParallelMoveResolverARMVIXL::Exchange(int mem1, int mem2) { |
| 7136 | // TODO(VIXL32): Double check the performance of this implementation. |
| 7137 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7138 | vixl32::Register temp1 = temps.Acquire(); |
| 7139 | ScratchRegisterScope ensure_scratch( |
| 7140 | this, temp1.GetCode(), r0.GetCode(), codegen_->GetNumberOfCoreRegisters()); |
| 7141 | vixl32::Register temp2(ensure_scratch.GetRegister()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7142 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7143 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 7144 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, sp, mem1 + stack_offset); |
| 7145 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, sp, mem2 + stack_offset); |
| 7146 | GetAssembler()->StoreToOffset(kStoreWord, temp1, sp, mem2 + stack_offset); |
| 7147 | GetAssembler()->StoreToOffset(kStoreWord, temp2, sp, mem1 + stack_offset); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7148 | } |
| 7149 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7150 | void ParallelMoveResolverARMVIXL::EmitSwap(size_t index) { |
| 7151 | MoveOperands* move = moves_[index]; |
| 7152 | Location source = move->GetSource(); |
| 7153 | Location destination = move->GetDestination(); |
| 7154 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 7155 | |
| 7156 | if (source.IsRegister() && destination.IsRegister()) { |
| 7157 | vixl32::Register temp = temps.Acquire(); |
| 7158 | DCHECK(!RegisterFrom(source).Is(temp)); |
| 7159 | DCHECK(!RegisterFrom(destination).Is(temp)); |
| 7160 | __ Mov(temp, RegisterFrom(destination)); |
| 7161 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 7162 | __ Mov(RegisterFrom(source), temp); |
| 7163 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| 7164 | Exchange(RegisterFrom(source), destination.GetStackIndex()); |
| 7165 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| 7166 | Exchange(RegisterFrom(destination), source.GetStackIndex()); |
| 7167 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7168 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7169 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7170 | vixl32::Register temp = temps.Acquire(); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7171 | __ Vmov(temp, SRegisterFrom(source)); |
| 7172 | __ Vmov(SRegisterFrom(source), SRegisterFrom(destination)); |
| 7173 | __ Vmov(SRegisterFrom(destination), temp); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7174 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
| 7175 | vixl32::DRegister temp = temps.AcquireD(); |
| 7176 | __ Vmov(temp, LowRegisterFrom(source), HighRegisterFrom(source)); |
| 7177 | __ Mov(LowRegisterFrom(source), LowRegisterFrom(destination)); |
| 7178 | __ Mov(HighRegisterFrom(source), HighRegisterFrom(destination)); |
| 7179 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), temp); |
| 7180 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
| 7181 | vixl32::Register low_reg = LowRegisterFrom(source.IsRegisterPair() ? source : destination); |
| 7182 | int mem = source.IsRegisterPair() ? destination.GetStackIndex() : source.GetStackIndex(); |
| 7183 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
| 7184 | vixl32::DRegister temp = temps.AcquireD(); |
| 7185 | __ Vmov(temp, low_reg, vixl32::Register(low_reg.GetCode() + 1)); |
| 7186 | GetAssembler()->LoadFromOffset(kLoadWordPair, low_reg, sp, mem); |
| 7187 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
| 7188 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7189 | vixl32::DRegister first = DRegisterFrom(source); |
| 7190 | vixl32::DRegister second = DRegisterFrom(destination); |
| 7191 | vixl32::DRegister temp = temps.AcquireD(); |
| 7192 | __ Vmov(temp, first); |
| 7193 | __ Vmov(first, second); |
| 7194 | __ Vmov(second, temp); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7195 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7196 | vixl32::DRegister reg = source.IsFpuRegisterPair() |
| 7197 | ? DRegisterFrom(source) |
| 7198 | : DRegisterFrom(destination); |
| 7199 | int mem = source.IsFpuRegisterPair() |
| 7200 | ? destination.GetStackIndex() |
| 7201 | : source.GetStackIndex(); |
| 7202 | vixl32::DRegister temp = temps.AcquireD(); |
| 7203 | __ Vmov(temp, reg); |
| 7204 | GetAssembler()->LoadDFromOffset(reg, sp, mem); |
| 7205 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7206 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7207 | vixl32::SRegister reg = source.IsFpuRegister() |
| 7208 | ? SRegisterFrom(source) |
| 7209 | : SRegisterFrom(destination); |
| 7210 | int mem = source.IsFpuRegister() |
| 7211 | ? destination.GetStackIndex() |
| 7212 | : source.GetStackIndex(); |
| 7213 | vixl32::Register temp = temps.Acquire(); |
| 7214 | __ Vmov(temp, reg); |
| 7215 | GetAssembler()->LoadSFromOffset(reg, sp, mem); |
| 7216 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7217 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 7218 | vixl32::DRegister temp1 = temps.AcquireD(); |
| 7219 | vixl32::DRegister temp2 = temps.AcquireD(); |
| 7220 | __ Vldr(temp1, MemOperand(sp, source.GetStackIndex())); |
| 7221 | __ Vldr(temp2, MemOperand(sp, destination.GetStackIndex())); |
| 7222 | __ Vstr(temp1, MemOperand(sp, destination.GetStackIndex())); |
| 7223 | __ Vstr(temp2, MemOperand(sp, source.GetStackIndex())); |
| 7224 | } else { |
| 7225 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
| 7226 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7227 | } |
| 7228 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7229 | void ParallelMoveResolverARMVIXL::SpillScratch(int reg) { |
| 7230 | __ Push(vixl32::Register(reg)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7231 | } |
| 7232 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7233 | void ParallelMoveResolverARMVIXL::RestoreScratch(int reg) { |
| 7234 | __ Pop(vixl32::Register(reg)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7235 | } |
| 7236 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7237 | HLoadClass::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadClassKind( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7238 | HLoadClass::LoadKind desired_class_load_kind) { |
| 7239 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7240 | case HLoadClass::LoadKind::kInvalid: |
| 7241 | LOG(FATAL) << "UNREACHABLE"; |
| 7242 | UNREACHABLE(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7243 | case HLoadClass::LoadKind::kReferrersClass: |
| 7244 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7245 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7246 | case HLoadClass::LoadKind::kBssEntry: |
| 7247 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 7248 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7249 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7250 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7251 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 7252 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7253 | case HLoadClass::LoadKind::kRuntimeCall: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7254 | break; |
| 7255 | } |
| 7256 | return desired_class_load_kind; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7257 | } |
| 7258 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7259 | void LocationsBuilderARMVIXL::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7260 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7261 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7262 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7263 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7264 | cls, |
| 7265 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7266 | LocationFrom(r0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7267 | DCHECK(calling_convention.GetRegisterAt(0).Is(r0)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7268 | return; |
| 7269 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7270 | DCHECK(!cls->NeedsAccessCheck()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7271 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7272 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 7273 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7274 | ? LocationSummary::kCallOnSlowPath |
| 7275 | : LocationSummary::kNoCall; |
| 7276 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7277 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7278 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7279 | } |
| 7280 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7281 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7282 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7283 | } |
| 7284 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7285 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 7286 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 7287 | // Rely on the type resolution or initialization and marking to save everything we need. |
| 7288 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 7289 | // to the custom calling convention) or by marking, so we request a different temp. |
| 7290 | locations->AddTemp(Location::RequiresRegister()); |
| 7291 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 7292 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7293 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7294 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 7295 | // that the the kPrimNot result register is the same as the first argument register. |
| 7296 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 7297 | } else { |
| 7298 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7299 | } |
| 7300 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 7301 | if (kUseBakerReadBarrier && kBakerReadBarrierLinkTimeThunksEnableForGcRoots) { |
| 7302 | if (load_kind == HLoadClass::LoadKind::kBssEntry || |
| 7303 | (load_kind == HLoadClass::LoadKind::kReferrersClass && |
| 7304 | !Runtime::Current()->UseJitCompilation())) { |
| 7305 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 7306 | } |
| 7307 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7308 | } |
| 7309 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7310 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7311 | // move. |
| 7312 | void InstructionCodeGeneratorARMVIXL::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7313 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7314 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7315 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7316 | return; |
| 7317 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7318 | DCHECK(!cls->NeedsAccessCheck()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7319 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7320 | LocationSummary* locations = cls->GetLocations(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7321 | Location out_loc = locations->Out(); |
| 7322 | vixl32::Register out = OutputRegister(cls); |
| 7323 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7324 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 7325 | ? kWithoutReadBarrier |
| 7326 | : kCompilerReadBarrierOption; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7327 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7328 | switch (load_kind) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7329 | case HLoadClass::LoadKind::kReferrersClass: { |
| 7330 | DCHECK(!cls->CanCallRuntime()); |
| 7331 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 7332 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 7333 | vixl32::Register current_method = InputRegisterAt(cls, 0); |
| 7334 | GenerateGcRootFieldLoad(cls, |
| 7335 | out_loc, |
| 7336 | current_method, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 7337 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7338 | read_barrier_option); |
| 7339 | break; |
| 7340 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7341 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7342 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7343 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 7344 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 7345 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 7346 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 7347 | break; |
| 7348 | } |
| 7349 | case HLoadClass::LoadKind::kBootImageAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7350 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7351 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 7352 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 7353 | DCHECK_NE(address, 0u); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7354 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7355 | break; |
| 7356 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7357 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7358 | vixl32::Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 7359 | ? RegisterFrom(locations->GetTemp(0)) |
| 7360 | : out; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7361 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7362 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7363 | codegen_->EmitMovwMovtPlaceholder(labels, temp); |
| 7364 | GenerateGcRootFieldLoad(cls, out_loc, temp, /* offset */ 0, read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7365 | generate_null_check = true; |
| 7366 | break; |
| 7367 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7368 | case HLoadClass::LoadKind::kJitTableAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7369 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 7370 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7371 | cls->GetClass())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7372 | // /* GcRoot<mirror::Class> */ out = *out |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7373 | GenerateGcRootFieldLoad(cls, out_loc, out, /* offset */ 0, read_barrier_option); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7374 | break; |
| 7375 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7376 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7377 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7378 | LOG(FATAL) << "UNREACHABLE"; |
| 7379 | UNREACHABLE(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7380 | } |
| 7381 | |
| 7382 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 7383 | DCHECK(cls->CanCallRuntime()); |
| 7384 | LoadClassSlowPathARMVIXL* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARMVIXL( |
| 7385 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 7386 | codegen_->AddSlowPath(slow_path); |
| 7387 | if (generate_null_check) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7388 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7389 | } |
| 7390 | if (cls->MustGenerateClinitCheck()) { |
| 7391 | GenerateClassInitializationCheck(slow_path, out); |
| 7392 | } else { |
| 7393 | __ Bind(slow_path->GetExitLabel()); |
| 7394 | } |
| 7395 | } |
| 7396 | } |
| 7397 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7398 | void LocationsBuilderARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 7399 | LocationSummary* locations = |
| 7400 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 7401 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7402 | if (check->HasUses()) { |
| 7403 | locations->SetOut(Location::SameAsFirstInput()); |
| 7404 | } |
| 7405 | } |
| 7406 | |
| 7407 | void InstructionCodeGeneratorARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 7408 | // We assume the class is not null. |
| 7409 | LoadClassSlowPathARMVIXL* slow_path = |
| 7410 | new (GetGraph()->GetArena()) LoadClassSlowPathARMVIXL(check->GetLoadClass(), |
| 7411 | check, |
| 7412 | check->GetDexPc(), |
| 7413 | /* do_clinit */ true); |
| 7414 | codegen_->AddSlowPath(slow_path); |
| 7415 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 7416 | } |
| 7417 | |
| 7418 | void InstructionCodeGeneratorARMVIXL::GenerateClassInitializationCheck( |
| 7419 | LoadClassSlowPathARMVIXL* slow_path, vixl32::Register class_reg) { |
| 7420 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 7421 | vixl32::Register temp = temps.Acquire(); |
| 7422 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 7423 | temp, |
| 7424 | class_reg, |
| 7425 | mirror::Class::StatusOffset().Int32Value()); |
| 7426 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 7427 | __ B(lt, slow_path->GetEntryLabel()); |
| 7428 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 7429 | // properly. Therefore, we do a memory fence. |
| 7430 | __ Dmb(ISH); |
| 7431 | __ Bind(slow_path->GetExitLabel()); |
| 7432 | } |
| 7433 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7434 | HLoadString::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadStringKind( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7435 | HLoadString::LoadKind desired_string_load_kind) { |
| 7436 | switch (desired_string_load_kind) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7437 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7438 | case HLoadString::LoadKind::kBssEntry: |
| 7439 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 7440 | break; |
| 7441 | case HLoadString::LoadKind::kJitTableAddress: |
| 7442 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7443 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 7444 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7445 | case HLoadString::LoadKind::kRuntimeCall: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7446 | break; |
| 7447 | } |
| 7448 | return desired_string_load_kind; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7449 | } |
| 7450 | |
| 7451 | void LocationsBuilderARMVIXL::VisitLoadString(HLoadString* load) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7452 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7453 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7454 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7455 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7456 | locations->SetOut(LocationFrom(r0)); |
| 7457 | } else { |
| 7458 | locations->SetOut(Location::RequiresRegister()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7459 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 7460 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7461 | // Rely on the pResolveString and marking to save everything we need, including temps. |
| 7462 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 7463 | // to the custom calling convention) or by marking, so we request a different temp. |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7464 | locations->AddTemp(Location::RequiresRegister()); |
| 7465 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 7466 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7467 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7468 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 7469 | // that the the kPrimNot result register is the same as the first argument register. |
| 7470 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 7471 | if (kUseBakerReadBarrier && kBakerReadBarrierLinkTimeThunksEnableForGcRoots) { |
| 7472 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 7473 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7474 | } else { |
| 7475 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7476 | } |
| 7477 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7478 | } |
| 7479 | } |
| 7480 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7481 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7482 | // move. |
| 7483 | void InstructionCodeGeneratorARMVIXL::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7484 | LocationSummary* locations = load->GetLocations(); |
| 7485 | Location out_loc = locations->Out(); |
| 7486 | vixl32::Register out = OutputRegister(load); |
| 7487 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 7488 | |
| 7489 | switch (load_kind) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7490 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 7491 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| 7492 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7493 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7494 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 7495 | return; // No dex cache slow path. |
| 7496 | } |
| 7497 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7498 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 7499 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 7500 | DCHECK_NE(address, 0u); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7501 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 7502 | return; // No dex cache slow path. |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7503 | } |
| 7504 | case HLoadString::LoadKind::kBssEntry: { |
| 7505 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7506 | vixl32::Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 7507 | ? RegisterFrom(locations->GetTemp(0)) |
| 7508 | : out; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7509 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7510 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7511 | codegen_->EmitMovwMovtPlaceholder(labels, temp); |
| 7512 | GenerateGcRootFieldLoad(load, out_loc, temp, /* offset */ 0, kCompilerReadBarrierOption); |
| 7513 | LoadStringSlowPathARMVIXL* slow_path = |
| 7514 | new (GetGraph()->GetArena()) LoadStringSlowPathARMVIXL(load); |
| 7515 | codegen_->AddSlowPath(slow_path); |
| 7516 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 7517 | __ Bind(slow_path->GetExitLabel()); |
| 7518 | return; |
| 7519 | } |
| 7520 | case HLoadString::LoadKind::kJitTableAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7521 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7522 | load->GetStringIndex(), |
| 7523 | load->GetString())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7524 | // /* GcRoot<mirror::String> */ out = *out |
| 7525 | GenerateGcRootFieldLoad(load, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
| 7526 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7527 | } |
| 7528 | default: |
| 7529 | break; |
| 7530 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7531 | |
| 7532 | // 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] | 7533 | DCHECK_EQ(load->GetLoadKind(), HLoadString::LoadKind::kRuntimeCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7534 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7535 | __ Mov(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7536 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 7537 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 7538 | } |
| 7539 | |
| 7540 | static int32_t GetExceptionTlsOffset() { |
| 7541 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
| 7542 | } |
| 7543 | |
| 7544 | void LocationsBuilderARMVIXL::VisitLoadException(HLoadException* load) { |
| 7545 | LocationSummary* locations = |
| 7546 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 7547 | locations->SetOut(Location::RequiresRegister()); |
| 7548 | } |
| 7549 | |
| 7550 | void InstructionCodeGeneratorARMVIXL::VisitLoadException(HLoadException* load) { |
| 7551 | vixl32::Register out = OutputRegister(load); |
| 7552 | GetAssembler()->LoadFromOffset(kLoadWord, out, tr, GetExceptionTlsOffset()); |
| 7553 | } |
| 7554 | |
| 7555 | |
| 7556 | void LocationsBuilderARMVIXL::VisitClearException(HClearException* clear) { |
| 7557 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 7558 | } |
| 7559 | |
| 7560 | void InstructionCodeGeneratorARMVIXL::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 7561 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 7562 | vixl32::Register temp = temps.Acquire(); |
| 7563 | __ Mov(temp, 0); |
| 7564 | GetAssembler()->StoreToOffset(kStoreWord, temp, tr, GetExceptionTlsOffset()); |
| 7565 | } |
| 7566 | |
| 7567 | void LocationsBuilderARMVIXL::VisitThrow(HThrow* instruction) { |
| 7568 | LocationSummary* locations = |
| 7569 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| 7570 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7571 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7572 | } |
| 7573 | |
| 7574 | void InstructionCodeGeneratorARMVIXL::VisitThrow(HThrow* instruction) { |
| 7575 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| 7576 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 7577 | } |
| 7578 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7579 | // Temp is used for read barrier. |
| 7580 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 7581 | if (kEmitCompilerReadBarrier && |
| 7582 | (kUseBakerReadBarrier || |
| 7583 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7584 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7585 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 7586 | return 1; |
| 7587 | } |
| 7588 | return 0; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7589 | } |
| 7590 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7591 | // Interface case has 3 temps, one for holding the number of interfaces, one for the current |
| 7592 | // interface pointer, one for loading the current interface. |
| 7593 | // The other checks have one temp for loading the object's class. |
| 7594 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 7595 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7596 | return 3; |
| 7597 | } |
| 7598 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 7599 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7600 | |
| 7601 | void LocationsBuilderARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 7602 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7603 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7604 | bool baker_read_barrier_slow_path = false; |
| 7605 | switch (type_check_kind) { |
| 7606 | case TypeCheckKind::kExactCheck: |
| 7607 | case TypeCheckKind::kAbstractClassCheck: |
| 7608 | case TypeCheckKind::kClassHierarchyCheck: |
| 7609 | case TypeCheckKind::kArrayObjectCheck: |
| 7610 | call_kind = |
| 7611 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 7612 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
| 7613 | break; |
| 7614 | case TypeCheckKind::kArrayCheck: |
| 7615 | case TypeCheckKind::kUnresolvedCheck: |
| 7616 | case TypeCheckKind::kInterfaceCheck: |
| 7617 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7618 | break; |
| 7619 | } |
| 7620 | |
| 7621 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 7622 | if (baker_read_barrier_slow_path) { |
| 7623 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 7624 | } |
| 7625 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7626 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7627 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 7628 | // Note that TypeCheckSlowPathARM uses this register too. |
| 7629 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7630 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 7631 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 7632 | codegen_->MaybeAddBakerCcEntrypointTempForFields(locations); |
| 7633 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7634 | } |
| 7635 | |
| 7636 | void InstructionCodeGeneratorARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 7637 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7638 | LocationSummary* locations = instruction->GetLocations(); |
| 7639 | Location obj_loc = locations->InAt(0); |
| 7640 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 7641 | vixl32::Register cls = InputRegisterAt(instruction, 1); |
| 7642 | Location out_loc = locations->Out(); |
| 7643 | vixl32::Register out = OutputRegister(instruction); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7644 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7645 | DCHECK_LE(num_temps, 1u); |
| 7646 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7647 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7648 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7649 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7650 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7651 | vixl32::Label done; |
| 7652 | vixl32::Label* const final_label = codegen_->GetFinalLabel(instruction, &done); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7653 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 7654 | |
| 7655 | // Return 0 if `obj` is null. |
| 7656 | // avoid null check if we know obj is not null. |
| 7657 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7658 | DCHECK(!out.Is(obj)); |
| 7659 | __ Mov(out, 0); |
| 7660 | __ CompareAndBranchIfZero(obj, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7661 | } |
| 7662 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7663 | switch (type_check_kind) { |
| 7664 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7665 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7666 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7667 | out_loc, |
| 7668 | obj_loc, |
| 7669 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7670 | maybe_temp_loc, |
| 7671 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7672 | // Classes must be equal for the instanceof to succeed. |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7673 | __ Cmp(out, cls); |
| 7674 | // We speculatively set the result to false without changing the condition |
| 7675 | // flags, which allows us to avoid some branching later. |
| 7676 | __ Mov(LeaveFlags, out, 0); |
| 7677 | |
| 7678 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7679 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7680 | // encoding can be used. |
| 7681 | if (out.IsLow()) { |
| 7682 | // We use the scope because of the IT block that follows. |
| 7683 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7684 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7685 | CodeBufferCheckScope::kExactSize); |
| 7686 | |
| 7687 | __ it(eq); |
| 7688 | __ mov(eq, out, 1); |
| 7689 | } else { |
| 7690 | __ B(ne, final_label, /* far_target */ false); |
| 7691 | __ Mov(out, 1); |
| 7692 | } |
| 7693 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7694 | break; |
| 7695 | } |
| 7696 | |
| 7697 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7698 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7699 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7700 | out_loc, |
| 7701 | obj_loc, |
| 7702 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7703 | maybe_temp_loc, |
| 7704 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7705 | // If the class is abstract, we eagerly fetch the super class of the |
| 7706 | // object to avoid doing a comparison we know will fail. |
| 7707 | vixl32::Label loop; |
| 7708 | __ Bind(&loop); |
| 7709 | // /* HeapReference<Class> */ out = out->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7710 | GenerateReferenceLoadOneRegister(instruction, |
| 7711 | out_loc, |
| 7712 | super_offset, |
| 7713 | maybe_temp_loc, |
| 7714 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7715 | // 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] | 7716 | __ CompareAndBranchIfZero(out, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7717 | __ Cmp(out, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7718 | __ B(ne, &loop, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7719 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7720 | break; |
| 7721 | } |
| 7722 | |
| 7723 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7724 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7725 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7726 | out_loc, |
| 7727 | obj_loc, |
| 7728 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7729 | maybe_temp_loc, |
| 7730 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7731 | // Walk over the class hierarchy to find a match. |
| 7732 | vixl32::Label loop, success; |
| 7733 | __ Bind(&loop); |
| 7734 | __ Cmp(out, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7735 | __ B(eq, &success, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7736 | // /* HeapReference<Class> */ out = out->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7737 | GenerateReferenceLoadOneRegister(instruction, |
| 7738 | out_loc, |
| 7739 | super_offset, |
| 7740 | maybe_temp_loc, |
| 7741 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7742 | // This is essentially a null check, but it sets the condition flags to the |
| 7743 | // proper value for the code that follows the loop, i.e. not `eq`. |
| 7744 | __ Cmp(out, 1); |
| 7745 | __ B(hs, &loop, /* far_target */ false); |
| 7746 | |
| 7747 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7748 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7749 | // encoding can be used. |
| 7750 | if (out.IsLow()) { |
| 7751 | // If `out` is null, we use it for the result, and the condition flags |
| 7752 | // have already been set to `ne`, so the IT block that comes afterwards |
| 7753 | // (and which handles the successful case) turns into a NOP (instead of |
| 7754 | // overwriting `out`). |
| 7755 | __ Bind(&success); |
| 7756 | |
| 7757 | // We use the scope because of the IT block that follows. |
| 7758 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7759 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7760 | CodeBufferCheckScope::kExactSize); |
| 7761 | |
| 7762 | // There is only one branch to the `success` label (which is bound to this |
| 7763 | // IT block), and it has the same condition, `eq`, so in that case the MOV |
| 7764 | // is executed. |
| 7765 | __ it(eq); |
| 7766 | __ mov(eq, out, 1); |
| 7767 | } else { |
| 7768 | // 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] | 7769 | __ B(final_label); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7770 | __ Bind(&success); |
| 7771 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7772 | } |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7773 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7774 | break; |
| 7775 | } |
| 7776 | |
| 7777 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7778 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7779 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7780 | out_loc, |
| 7781 | obj_loc, |
| 7782 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7783 | maybe_temp_loc, |
| 7784 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7785 | // Do an exact check. |
| 7786 | vixl32::Label exact_check; |
| 7787 | __ Cmp(out, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7788 | __ B(eq, &exact_check, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7789 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 7790 | // /* HeapReference<Class> */ out = out->component_type_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7791 | GenerateReferenceLoadOneRegister(instruction, |
| 7792 | out_loc, |
| 7793 | component_offset, |
| 7794 | maybe_temp_loc, |
| 7795 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7796 | // 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] | 7797 | __ CompareAndBranchIfZero(out, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7798 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 7799 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7800 | __ Cmp(out, 0); |
| 7801 | // We speculatively set the result to false without changing the condition |
| 7802 | // flags, which allows us to avoid some branching later. |
| 7803 | __ Mov(LeaveFlags, out, 0); |
| 7804 | |
| 7805 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7806 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7807 | // encoding can be used. |
| 7808 | if (out.IsLow()) { |
| 7809 | __ Bind(&exact_check); |
| 7810 | |
| 7811 | // We use the scope because of the IT block that follows. |
| 7812 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7813 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7814 | CodeBufferCheckScope::kExactSize); |
| 7815 | |
| 7816 | __ it(eq); |
| 7817 | __ mov(eq, out, 1); |
| 7818 | } else { |
| 7819 | __ B(ne, final_label, /* far_target */ false); |
| 7820 | __ Bind(&exact_check); |
| 7821 | __ Mov(out, 1); |
| 7822 | } |
| 7823 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7824 | break; |
| 7825 | } |
| 7826 | |
| 7827 | case TypeCheckKind::kArrayCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7828 | // No read barrier since the slow path will retry upon failure. |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7829 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7830 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7831 | out_loc, |
| 7832 | obj_loc, |
| 7833 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7834 | maybe_temp_loc, |
| 7835 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7836 | __ Cmp(out, cls); |
| 7837 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 7838 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARMVIXL(instruction, |
| 7839 | /* is_fatal */ false); |
| 7840 | codegen_->AddSlowPath(slow_path); |
| 7841 | __ B(ne, slow_path->GetEntryLabel()); |
| 7842 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7843 | break; |
| 7844 | } |
| 7845 | |
| 7846 | case TypeCheckKind::kUnresolvedCheck: |
| 7847 | case TypeCheckKind::kInterfaceCheck: { |
| 7848 | // Note that we indeed only call on slow path, but we always go |
| 7849 | // into the slow path for the unresolved and interface check |
| 7850 | // cases. |
| 7851 | // |
| 7852 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7853 | // entry point without resorting to a type checking slow path |
| 7854 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7855 | // require to assign fixed registers for the inputs of this |
| 7856 | // HInstanceOf instruction (following the runtime calling |
| 7857 | // convention), which might be cluttered by the potential first |
| 7858 | // read barrier emission at the beginning of this method. |
| 7859 | // |
| 7860 | // TODO: Introduce a new runtime entry point taking the object |
| 7861 | // to test (instead of its class) as argument, and let it deal |
| 7862 | // with the read barrier issues. This will let us refactor this |
| 7863 | // case of the `switch` code as it was previously (with a direct |
| 7864 | // call to the runtime not using a type checking slow path). |
| 7865 | // This should also be beneficial for the other cases above. |
| 7866 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 7867 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARMVIXL(instruction, |
| 7868 | /* is_fatal */ false); |
| 7869 | codegen_->AddSlowPath(slow_path); |
| 7870 | __ B(slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7871 | break; |
| 7872 | } |
| 7873 | } |
| 7874 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7875 | if (done.IsReferenced()) { |
| 7876 | __ Bind(&done); |
| 7877 | } |
| 7878 | |
| 7879 | if (slow_path != nullptr) { |
| 7880 | __ Bind(slow_path->GetExitLabel()); |
| 7881 | } |
| 7882 | } |
| 7883 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7884 | void LocationsBuilderARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
| 7885 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7886 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 7887 | |
| 7888 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7889 | switch (type_check_kind) { |
| 7890 | case TypeCheckKind::kExactCheck: |
| 7891 | case TypeCheckKind::kAbstractClassCheck: |
| 7892 | case TypeCheckKind::kClassHierarchyCheck: |
| 7893 | case TypeCheckKind::kArrayObjectCheck: |
| 7894 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 7895 | LocationSummary::kCallOnSlowPath : |
| 7896 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
| 7897 | break; |
| 7898 | case TypeCheckKind::kArrayCheck: |
| 7899 | case TypeCheckKind::kUnresolvedCheck: |
| 7900 | case TypeCheckKind::kInterfaceCheck: |
| 7901 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7902 | break; |
| 7903 | } |
| 7904 | |
| 7905 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 7906 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7907 | locations->SetInAt(1, Location::RequiresRegister()); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7908 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7909 | } |
| 7910 | |
| 7911 | void InstructionCodeGeneratorARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
| 7912 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7913 | LocationSummary* locations = instruction->GetLocations(); |
| 7914 | Location obj_loc = locations->InAt(0); |
| 7915 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 7916 | vixl32::Register cls = InputRegisterAt(instruction, 1); |
| 7917 | Location temp_loc = locations->GetTemp(0); |
| 7918 | vixl32::Register temp = RegisterFrom(temp_loc); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7919 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 7920 | DCHECK_LE(num_temps, 3u); |
| 7921 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 7922 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 7923 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7924 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7925 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7926 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 7927 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 7928 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 7929 | const uint32_t object_array_data_offset = |
| 7930 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7931 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7932 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 7933 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 7934 | // read barriers is done for performance and code size reasons. |
| 7935 | bool is_type_check_slow_path_fatal = false; |
| 7936 | if (!kEmitCompilerReadBarrier) { |
| 7937 | is_type_check_slow_path_fatal = |
| 7938 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 7939 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7940 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7941 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 7942 | !instruction->CanThrowIntoCatchBlock(); |
| 7943 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7944 | SlowPathCodeARMVIXL* type_check_slow_path = |
| 7945 | new (GetGraph()->GetArena()) TypeCheckSlowPathARMVIXL(instruction, |
| 7946 | is_type_check_slow_path_fatal); |
| 7947 | codegen_->AddSlowPath(type_check_slow_path); |
| 7948 | |
| 7949 | vixl32::Label done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7950 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7951 | // Avoid null check if we know obj is not null. |
| 7952 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7953 | __ CompareAndBranchIfZero(obj, final_label, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7954 | } |
| 7955 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7956 | switch (type_check_kind) { |
| 7957 | case TypeCheckKind::kExactCheck: |
| 7958 | case TypeCheckKind::kArrayCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7959 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7960 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7961 | temp_loc, |
| 7962 | obj_loc, |
| 7963 | class_offset, |
| 7964 | maybe_temp2_loc, |
| 7965 | kWithoutReadBarrier); |
| 7966 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7967 | __ Cmp(temp, cls); |
| 7968 | // Jump to slow path for throwing the exception or doing a |
| 7969 | // more involved array check. |
| 7970 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 7971 | break; |
| 7972 | } |
| 7973 | |
| 7974 | case TypeCheckKind::kAbstractClassCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7975 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7976 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7977 | temp_loc, |
| 7978 | obj_loc, |
| 7979 | class_offset, |
| 7980 | maybe_temp2_loc, |
| 7981 | kWithoutReadBarrier); |
| 7982 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7983 | // If the class is abstract, we eagerly fetch the super class of the |
| 7984 | // object to avoid doing a comparison we know will fail. |
| 7985 | vixl32::Label loop; |
| 7986 | __ Bind(&loop); |
| 7987 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7988 | GenerateReferenceLoadOneRegister(instruction, |
| 7989 | temp_loc, |
| 7990 | super_offset, |
| 7991 | maybe_temp2_loc, |
| 7992 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7993 | |
| 7994 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7995 | // exception. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7996 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7997 | |
| 7998 | // Otherwise, compare the classes. |
| 7999 | __ Cmp(temp, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 8000 | __ B(ne, &loop, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8001 | break; |
| 8002 | } |
| 8003 | |
| 8004 | case TypeCheckKind::kClassHierarchyCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8005 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8006 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8007 | temp_loc, |
| 8008 | obj_loc, |
| 8009 | class_offset, |
| 8010 | maybe_temp2_loc, |
| 8011 | kWithoutReadBarrier); |
| 8012 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8013 | // Walk over the class hierarchy to find a match. |
| 8014 | vixl32::Label loop; |
| 8015 | __ Bind(&loop); |
| 8016 | __ Cmp(temp, cls); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 8017 | __ B(eq, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8018 | |
| 8019 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8020 | GenerateReferenceLoadOneRegister(instruction, |
| 8021 | temp_loc, |
| 8022 | super_offset, |
| 8023 | maybe_temp2_loc, |
| 8024 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8025 | |
| 8026 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 8027 | // exception. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 8028 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8029 | // Otherwise, jump to the beginning of the loop. |
| 8030 | __ B(&loop); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8031 | break; |
| 8032 | } |
| 8033 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8034 | case TypeCheckKind::kArrayObjectCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8035 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8036 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8037 | temp_loc, |
| 8038 | obj_loc, |
| 8039 | class_offset, |
| 8040 | maybe_temp2_loc, |
| 8041 | kWithoutReadBarrier); |
| 8042 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8043 | // Do an exact check. |
| 8044 | __ Cmp(temp, cls); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 8045 | __ B(eq, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8046 | |
| 8047 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 8048 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8049 | GenerateReferenceLoadOneRegister(instruction, |
| 8050 | temp_loc, |
| 8051 | component_offset, |
| 8052 | maybe_temp2_loc, |
| 8053 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8054 | // 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] | 8055 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8056 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 8057 | // to further check that this component type is not a primitive type. |
| 8058 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| 8059 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 8060 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8061 | break; |
| 8062 | } |
| 8063 | |
| 8064 | case TypeCheckKind::kUnresolvedCheck: |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8065 | // 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] | 8066 | // We cannot directly call the CheckCast runtime entry point |
| 8067 | // without resorting to a type checking slow path here (i.e. by |
| 8068 | // calling InvokeRuntime directly), as it would require to |
| 8069 | // assign fixed registers for the inputs of this HInstanceOf |
| 8070 | // instruction (following the runtime calling convention), which |
| 8071 | // might be cluttered by the potential first read barrier |
| 8072 | // emission at the beginning of this method. |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8073 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8074 | __ B(type_check_slow_path->GetEntryLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8075 | break; |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8076 | |
| 8077 | case TypeCheckKind::kInterfaceCheck: { |
| 8078 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 8079 | // positives by doing this. |
| 8080 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8081 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8082 | temp_loc, |
| 8083 | obj_loc, |
| 8084 | class_offset, |
| 8085 | maybe_temp2_loc, |
| 8086 | kWithoutReadBarrier); |
| 8087 | |
| 8088 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 8089 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8090 | temp_loc, |
| 8091 | temp_loc, |
| 8092 | iftable_offset, |
| 8093 | maybe_temp2_loc, |
| 8094 | kWithoutReadBarrier); |
| 8095 | // Iftable is never null. |
| 8096 | __ Ldr(RegisterFrom(maybe_temp2_loc), MemOperand(temp, array_length_offset)); |
| 8097 | // Loop through the iftable and check if any class matches. |
| 8098 | vixl32::Label start_loop; |
| 8099 | __ Bind(&start_loop); |
| 8100 | __ CompareAndBranchIfZero(RegisterFrom(maybe_temp2_loc), |
| 8101 | type_check_slow_path->GetEntryLabel()); |
| 8102 | __ Ldr(RegisterFrom(maybe_temp3_loc), MemOperand(temp, object_array_data_offset)); |
| 8103 | GetAssembler()->MaybeUnpoisonHeapReference(RegisterFrom(maybe_temp3_loc)); |
| 8104 | // Go to next interface. |
| 8105 | __ Add(temp, temp, Operand::From(2 * kHeapReferenceSize)); |
| 8106 | __ Sub(RegisterFrom(maybe_temp2_loc), RegisterFrom(maybe_temp2_loc), 2); |
| 8107 | // Compare the classes and continue the loop if they do not match. |
| 8108 | __ Cmp(cls, RegisterFrom(maybe_temp3_loc)); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 8109 | __ B(ne, &start_loop, /* far_target */ false); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8110 | break; |
| 8111 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8112 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 8113 | if (done.IsReferenced()) { |
| 8114 | __ Bind(&done); |
| 8115 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8116 | |
| 8117 | __ Bind(type_check_slow_path->GetExitLabel()); |
| 8118 | } |
| 8119 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8120 | void LocationsBuilderARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 8121 | LocationSummary* locations = |
| 8122 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| 8123 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 8124 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 8125 | } |
| 8126 | |
| 8127 | void InstructionCodeGeneratorARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 8128 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 8129 | instruction, |
| 8130 | instruction->GetDexPc()); |
| 8131 | if (instruction->IsEnter()) { |
| 8132 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 8133 | } else { |
| 8134 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 8135 | } |
| 8136 | } |
| 8137 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8138 | void LocationsBuilderARMVIXL::VisitAnd(HAnd* instruction) { |
| 8139 | HandleBitwiseOperation(instruction, AND); |
| 8140 | } |
| 8141 | |
| 8142 | void LocationsBuilderARMVIXL::VisitOr(HOr* instruction) { |
| 8143 | HandleBitwiseOperation(instruction, ORR); |
| 8144 | } |
| 8145 | |
| 8146 | void LocationsBuilderARMVIXL::VisitXor(HXor* instruction) { |
| 8147 | HandleBitwiseOperation(instruction, EOR); |
| 8148 | } |
| 8149 | |
| 8150 | void LocationsBuilderARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
| 8151 | LocationSummary* locations = |
| 8152 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 8153 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 8154 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 8155 | // Note: GVN reorders commutative operations to have the constant on the right hand side. |
| 8156 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8157 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
| 8158 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8159 | } |
| 8160 | |
| 8161 | void InstructionCodeGeneratorARMVIXL::VisitAnd(HAnd* instruction) { |
| 8162 | HandleBitwiseOperation(instruction); |
| 8163 | } |
| 8164 | |
| 8165 | void InstructionCodeGeneratorARMVIXL::VisitOr(HOr* instruction) { |
| 8166 | HandleBitwiseOperation(instruction); |
| 8167 | } |
| 8168 | |
| 8169 | void InstructionCodeGeneratorARMVIXL::VisitXor(HXor* instruction) { |
| 8170 | HandleBitwiseOperation(instruction); |
| 8171 | } |
| 8172 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8173 | void LocationsBuilderARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 8174 | LocationSummary* locations = |
| 8175 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 8176 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 8177 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 8178 | |
| 8179 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8180 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8181 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8182 | } |
| 8183 | |
| 8184 | void InstructionCodeGeneratorARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 8185 | LocationSummary* locations = instruction->GetLocations(); |
| 8186 | Location first = locations->InAt(0); |
| 8187 | Location second = locations->InAt(1); |
| 8188 | Location out = locations->Out(); |
| 8189 | |
| 8190 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 8191 | vixl32::Register first_reg = RegisterFrom(first); |
| 8192 | vixl32::Register second_reg = RegisterFrom(second); |
| 8193 | vixl32::Register out_reg = RegisterFrom(out); |
| 8194 | |
| 8195 | switch (instruction->GetOpKind()) { |
| 8196 | case HInstruction::kAnd: |
| 8197 | __ Bic(out_reg, first_reg, second_reg); |
| 8198 | break; |
| 8199 | case HInstruction::kOr: |
| 8200 | __ Orn(out_reg, first_reg, second_reg); |
| 8201 | break; |
| 8202 | // There is no EON on arm. |
| 8203 | case HInstruction::kXor: |
| 8204 | default: |
| 8205 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 8206 | UNREACHABLE(); |
| 8207 | } |
| 8208 | return; |
| 8209 | |
| 8210 | } else { |
| 8211 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 8212 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8213 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8214 | vixl32::Register second_low = LowRegisterFrom(second); |
| 8215 | vixl32::Register second_high = HighRegisterFrom(second); |
| 8216 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8217 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8218 | |
| 8219 | switch (instruction->GetOpKind()) { |
| 8220 | case HInstruction::kAnd: |
| 8221 | __ Bic(out_low, first_low, second_low); |
| 8222 | __ Bic(out_high, first_high, second_high); |
| 8223 | break; |
| 8224 | case HInstruction::kOr: |
| 8225 | __ Orn(out_low, first_low, second_low); |
| 8226 | __ Orn(out_high, first_high, second_high); |
| 8227 | break; |
| 8228 | // There is no EON on arm. |
| 8229 | case HInstruction::kXor: |
| 8230 | default: |
| 8231 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 8232 | UNREACHABLE(); |
| 8233 | } |
| 8234 | } |
| 8235 | } |
| 8236 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8237 | void LocationsBuilderARMVIXL::VisitDataProcWithShifterOp( |
| 8238 | HDataProcWithShifterOp* instruction) { |
| 8239 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 8240 | instruction->GetType() == Primitive::kPrimLong); |
| 8241 | LocationSummary* locations = |
| 8242 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 8243 | const bool overlap = instruction->GetType() == Primitive::kPrimLong && |
| 8244 | HDataProcWithShifterOp::IsExtensionOp(instruction->GetOpKind()); |
| 8245 | |
| 8246 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8247 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8248 | locations->SetOut(Location::RequiresRegister(), |
| 8249 | overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 8250 | } |
| 8251 | |
| 8252 | void InstructionCodeGeneratorARMVIXL::VisitDataProcWithShifterOp( |
| 8253 | HDataProcWithShifterOp* instruction) { |
| 8254 | const LocationSummary* const locations = instruction->GetLocations(); |
| 8255 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 8256 | const HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 8257 | |
| 8258 | if (instruction->GetType() == Primitive::kPrimInt) { |
| 8259 | DCHECK(!HDataProcWithShifterOp::IsExtensionOp(op_kind)); |
| 8260 | |
| 8261 | const vixl32::Register second = instruction->InputAt(1)->GetType() == Primitive::kPrimLong |
| 8262 | ? LowRegisterFrom(locations->InAt(1)) |
| 8263 | : InputRegisterAt(instruction, 1); |
| 8264 | |
| 8265 | GenerateDataProcInstruction(kind, |
| 8266 | OutputRegister(instruction), |
| 8267 | InputRegisterAt(instruction, 0), |
| 8268 | Operand(second, |
| 8269 | ShiftFromOpKind(op_kind), |
| 8270 | instruction->GetShiftAmount()), |
| 8271 | codegen_); |
| 8272 | } else { |
| 8273 | DCHECK_EQ(instruction->GetType(), Primitive::kPrimLong); |
| 8274 | |
| 8275 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 8276 | const vixl32::Register second = InputRegisterAt(instruction, 1); |
| 8277 | |
| 8278 | DCHECK(!LowRegisterFrom(locations->Out()).Is(second)); |
| 8279 | GenerateDataProc(kind, |
| 8280 | locations->Out(), |
| 8281 | locations->InAt(0), |
| 8282 | second, |
| 8283 | Operand(second, ShiftType::ASR, 31), |
| 8284 | codegen_); |
| 8285 | } else { |
| 8286 | GenerateLongDataProc(instruction, codegen_); |
| 8287 | } |
| 8288 | } |
| 8289 | } |
| 8290 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8291 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8292 | void InstructionCodeGeneratorARMVIXL::GenerateAndConst(vixl32::Register out, |
| 8293 | vixl32::Register first, |
| 8294 | uint32_t value) { |
| 8295 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 8296 | if (value == 0xffffffffu) { |
| 8297 | if (!out.Is(first)) { |
| 8298 | __ Mov(out, first); |
| 8299 | } |
| 8300 | return; |
| 8301 | } |
| 8302 | if (value == 0u) { |
| 8303 | __ Mov(out, 0); |
| 8304 | return; |
| 8305 | } |
| 8306 | if (GetAssembler()->ShifterOperandCanHold(AND, value)) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 8307 | __ And(out, first, value); |
| 8308 | } else if (GetAssembler()->ShifterOperandCanHold(BIC, ~value)) { |
| 8309 | __ Bic(out, first, ~value); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8310 | } else { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 8311 | DCHECK(IsPowerOfTwo(value + 1)); |
| 8312 | __ Ubfx(out, first, 0, WhichPowerOf2(value + 1)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8313 | } |
| 8314 | } |
| 8315 | |
| 8316 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8317 | void InstructionCodeGeneratorARMVIXL::GenerateOrrConst(vixl32::Register out, |
| 8318 | vixl32::Register first, |
| 8319 | uint32_t value) { |
| 8320 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 8321 | if (value == 0u) { |
| 8322 | if (!out.Is(first)) { |
| 8323 | __ Mov(out, first); |
| 8324 | } |
| 8325 | return; |
| 8326 | } |
| 8327 | if (value == 0xffffffffu) { |
| 8328 | __ Mvn(out, 0); |
| 8329 | return; |
| 8330 | } |
| 8331 | if (GetAssembler()->ShifterOperandCanHold(ORR, value)) { |
| 8332 | __ Orr(out, first, value); |
| 8333 | } else { |
| 8334 | DCHECK(GetAssembler()->ShifterOperandCanHold(ORN, ~value)); |
| 8335 | __ Orn(out, first, ~value); |
| 8336 | } |
| 8337 | } |
| 8338 | |
| 8339 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8340 | void InstructionCodeGeneratorARMVIXL::GenerateEorConst(vixl32::Register out, |
| 8341 | vixl32::Register first, |
| 8342 | uint32_t value) { |
| 8343 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 8344 | if (value == 0u) { |
| 8345 | if (!out.Is(first)) { |
| 8346 | __ Mov(out, first); |
| 8347 | } |
| 8348 | return; |
| 8349 | } |
| 8350 | __ Eor(out, first, value); |
| 8351 | } |
| 8352 | |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8353 | void InstructionCodeGeneratorARMVIXL::GenerateAddLongConst(Location out, |
| 8354 | Location first, |
| 8355 | uint64_t value) { |
| 8356 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8357 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8358 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8359 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8360 | uint32_t value_low = Low32Bits(value); |
| 8361 | uint32_t value_high = High32Bits(value); |
| 8362 | if (value_low == 0u) { |
| 8363 | if (!out_low.Is(first_low)) { |
| 8364 | __ Mov(out_low, first_low); |
| 8365 | } |
| 8366 | __ Add(out_high, first_high, value_high); |
| 8367 | return; |
| 8368 | } |
| 8369 | __ Adds(out_low, first_low, value_low); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 8370 | if (GetAssembler()->ShifterOperandCanHold(ADC, value_high, kCcDontCare)) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8371 | __ Adc(out_high, first_high, value_high); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 8372 | } else if (GetAssembler()->ShifterOperandCanHold(SBC, ~value_high, kCcDontCare)) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8373 | __ Sbc(out_high, first_high, ~value_high); |
| 8374 | } else { |
| 8375 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 8376 | UNREACHABLE(); |
| 8377 | } |
| 8378 | } |
| 8379 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8380 | void InstructionCodeGeneratorARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 8381 | LocationSummary* locations = instruction->GetLocations(); |
| 8382 | Location first = locations->InAt(0); |
| 8383 | Location second = locations->InAt(1); |
| 8384 | Location out = locations->Out(); |
| 8385 | |
| 8386 | if (second.IsConstant()) { |
| 8387 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 8388 | uint32_t value_low = Low32Bits(value); |
| 8389 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 8390 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 8391 | vixl32::Register out_reg = OutputRegister(instruction); |
| 8392 | if (instruction->IsAnd()) { |
| 8393 | GenerateAndConst(out_reg, first_reg, value_low); |
| 8394 | } else if (instruction->IsOr()) { |
| 8395 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 8396 | } else { |
| 8397 | DCHECK(instruction->IsXor()); |
| 8398 | GenerateEorConst(out_reg, first_reg, value_low); |
| 8399 | } |
| 8400 | } else { |
| 8401 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 8402 | uint32_t value_high = High32Bits(value); |
| 8403 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8404 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8405 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8406 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8407 | if (instruction->IsAnd()) { |
| 8408 | GenerateAndConst(out_low, first_low, value_low); |
| 8409 | GenerateAndConst(out_high, first_high, value_high); |
| 8410 | } else if (instruction->IsOr()) { |
| 8411 | GenerateOrrConst(out_low, first_low, value_low); |
| 8412 | GenerateOrrConst(out_high, first_high, value_high); |
| 8413 | } else { |
| 8414 | DCHECK(instruction->IsXor()); |
| 8415 | GenerateEorConst(out_low, first_low, value_low); |
| 8416 | GenerateEorConst(out_high, first_high, value_high); |
| 8417 | } |
| 8418 | } |
| 8419 | return; |
| 8420 | } |
| 8421 | |
| 8422 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 8423 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 8424 | vixl32::Register second_reg = InputRegisterAt(instruction, 1); |
| 8425 | vixl32::Register out_reg = OutputRegister(instruction); |
| 8426 | if (instruction->IsAnd()) { |
| 8427 | __ And(out_reg, first_reg, second_reg); |
| 8428 | } else if (instruction->IsOr()) { |
| 8429 | __ Orr(out_reg, first_reg, second_reg); |
| 8430 | } else { |
| 8431 | DCHECK(instruction->IsXor()); |
| 8432 | __ Eor(out_reg, first_reg, second_reg); |
| 8433 | } |
| 8434 | } else { |
| 8435 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 8436 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8437 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8438 | vixl32::Register second_low = LowRegisterFrom(second); |
| 8439 | vixl32::Register second_high = HighRegisterFrom(second); |
| 8440 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8441 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8442 | if (instruction->IsAnd()) { |
| 8443 | __ And(out_low, first_low, second_low); |
| 8444 | __ And(out_high, first_high, second_high); |
| 8445 | } else if (instruction->IsOr()) { |
| 8446 | __ Orr(out_low, first_low, second_low); |
| 8447 | __ Orr(out_high, first_high, second_high); |
| 8448 | } else { |
| 8449 | DCHECK(instruction->IsXor()); |
| 8450 | __ Eor(out_low, first_low, second_low); |
| 8451 | __ Eor(out_high, first_high, second_high); |
| 8452 | } |
| 8453 | } |
| 8454 | } |
| 8455 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8456 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadOneRegister( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8457 | HInstruction* instruction, |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8458 | Location out, |
| 8459 | uint32_t offset, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8460 | Location maybe_temp, |
| 8461 | ReadBarrierOption read_barrier_option) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8462 | vixl32::Register out_reg = RegisterFrom(out); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8463 | if (read_barrier_option == kWithReadBarrier) { |
| 8464 | CHECK(kEmitCompilerReadBarrier); |
| 8465 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 8466 | if (kUseBakerReadBarrier) { |
| 8467 | // Load with fast path based Baker's read barrier. |
| 8468 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8469 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 8470 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
| 8471 | } else { |
| 8472 | // Load with slow path based read barrier. |
| 8473 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 8474 | // in the following move operation, as we will need it for the |
| 8475 | // read barrier below. |
| 8476 | __ Mov(RegisterFrom(maybe_temp), out_reg); |
| 8477 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8478 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 8479 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 8480 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8481 | } else { |
| 8482 | // Plain load with no read barrier. |
| 8483 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8484 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 8485 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 8486 | } |
| 8487 | } |
| 8488 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8489 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadTwoRegisters( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8490 | HInstruction* instruction, |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8491 | Location out, |
| 8492 | Location obj, |
| 8493 | uint32_t offset, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8494 | Location maybe_temp, |
| 8495 | ReadBarrierOption read_barrier_option) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8496 | vixl32::Register out_reg = RegisterFrom(out); |
| 8497 | vixl32::Register obj_reg = RegisterFrom(obj); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8498 | if (read_barrier_option == kWithReadBarrier) { |
| 8499 | CHECK(kEmitCompilerReadBarrier); |
| 8500 | if (kUseBakerReadBarrier) { |
| 8501 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 8502 | // Load with fast path based Baker's read barrier. |
| 8503 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8504 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 8505 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
| 8506 | } else { |
| 8507 | // Load with slow path based read barrier. |
| 8508 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8509 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8510 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 8511 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8512 | } else { |
| 8513 | // Plain load with no read barrier. |
| 8514 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8515 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8516 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 8517 | } |
| 8518 | } |
| 8519 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8520 | void InstructionCodeGeneratorARMVIXL::GenerateGcRootFieldLoad( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8521 | HInstruction* instruction, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8522 | Location root, |
| 8523 | vixl32::Register obj, |
| 8524 | uint32_t offset, |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8525 | ReadBarrierOption read_barrier_option) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8526 | vixl32::Register root_reg = RegisterFrom(root); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8527 | if (read_barrier_option == kWithReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8528 | DCHECK(kEmitCompilerReadBarrier); |
| 8529 | if (kUseBakerReadBarrier) { |
| 8530 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8531 | // Baker's read barrier are used. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8532 | if (kBakerReadBarrierLinkTimeThunksEnableForGcRoots && |
| 8533 | !Runtime::Current()->UseJitCompilation()) { |
| 8534 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 8535 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 8536 | // load into `temp` (actually kBakerCcEntrypointRegister) the read |
| 8537 | // barrier mark introspection entrypoint. If `temp` is null, it means |
| 8538 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8539 | // |
| 8540 | // We use link-time generated thunks for the slow path. That thunk |
| 8541 | // checks the reference and jumps to the entrypoint if needed. |
| 8542 | // |
| 8543 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
| 8544 | // lr = &return_address; |
| 8545 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 8546 | // if (temp != nullptr) { |
| 8547 | // goto gc_root_thunk<root_reg>(lr) |
| 8548 | // } |
| 8549 | // return_address: |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8550 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8551 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8552 | ExcludeIPAndBakerCcEntrypointRegister(&temps, instruction); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8553 | bool narrow = CanEmitNarrowLdr(root_reg, obj, offset); |
| 8554 | uint32_t custom_data = linker::Thumb2RelativePatcher::EncodeBakerReadBarrierGcRootData( |
| 8555 | root_reg.GetCode(), narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8556 | vixl32::Label* bne_label = codegen_->NewBakerReadBarrierPatch(custom_data); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8557 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8558 | // entrypoint_reg = |
| 8559 | // Thread::Current()->pReadBarrierMarkReg12, i.e. pReadBarrierMarkIntrospection. |
| 8560 | DCHECK_EQ(ip.GetCode(), 12u); |
| 8561 | const int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 8562 | Thread::ReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ip.GetCode()); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8563 | __ Ldr(kBakerCcEntrypointRegister, MemOperand(tr, entry_point_offset)); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8564 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8565 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), |
| 8566 | 4 * vixl32::kMaxInstructionSizeInBytes); |
| 8567 | vixl32::Label return_address; |
| 8568 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8569 | __ cmp(kBakerCcEntrypointRegister, Operand(0)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8570 | // Currently the offset is always within range. If that changes, |
| 8571 | // we shall have to split the load the same way as for fields. |
| 8572 | DCHECK_LT(offset, kReferenceLoadMinFarOffset); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8573 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8574 | __ ldr(EncodingSize(narrow ? Narrow : Wide), root_reg, MemOperand(obj, offset)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8575 | EmitPlaceholderBne(codegen_, bne_label); |
| 8576 | __ Bind(&return_address); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8577 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8578 | narrow ? BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_OFFSET |
| 8579 | : BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8580 | } else { |
| 8581 | // Note that we do not actually check the value of |
| 8582 | // `GetIsGcMarking()` to decide whether to mark the loaded GC |
| 8583 | // root or not. Instead, we load into `temp` the read barrier |
| 8584 | // mark entry point corresponding to register `root`. If `temp` |
| 8585 | // is null, it means that `GetIsGcMarking()` is false, and vice |
| 8586 | // versa. |
| 8587 | // |
| 8588 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8589 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 8590 | // if (temp != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 8591 | // // Slow path. |
| 8592 | // root = temp(root); // root = ReadBarrier::Mark(root); // Runtime entry point call. |
| 8593 | // } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8594 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8595 | // Slow path marking the GC root `root`. The entrypoint will already be loaded in `temp`. |
| 8596 | Location temp = LocationFrom(lr); |
| 8597 | SlowPathCodeARMVIXL* slow_path = |
| 8598 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARMVIXL( |
| 8599 | instruction, root, /* entrypoint */ temp); |
| 8600 | codegen_->AddSlowPath(slow_path); |
| 8601 | |
| 8602 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8603 | const int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 8604 | Thread::ReadBarrierMarkEntryPointsOffset<kArmPointerSize>(root.reg()); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8605 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 8606 | // threads are suspended or running a checkpoint. |
| 8607 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp), tr, entry_point_offset); |
| 8608 | |
| 8609 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8610 | GetAssembler()->LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8611 | static_assert( |
| 8612 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 8613 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 8614 | "have different sizes."); |
| 8615 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 8616 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 8617 | "have different sizes."); |
| 8618 | |
| 8619 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 8620 | // checking GetIsGcMarking. |
| 8621 | __ CompareAndBranchIfNonZero(RegisterFrom(temp), slow_path->GetEntryLabel()); |
| 8622 | __ Bind(slow_path->GetExitLabel()); |
| 8623 | } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8624 | } else { |
| 8625 | // GC root loaded through a slow path for read barriers other |
| 8626 | // than Baker's. |
| 8627 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 8628 | __ Add(root_reg, obj, offset); |
| 8629 | // /* mirror::Object* */ root = root->Read() |
| 8630 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 8631 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8632 | } else { |
| 8633 | // Plain GC root load with no read barrier. |
| 8634 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8635 | GetAssembler()->LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8636 | // Note that GC roots are not affected by heap poisoning, thus we |
| 8637 | // do not have to unpoison `root_reg` here. |
| 8638 | } |
| 8639 | } |
| 8640 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8641 | void CodeGeneratorARMVIXL::MaybeAddBakerCcEntrypointTempForFields(LocationSummary* locations) { |
| 8642 | DCHECK(kEmitCompilerReadBarrier); |
| 8643 | DCHECK(kUseBakerReadBarrier); |
| 8644 | if (kBakerReadBarrierLinkTimeThunksEnableForFields) { |
| 8645 | if (!Runtime::Current()->UseJitCompilation()) { |
| 8646 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister.GetCode())); |
| 8647 | } |
| 8648 | } |
| 8649 | } |
| 8650 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8651 | void CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8652 | Location ref, |
| 8653 | vixl32::Register obj, |
| 8654 | uint32_t offset, |
| 8655 | Location temp, |
| 8656 | bool needs_null_check) { |
| 8657 | DCHECK(kEmitCompilerReadBarrier); |
| 8658 | DCHECK(kUseBakerReadBarrier); |
| 8659 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8660 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 8661 | !Runtime::Current()->UseJitCompilation()) { |
| 8662 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 8663 | // to decide whether to mark the loaded reference or not. Instead, we |
| 8664 | // load into `temp` (actually kBakerCcEntrypointRegister) the read |
| 8665 | // barrier mark introspection entrypoint. If `temp` is null, it means |
| 8666 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8667 | // |
| 8668 | // We use link-time generated thunks for the slow path. That thunk checks |
| 8669 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 8670 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 8671 | // |
| 8672 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
| 8673 | // lr = &gray_return_address; |
| 8674 | // if (temp != nullptr) { |
| 8675 | // goto field_thunk<holder_reg, base_reg>(lr) |
| 8676 | // } |
| 8677 | // not_gray_return_address: |
| 8678 | // // Original reference load. If the offset is too large to fit |
| 8679 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8680 | // HeapReference<mirror::Object> reference = *(obj+offset); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8681 | // gray_return_address: |
| 8682 | |
| 8683 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8684 | vixl32::Register ref_reg = RegisterFrom(ref, Primitive::kPrimNot); |
| 8685 | bool narrow = CanEmitNarrowLdr(ref_reg, obj, offset); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8686 | vixl32::Register base = obj; |
| 8687 | if (offset >= kReferenceLoadMinFarOffset) { |
| 8688 | base = RegisterFrom(temp); |
| 8689 | DCHECK(!base.Is(kBakerCcEntrypointRegister)); |
| 8690 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 8691 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 8692 | offset &= (kReferenceLoadMinFarOffset - 1u); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8693 | // Use narrow LDR only for small offsets. Generating narrow encoding LDR for the large |
| 8694 | // offsets with `(offset & (kReferenceLoadMinFarOffset - 1u)) < 32u` would most likely |
| 8695 | // increase the overall code size when taking the generated thunks into account. |
| 8696 | DCHECK(!narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8697 | } |
| 8698 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8699 | ExcludeIPAndBakerCcEntrypointRegister(&temps, instruction); |
| 8700 | uint32_t custom_data = linker::Thumb2RelativePatcher::EncodeBakerReadBarrierFieldData( |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8701 | base.GetCode(), obj.GetCode(), narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8702 | vixl32::Label* bne_label = NewBakerReadBarrierPatch(custom_data); |
| 8703 | |
| 8704 | // entrypoint_reg = |
| 8705 | // Thread::Current()->pReadBarrierMarkReg12, i.e. pReadBarrierMarkIntrospection. |
| 8706 | DCHECK_EQ(ip.GetCode(), 12u); |
| 8707 | const int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 8708 | Thread::ReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ip.GetCode()); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8709 | __ Ldr(kBakerCcEntrypointRegister, MemOperand(tr, entry_point_offset)); |
| 8710 | |
| 8711 | vixl::EmissionCheckScope guard( |
| 8712 | GetVIXLAssembler(), |
| 8713 | (kPoisonHeapReferences ? 5u : 4u) * vixl32::kMaxInstructionSizeInBytes); |
| 8714 | vixl32::Label return_address; |
| 8715 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8716 | __ cmp(kBakerCcEntrypointRegister, Operand(0)); |
| 8717 | EmitPlaceholderBne(this, bne_label); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8718 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8719 | __ ldr(EncodingSize(narrow ? Narrow : Wide), ref_reg, MemOperand(base, offset)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8720 | if (needs_null_check) { |
| 8721 | MaybeRecordImplicitNullCheck(instruction); |
| 8722 | } |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8723 | // Note: We need a specific width for the unpoisoning NEG. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8724 | if (kPoisonHeapReferences) { |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8725 | if (narrow) { |
| 8726 | // The only 16-bit encoding is T1 which sets flags outside IT block (i.e. RSBS, not RSB). |
| 8727 | __ rsbs(EncodingSize(Narrow), ref_reg, ref_reg, Operand(0)); |
| 8728 | } else { |
| 8729 | __ rsb(EncodingSize(Wide), ref_reg, ref_reg, Operand(0)); |
| 8730 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8731 | } |
| 8732 | __ Bind(&return_address); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8733 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8734 | narrow ? BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_OFFSET |
| 8735 | : BAKER_MARK_INTROSPECTION_FIELD_LDR_WIDE_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8736 | return; |
| 8737 | } |
| 8738 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8739 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 8740 | Location no_index = Location::NoLocation(); |
| 8741 | ScaleFactor no_scale_factor = TIMES_1; |
| 8742 | GenerateReferenceLoadWithBakerReadBarrier( |
| 8743 | 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] | 8744 | } |
| 8745 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8746 | void CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8747 | Location ref, |
| 8748 | vixl32::Register obj, |
| 8749 | uint32_t data_offset, |
| 8750 | Location index, |
| 8751 | Location temp, |
| 8752 | bool needs_null_check) { |
| 8753 | DCHECK(kEmitCompilerReadBarrier); |
| 8754 | DCHECK(kUseBakerReadBarrier); |
| 8755 | |
| 8756 | static_assert( |
| 8757 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 8758 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8759 | ScaleFactor scale_factor = TIMES_4; |
| 8760 | |
| 8761 | if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 8762 | !Runtime::Current()->UseJitCompilation()) { |
| 8763 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 8764 | // to decide whether to mark the loaded reference or not. Instead, we |
| 8765 | // load into `temp` (actually kBakerCcEntrypointRegister) the read |
| 8766 | // barrier mark introspection entrypoint. If `temp` is null, it means |
| 8767 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8768 | // |
| 8769 | // We use link-time generated thunks for the slow path. That thunk checks |
| 8770 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 8771 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 8772 | // |
| 8773 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
| 8774 | // lr = &gray_return_address; |
| 8775 | // if (temp != nullptr) { |
| 8776 | // goto field_thunk<holder_reg, base_reg>(lr) |
| 8777 | // } |
| 8778 | // not_gray_return_address: |
| 8779 | // // Original reference load. If the offset is too large to fit |
| 8780 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8781 | // HeapReference<mirror::Object> reference = data[index]; |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8782 | // gray_return_address: |
| 8783 | |
| 8784 | DCHECK(index.IsValid()); |
| 8785 | vixl32::Register index_reg = RegisterFrom(index, Primitive::kPrimInt); |
| 8786 | vixl32::Register ref_reg = RegisterFrom(ref, Primitive::kPrimNot); |
| 8787 | vixl32::Register data_reg = RegisterFrom(temp, Primitive::kPrimInt); // Raw pointer. |
| 8788 | DCHECK(!data_reg.Is(kBakerCcEntrypointRegister)); |
| 8789 | |
| 8790 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8791 | ExcludeIPAndBakerCcEntrypointRegister(&temps, instruction); |
| 8792 | uint32_t custom_data = |
| 8793 | linker::Thumb2RelativePatcher::EncodeBakerReadBarrierArrayData(data_reg.GetCode()); |
| 8794 | vixl32::Label* bne_label = NewBakerReadBarrierPatch(custom_data); |
| 8795 | |
| 8796 | // entrypoint_reg = |
| 8797 | // Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 8798 | DCHECK_EQ(ip.GetCode(), 12u); |
| 8799 | const int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 8800 | Thread::ReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ip.GetCode()); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8801 | __ Ldr(kBakerCcEntrypointRegister, MemOperand(tr, entry_point_offset)); |
| 8802 | __ Add(data_reg, obj, Operand(data_offset)); |
| 8803 | |
| 8804 | vixl::EmissionCheckScope guard( |
| 8805 | GetVIXLAssembler(), |
| 8806 | (kPoisonHeapReferences ? 5u : 4u) * vixl32::kMaxInstructionSizeInBytes); |
| 8807 | vixl32::Label return_address; |
| 8808 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8809 | __ cmp(kBakerCcEntrypointRegister, Operand(0)); |
| 8810 | EmitPlaceholderBne(this, bne_label); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8811 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8812 | __ ldr(ref_reg, MemOperand(data_reg, index_reg, vixl32::LSL, scale_factor)); |
| 8813 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 8814 | // Note: We need a Wide NEG for the unpoisoning. |
| 8815 | if (kPoisonHeapReferences) { |
| 8816 | __ rsb(EncodingSize(Wide), ref_reg, ref_reg, Operand(0)); |
| 8817 | } |
| 8818 | __ Bind(&return_address); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8819 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8820 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8821 | return; |
| 8822 | } |
| 8823 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8824 | // /* HeapReference<Object> */ ref = |
| 8825 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8826 | GenerateReferenceLoadWithBakerReadBarrier( |
| 8827 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | 6070e88 | 2016-11-03 17:51:58 +0000 | [diff] [blame] | 8828 | } |
| 8829 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8830 | void CodeGeneratorARMVIXL::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8831 | Location ref, |
| 8832 | vixl32::Register obj, |
| 8833 | uint32_t offset, |
| 8834 | Location index, |
| 8835 | ScaleFactor scale_factor, |
| 8836 | Location temp, |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8837 | bool needs_null_check) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8838 | DCHECK(kEmitCompilerReadBarrier); |
| 8839 | DCHECK(kUseBakerReadBarrier); |
| 8840 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8841 | // Query `art::Thread::Current()->GetIsGcMarking()` to decide |
| 8842 | // whether we need to enter the slow path to mark the reference. |
| 8843 | // Then, in the slow path, check the gray bit in the lock word of |
| 8844 | // the reference's holder (`obj`) to decide whether to mark `ref` or |
| 8845 | // not. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8846 | // |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8847 | // Note that we do not actually check the value of `GetIsGcMarking()`; |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8848 | // instead, we load into `temp2` the read barrier mark entry point |
| 8849 | // corresponding to register `ref`. If `temp2` is null, it means |
| 8850 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8851 | // |
| 8852 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8853 | // if (temp2 != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 8854 | // // Slow path. |
| 8855 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8856 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 8857 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 8858 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 8859 | // if (is_gray) { |
| 8860 | // ref = temp2(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 8861 | // } |
| 8862 | // } else { |
| 8863 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 8864 | // } |
| 8865 | |
| 8866 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 8867 | |
| 8868 | // Slow path marking the object `ref` when the GC is marking. The |
| 8869 | // entrypoint will already be loaded in `temp2`. |
| 8870 | Location temp2 = LocationFrom(lr); |
| 8871 | SlowPathCodeARMVIXL* slow_path = |
| 8872 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierSlowPathARMVIXL( |
| 8873 | instruction, |
| 8874 | ref, |
| 8875 | obj, |
| 8876 | offset, |
| 8877 | index, |
| 8878 | scale_factor, |
| 8879 | needs_null_check, |
| 8880 | temp_reg, |
| 8881 | /* entrypoint */ temp2); |
| 8882 | AddSlowPath(slow_path); |
| 8883 | |
| 8884 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## ref.reg() |
| 8885 | const int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 8886 | Thread::ReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref.reg()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8887 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 8888 | // threads are suspended or running a checkpoint. |
| 8889 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp2), tr, entry_point_offset); |
| 8890 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 8891 | // checking GetIsGcMarking. |
| 8892 | __ CompareAndBranchIfNonZero(RegisterFrom(temp2), slow_path->GetEntryLabel()); |
| 8893 | // Fast path: the GC is not marking: just load the reference. |
| 8894 | GenerateRawReferenceLoad(instruction, ref, obj, offset, index, scale_factor, needs_null_check); |
| 8895 | __ Bind(slow_path->GetExitLabel()); |
| 8896 | } |
| 8897 | |
| 8898 | void CodeGeneratorARMVIXL::UpdateReferenceFieldWithBakerReadBarrier(HInstruction* instruction, |
| 8899 | Location ref, |
| 8900 | vixl32::Register obj, |
| 8901 | Location field_offset, |
| 8902 | Location temp, |
| 8903 | bool needs_null_check, |
| 8904 | vixl32::Register temp2) { |
| 8905 | DCHECK(kEmitCompilerReadBarrier); |
| 8906 | DCHECK(kUseBakerReadBarrier); |
| 8907 | |
| 8908 | // Query `art::Thread::Current()->GetIsGcMarking()` to decide |
| 8909 | // whether we need to enter the slow path to update the reference |
| 8910 | // field within `obj`. Then, in the slow path, check the gray bit |
| 8911 | // in the lock word of the reference's holder (`obj`) to decide |
| 8912 | // whether to mark `ref` and update the field or not. |
| 8913 | // |
| 8914 | // Note that we do not actually check the value of `GetIsGcMarking()`; |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8915 | // instead, we load into `temp3` the read barrier mark entry point |
| 8916 | // corresponding to register `ref`. If `temp3` is null, it means |
| 8917 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8918 | // |
| 8919 | // temp3 = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8920 | // if (temp3 != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 8921 | // // Slow path. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8922 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8923 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8924 | // HeapReference<mirror::Object> ref = *(obj + field_offset); // Reference load. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8925 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 8926 | // if (is_gray) { |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8927 | // old_ref = ref; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8928 | // ref = temp3(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8929 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8930 | // } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8931 | // } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8932 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8933 | vixl32::Register temp_reg = RegisterFrom(temp); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8934 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8935 | // Slow path updating the object reference at address `obj + field_offset` |
| 8936 | // when the GC is marking. The entrypoint will already be loaded in `temp3`. |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8937 | Location temp3 = LocationFrom(lr); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8938 | SlowPathCodeARMVIXL* slow_path = |
| 8939 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL( |
| 8940 | instruction, |
| 8941 | ref, |
| 8942 | obj, |
| 8943 | /* offset */ 0u, |
| 8944 | /* index */ field_offset, |
| 8945 | /* scale_factor */ ScaleFactor::TIMES_1, |
| 8946 | needs_null_check, |
| 8947 | temp_reg, |
| 8948 | temp2, |
| 8949 | /* entrypoint */ temp3); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8950 | AddSlowPath(slow_path); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8951 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8952 | // temp3 = Thread::Current()->pReadBarrierMarkReg ## ref.reg() |
| 8953 | const int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 8954 | Thread::ReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref.reg()); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8955 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 8956 | // threads are suspended or running a checkpoint. |
| 8957 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp3), tr, entry_point_offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8958 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 8959 | // checking GetIsGcMarking. |
| 8960 | __ CompareAndBranchIfNonZero(RegisterFrom(temp3), slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8961 | // Fast path: the GC is not marking: nothing to do (the field is |
| 8962 | // up-to-date, and we don't need to load the reference). |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8963 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 844e653 | 2016-11-03 16:09:47 +0000 | [diff] [blame] | 8964 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8965 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8966 | void CodeGeneratorARMVIXL::GenerateRawReferenceLoad(HInstruction* instruction, |
| 8967 | Location ref, |
| 8968 | vixl::aarch32::Register obj, |
| 8969 | uint32_t offset, |
| 8970 | Location index, |
| 8971 | ScaleFactor scale_factor, |
| 8972 | bool needs_null_check) { |
| 8973 | Primitive::Type type = Primitive::kPrimNot; |
| 8974 | vixl32::Register ref_reg = RegisterFrom(ref, type); |
| 8975 | |
| 8976 | // If needed, vixl::EmissionCheckScope guards are used to ensure |
| 8977 | // that no pools are emitted between the load (macro) instruction |
| 8978 | // and MaybeRecordImplicitNullCheck. |
| 8979 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8980 | if (index.IsValid()) { |
| 8981 | // Load types involving an "index": ArrayGet, |
| 8982 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 8983 | // intrinsics. |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8984 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8985 | if (index.IsConstant()) { |
| 8986 | size_t computed_offset = |
| 8987 | (Int32ConstantFrom(index) << scale_factor) + offset; |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8988 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8989 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8990 | if (needs_null_check) { |
| 8991 | MaybeRecordImplicitNullCheck(instruction); |
| 8992 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8993 | } else { |
| 8994 | // Handle the special case of the |
| 8995 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 8996 | // intrinsics, which use a register pair as index ("long |
| 8997 | // offset"), of which only the low part contains data. |
| 8998 | vixl32::Register index_reg = index.IsRegisterPair() |
| 8999 | ? LowRegisterFrom(index) |
| 9000 | : RegisterFrom(index); |
| 9001 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 9002 | vixl32::Register temp = temps.Acquire(); |
| 9003 | __ Add(temp, obj, Operand(index_reg, ShiftType::LSL, scale_factor)); |
| 9004 | { |
| 9005 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 9006 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, temp, offset); |
| 9007 | if (needs_null_check) { |
| 9008 | MaybeRecordImplicitNullCheck(instruction); |
| 9009 | } |
| 9010 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9011 | } |
| 9012 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 9013 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
| 9014 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9015 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 9016 | if (needs_null_check) { |
| 9017 | MaybeRecordImplicitNullCheck(instruction); |
| 9018 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9019 | } |
| 9020 | |
Roland Levillain | 844e653 | 2016-11-03 16:09:47 +0000 | [diff] [blame] | 9021 | // Object* ref = ref_addr->AsMirrorPtr() |
| 9022 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | 844e653 | 2016-11-03 16:09:47 +0000 | [diff] [blame] | 9023 | } |
| 9024 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9025 | void CodeGeneratorARMVIXL::GenerateReadBarrierSlow(HInstruction* instruction, |
| 9026 | Location out, |
| 9027 | Location ref, |
| 9028 | Location obj, |
| 9029 | uint32_t offset, |
| 9030 | Location index) { |
| 9031 | DCHECK(kEmitCompilerReadBarrier); |
| 9032 | |
| 9033 | // Insert a slow path based read barrier *after* the reference load. |
| 9034 | // |
| 9035 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 9036 | // reference will be carried out by the runtime within the slow |
| 9037 | // path. |
| 9038 | // |
| 9039 | // Note that `ref` currently does not get unpoisoned (when heap |
| 9040 | // poisoning is enabled), which is alright as the `ref` argument is |
| 9041 | // not used by the artReadBarrierSlow entry point. |
| 9042 | // |
| 9043 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 9044 | SlowPathCodeARMVIXL* slow_path = new (GetGraph()->GetArena()) |
| 9045 | ReadBarrierForHeapReferenceSlowPathARMVIXL(instruction, out, ref, obj, offset, index); |
| 9046 | AddSlowPath(slow_path); |
| 9047 | |
| 9048 | __ B(slow_path->GetEntryLabel()); |
| 9049 | __ Bind(slow_path->GetExitLabel()); |
| 9050 | } |
| 9051 | |
| 9052 | void CodeGeneratorARMVIXL::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9053 | Location out, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9054 | Location ref, |
| 9055 | Location obj, |
| 9056 | uint32_t offset, |
| 9057 | Location index) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9058 | if (kEmitCompilerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9059 | // Baker's read barriers shall be handled by the fast path |
| 9060 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9061 | DCHECK(!kUseBakerReadBarrier); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9062 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 9063 | // by the runtime within the slow path. |
| 9064 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9065 | } else if (kPoisonHeapReferences) { |
| 9066 | GetAssembler()->UnpoisonHeapReference(RegisterFrom(out)); |
| 9067 | } |
| 9068 | } |
| 9069 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9070 | void CodeGeneratorARMVIXL::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 9071 | Location out, |
| 9072 | Location root) { |
| 9073 | DCHECK(kEmitCompilerReadBarrier); |
| 9074 | |
| 9075 | // Insert a slow path based read barrier *after* the GC root load. |
| 9076 | // |
| 9077 | // Note that GC roots are not affected by heap poisoning, so we do |
| 9078 | // not need to do anything special for this here. |
| 9079 | SlowPathCodeARMVIXL* slow_path = |
| 9080 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARMVIXL(instruction, out, root); |
| 9081 | AddSlowPath(slow_path); |
| 9082 | |
| 9083 | __ B(slow_path->GetEntryLabel()); |
| 9084 | __ Bind(slow_path->GetExitLabel()); |
| 9085 | } |
| 9086 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9087 | // Check if the desired_dispatch_info is supported. If it is, return it, |
| 9088 | // otherwise return a fall-back info that should be used instead. |
| 9089 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARMVIXL::GetSupportedInvokeStaticOrDirectDispatch( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9090 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 9091 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e807ff7 | 2017-01-23 09:03:12 +0000 | [diff] [blame] | 9092 | return desired_dispatch_info; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9093 | } |
| 9094 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9095 | vixl32::Register CodeGeneratorARMVIXL::GetInvokeStaticOrDirectExtraParameter( |
| 9096 | HInvokeStaticOrDirect* invoke, vixl32::Register temp) { |
| 9097 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 9098 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 9099 | if (!invoke->GetLocations()->Intrinsified()) { |
| 9100 | return RegisterFrom(location); |
| 9101 | } |
| 9102 | // For intrinsics we allow any location, so it may be on the stack. |
| 9103 | if (!location.IsRegister()) { |
| 9104 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, location.GetStackIndex()); |
| 9105 | return temp; |
| 9106 | } |
| 9107 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 9108 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 9109 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 9110 | // simple and more robust approach rather that trying to determine if that's the case. |
| 9111 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Scott Wakeling | d5cd497 | 2017-02-03 11:38:35 +0000 | [diff] [blame] | 9112 | if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(RegisterFrom(location).GetCode())) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9113 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(RegisterFrom(location).GetCode()); |
| 9114 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, stack_offset); |
| 9115 | return temp; |
| 9116 | } |
| 9117 | return RegisterFrom(location); |
| 9118 | } |
| 9119 | |
Vladimir Marko | d254f5c | 2017-06-02 15:18:36 +0000 | [diff] [blame] | 9120 | void CodeGeneratorARMVIXL::GenerateStaticOrDirectCall( |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9121 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9122 | 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] | 9123 | switch (invoke->GetMethodLoadKind()) { |
| 9124 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 9125 | uint32_t offset = |
| 9126 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 9127 | // temp = thread->string_init_entrypoint |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9128 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp), tr, offset); |
| 9129 | break; |
| 9130 | } |
| 9131 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 9132 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 9133 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9134 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 9135 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 9136 | PcRelativePatchInfo* labels = NewPcRelativeMethodPatch(invoke->GetTargetMethod()); |
| 9137 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 9138 | EmitMovwMovtPlaceholder(labels, temp_reg); |
| 9139 | break; |
| 9140 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9141 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 9142 | __ Mov(RegisterFrom(temp), Operand::From(invoke->GetMethodAddress())); |
| 9143 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9144 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
| 9145 | PcRelativePatchInfo* labels = NewMethodBssEntryPatch( |
| 9146 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex())); |
| 9147 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 9148 | EmitMovwMovtPlaceholder(labels, temp_reg); |
| 9149 | GetAssembler()->LoadFromOffset(kLoadWord, temp_reg, temp_reg, /* offset*/ 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9150 | break; |
| 9151 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9152 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 9153 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 9154 | return; // No code pointer retrieval; the runtime performs the call directly. |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9155 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9156 | } |
| 9157 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9158 | switch (invoke->GetCodePtrLocation()) { |
| 9159 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9160 | { |
| 9161 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 9162 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9163 | vixl32::k32BitT32InstructionSizeInBytes, |
| 9164 | CodeBufferCheckScope::kMaximumSize); |
| 9165 | __ bl(GetFrameEntryLabel()); |
| 9166 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 9167 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9168 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9169 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 9170 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 9171 | GetAssembler()->LoadFromOffset( |
| 9172 | kLoadWord, |
| 9173 | lr, |
| 9174 | RegisterFrom(callee_method), |
| 9175 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9176 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9177 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9178 | // 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] | 9179 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9180 | vixl32::k16BitT32InstructionSizeInBytes, |
| 9181 | CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9182 | // LR() |
| 9183 | __ blx(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9184 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9185 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9186 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9187 | } |
| 9188 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9189 | DCHECK(!IsLeafMethod()); |
| 9190 | } |
| 9191 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9192 | void CodeGeneratorARMVIXL::GenerateVirtualCall( |
| 9193 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9194 | vixl32::Register temp = RegisterFrom(temp_location); |
| 9195 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 9196 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
| 9197 | |
| 9198 | // Use the calling convention instead of the location of the receiver, as |
| 9199 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 9200 | // slow path, the arguments have been moved to the right place, so here we are |
| 9201 | // guaranteed that the receiver is the first register of the calling convention. |
| 9202 | InvokeDexCallingConventionARMVIXL calling_convention; |
| 9203 | vixl32::Register receiver = calling_convention.GetRegisterAt(0); |
| 9204 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9205 | { |
| 9206 | // Make sure the pc is recorded immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 9207 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9208 | vixl32::kMaxInstructionSizeInBytes, |
| 9209 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9210 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 9211 | __ ldr(temp, MemOperand(receiver, class_offset)); |
| 9212 | MaybeRecordImplicitNullCheck(invoke); |
| 9213 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9214 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 9215 | // emit a read barrier for the previous class reference load. |
| 9216 | // However this is not required in practice, as this is an |
| 9217 | // intermediate/temporary reference and because the current |
| 9218 | // concurrent copying collector keeps the from-space memory |
| 9219 | // intact/accessible until the end of the marking phase (the |
| 9220 | // concurrent copying collector may not in the future). |
| 9221 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 9222 | |
| 9223 | // temp = temp->GetMethodAt(method_offset); |
| 9224 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 9225 | kArmPointerSize).Int32Value(); |
| 9226 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 9227 | // LR = temp->GetEntryPoint(); |
| 9228 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9229 | { |
| 9230 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 9231 | // blx in T32 has only 16bit encoding that's why a stricter check for the scope is used. |
| 9232 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9233 | vixl32::k16BitT32InstructionSizeInBytes, |
| 9234 | CodeBufferCheckScope::kExactSize); |
| 9235 | // LR(); |
| 9236 | __ blx(lr); |
| 9237 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 9238 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9239 | } |
| 9240 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9241 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeMethodPatch( |
| 9242 | MethodReference target_method) { |
| 9243 | return NewPcRelativePatch(*target_method.dex_file, |
| 9244 | target_method.dex_method_index, |
| 9245 | &pc_relative_method_patches_); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9246 | } |
| 9247 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9248 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewMethodBssEntryPatch( |
| 9249 | MethodReference target_method) { |
| 9250 | return NewPcRelativePatch(*target_method.dex_file, |
| 9251 | target_method.dex_method_index, |
| 9252 | &method_bss_entry_patches_); |
| 9253 | } |
| 9254 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9255 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeTypePatch( |
| 9256 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 9257 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
| 9258 | } |
| 9259 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9260 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewTypeBssEntryPatch( |
| 9261 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 9262 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 9263 | } |
| 9264 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9265 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeStringPatch( |
| 9266 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 9267 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
| 9268 | } |
| 9269 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9270 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativePatch( |
| 9271 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 9272 | patches->emplace_back(dex_file, offset_or_index); |
| 9273 | return &patches->back(); |
| 9274 | } |
| 9275 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9276 | vixl::aarch32::Label* CodeGeneratorARMVIXL::NewBakerReadBarrierPatch(uint32_t custom_data) { |
| 9277 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 9278 | return &baker_read_barrier_patches_.back().label; |
| 9279 | } |
| 9280 | |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9281 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateBootImageAddressLiteral(uint32_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 9282 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9283 | } |
| 9284 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 9285 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitStringLiteral( |
| 9286 | const DexFile& dex_file, |
| 9287 | dex::StringIndex string_index, |
| 9288 | Handle<mirror::String> handle) { |
| 9289 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 9290 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9291 | return jit_string_patches_.GetOrCreate( |
| 9292 | StringReference(&dex_file, string_index), |
| 9293 | [this]() { |
| 9294 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 9295 | }); |
| 9296 | } |
| 9297 | |
| 9298 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 9299 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 9300 | Handle<mirror::Class> handle) { |
| 9301 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 9302 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9303 | return jit_class_patches_.GetOrCreate( |
| 9304 | TypeReference(&dex_file, type_index), |
| 9305 | [this]() { |
| 9306 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 9307 | }); |
| 9308 | } |
| 9309 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9310 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 9311 | inline void CodeGeneratorARMVIXL::EmitPcRelativeLinkerPatches( |
| 9312 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 9313 | ArenaVector<LinkerPatch>* linker_patches) { |
| 9314 | for (const PcRelativePatchInfo& info : infos) { |
| 9315 | const DexFile& dex_file = info.target_dex_file; |
| 9316 | size_t offset_or_index = info.offset_or_index; |
| 9317 | DCHECK(info.add_pc_label.IsBound()); |
| 9318 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.GetLocation()); |
| 9319 | // Add MOVW patch. |
| 9320 | DCHECK(info.movw_label.IsBound()); |
| 9321 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.GetLocation()); |
| 9322 | linker_patches->push_back(Factory(movw_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 9323 | // Add MOVT patch. |
| 9324 | DCHECK(info.movt_label.IsBound()); |
| 9325 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.GetLocation()); |
| 9326 | linker_patches->push_back(Factory(movt_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 9327 | } |
| 9328 | } |
| 9329 | |
| 9330 | void CodeGeneratorARMVIXL::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 9331 | DCHECK(linker_patches->empty()); |
| 9332 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9333 | /* MOVW+MOVT for each entry */ 2u * pc_relative_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9334 | /* MOVW+MOVT for each entry */ 2u * method_bss_entry_patches_.size() + |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9335 | /* MOVW+MOVT for each entry */ 2u * pc_relative_type_patches_.size() + |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9336 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9337 | /* MOVW+MOVT for each entry */ 2u * pc_relative_string_patches_.size() + |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9338 | baker_read_barrier_patches_.size(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9339 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9340 | if (GetCompilerOptions().IsBootImage()) { |
| 9341 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeMethodPatch>(pc_relative_method_patches_, |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9342 | linker_patches); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 9343 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 9344 | linker_patches); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9345 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 9346 | linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9347 | } else { |
| 9348 | DCHECK(pc_relative_method_patches_.empty()); |
| 9349 | DCHECK(pc_relative_type_patches_.empty()); |
| 9350 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 9351 | linker_patches); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9352 | } |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9353 | EmitPcRelativeLinkerPatches<LinkerPatch::MethodBssEntryPatch>(method_bss_entry_patches_, |
| 9354 | linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9355 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 9356 | linker_patches); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9357 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 9358 | linker_patches->push_back(LinkerPatch::BakerReadBarrierBranchPatch(info.label.GetLocation(), |
| 9359 | info.custom_data)); |
| 9360 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9361 | DCHECK_EQ(size, linker_patches->size()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9362 | } |
| 9363 | |
| 9364 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateUint32Literal( |
| 9365 | uint32_t value, |
| 9366 | Uint32ToLiteralMap* map) { |
| 9367 | return map->GetOrCreate( |
| 9368 | value, |
| 9369 | [this, value]() { |
| 9370 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ value); |
| 9371 | }); |
| 9372 | } |
| 9373 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 9374 | void LocationsBuilderARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 9375 | LocationSummary* locations = |
| 9376 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 9377 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 9378 | Location::RequiresRegister()); |
| 9379 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 9380 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 9381 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 9382 | } |
| 9383 | |
| 9384 | void InstructionCodeGeneratorARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 9385 | vixl32::Register res = OutputRegister(instr); |
| 9386 | vixl32::Register accumulator = |
| 9387 | InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 9388 | vixl32::Register mul_left = |
| 9389 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 9390 | vixl32::Register mul_right = |
| 9391 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
| 9392 | |
| 9393 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 9394 | __ Mla(res, mul_left, mul_right, accumulator); |
| 9395 | } else { |
| 9396 | __ Mls(res, mul_left, mul_right, accumulator); |
| 9397 | } |
| 9398 | } |
| 9399 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9400 | void LocationsBuilderARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9401 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9402 | LOG(FATAL) << "Unreachable"; |
| 9403 | } |
| 9404 | |
| 9405 | void InstructionCodeGeneratorARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9406 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9407 | LOG(FATAL) << "Unreachable"; |
| 9408 | } |
| 9409 | |
| 9410 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 9411 | void LocationsBuilderARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9412 | LocationSummary* locations = |
| 9413 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 9414 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9415 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
| 9416 | codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 9417 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 9418 | if (switch_instr->GetStartValue() != 0) { |
| 9419 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 9420 | } |
| 9421 | } |
| 9422 | } |
| 9423 | |
| 9424 | // TODO(VIXL): Investigate and reach the parity with old arm codegen. |
| 9425 | void InstructionCodeGeneratorARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9426 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 9427 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9428 | LocationSummary* locations = switch_instr->GetLocations(); |
| 9429 | vixl32::Register value_reg = InputRegisterAt(switch_instr, 0); |
| 9430 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 9431 | |
| 9432 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
| 9433 | !codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 9434 | // Create a series of compare/jumps. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9435 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9436 | vixl32::Register temp_reg = temps.Acquire(); |
| 9437 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 9438 | // the immediate, because IP is used as the destination register. For the other |
| 9439 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 9440 | // and they can be encoded in the instruction without making use of IP register. |
| 9441 | __ Adds(temp_reg, value_reg, -lower_bound); |
| 9442 | |
| 9443 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 9444 | // Jump to successors[0] if value == lower_bound. |
| 9445 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 9446 | int32_t last_index = 0; |
| 9447 | for (; num_entries - last_index > 2; last_index += 2) { |
| 9448 | __ Adds(temp_reg, temp_reg, -2); |
| 9449 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 9450 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9451 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 9452 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 9453 | } |
| 9454 | if (num_entries - last_index == 2) { |
| 9455 | // The last missing case_value. |
| 9456 | __ Cmp(temp_reg, 1); |
| 9457 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9458 | } |
| 9459 | |
| 9460 | // And the default for any other value. |
| 9461 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 9462 | __ B(codegen_->GetLabelOf(default_block)); |
| 9463 | } |
| 9464 | } else { |
| 9465 | // Create a table lookup. |
| 9466 | vixl32::Register table_base = RegisterFrom(locations->GetTemp(0)); |
| 9467 | |
| 9468 | JumpTableARMVIXL* jump_table = codegen_->CreateJumpTable(switch_instr); |
| 9469 | |
| 9470 | // Remove the bias. |
| 9471 | vixl32::Register key_reg; |
| 9472 | if (lower_bound != 0) { |
| 9473 | key_reg = RegisterFrom(locations->GetTemp(1)); |
| 9474 | __ Sub(key_reg, value_reg, lower_bound); |
| 9475 | } else { |
| 9476 | key_reg = value_reg; |
| 9477 | } |
| 9478 | |
| 9479 | // Check whether the value is in the table, jump to default block if not. |
| 9480 | __ Cmp(key_reg, num_entries - 1); |
| 9481 | __ B(hi, codegen_->GetLabelOf(default_block)); |
| 9482 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9483 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9484 | vixl32::Register jump_offset = temps.Acquire(); |
| 9485 | |
| 9486 | // Load jump offset from the table. |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9487 | { |
| 9488 | const size_t jump_size = switch_instr->GetNumEntries() * sizeof(int32_t); |
| 9489 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9490 | (vixl32::kMaxInstructionSizeInBytes * 4) + jump_size, |
| 9491 | CodeBufferCheckScope::kMaximumSize); |
| 9492 | __ adr(table_base, jump_table->GetTableStartLabel()); |
| 9493 | __ ldr(jump_offset, MemOperand(table_base, key_reg, vixl32::LSL, 2)); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9494 | |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9495 | // Jump to target block by branching to table_base(pc related) + offset. |
| 9496 | vixl32::Register target_address = table_base; |
| 9497 | __ add(target_address, table_base, jump_offset); |
| 9498 | __ bx(target_address); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 9499 | |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9500 | jump_table->EmitTable(codegen_); |
| 9501 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9502 | } |
| 9503 | } |
| 9504 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9505 | // Copy the result of a call into the given target. |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9506 | void CodeGeneratorARMVIXL::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 9507 | if (!trg.IsValid()) { |
| 9508 | DCHECK_EQ(type, Primitive::kPrimVoid); |
| 9509 | return; |
| 9510 | } |
| 9511 | |
| 9512 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 9513 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9514 | Location return_loc = InvokeDexCallingConventionVisitorARMVIXL().GetReturnLocation(type); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9515 | if (return_loc.Equals(trg)) { |
| 9516 | return; |
| 9517 | } |
| 9518 | |
| 9519 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 9520 | // with the last branch. |
| 9521 | if (type == Primitive::kPrimLong) { |
| 9522 | TODO_VIXL32(FATAL); |
| 9523 | } else if (type == Primitive::kPrimDouble) { |
| 9524 | TODO_VIXL32(FATAL); |
| 9525 | } else { |
| 9526 | // Let the parallel move resolver take care of all of this. |
| 9527 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 9528 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 9529 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 9530 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9531 | } |
| 9532 | |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9533 | void LocationsBuilderARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 9534 | LocationSummary* locations = |
| 9535 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 9536 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9537 | locations->SetOut(Location::RequiresRegister()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9538 | } |
| 9539 | |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9540 | void InstructionCodeGeneratorARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 9541 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| 9542 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 9543 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
| 9544 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9545 | OutputRegister(instruction), |
| 9546 | InputRegisterAt(instruction, 0), |
| 9547 | method_offset); |
| 9548 | } else { |
| 9549 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 9550 | instruction->GetIndex(), kArmPointerSize)); |
| 9551 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9552 | OutputRegister(instruction), |
| 9553 | InputRegisterAt(instruction, 0), |
| 9554 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 9555 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9556 | OutputRegister(instruction), |
| 9557 | OutputRegister(instruction), |
| 9558 | method_offset); |
| 9559 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9560 | } |
| 9561 | |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9562 | static void PatchJitRootUse(uint8_t* code, |
| 9563 | const uint8_t* roots_data, |
| 9564 | VIXLUInt32Literal* literal, |
| 9565 | uint64_t index_in_table) { |
| 9566 | DCHECK(literal->IsBound()); |
| 9567 | uint32_t literal_offset = literal->GetLocation(); |
| 9568 | uintptr_t address = |
| 9569 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 9570 | uint8_t* data = code + literal_offset; |
| 9571 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 9572 | } |
| 9573 | |
| 9574 | void CodeGeneratorARMVIXL::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 9575 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9576 | const StringReference& string_reference = entry.first; |
| 9577 | VIXLUInt32Literal* table_entry_literal = entry.second; |
| 9578 | const auto it = jit_string_roots_.find(string_reference); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9579 | DCHECK(it != jit_string_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9580 | uint64_t index_in_table = it->second; |
| 9581 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9582 | } |
| 9583 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9584 | const TypeReference& type_reference = entry.first; |
| 9585 | VIXLUInt32Literal* table_entry_literal = entry.second; |
| 9586 | const auto it = jit_class_roots_.find(type_reference); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9587 | DCHECK(it != jit_class_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9588 | uint64_t index_in_table = it->second; |
| 9589 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9590 | } |
| 9591 | } |
| 9592 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9593 | void CodeGeneratorARMVIXL::EmitMovwMovtPlaceholder( |
| 9594 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels, |
| 9595 | vixl32::Register out) { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 9596 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9597 | 3 * vixl32::kMaxInstructionSizeInBytes, |
| 9598 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9599 | // TODO(VIXL): Think about using mov instead of movw. |
| 9600 | __ bind(&labels->movw_label); |
| 9601 | __ movw(out, /* placeholder */ 0u); |
| 9602 | __ bind(&labels->movt_label); |
| 9603 | __ movt(out, /* placeholder */ 0u); |
| 9604 | __ bind(&labels->add_pc_label); |
| 9605 | __ add(out, out, pc); |
| 9606 | } |
| 9607 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9608 | #undef __ |
| 9609 | #undef QUICK_ENTRY_POINT |
| 9610 | #undef TODO_VIXL32 |
| 9611 | |
| 9612 | } // namespace arm |
| 9613 | } // namespace art |