| 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 | |
| 19 | #include "arch/arm/instruction_set_features_arm.h" |
| 20 | #include "art_method.h" |
| 21 | #include "code_generator_utils.h" |
| 22 | #include "common_arm.h" |
| 23 | #include "compiled_method.h" |
| 24 | #include "entrypoints/quick/quick_entrypoints.h" |
| 25 | #include "gc/accounting/card_table.h" |
| Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 26 | #include "intrinsics_arm_vixl.h" |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 27 | #include "mirror/array-inl.h" |
| 28 | #include "mirror/class-inl.h" |
| 29 | #include "thread.h" |
| 30 | #include "utils/arm/assembler_arm_vixl.h" |
| 31 | #include "utils/arm/managed_register_arm.h" |
| 32 | #include "utils/assembler.h" |
| 33 | #include "utils/stack_checks.h" |
| 34 | |
| 35 | namespace art { |
| 36 | namespace arm { |
| 37 | |
| 38 | namespace vixl32 = vixl::aarch32; |
| 39 | using namespace vixl32; // NOLINT(build/namespaces) |
| 40 | |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 41 | using helpers::DRegisterFrom; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 42 | using helpers::DWARFReg; |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 43 | using helpers::HighDRegisterFrom; |
| 44 | using helpers::HighRegisterFrom; |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 45 | using helpers::InputDRegisterAt; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 46 | using helpers::InputOperandAt; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 47 | using helpers::InputRegister; |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 48 | using helpers::InputRegisterAt; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 49 | using helpers::InputSRegisterAt; |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 50 | using helpers::InputVRegister; |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 51 | using helpers::InputVRegisterAt; |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 52 | using helpers::Int32ConstantFrom; |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 53 | using helpers::Int64ConstantFrom; |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 54 | using helpers::LocationFrom; |
| 55 | using helpers::LowRegisterFrom; |
| 56 | using helpers::LowSRegisterFrom; |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 57 | using helpers::OperandFrom; |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 58 | using helpers::OutputRegister; |
| 59 | using helpers::OutputSRegister; |
| 60 | using helpers::OutputVRegister; |
| 61 | using helpers::RegisterFrom; |
| 62 | using helpers::SRegisterFrom; |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 63 | using helpers::Uint64ConstantFrom; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 64 | |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 65 | using vixl::ExactAssemblyScope; |
| 66 | using vixl::CodeBufferCheckScope; |
| 67 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 68 | using RegisterList = vixl32::RegisterList; |
| 69 | |
| 70 | static bool ExpectedPairLayout(Location location) { |
| 71 | // We expected this for both core and fpu register pairs. |
| 72 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 73 | } |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 74 | // Use a local definition to prevent copying mistakes. |
| 75 | static constexpr size_t kArmWordSize = static_cast<size_t>(kArmPointerSize); |
| 76 | static constexpr size_t kArmBitsPerWord = kArmWordSize * kBitsPerByte; |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 77 | static constexpr int kCurrentMethodStackOffset = 0; |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 78 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 79 | |
| 80 | #ifdef __ |
| 81 | #error "ARM Codegen VIXL macro-assembler macro already defined." |
| 82 | #endif |
| 83 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 84 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 85 | #define __ down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()-> // NOLINT |
| 86 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, x).Int32Value() |
| 87 | |
| 88 | // Marker that code is yet to be, and must, be implemented. |
| 89 | #define TODO_VIXL32(level) LOG(level) << __PRETTY_FUNCTION__ << " unimplemented " |
| 90 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 91 | // SaveLiveRegisters and RestoreLiveRegisters from SlowPathCodeARM operate on sets of S registers, |
| 92 | // for each live D registers they treat two corresponding S registers as live ones. |
| 93 | // |
| 94 | // Two following functions (SaveContiguousSRegisterList, RestoreContiguousSRegisterList) build |
| 95 | // from a list of contiguous S registers a list of contiguous D registers (processing first/last |
| 96 | // S registers corner cases) and save/restore this new list treating them as D registers. |
| 97 | // - decreasing code size |
| 98 | // - avoiding hazards on Cortex-A57, when a pair of S registers for an actual live D register is |
| 99 | // restored and then used in regular non SlowPath code as D register. |
| 100 | // |
| 101 | // For the following example (v means the S register is live): |
| 102 | // D names: | D0 | D1 | D2 | D4 | ... |
| 103 | // S names: | S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | ... |
| 104 | // Live? | | v | v | v | v | v | v | | ... |
| 105 | // |
| 106 | // S1 and S6 will be saved/restored independently; D registers list (D1, D2) will be processed |
| 107 | // as D registers. |
| 108 | // |
| 109 | // TODO(VIXL): All this code should be unnecessary once the VIXL AArch32 backend provides helpers |
| 110 | // for lists of floating-point registers. |
| 111 | static size_t SaveContiguousSRegisterList(size_t first, |
| 112 | size_t last, |
| 113 | CodeGenerator* codegen, |
| 114 | size_t stack_offset) { |
| 115 | static_assert(kSRegSizeInBytes == kArmWordSize, "Broken assumption on reg/word sizes."); |
| 116 | static_assert(kDRegSizeInBytes == 2 * kArmWordSize, "Broken assumption on reg/word sizes."); |
| 117 | DCHECK_LE(first, last); |
| 118 | if ((first == last) && (first == 0)) { |
| 119 | __ Vstr(vixl32::SRegister(first), MemOperand(sp, stack_offset)); |
| 120 | return stack_offset + kSRegSizeInBytes; |
| 121 | } |
| 122 | if (first % 2 == 1) { |
| 123 | __ Vstr(vixl32::SRegister(first++), MemOperand(sp, stack_offset)); |
| 124 | stack_offset += kSRegSizeInBytes; |
| 125 | } |
| 126 | |
| 127 | bool save_last = false; |
| 128 | if (last % 2 == 0) { |
| 129 | save_last = true; |
| 130 | --last; |
| 131 | } |
| 132 | |
| 133 | if (first < last) { |
| 134 | vixl32::DRegister d_reg = vixl32::DRegister(first / 2); |
| 135 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 136 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 137 | |
| 138 | if (number_of_d_regs == 1) { |
| 139 | __ Vstr(d_reg, MemOperand(sp, stack_offset)); |
| 140 | } else if (number_of_d_regs > 1) { |
| 141 | UseScratchRegisterScope temps(down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 142 | vixl32::Register base = sp; |
| 143 | if (stack_offset != 0) { |
| 144 | base = temps.Acquire(); |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 145 | __ Add(base, sp, Operand::From(stack_offset)); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 146 | } |
| 147 | __ Vstm(F64, base, NO_WRITE_BACK, DRegisterList(d_reg, number_of_d_regs)); |
| 148 | } |
| 149 | stack_offset += number_of_d_regs * kDRegSizeInBytes; |
| 150 | } |
| 151 | |
| 152 | if (save_last) { |
| 153 | __ Vstr(vixl32::SRegister(last + 1), MemOperand(sp, stack_offset)); |
| 154 | stack_offset += kSRegSizeInBytes; |
| 155 | } |
| 156 | |
| 157 | return stack_offset; |
| 158 | } |
| 159 | |
| 160 | static size_t RestoreContiguousSRegisterList(size_t first, |
| 161 | size_t last, |
| 162 | CodeGenerator* codegen, |
| 163 | size_t stack_offset) { |
| 164 | static_assert(kSRegSizeInBytes == kArmWordSize, "Broken assumption on reg/word sizes."); |
| 165 | static_assert(kDRegSizeInBytes == 2 * kArmWordSize, "Broken assumption on reg/word sizes."); |
| 166 | DCHECK_LE(first, last); |
| 167 | if ((first == last) && (first == 0)) { |
| 168 | __ Vldr(vixl32::SRegister(first), MemOperand(sp, stack_offset)); |
| 169 | return stack_offset + kSRegSizeInBytes; |
| 170 | } |
| 171 | if (first % 2 == 1) { |
| 172 | __ Vldr(vixl32::SRegister(first++), MemOperand(sp, stack_offset)); |
| 173 | stack_offset += kSRegSizeInBytes; |
| 174 | } |
| 175 | |
| 176 | bool restore_last = false; |
| 177 | if (last % 2 == 0) { |
| 178 | restore_last = true; |
| 179 | --last; |
| 180 | } |
| 181 | |
| 182 | if (first < last) { |
| 183 | vixl32::DRegister d_reg = vixl32::DRegister(first / 2); |
| 184 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 185 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 186 | if (number_of_d_regs == 1) { |
| 187 | __ Vldr(d_reg, MemOperand(sp, stack_offset)); |
| 188 | } else if (number_of_d_regs > 1) { |
| 189 | UseScratchRegisterScope temps(down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 190 | vixl32::Register base = sp; |
| 191 | if (stack_offset != 0) { |
| 192 | base = temps.Acquire(); |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 193 | __ Add(base, sp, Operand::From(stack_offset)); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 194 | } |
| 195 | __ Vldm(F64, base, NO_WRITE_BACK, DRegisterList(d_reg, number_of_d_regs)); |
| 196 | } |
| 197 | stack_offset += number_of_d_regs * kDRegSizeInBytes; |
| 198 | } |
| 199 | |
| 200 | if (restore_last) { |
| 201 | __ Vldr(vixl32::SRegister(last + 1), MemOperand(sp, stack_offset)); |
| 202 | stack_offset += kSRegSizeInBytes; |
| 203 | } |
| 204 | |
| 205 | return stack_offset; |
| 206 | } |
| 207 | |
| 208 | void SlowPathCodeARMVIXL::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 209 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 210 | size_t orig_offset = stack_offset; |
| 211 | |
| 212 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 213 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 214 | // If the register holds an object, update the stack mask. |
| 215 | if (locations->RegisterContainsObject(i)) { |
| 216 | locations->SetStackBit(stack_offset / kVRegSize); |
| 217 | } |
| 218 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 219 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 220 | saved_core_stack_offsets_[i] = stack_offset; |
| 221 | stack_offset += kArmWordSize; |
| 222 | } |
| 223 | |
| 224 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 225 | arm_codegen->GetAssembler()->StoreRegisterList(core_spills, orig_offset); |
| 226 | |
| 227 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 228 | orig_offset = stack_offset; |
| 229 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 230 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 231 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 232 | stack_offset += kArmWordSize; |
| 233 | } |
| 234 | |
| 235 | stack_offset = orig_offset; |
| 236 | while (fp_spills != 0u) { |
| 237 | uint32_t begin = CTZ(fp_spills); |
| 238 | uint32_t tmp = fp_spills + (1u << begin); |
| 239 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 240 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 241 | stack_offset = SaveContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 242 | } |
| 243 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 244 | } |
| 245 | |
| 246 | void SlowPathCodeARMVIXL::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 247 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 248 | size_t orig_offset = stack_offset; |
| 249 | |
| 250 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 251 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 252 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 253 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 254 | stack_offset += kArmWordSize; |
| 255 | } |
| 256 | |
| 257 | // TODO(VIXL): Check the coherency of stack_offset after this with a test. |
| 258 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 259 | arm_codegen->GetAssembler()->LoadRegisterList(core_spills, orig_offset); |
| 260 | |
| 261 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 262 | while (fp_spills != 0u) { |
| 263 | uint32_t begin = CTZ(fp_spills); |
| 264 | uint32_t tmp = fp_spills + (1u << begin); |
| 265 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 266 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 267 | stack_offset = RestoreContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 268 | } |
| 269 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 270 | } |
| 271 | |
| 272 | class NullCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 273 | public: |
| 274 | explicit NullCheckSlowPathARMVIXL(HNullCheck* instruction) : SlowPathCodeARMVIXL(instruction) {} |
| 275 | |
| 276 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 277 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 278 | __ Bind(GetEntryLabel()); |
| 279 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 280 | // Live registers will be restored in the catch block if caught. |
| 281 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 282 | } |
| 283 | arm_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 284 | instruction_, |
| 285 | instruction_->GetDexPc(), |
| 286 | this); |
| 287 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| 288 | } |
| 289 | |
| 290 | bool IsFatal() const OVERRIDE { return true; } |
| 291 | |
| 292 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARMVIXL"; } |
| 293 | |
| 294 | private: |
| 295 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARMVIXL); |
| 296 | }; |
| 297 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 298 | class DivZeroCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 299 | public: |
| 300 | explicit DivZeroCheckSlowPathARMVIXL(HDivZeroCheck* instruction) |
| 301 | : SlowPathCodeARMVIXL(instruction) {} |
| 302 | |
| 303 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 304 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 305 | __ Bind(GetEntryLabel()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 306 | arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 307 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| 308 | } |
| 309 | |
| 310 | bool IsFatal() const OVERRIDE { return true; } |
| 311 | |
| 312 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARMVIXL"; } |
| 313 | |
| 314 | private: |
| 315 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARMVIXL); |
| 316 | }; |
| 317 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 318 | class SuspendCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 319 | public: |
| 320 | SuspendCheckSlowPathARMVIXL(HSuspendCheck* instruction, HBasicBlock* successor) |
| 321 | : SlowPathCodeARMVIXL(instruction), successor_(successor) {} |
| 322 | |
| 323 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 324 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 325 | __ Bind(GetEntryLabel()); |
| 326 | arm_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
| 327 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
| 328 | if (successor_ == nullptr) { |
| 329 | __ B(GetReturnLabel()); |
| 330 | } else { |
| 331 | __ B(arm_codegen->GetLabelOf(successor_)); |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | vixl32::Label* GetReturnLabel() { |
| 336 | DCHECK(successor_ == nullptr); |
| 337 | return &return_label_; |
| 338 | } |
| 339 | |
| 340 | HBasicBlock* GetSuccessor() const { |
| 341 | return successor_; |
| 342 | } |
| 343 | |
| 344 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARMVIXL"; } |
| 345 | |
| 346 | private: |
| 347 | // If not null, the block to branch to after the suspend check. |
| 348 | HBasicBlock* const successor_; |
| 349 | |
| 350 | // If `successor_` is null, the label to branch to after the suspend check. |
| 351 | vixl32::Label return_label_; |
| 352 | |
| 353 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARMVIXL); |
| 354 | }; |
| 355 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 356 | class BoundsCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 357 | public: |
| 358 | explicit BoundsCheckSlowPathARMVIXL(HBoundsCheck* instruction) |
| 359 | : SlowPathCodeARMVIXL(instruction) {} |
| 360 | |
| 361 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 362 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 363 | LocationSummary* locations = instruction_->GetLocations(); |
| 364 | |
| 365 | __ Bind(GetEntryLabel()); |
| 366 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 367 | // Live registers will be restored in the catch block if caught. |
| 368 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 369 | } |
| 370 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 371 | // move resolver. |
| 372 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 373 | codegen->EmitParallelMoves( |
| 374 | locations->InAt(0), |
| 375 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 376 | Primitive::kPrimInt, |
| 377 | locations->InAt(1), |
| 378 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 379 | Primitive::kPrimInt); |
| 380 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 381 | ? kQuickThrowStringBounds |
| 382 | : kQuickThrowArrayBounds; |
| 383 | arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
| 384 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
| 385 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| 386 | } |
| 387 | |
| 388 | bool IsFatal() const OVERRIDE { return true; } |
| 389 | |
| 390 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARMVIXL"; } |
| 391 | |
| 392 | private: |
| 393 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARMVIXL); |
| 394 | }; |
| 395 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 396 | class LoadClassSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 397 | public: |
| 398 | LoadClassSlowPathARMVIXL(HLoadClass* cls, HInstruction* at, uint32_t dex_pc, bool do_clinit) |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 399 | : SlowPathCodeARMVIXL(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 400 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 401 | } |
| 402 | |
| 403 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 404 | LocationSummary* locations = instruction_->GetLocations(); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 405 | Location out = locations->Out(); |
| 406 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 407 | |
| 408 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 409 | __ Bind(GetEntryLabel()); |
| 410 | SaveLiveRegisters(codegen, locations); |
| 411 | |
| 412 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 413 | // For HLoadClass/kBssEntry/kSaveEverything, make sure we preserve the address of the entry. |
| 414 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 415 | bool is_load_class_bss_entry = |
| 416 | (cls_ == instruction_) && (cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry); |
| 417 | vixl32::Register entry_address; |
| 418 | if (is_load_class_bss_entry && call_saves_everything_except_r0) { |
| 419 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 420 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
| 421 | // the kSaveEverything call. |
| 422 | bool temp_is_r0 = temp.Is(calling_convention.GetRegisterAt(0)); |
| 423 | entry_address = temp_is_r0 ? RegisterFrom(out) : temp; |
| 424 | DCHECK(!entry_address.Is(calling_convention.GetRegisterAt(0))); |
| 425 | if (temp_is_r0) { |
| 426 | __ Mov(entry_address, temp); |
| 427 | } |
| 428 | } |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 429 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 430 | __ Mov(calling_convention.GetRegisterAt(0), type_index.index_); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 431 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 432 | : kQuickInitializeType; |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 433 | arm_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 434 | if (do_clinit_) { |
| 435 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 436 | } else { |
| 437 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 438 | } |
| 439 | |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 440 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
| 441 | if (is_load_class_bss_entry) { |
| 442 | if (call_saves_everything_except_r0) { |
| 443 | // The class entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 444 | __ Str(r0, MemOperand(entry_address)); |
| 445 | } else { |
| 446 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
| 447 | UseScratchRegisterScope temps( |
| 448 | down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 449 | vixl32::Register temp = temps.Acquire(); |
| 450 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 451 | arm_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index); |
| 452 | arm_codegen->EmitMovwMovtPlaceholder(labels, temp); |
| 453 | __ Str(r0, MemOperand(temp)); |
| 454 | } |
| 455 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 456 | // Move the class to the desired location. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 457 | if (out.IsValid()) { |
| 458 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 459 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
| 460 | } |
| 461 | RestoreLiveRegisters(codegen, locations); |
| 462 | __ B(GetExitLabel()); |
| 463 | } |
| 464 | |
| 465 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARMVIXL"; } |
| 466 | |
| 467 | private: |
| 468 | // The class this slow path will load. |
| 469 | HLoadClass* const cls_; |
| 470 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 471 | // The dex PC of `at_`. |
| 472 | const uint32_t dex_pc_; |
| 473 | |
| 474 | // Whether to initialize the class. |
| 475 | const bool do_clinit_; |
| 476 | |
| 477 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARMVIXL); |
| 478 | }; |
| 479 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 480 | class LoadStringSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 481 | public: |
| 482 | explicit LoadStringSlowPathARMVIXL(HLoadString* instruction) |
| 483 | : SlowPathCodeARMVIXL(instruction) {} |
| 484 | |
| 485 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 486 | DCHECK(instruction_->IsLoadString()); |
| 487 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 488 | LocationSummary* locations = instruction_->GetLocations(); |
| 489 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 490 | HLoadString* load = instruction_->AsLoadString(); |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 491 | const dex::StringIndex string_index = load->GetStringIndex(); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 492 | vixl32::Register out = OutputRegister(load); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 493 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
| 494 | |
| 495 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 496 | __ Bind(GetEntryLabel()); |
| 497 | SaveLiveRegisters(codegen, locations); |
| 498 | |
| 499 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 500 | // 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] | 501 | // the kSaveEverything call. |
| 502 | vixl32::Register entry_address; |
| 503 | if (call_saves_everything_except_r0) { |
| 504 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 505 | bool temp_is_r0 = (temp.Is(calling_convention.GetRegisterAt(0))); |
| 506 | entry_address = temp_is_r0 ? out : temp; |
| 507 | DCHECK(!entry_address.Is(calling_convention.GetRegisterAt(0))); |
| 508 | if (temp_is_r0) { |
| 509 | __ Mov(entry_address, temp); |
| 510 | } |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 511 | } |
| 512 | |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 513 | __ Mov(calling_convention.GetRegisterAt(0), string_index.index_); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 514 | arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 515 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 516 | |
| 517 | // Store the resolved String to the .bss entry. |
| 518 | if (call_saves_everything_except_r0) { |
| 519 | // The string entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 520 | __ Str(r0, MemOperand(entry_address)); |
| 521 | } else { |
| 522 | // 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] | 523 | UseScratchRegisterScope temps( |
| 524 | down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 525 | vixl32::Register temp = temps.Acquire(); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 526 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 527 | arm_codegen->NewPcRelativeStringPatch(load->GetDexFile(), string_index); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 528 | arm_codegen->EmitMovwMovtPlaceholder(labels, temp); |
| 529 | __ Str(r0, MemOperand(temp)); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
| 533 | RestoreLiveRegisters(codegen, locations); |
| 534 | |
| 535 | __ B(GetExitLabel()); |
| 536 | } |
| 537 | |
| 538 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARMVIXL"; } |
| 539 | |
| 540 | private: |
| 541 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARMVIXL); |
| 542 | }; |
| 543 | |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 544 | class TypeCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 545 | public: |
| 546 | TypeCheckSlowPathARMVIXL(HInstruction* instruction, bool is_fatal) |
| 547 | : SlowPathCodeARMVIXL(instruction), is_fatal_(is_fatal) {} |
| 548 | |
| 549 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 550 | LocationSummary* locations = instruction_->GetLocations(); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 551 | DCHECK(instruction_->IsCheckCast() |
| 552 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 553 | |
| 554 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 555 | __ Bind(GetEntryLabel()); |
| 556 | |
| 557 | if (!is_fatal_) { |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 558 | SaveLiveRegisters(codegen, locations); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 562 | // move resolver. |
| 563 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 564 | |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 565 | codegen->EmitParallelMoves(locations->InAt(0), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 566 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 567 | Primitive::kPrimNot, |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 568 | locations->InAt(1), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 569 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 570 | Primitive::kPrimNot); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 571 | if (instruction_->IsInstanceOf()) { |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 572 | arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
| 573 | instruction_, |
| 574 | instruction_->GetDexPc(), |
| 575 | this); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 576 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 577 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 578 | } else { |
| 579 | DCHECK(instruction_->IsCheckCast()); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 580 | arm_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 581 | instruction_, |
| 582 | instruction_->GetDexPc(), |
| 583 | this); |
| 584 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | if (!is_fatal_) { |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 588 | RestoreLiveRegisters(codegen, locations); |
| 589 | __ B(GetExitLabel()); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 590 | } |
| 591 | } |
| 592 | |
| 593 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARMVIXL"; } |
| 594 | |
| 595 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 596 | |
| 597 | private: |
| 598 | const bool is_fatal_; |
| 599 | |
| 600 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARMVIXL); |
| 601 | }; |
| 602 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 603 | class DeoptimizationSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 604 | public: |
| 605 | explicit DeoptimizationSlowPathARMVIXL(HDeoptimize* instruction) |
| 606 | : SlowPathCodeARMVIXL(instruction) {} |
| 607 | |
| 608 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 609 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 610 | __ Bind(GetEntryLabel()); |
| 611 | arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
| 612 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
| 613 | } |
| 614 | |
| 615 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARMVIXL"; } |
| 616 | |
| 617 | private: |
| 618 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARMVIXL); |
| 619 | }; |
| 620 | |
| 621 | class ArraySetSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 622 | public: |
| 623 | explicit ArraySetSlowPathARMVIXL(HInstruction* instruction) : SlowPathCodeARMVIXL(instruction) {} |
| 624 | |
| 625 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 626 | LocationSummary* locations = instruction_->GetLocations(); |
| 627 | __ Bind(GetEntryLabel()); |
| 628 | SaveLiveRegisters(codegen, locations); |
| 629 | |
| 630 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 631 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 632 | parallel_move.AddMove( |
| 633 | locations->InAt(0), |
| 634 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 635 | Primitive::kPrimNot, |
| 636 | nullptr); |
| 637 | parallel_move.AddMove( |
| 638 | locations->InAt(1), |
| 639 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 640 | Primitive::kPrimInt, |
| 641 | nullptr); |
| 642 | parallel_move.AddMove( |
| 643 | locations->InAt(2), |
| 644 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 645 | Primitive::kPrimNot, |
| 646 | nullptr); |
| 647 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 648 | |
| 649 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 650 | arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| 651 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 652 | RestoreLiveRegisters(codegen, locations); |
| 653 | __ B(GetExitLabel()); |
| 654 | } |
| 655 | |
| 656 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARMVIXL"; } |
| 657 | |
| 658 | private: |
| 659 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARMVIXL); |
| 660 | }; |
| 661 | |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 662 | // Abstract base class for read barrier slow paths marking a reference |
| 663 | // `ref`. |
| Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 664 | // |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 665 | // Argument `entrypoint` must be a register location holding the read |
| 666 | // barrier marking runtime entry point to be invoked. |
| 667 | class ReadBarrierMarkSlowPathBaseARMVIXL : public SlowPathCodeARMVIXL { |
| 668 | protected: |
| 669 | ReadBarrierMarkSlowPathBaseARMVIXL(HInstruction* instruction, Location ref, Location entrypoint) |
| Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 670 | : SlowPathCodeARMVIXL(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 671 | DCHECK(kEmitCompilerReadBarrier); |
| 672 | } |
| 673 | |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 674 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathBaseARMVIXL"; } |
| Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 675 | |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 676 | // Generate assembly code calling the read barrier marking runtime |
| 677 | // entry point (ReadBarrierMarkRegX). |
| 678 | void GenerateReadBarrierMarkRuntimeCall(CodeGenerator* codegen) { |
| Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 679 | vixl32::Register ref_reg = RegisterFrom(ref_); |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 680 | |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 681 | // No need to save live registers; it's taken care of by the |
| 682 | // entrypoint. Also, there is no need to update the stack mask, |
| 683 | // as this runtime call will not trigger a garbage collection. |
| 684 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 685 | DCHECK(!ref_reg.Is(sp)); |
| 686 | DCHECK(!ref_reg.Is(lr)); |
| 687 | DCHECK(!ref_reg.Is(pc)); |
| 688 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 689 | // as a temporary, it cannot be the entry point's input/output. |
| 690 | DCHECK(!ref_reg.Is(ip)); |
| 691 | DCHECK(ref_reg.IsRegister()) << ref_reg; |
| 692 | // "Compact" slow path, saving two moves. |
| 693 | // |
| 694 | // Instead of using the standard runtime calling convention (input |
| 695 | // and output in R0): |
| 696 | // |
| 697 | // R0 <- ref |
| 698 | // R0 <- ReadBarrierMark(R0) |
| 699 | // ref <- R0 |
| 700 | // |
| 701 | // we just use rX (the register containing `ref`) as input and output |
| 702 | // of a dedicated entrypoint: |
| 703 | // |
| 704 | // rX <- ReadBarrierMarkRegX(rX) |
| 705 | // |
| 706 | if (entrypoint_.IsValid()) { |
| 707 | arm_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 708 | __ Blx(RegisterFrom(entrypoint_)); |
| 709 | } else { |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 710 | // Entrypoint is not already loaded, load from the thread. |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 711 | int32_t entry_point_offset = |
| 712 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg.GetCode()); |
| 713 | // This runtime call does not require a stack map. |
| 714 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 715 | } |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 716 | } |
| 717 | |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 718 | // The location (register) of the marked object reference. |
| 719 | const Location ref_; |
| 720 | |
| 721 | // The location of the entrypoint if already loaded. |
| 722 | const Location entrypoint_; |
| 723 | |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 724 | private: |
| 725 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathBaseARMVIXL); |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 726 | }; |
| 727 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 728 | // Slow path marking an object reference `ref` during a read |
| 729 | // barrier. The field `obj.field` in the object `obj` holding this |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 730 | // reference does not get updated by this slow path after marking. |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 731 | // |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 732 | // This means that after the execution of this slow path, `ref` will |
| Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 733 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 734 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 735 | // probably still be a from-space reference (unless it gets updated by |
| 736 | // another thread, or if another thread installed another object |
| 737 | // reference (different from `ref`) in `obj.field`). |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 738 | // |
| 739 | // If `entrypoint` is a valid location it is assumed to already be |
| 740 | // holding the entrypoint. The case where the entrypoint is passed in |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 741 | // is when the decision to mark is based on whether the GC is marking. |
| 742 | class ReadBarrierMarkSlowPathARMVIXL : public ReadBarrierMarkSlowPathBaseARMVIXL { |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 743 | public: |
| Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 744 | ReadBarrierMarkSlowPathARMVIXL(HInstruction* instruction, |
| 745 | Location ref, |
| 746 | Location entrypoint = Location::NoLocation()) |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 747 | : ReadBarrierMarkSlowPathBaseARMVIXL(instruction, ref, entrypoint) { |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 748 | DCHECK(kEmitCompilerReadBarrier); |
| 749 | } |
| 750 | |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 751 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARMVIXL"; } |
| 752 | |
| 753 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 754 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 755 | DCHECK(locations->CanCall()); |
| 756 | DCHECK(ref_.IsRegister()) << ref_; |
| 757 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
| 758 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 759 | << "Unexpected instruction in read barrier marking slow path: " |
| 760 | << instruction_->DebugName(); |
| 761 | |
| 762 | __ Bind(GetEntryLabel()); |
| 763 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 764 | __ B(GetExitLabel()); |
| 765 | } |
| 766 | |
| 767 | private: |
| 768 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARMVIXL); |
| 769 | }; |
| 770 | |
| 771 | // Slow path loading `obj`'s lock word, loading a reference from |
| 772 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 773 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 774 | // read barrier). The field `obj.field` in the object `obj` holding |
| 775 | // this reference does not get updated by this slow path after marking |
| 776 | // (see LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL |
| 777 | // below for that). |
| 778 | // |
| 779 | // This means that after the execution of this slow path, `ref` will |
| 780 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 781 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 782 | // probably still be a from-space reference (unless it gets updated by |
| 783 | // another thread, or if another thread installed another object |
| 784 | // reference (different from `ref`) in `obj.field`). |
| 785 | // |
| 786 | // Argument `entrypoint` must be a register location holding the read |
| 787 | // barrier marking runtime entry point to be invoked. |
| 788 | class LoadReferenceWithBakerReadBarrierSlowPathARMVIXL : public ReadBarrierMarkSlowPathBaseARMVIXL { |
| 789 | public: |
| 790 | LoadReferenceWithBakerReadBarrierSlowPathARMVIXL(HInstruction* instruction, |
| 791 | Location ref, |
| 792 | vixl32::Register obj, |
| 793 | uint32_t offset, |
| 794 | Location index, |
| 795 | ScaleFactor scale_factor, |
| 796 | bool needs_null_check, |
| 797 | vixl32::Register temp, |
| 798 | Location entrypoint) |
| 799 | : ReadBarrierMarkSlowPathBaseARMVIXL(instruction, ref, entrypoint), |
| 800 | obj_(obj), |
| 801 | offset_(offset), |
| 802 | index_(index), |
| 803 | scale_factor_(scale_factor), |
| 804 | needs_null_check_(needs_null_check), |
| 805 | temp_(temp) { |
| 806 | DCHECK(kEmitCompilerReadBarrier); |
| 807 | DCHECK(kUseBakerReadBarrier); |
| 808 | } |
| 809 | |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 810 | const char* GetDescription() const OVERRIDE { |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 811 | return "LoadReferenceWithBakerReadBarrierSlowPathARMVIXL"; |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 815 | LocationSummary* locations = instruction_->GetLocations(); |
| 816 | vixl32::Register ref_reg = RegisterFrom(ref_); |
| 817 | DCHECK(locations->CanCall()); |
| 818 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg.GetCode())) << ref_reg; |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 819 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 820 | instruction_->IsStaticFieldGet() || |
| 821 | instruction_->IsArrayGet() || |
| 822 | instruction_->IsArraySet() || |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 823 | instruction_->IsInstanceOf() || |
| 824 | instruction_->IsCheckCast() || |
| 825 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 826 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 827 | << "Unexpected instruction in read barrier marking slow path: " |
| 828 | << instruction_->DebugName(); |
| 829 | // The read barrier instrumentation of object ArrayGet |
| 830 | // instructions does not support the HIntermediateAddress |
| 831 | // instruction. |
| 832 | DCHECK(!(instruction_->IsArrayGet() && |
| 833 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 834 | |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 835 | // Temporary register `temp_`, used to store the lock word, must |
| 836 | // not be IP, as we may use it to emit the reference load (in the |
| 837 | // call to GenerateRawReferenceLoad below), and we need the lock |
| 838 | // word to still be in `temp_` after the reference load. |
| 839 | DCHECK(!temp_.Is(ip)); |
| 840 | |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 841 | __ Bind(GetEntryLabel()); |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 842 | |
| 843 | // When using MaybeGenerateReadBarrierSlow, the read barrier call is |
| 844 | // inserted after the original load. However, in fast path based |
| 845 | // Baker's read barriers, we need to perform the load of |
| 846 | // mirror::Object::monitor_ *before* the original reference load. |
| 847 | // This load-load ordering is required by the read barrier. |
| Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame^] | 848 | // The slow path (for Baker's algorithm) should look like: |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 849 | // |
| 850 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 851 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 852 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 853 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 854 | // if (is_gray) { |
| 855 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 856 | // } |
| 857 | // |
| 858 | // Note: the original implementation in ReadBarrier::Barrier is |
| 859 | // slightly more complex as it performs additional checks that we do |
| 860 | // not do here for performance reasons. |
| 861 | |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 862 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 863 | |
| 864 | // /* int32_t */ monitor = obj->monitor_ |
| 865 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 866 | arm_codegen->GetAssembler()->LoadFromOffset(kLoadWord, temp_, obj_, monitor_offset); |
| 867 | if (needs_null_check_) { |
| 868 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 869 | } |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 870 | // /* LockWord */ lock_word = LockWord(monitor) |
| 871 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 872 | "art::LockWord and int32_t have different sizes."); |
| 873 | |
| 874 | // Introduce a dependency on the lock_word including the rb_state, |
| 875 | // which shall prevent load-load reordering without using |
| 876 | // a memory barrier (which would be more expensive). |
| 877 | // `obj` is unchanged by this operation, but its value now depends |
| 878 | // on `temp`. |
| 879 | __ Add(obj_, obj_, Operand(temp_, ShiftType::LSR, 32)); |
| 880 | |
| 881 | // The actual reference load. |
| 882 | // A possible implicit null check has already been handled above. |
| 883 | arm_codegen->GenerateRawReferenceLoad( |
| 884 | instruction_, ref_, obj_, offset_, index_, scale_factor_, /* needs_null_check */ false); |
| 885 | |
| 886 | // Mark the object `ref` when `obj` is gray. |
| 887 | // |
| 888 | // if (rb_state == ReadBarrier::GrayState()) |
| 889 | // ref = ReadBarrier::Mark(ref); |
| 890 | // |
| 891 | // Given the numeric representation, it's enough to check the low bit of the |
| 892 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 893 | // which can be a 16-bit instruction unlike the TST immediate. |
| 894 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 895 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 896 | __ Lsrs(temp_, temp_, LockWord::kReadBarrierStateShift + 1); |
| 897 | __ B(cc, GetExitLabel()); // Carry flag is the last bit shifted out by LSRS. |
| 898 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 899 | |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 900 | __ B(GetExitLabel()); |
| 901 | } |
| 902 | |
| 903 | private: |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 904 | // The register containing the object holding the marked object reference field. |
| 905 | vixl32::Register obj_; |
| 906 | // The offset, index and scale factor to access the reference in `obj_`. |
| 907 | uint32_t offset_; |
| 908 | Location index_; |
| 909 | ScaleFactor scale_factor_; |
| 910 | // Is a null check required? |
| 911 | bool needs_null_check_; |
| 912 | // A temporary register used to hold the lock word of `obj_`. |
| 913 | vixl32::Register temp_; |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 914 | |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 915 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierSlowPathARMVIXL); |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 916 | }; |
| 917 | |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 918 | // Slow path loading `obj`'s lock word, loading a reference from |
| 919 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 920 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 921 | // read barrier). If needed, this slow path also atomically updates |
| 922 | // the field `obj.field` in the object `obj` holding this reference |
| 923 | // after marking (contrary to |
| 924 | // LoadReferenceWithBakerReadBarrierSlowPathARMVIXL above, which never |
| 925 | // tries to update `obj.field`). |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 926 | // |
| 927 | // This means that after the execution of this slow path, both `ref` |
| 928 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 929 | // hold the same to-space reference (unless another thread installed |
| 930 | // another object reference (different from `ref`) in `obj.field`). |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 931 | // |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 932 | // |
| 933 | // Argument `entrypoint` must be a register location holding the read |
| 934 | // barrier marking runtime entry point to be invoked. |
| 935 | class LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL |
| 936 | : public ReadBarrierMarkSlowPathBaseARMVIXL { |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 937 | public: |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 938 | LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL(HInstruction* instruction, |
| 939 | Location ref, |
| 940 | vixl32::Register obj, |
| 941 | uint32_t offset, |
| 942 | Location index, |
| 943 | ScaleFactor scale_factor, |
| 944 | bool needs_null_check, |
| 945 | vixl32::Register temp1, |
| 946 | vixl32::Register temp2, |
| 947 | Location entrypoint) |
| 948 | : ReadBarrierMarkSlowPathBaseARMVIXL(instruction, ref, entrypoint), |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 949 | obj_(obj), |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 950 | offset_(offset), |
| 951 | index_(index), |
| 952 | scale_factor_(scale_factor), |
| 953 | needs_null_check_(needs_null_check), |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 954 | temp1_(temp1), |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 955 | temp2_(temp2) { |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 956 | DCHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 957 | DCHECK(kUseBakerReadBarrier); |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | const char* GetDescription() const OVERRIDE { |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 961 | return "LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL"; |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 965 | LocationSummary* locations = instruction_->GetLocations(); |
| 966 | vixl32::Register ref_reg = RegisterFrom(ref_); |
| 967 | DCHECK(locations->CanCall()); |
| 968 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg.GetCode())) << ref_reg; |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 969 | DCHECK_NE(ref_.reg(), LocationFrom(temp1_).reg()); |
| 970 | |
| 971 | // 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] | 972 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 973 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 974 | << instruction_->DebugName(); |
| 975 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 976 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 977 | DCHECK_EQ(offset_, 0u); |
| 978 | DCHECK_EQ(scale_factor_, ScaleFactor::TIMES_1); |
| 979 | Location field_offset = index_; |
| 980 | DCHECK(field_offset.IsRegisterPair()) << field_offset; |
| 981 | |
| 982 | // Temporary register `temp1_`, used to store the lock word, must |
| 983 | // not be IP, as we may use it to emit the reference load (in the |
| 984 | // call to GenerateRawReferenceLoad below), and we need the lock |
| 985 | // word to still be in `temp1_` after the reference load. |
| 986 | DCHECK(!temp1_.Is(ip)); |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 987 | |
| 988 | __ Bind(GetEntryLabel()); |
| 989 | |
| Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame^] | 990 | // The implementation is similar to LoadReferenceWithBakerReadBarrierSlowPathARMVIXL's: |
| 991 | // |
| 992 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 993 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 994 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 995 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 996 | // if (is_gray) { |
| 997 | // old_ref = ref; |
| 998 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 999 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 1000 | // } |
| 1001 | |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1002 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 1003 | |
| 1004 | // /* int32_t */ monitor = obj->monitor_ |
| 1005 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 1006 | arm_codegen->GetAssembler()->LoadFromOffset(kLoadWord, temp1_, obj_, monitor_offset); |
| 1007 | if (needs_null_check_) { |
| 1008 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| 1009 | } |
| 1010 | // /* LockWord */ lock_word = LockWord(monitor) |
| 1011 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 1012 | "art::LockWord and int32_t have different sizes."); |
| 1013 | |
| 1014 | // Introduce a dependency on the lock_word including the rb_state, |
| 1015 | // which shall prevent load-load reordering without using |
| 1016 | // a memory barrier (which would be more expensive). |
| 1017 | // `obj` is unchanged by this operation, but its value now depends |
| 1018 | // on `temp`. |
| 1019 | __ Add(obj_, obj_, Operand(temp1_, ShiftType::LSR, 32)); |
| 1020 | |
| 1021 | // The actual reference load. |
| 1022 | // A possible implicit null check has already been handled above. |
| 1023 | arm_codegen->GenerateRawReferenceLoad( |
| 1024 | instruction_, ref_, obj_, offset_, index_, scale_factor_, /* needs_null_check */ false); |
| 1025 | |
| 1026 | // Mark the object `ref` when `obj` is gray. |
| 1027 | // |
| 1028 | // if (rb_state == ReadBarrier::GrayState()) |
| 1029 | // ref = ReadBarrier::Mark(ref); |
| 1030 | // |
| 1031 | // Given the numeric representation, it's enough to check the low bit of the |
| 1032 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 1033 | // which can be a 16-bit instruction unlike the TST immediate. |
| 1034 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 1035 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 1036 | __ Lsrs(temp1_, temp1_, LockWord::kReadBarrierStateShift + 1); |
| 1037 | __ B(cc, GetExitLabel()); // Carry flag is the last bit shifted out by LSRS. |
| 1038 | |
| 1039 | // Save the old value of the reference before marking it. |
| Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1040 | // Note that we cannot use IP to save the old reference, as IP is |
| 1041 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 1042 | // need the old reference after the call to that entry point. |
| 1043 | DCHECK(!temp1_.Is(ip)); |
| 1044 | __ Mov(temp1_, ref_reg); |
| Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 1045 | |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1046 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1047 | |
| 1048 | // If the new reference is different from the old reference, |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1049 | // update the field in the holder (`*(obj_ + field_offset)`). |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1050 | // |
| 1051 | // Note that this field could also hold a different object, if |
| 1052 | // another thread had concurrently changed it. In that case, the |
| 1053 | // LDREX/SUBS/ITNE sequence of instructions in the compare-and-set |
| 1054 | // (CAS) operation below would abort the CAS, leaving the field |
| 1055 | // as-is. |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1056 | __ Cmp(temp1_, ref_reg); |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1057 | __ B(eq, GetExitLabel()); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1058 | |
| 1059 | // Update the the holder's field atomically. This may fail if |
| 1060 | // mutator updates before us, but it's OK. This is achieved |
| 1061 | // using a strong compare-and-set (CAS) operation with relaxed |
| 1062 | // memory synchronization ordering, where the expected value is |
| 1063 | // the old reference and the desired value is the new reference. |
| 1064 | |
| 1065 | UseScratchRegisterScope temps(arm_codegen->GetVIXLAssembler()); |
| 1066 | // Convenience aliases. |
| 1067 | vixl32::Register base = obj_; |
| 1068 | // The UnsafeCASObject intrinsic uses a register pair as field |
| 1069 | // offset ("long offset"), of which only the low part contains |
| 1070 | // data. |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1071 | vixl32::Register offset = LowRegisterFrom(field_offset); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1072 | vixl32::Register expected = temp1_; |
| 1073 | vixl32::Register value = ref_reg; |
| 1074 | vixl32::Register tmp_ptr = temps.Acquire(); // Pointer to actual memory. |
| 1075 | vixl32::Register tmp = temp2_; // Value in memory. |
| 1076 | |
| 1077 | __ Add(tmp_ptr, base, offset); |
| 1078 | |
| 1079 | if (kPoisonHeapReferences) { |
| 1080 | arm_codegen->GetAssembler()->PoisonHeapReference(expected); |
| 1081 | if (value.Is(expected)) { |
| 1082 | // Do not poison `value`, as it is the same register as |
| 1083 | // `expected`, which has just been poisoned. |
| 1084 | } else { |
| 1085 | arm_codegen->GetAssembler()->PoisonHeapReference(value); |
| 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | // do { |
| 1090 | // tmp = [r_ptr] - expected; |
| 1091 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 1092 | |
| 1093 | vixl32::Label loop_head, exit_loop; |
| 1094 | __ Bind(&loop_head); |
| 1095 | |
| 1096 | __ Ldrex(tmp, MemOperand(tmp_ptr)); |
| 1097 | |
| 1098 | __ Subs(tmp, tmp, expected); |
| 1099 | |
| 1100 | { |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 1101 | ExactAssemblyScope aas(arm_codegen->GetVIXLAssembler(), |
| 1102 | 2 * kMaxInstructionSizeInBytes, |
| 1103 | CodeBufferCheckScope::kMaximumSize); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1104 | |
| 1105 | __ it(ne); |
| 1106 | __ clrex(ne); |
| 1107 | } |
| 1108 | |
| Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 1109 | __ B(ne, &exit_loop, /* far_target */ false); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1110 | |
| 1111 | __ Strex(tmp, value, MemOperand(tmp_ptr)); |
| 1112 | __ Cmp(tmp, 1); |
| Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 1113 | __ B(eq, &loop_head, /* far_target */ false); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1114 | |
| 1115 | __ Bind(&exit_loop); |
| 1116 | |
| 1117 | if (kPoisonHeapReferences) { |
| 1118 | arm_codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 1119 | if (value.Is(expected)) { |
| 1120 | // Do not unpoison `value`, as it is the same register as |
| 1121 | // `expected`, which has just been unpoisoned. |
| 1122 | } else { |
| 1123 | arm_codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 1124 | } |
| 1125 | } |
| 1126 | |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1127 | __ B(GetExitLabel()); |
| 1128 | } |
| 1129 | |
| 1130 | private: |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1131 | // The register containing the object holding the marked object reference field. |
| 1132 | const vixl32::Register obj_; |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1133 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1134 | uint32_t offset_; |
| 1135 | Location index_; |
| 1136 | ScaleFactor scale_factor_; |
| 1137 | // Is a null check required? |
| 1138 | bool needs_null_check_; |
| 1139 | // A temporary register used to hold the lock word of `obj_`; and |
| 1140 | // also to hold the original reference value, when the reference is |
| 1141 | // marked. |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1142 | const vixl32::Register temp1_; |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1143 | // A temporary register used in the implementation of the CAS, to |
| 1144 | // update the object's reference field. |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1145 | const vixl32::Register temp2_; |
| 1146 | |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1147 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1148 | }; |
| 1149 | |
| 1150 | // Slow path generating a read barrier for a heap reference. |
| 1151 | class ReadBarrierForHeapReferenceSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 1152 | public: |
| 1153 | ReadBarrierForHeapReferenceSlowPathARMVIXL(HInstruction* instruction, |
| 1154 | Location out, |
| 1155 | Location ref, |
| 1156 | Location obj, |
| 1157 | uint32_t offset, |
| 1158 | Location index) |
| 1159 | : SlowPathCodeARMVIXL(instruction), |
| 1160 | out_(out), |
| 1161 | ref_(ref), |
| 1162 | obj_(obj), |
| 1163 | offset_(offset), |
| 1164 | index_(index) { |
| 1165 | DCHECK(kEmitCompilerReadBarrier); |
| 1166 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 1167 | // has been overwritten by (or after) the heap object reference load |
| 1168 | // to be instrumented, e.g.: |
| 1169 | // |
| 1170 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
| 1171 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| 1172 | // |
| 1173 | // In that case, we have lost the information about the original |
| 1174 | // object, and the emitted read barrier cannot work properly. |
| 1175 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 1176 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 1177 | } |
| 1178 | |
| 1179 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1180 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 1181 | LocationSummary* locations = instruction_->GetLocations(); |
| 1182 | vixl32::Register reg_out = RegisterFrom(out_); |
| 1183 | DCHECK(locations->CanCall()); |
| 1184 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.GetCode())); |
| 1185 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 1186 | instruction_->IsStaticFieldGet() || |
| 1187 | instruction_->IsArrayGet() || |
| 1188 | instruction_->IsInstanceOf() || |
| 1189 | instruction_->IsCheckCast() || |
| Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 1190 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1191 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 1192 | << instruction_->DebugName(); |
| 1193 | // The read barrier instrumentation of object ArrayGet |
| 1194 | // instructions does not support the HIntermediateAddress |
| 1195 | // instruction. |
| 1196 | DCHECK(!(instruction_->IsArrayGet() && |
| 1197 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 1198 | |
| 1199 | __ Bind(GetEntryLabel()); |
| 1200 | SaveLiveRegisters(codegen, locations); |
| 1201 | |
| 1202 | // We may have to change the index's value, but as `index_` is a |
| 1203 | // constant member (like other "inputs" of this slow path), |
| 1204 | // introduce a copy of it, `index`. |
| 1205 | Location index = index_; |
| 1206 | if (index_.IsValid()) { |
| 1207 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 1208 | if (instruction_->IsArrayGet()) { |
| 1209 | // Compute the actual memory offset and store it in `index`. |
| 1210 | vixl32::Register index_reg = RegisterFrom(index_); |
| 1211 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg.GetCode())); |
| 1212 | if (codegen->IsCoreCalleeSaveRegister(index_reg.GetCode())) { |
| 1213 | // We are about to change the value of `index_reg` (see the |
| 1214 | // calls to art::arm::Thumb2Assembler::Lsl and |
| 1215 | // art::arm::Thumb2Assembler::AddConstant below), but it has |
| 1216 | // not been saved by the previous call to |
| 1217 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1218 | // callee-save register -- |
| 1219 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1220 | // callee-save registers, as it has been designed with the |
| 1221 | // assumption that callee-save registers are supposed to be |
| 1222 | // handled by the called function. So, as a callee-save |
| 1223 | // register, `index_reg` _would_ eventually be saved onto |
| 1224 | // the stack, but it would be too late: we would have |
| 1225 | // changed its value earlier. Therefore, we manually save |
| 1226 | // it here into another freely available register, |
| 1227 | // `free_reg`, chosen of course among the caller-save |
| 1228 | // registers (as a callee-save `free_reg` register would |
| 1229 | // exhibit the same problem). |
| 1230 | // |
| 1231 | // Note we could have requested a temporary register from |
| 1232 | // the register allocator instead; but we prefer not to, as |
| 1233 | // this is a slow path, and we know we can find a |
| 1234 | // caller-save register that is available. |
| 1235 | vixl32::Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1236 | __ Mov(free_reg, index_reg); |
| 1237 | index_reg = free_reg; |
| 1238 | index = LocationFrom(index_reg); |
| 1239 | } else { |
| 1240 | // The initial register stored in `index_` has already been |
| 1241 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1242 | // (as it is not a callee-save register), so we can freely |
| 1243 | // use it. |
| 1244 | } |
| 1245 | // Shifting the index value contained in `index_reg` by the scale |
| 1246 | // factor (2) cannot overflow in practice, as the runtime is |
| 1247 | // unable to allocate object arrays with a size larger than |
| 1248 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 1249 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 1250 | static_assert( |
| 1251 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1252 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1253 | __ Add(index_reg, index_reg, offset_); |
| 1254 | } else { |
| 1255 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1256 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1257 | // (as in the case of ArrayGet), as it is actually an offset |
| 1258 | // to an object field within an object. |
| 1259 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| 1260 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1261 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1262 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1263 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 1264 | DCHECK_EQ(offset_, 0U); |
| 1265 | DCHECK(index_.IsRegisterPair()); |
| 1266 | // UnsafeGet's offset location is a register pair, the low |
| 1267 | // part contains the correct offset. |
| 1268 | index = index_.ToLow(); |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | // We're moving two or three locations to locations that could |
| 1273 | // overlap, so we need a parallel move resolver. |
| 1274 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 1275 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 1276 | parallel_move.AddMove(ref_, |
| 1277 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1278 | Primitive::kPrimNot, |
| 1279 | nullptr); |
| 1280 | parallel_move.AddMove(obj_, |
| 1281 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 1282 | Primitive::kPrimNot, |
| 1283 | nullptr); |
| 1284 | if (index.IsValid()) { |
| 1285 | parallel_move.AddMove(index, |
| 1286 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 1287 | Primitive::kPrimInt, |
| 1288 | nullptr); |
| 1289 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1290 | } else { |
| 1291 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1292 | __ Mov(calling_convention.GetRegisterAt(2), offset_); |
| 1293 | } |
| 1294 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
| 1295 | CheckEntrypointTypes< |
| 1296 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1297 | arm_codegen->Move32(out_, LocationFrom(r0)); |
| 1298 | |
| 1299 | RestoreLiveRegisters(codegen, locations); |
| 1300 | __ B(GetExitLabel()); |
| 1301 | } |
| 1302 | |
| 1303 | const char* GetDescription() const OVERRIDE { |
| 1304 | return "ReadBarrierForHeapReferenceSlowPathARMVIXL"; |
| 1305 | } |
| 1306 | |
| 1307 | private: |
| 1308 | vixl32::Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 1309 | uint32_t ref = RegisterFrom(ref_).GetCode(); |
| 1310 | uint32_t obj = RegisterFrom(obj_).GetCode(); |
| 1311 | for (uint32_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1312 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1313 | return vixl32::Register(i); |
| 1314 | } |
| 1315 | } |
| 1316 | // We shall never fail to find a free caller-save register, as |
| 1317 | // there are more than two core caller-save registers on ARM |
| 1318 | // (meaning it is possible to find one which is different from |
| 1319 | // `ref` and `obj`). |
| 1320 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1321 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 1322 | UNREACHABLE(); |
| 1323 | } |
| 1324 | |
| 1325 | const Location out_; |
| 1326 | const Location ref_; |
| 1327 | const Location obj_; |
| 1328 | const uint32_t offset_; |
| 1329 | // An additional location containing an index to an array. |
| 1330 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1331 | // UnsafeGetObjectVolatile intrinsics. |
| 1332 | const Location index_; |
| 1333 | |
| 1334 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARMVIXL); |
| 1335 | }; |
| 1336 | |
| 1337 | // Slow path generating a read barrier for a GC root. |
| 1338 | class ReadBarrierForRootSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 1339 | public: |
| 1340 | ReadBarrierForRootSlowPathARMVIXL(HInstruction* instruction, Location out, Location root) |
| 1341 | : SlowPathCodeARMVIXL(instruction), out_(out), root_(root) { |
| 1342 | DCHECK(kEmitCompilerReadBarrier); |
| 1343 | } |
| 1344 | |
| 1345 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1346 | LocationSummary* locations = instruction_->GetLocations(); |
| 1347 | vixl32::Register reg_out = RegisterFrom(out_); |
| 1348 | DCHECK(locations->CanCall()); |
| 1349 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.GetCode())); |
| 1350 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1351 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1352 | << instruction_->DebugName(); |
| 1353 | |
| 1354 | __ Bind(GetEntryLabel()); |
| 1355 | SaveLiveRegisters(codegen, locations); |
| 1356 | |
| 1357 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 1358 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 1359 | arm_codegen->Move32(LocationFrom(calling_convention.GetRegisterAt(0)), root_); |
| 1360 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| 1361 | instruction_, |
| 1362 | instruction_->GetDexPc(), |
| 1363 | this); |
| 1364 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1365 | arm_codegen->Move32(out_, LocationFrom(r0)); |
| 1366 | |
| 1367 | RestoreLiveRegisters(codegen, locations); |
| 1368 | __ B(GetExitLabel()); |
| 1369 | } |
| 1370 | |
| 1371 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARMVIXL"; } |
| 1372 | |
| 1373 | private: |
| 1374 | const Location out_; |
| 1375 | const Location root_; |
| 1376 | |
| 1377 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARMVIXL); |
| 1378 | }; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 1379 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1380 | inline vixl32::Condition ARMCondition(IfCondition cond) { |
| 1381 | switch (cond) { |
| 1382 | case kCondEQ: return eq; |
| 1383 | case kCondNE: return ne; |
| 1384 | case kCondLT: return lt; |
| 1385 | case kCondLE: return le; |
| 1386 | case kCondGT: return gt; |
| 1387 | case kCondGE: return ge; |
| 1388 | case kCondB: return lo; |
| 1389 | case kCondBE: return ls; |
| 1390 | case kCondA: return hi; |
| 1391 | case kCondAE: return hs; |
| 1392 | } |
| 1393 | LOG(FATAL) << "Unreachable"; |
| 1394 | UNREACHABLE(); |
| 1395 | } |
| 1396 | |
| 1397 | // Maps signed condition to unsigned condition. |
| 1398 | inline vixl32::Condition ARMUnsignedCondition(IfCondition cond) { |
| 1399 | switch (cond) { |
| 1400 | case kCondEQ: return eq; |
| 1401 | case kCondNE: return ne; |
| 1402 | // Signed to unsigned. |
| 1403 | case kCondLT: return lo; |
| 1404 | case kCondLE: return ls; |
| 1405 | case kCondGT: return hi; |
| 1406 | case kCondGE: return hs; |
| 1407 | // Unsigned remain unchanged. |
| 1408 | case kCondB: return lo; |
| 1409 | case kCondBE: return ls; |
| 1410 | case kCondA: return hi; |
| 1411 | case kCondAE: return hs; |
| 1412 | } |
| 1413 | LOG(FATAL) << "Unreachable"; |
| 1414 | UNREACHABLE(); |
| 1415 | } |
| 1416 | |
| 1417 | inline vixl32::Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 1418 | // The ARM condition codes can express all the necessary branches, see the |
| 1419 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 1420 | // There is no dex instruction or HIR that would need the missing conditions |
| 1421 | // "equal or unordered" or "not equal". |
| 1422 | switch (cond) { |
| 1423 | case kCondEQ: return eq; |
| 1424 | case kCondNE: return ne /* unordered */; |
| 1425 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 1426 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 1427 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 1428 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 1429 | default: |
| 1430 | LOG(FATAL) << "UNREACHABLE"; |
| 1431 | UNREACHABLE(); |
| 1432 | } |
| 1433 | } |
| 1434 | |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1435 | inline ShiftType ShiftFromOpKind(HDataProcWithShifterOp::OpKind op_kind) { |
| 1436 | switch (op_kind) { |
| 1437 | case HDataProcWithShifterOp::kASR: return ShiftType::ASR; |
| 1438 | case HDataProcWithShifterOp::kLSL: return ShiftType::LSL; |
| 1439 | case HDataProcWithShifterOp::kLSR: return ShiftType::LSR; |
| 1440 | default: |
| 1441 | LOG(FATAL) << "Unexpected op kind " << op_kind; |
| 1442 | UNREACHABLE(); |
| 1443 | } |
| 1444 | } |
| 1445 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1446 | void CodeGeneratorARMVIXL::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 1447 | stream << vixl32::Register(reg); |
| 1448 | } |
| 1449 | |
| 1450 | void CodeGeneratorARMVIXL::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| 1451 | stream << vixl32::SRegister(reg); |
| 1452 | } |
| 1453 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1454 | static uint32_t ComputeSRegisterListMask(const SRegisterList& regs) { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1455 | uint32_t mask = 0; |
| 1456 | for (uint32_t i = regs.GetFirstSRegister().GetCode(); |
| 1457 | i <= regs.GetLastSRegister().GetCode(); |
| 1458 | ++i) { |
| 1459 | mask |= (1 << i); |
| 1460 | } |
| 1461 | return mask; |
| 1462 | } |
| 1463 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1464 | // Saves the register in the stack. Returns the size taken on stack. |
| 1465 | size_t CodeGeneratorARMVIXL::SaveCoreRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1466 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1467 | TODO_VIXL32(FATAL); |
| 1468 | return 0; |
| 1469 | } |
| 1470 | |
| 1471 | // Restores the register from the stack. Returns the size taken on stack. |
| 1472 | size_t CodeGeneratorARMVIXL::RestoreCoreRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1473 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1474 | TODO_VIXL32(FATAL); |
| 1475 | return 0; |
| 1476 | } |
| 1477 | |
| 1478 | size_t CodeGeneratorARMVIXL::SaveFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1479 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1480 | TODO_VIXL32(FATAL); |
| 1481 | return 0; |
| 1482 | } |
| 1483 | |
| 1484 | size_t CodeGeneratorARMVIXL::RestoreFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1485 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1486 | TODO_VIXL32(FATAL); |
| 1487 | return 0; |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 1488 | } |
| 1489 | |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1490 | static void GenerateDataProcInstruction(HInstruction::InstructionKind kind, |
| 1491 | vixl32::Register out, |
| 1492 | vixl32::Register first, |
| 1493 | const Operand& second, |
| 1494 | CodeGeneratorARMVIXL* codegen) { |
| 1495 | if (second.IsImmediate() && second.GetImmediate() == 0) { |
| 1496 | const Operand in = kind == HInstruction::kAnd |
| 1497 | ? Operand(0) |
| 1498 | : Operand(first); |
| 1499 | |
| 1500 | __ Mov(out, in); |
| 1501 | } else { |
| 1502 | switch (kind) { |
| 1503 | case HInstruction::kAdd: |
| 1504 | __ Add(out, first, second); |
| 1505 | break; |
| 1506 | case HInstruction::kAnd: |
| 1507 | __ And(out, first, second); |
| 1508 | break; |
| 1509 | case HInstruction::kOr: |
| 1510 | __ Orr(out, first, second); |
| 1511 | break; |
| 1512 | case HInstruction::kSub: |
| 1513 | __ Sub(out, first, second); |
| 1514 | break; |
| 1515 | case HInstruction::kXor: |
| 1516 | __ Eor(out, first, second); |
| 1517 | break; |
| 1518 | default: |
| 1519 | LOG(FATAL) << "Unexpected instruction kind: " << kind; |
| 1520 | UNREACHABLE(); |
| 1521 | } |
| 1522 | } |
| 1523 | } |
| 1524 | |
| 1525 | static void GenerateDataProc(HInstruction::InstructionKind kind, |
| 1526 | const Location& out, |
| 1527 | const Location& first, |
| 1528 | const Operand& second_lo, |
| 1529 | const Operand& second_hi, |
| 1530 | CodeGeneratorARMVIXL* codegen) { |
| 1531 | const vixl32::Register first_hi = HighRegisterFrom(first); |
| 1532 | const vixl32::Register first_lo = LowRegisterFrom(first); |
| 1533 | const vixl32::Register out_hi = HighRegisterFrom(out); |
| 1534 | const vixl32::Register out_lo = LowRegisterFrom(out); |
| 1535 | |
| 1536 | if (kind == HInstruction::kAdd) { |
| 1537 | __ Adds(out_lo, first_lo, second_lo); |
| 1538 | __ Adc(out_hi, first_hi, second_hi); |
| 1539 | } else if (kind == HInstruction::kSub) { |
| 1540 | __ Subs(out_lo, first_lo, second_lo); |
| 1541 | __ Sbc(out_hi, first_hi, second_hi); |
| 1542 | } else { |
| 1543 | GenerateDataProcInstruction(kind, out_lo, first_lo, second_lo, codegen); |
| 1544 | GenerateDataProcInstruction(kind, out_hi, first_hi, second_hi, codegen); |
| 1545 | } |
| 1546 | } |
| 1547 | |
| 1548 | static Operand GetShifterOperand(vixl32::Register rm, ShiftType shift, uint32_t shift_imm) { |
| 1549 | return shift_imm == 0 ? Operand(rm) : Operand(rm, shift, shift_imm); |
| 1550 | } |
| 1551 | |
| 1552 | static void GenerateLongDataProc(HDataProcWithShifterOp* instruction, |
| 1553 | CodeGeneratorARMVIXL* codegen) { |
| 1554 | DCHECK_EQ(instruction->GetType(), Primitive::kPrimLong); |
| 1555 | DCHECK(HDataProcWithShifterOp::IsShiftOp(instruction->GetOpKind())); |
| 1556 | |
| 1557 | const LocationSummary* const locations = instruction->GetLocations(); |
| 1558 | const uint32_t shift_value = instruction->GetShiftAmount(); |
| 1559 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 1560 | const Location first = locations->InAt(0); |
| 1561 | const Location second = locations->InAt(1); |
| 1562 | const Location out = locations->Out(); |
| 1563 | const vixl32::Register first_hi = HighRegisterFrom(first); |
| 1564 | const vixl32::Register first_lo = LowRegisterFrom(first); |
| 1565 | const vixl32::Register out_hi = HighRegisterFrom(out); |
| 1566 | const vixl32::Register out_lo = LowRegisterFrom(out); |
| 1567 | const vixl32::Register second_hi = HighRegisterFrom(second); |
| 1568 | const vixl32::Register second_lo = LowRegisterFrom(second); |
| 1569 | const ShiftType shift = ShiftFromOpKind(instruction->GetOpKind()); |
| 1570 | |
| 1571 | if (shift_value >= 32) { |
| 1572 | if (shift == ShiftType::LSL) { |
| 1573 | GenerateDataProcInstruction(kind, |
| 1574 | out_hi, |
| 1575 | first_hi, |
| 1576 | Operand(second_lo, ShiftType::LSL, shift_value - 32), |
| 1577 | codegen); |
| 1578 | GenerateDataProcInstruction(kind, out_lo, first_lo, 0, codegen); |
| 1579 | } else if (shift == ShiftType::ASR) { |
| 1580 | GenerateDataProc(kind, |
| 1581 | out, |
| 1582 | first, |
| 1583 | GetShifterOperand(second_hi, ShiftType::ASR, shift_value - 32), |
| 1584 | Operand(second_hi, ShiftType::ASR, 31), |
| 1585 | codegen); |
| 1586 | } else { |
| 1587 | DCHECK_EQ(shift, ShiftType::LSR); |
| 1588 | GenerateDataProc(kind, |
| 1589 | out, |
| 1590 | first, |
| 1591 | GetShifterOperand(second_hi, ShiftType::LSR, shift_value - 32), |
| 1592 | 0, |
| 1593 | codegen); |
| 1594 | } |
| 1595 | } else { |
| 1596 | DCHECK_GT(shift_value, 1U); |
| 1597 | DCHECK_LT(shift_value, 32U); |
| 1598 | |
| 1599 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1600 | |
| 1601 | if (shift == ShiftType::LSL) { |
| 1602 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1603 | // Location::kOutputOverlap; not applicable to other cases. |
| 1604 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1605 | GenerateDataProcInstruction(kind, |
| 1606 | out_hi, |
| 1607 | first_hi, |
| 1608 | Operand(second_hi, ShiftType::LSL, shift_value), |
| 1609 | codegen); |
| 1610 | GenerateDataProcInstruction(kind, |
| 1611 | out_hi, |
| 1612 | out_hi, |
| 1613 | Operand(second_lo, ShiftType::LSR, 32 - shift_value), |
| 1614 | codegen); |
| 1615 | GenerateDataProcInstruction(kind, |
| 1616 | out_lo, |
| 1617 | first_lo, |
| 1618 | Operand(second_lo, ShiftType::LSL, shift_value), |
| 1619 | codegen); |
| 1620 | } else { |
| 1621 | const vixl32::Register temp = temps.Acquire(); |
| 1622 | |
| 1623 | __ Lsl(temp, second_hi, shift_value); |
| 1624 | __ Orr(temp, temp, Operand(second_lo, ShiftType::LSR, 32 - shift_value)); |
| 1625 | GenerateDataProc(kind, |
| 1626 | out, |
| 1627 | first, |
| 1628 | Operand(second_lo, ShiftType::LSL, shift_value), |
| 1629 | temp, |
| 1630 | codegen); |
| 1631 | } |
| 1632 | } else { |
| 1633 | DCHECK(shift == ShiftType::ASR || shift == ShiftType::LSR); |
| 1634 | |
| 1635 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1636 | // Location::kOutputOverlap; not applicable to other cases. |
| 1637 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1638 | GenerateDataProcInstruction(kind, |
| 1639 | out_lo, |
| 1640 | first_lo, |
| 1641 | Operand(second_lo, ShiftType::LSR, shift_value), |
| 1642 | codegen); |
| 1643 | GenerateDataProcInstruction(kind, |
| 1644 | out_lo, |
| 1645 | out_lo, |
| 1646 | Operand(second_hi, ShiftType::LSL, 32 - shift_value), |
| 1647 | codegen); |
| 1648 | GenerateDataProcInstruction(kind, |
| 1649 | out_hi, |
| 1650 | first_hi, |
| 1651 | Operand(second_hi, shift, shift_value), |
| 1652 | codegen); |
| 1653 | } else { |
| 1654 | const vixl32::Register temp = temps.Acquire(); |
| 1655 | |
| 1656 | __ Lsr(temp, second_lo, shift_value); |
| 1657 | __ Orr(temp, temp, Operand(second_hi, ShiftType::LSL, 32 - shift_value)); |
| 1658 | GenerateDataProc(kind, |
| 1659 | out, |
| 1660 | first, |
| 1661 | temp, |
| 1662 | Operand(second_hi, shift, shift_value), |
| 1663 | codegen); |
| 1664 | } |
| 1665 | } |
| 1666 | } |
| 1667 | } |
| 1668 | |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1669 | static void GenerateVcmp(HInstruction* instruction, CodeGeneratorARMVIXL* codegen) { |
| 1670 | const Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1671 | if (rhs_loc.IsConstant()) { |
| 1672 | // 0.0 is the only immediate that can be encoded directly in |
| 1673 | // a VCMP instruction. |
| 1674 | // |
| 1675 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1676 | // specify that in a floating-point comparison, positive zero |
| 1677 | // and negative zero are considered equal, so we can use the |
| 1678 | // literal 0.0 for both cases here. |
| 1679 | // |
| 1680 | // Note however that some methods (Float.equal, Float.compare, |
| 1681 | // Float.compareTo, Double.equal, Double.compare, |
| 1682 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1683 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1684 | // -0.0. So if we ever translate calls to these methods into a |
| 1685 | // HCompare instruction, we must handle the -0.0 case with |
| 1686 | // care here. |
| 1687 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1688 | |
| 1689 | const Primitive::Type type = instruction->InputAt(0)->GetType(); |
| 1690 | |
| 1691 | if (type == Primitive::kPrimFloat) { |
| 1692 | __ Vcmp(F32, InputSRegisterAt(instruction, 0), 0.0); |
| 1693 | } else { |
| 1694 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1695 | __ Vcmp(F64, InputDRegisterAt(instruction, 0), 0.0); |
| 1696 | } |
| 1697 | } else { |
| 1698 | __ Vcmp(InputVRegisterAt(instruction, 0), InputVRegisterAt(instruction, 1)); |
| 1699 | } |
| 1700 | } |
| 1701 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1702 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateLongTestConstant( |
| 1703 | HCondition* condition, |
| 1704 | bool invert, |
| 1705 | CodeGeneratorARMVIXL* codegen) { |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1706 | DCHECK_EQ(condition->GetLeft()->GetType(), Primitive::kPrimLong); |
| 1707 | |
| 1708 | const LocationSummary* const locations = condition->GetLocations(); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1709 | IfCondition cond = condition->GetCondition(); |
| 1710 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1711 | |
| 1712 | if (invert) { |
| 1713 | std::swap(cond, opposite); |
| 1714 | } |
| 1715 | |
| 1716 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1717 | const Location left = locations->InAt(0); |
| 1718 | const Location right = locations->InAt(1); |
| 1719 | |
| 1720 | DCHECK(right.IsConstant()); |
| 1721 | |
| 1722 | const vixl32::Register left_high = HighRegisterFrom(left); |
| 1723 | const vixl32::Register left_low = LowRegisterFrom(left); |
| 1724 | int64_t value = Int64ConstantFrom(right); |
| 1725 | |
| 1726 | switch (cond) { |
| 1727 | case kCondEQ: |
| 1728 | case kCondNE: |
| 1729 | case kCondB: |
| 1730 | case kCondBE: |
| 1731 | case kCondA: |
| 1732 | case kCondAE: { |
| 1733 | __ Cmp(left_high, High32Bits(value)); |
| 1734 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1735 | // We use the scope because of the IT block that follows. |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1736 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1737 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1738 | CodeBufferCheckScope::kExactSize); |
| 1739 | |
| 1740 | __ it(eq); |
| 1741 | __ cmp(eq, left_low, Low32Bits(value)); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1742 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1743 | break; |
| 1744 | } |
| 1745 | case kCondLE: |
| 1746 | case kCondGT: |
| 1747 | // Trivially true or false. |
| 1748 | if (value == std::numeric_limits<int64_t>::max()) { |
| 1749 | __ Cmp(left_low, left_low); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1750 | 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] | 1751 | break; |
| 1752 | } |
| 1753 | |
| 1754 | if (cond == kCondLE) { |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1755 | DCHECK_EQ(opposite, kCondGT); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1756 | cond = kCondLT; |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1757 | opposite = kCondGE; |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1758 | } else { |
| 1759 | DCHECK_EQ(cond, kCondGT); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1760 | DCHECK_EQ(opposite, kCondLE); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1761 | cond = kCondGE; |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1762 | opposite = kCondLT; |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | value++; |
| 1766 | FALLTHROUGH_INTENDED; |
| 1767 | case kCondGE: |
| 1768 | case kCondLT: { |
| 1769 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1770 | |
| 1771 | __ Cmp(left_low, Low32Bits(value)); |
| 1772 | __ Sbcs(temps.Acquire(), left_high, High32Bits(value)); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1773 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1774 | break; |
| 1775 | } |
| 1776 | default: |
| 1777 | LOG(FATAL) << "Unreachable"; |
| 1778 | UNREACHABLE(); |
| 1779 | } |
| 1780 | |
| 1781 | return ret; |
| 1782 | } |
| 1783 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1784 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateLongTest( |
| 1785 | HCondition* condition, |
| 1786 | bool invert, |
| 1787 | CodeGeneratorARMVIXL* codegen) { |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1788 | DCHECK_EQ(condition->GetLeft()->GetType(), Primitive::kPrimLong); |
| 1789 | |
| 1790 | const LocationSummary* const locations = condition->GetLocations(); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1791 | IfCondition cond = condition->GetCondition(); |
| 1792 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1793 | |
| 1794 | if (invert) { |
| 1795 | std::swap(cond, opposite); |
| 1796 | } |
| 1797 | |
| 1798 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1799 | Location left = locations->InAt(0); |
| 1800 | Location right = locations->InAt(1); |
| 1801 | |
| 1802 | DCHECK(right.IsRegisterPair()); |
| 1803 | |
| 1804 | switch (cond) { |
| 1805 | case kCondEQ: |
| 1806 | case kCondNE: |
| 1807 | case kCondB: |
| 1808 | case kCondBE: |
| 1809 | case kCondA: |
| 1810 | case kCondAE: { |
| 1811 | __ Cmp(HighRegisterFrom(left), HighRegisterFrom(right)); |
| 1812 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1813 | // We use the scope because of the IT block that follows. |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1814 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1815 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1816 | CodeBufferCheckScope::kExactSize); |
| 1817 | |
| 1818 | __ it(eq); |
| 1819 | __ cmp(eq, LowRegisterFrom(left), LowRegisterFrom(right)); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1820 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1821 | break; |
| 1822 | } |
| 1823 | case kCondLE: |
| 1824 | case kCondGT: |
| 1825 | if (cond == kCondLE) { |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1826 | DCHECK_EQ(opposite, kCondGT); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1827 | cond = kCondGE; |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1828 | opposite = kCondLT; |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1829 | } else { |
| 1830 | DCHECK_EQ(cond, kCondGT); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1831 | DCHECK_EQ(opposite, kCondLE); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1832 | cond = kCondLT; |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1833 | opposite = kCondGE; |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1834 | } |
| 1835 | |
| 1836 | std::swap(left, right); |
| 1837 | FALLTHROUGH_INTENDED; |
| 1838 | case kCondGE: |
| 1839 | case kCondLT: { |
| 1840 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1841 | |
| 1842 | __ Cmp(LowRegisterFrom(left), LowRegisterFrom(right)); |
| 1843 | __ Sbcs(temps.Acquire(), HighRegisterFrom(left), HighRegisterFrom(right)); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1844 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1845 | break; |
| 1846 | } |
| 1847 | default: |
| 1848 | LOG(FATAL) << "Unreachable"; |
| 1849 | UNREACHABLE(); |
| 1850 | } |
| 1851 | |
| 1852 | return ret; |
| 1853 | } |
| 1854 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1855 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateTest(HCondition* condition, |
| 1856 | bool invert, |
| 1857 | CodeGeneratorARMVIXL* codegen) { |
| 1858 | const Primitive::Type type = condition->GetLeft()->GetType(); |
| 1859 | IfCondition cond = condition->GetCondition(); |
| 1860 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1861 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1862 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1863 | if (invert) { |
| 1864 | std::swap(cond, opposite); |
| 1865 | } |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1866 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1867 | if (type == Primitive::kPrimLong) { |
| 1868 | ret = condition->GetLocations()->InAt(1).IsConstant() |
| 1869 | ? GenerateLongTestConstant(condition, invert, codegen) |
| 1870 | : GenerateLongTest(condition, invert, codegen); |
| 1871 | } else if (Primitive::IsFloatingPointType(type)) { |
| 1872 | GenerateVcmp(condition, codegen); |
| 1873 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 1874 | ret = std::make_pair(ARMFPCondition(cond, condition->IsGtBias()), |
| 1875 | ARMFPCondition(opposite, condition->IsGtBias())); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1876 | } else { |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1877 | DCHECK(Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) << type; |
| 1878 | __ Cmp(InputRegisterAt(condition, 0), InputOperandAt(condition, 1)); |
| 1879 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1880 | } |
| 1881 | |
| 1882 | return ret; |
| 1883 | } |
| 1884 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1885 | static bool CanGenerateTest(HCondition* condition, ArmVIXLAssembler* assembler) { |
| 1886 | if (condition->GetLeft()->GetType() == Primitive::kPrimLong) { |
| 1887 | const LocationSummary* const locations = condition->GetLocations(); |
| 1888 | const IfCondition c = condition->GetCondition(); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1889 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1890 | if (locations->InAt(1).IsConstant()) { |
| 1891 | const int64_t value = Int64ConstantFrom(locations->InAt(1)); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1892 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1893 | if (c < kCondLT || c > kCondGE) { |
| 1894 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1895 | // we check that the least significant half of the first input to be compared |
| 1896 | // is in a low register (the other half is read outside an IT block), and |
| 1897 | // the constant fits in an 8-bit unsigned integer, so that a 16-bit CMP |
| 1898 | // encoding can be used. |
| 1899 | if (!LowRegisterFrom(locations->InAt(0)).IsLow() || !IsUint<8>(Low32Bits(value))) { |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1900 | return false; |
| 1901 | } |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1902 | // TODO(VIXL): The rest of the checks are there to keep the backend in sync with |
| 1903 | // the previous one, but are not strictly necessary. |
| 1904 | } else if (c == kCondLE || c == kCondGT) { |
| 1905 | if (value < std::numeric_limits<int64_t>::max() && |
| 1906 | !assembler->ShifterOperandCanHold(SBC, High32Bits(value + 1), kCcSet)) { |
| 1907 | return false; |
| 1908 | } |
| 1909 | } else if (!assembler->ShifterOperandCanHold(SBC, High32Bits(value), kCcSet)) { |
| 1910 | return false; |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1911 | } |
| 1912 | } |
| 1913 | } |
| 1914 | |
| 1915 | return true; |
| 1916 | } |
| 1917 | |
| 1918 | static bool CanEncodeConstantAs8BitImmediate(HConstant* constant) { |
| 1919 | const Primitive::Type type = constant->GetType(); |
| 1920 | bool ret = false; |
| 1921 | |
| 1922 | DCHECK(Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) << type; |
| 1923 | |
| 1924 | if (type == Primitive::kPrimLong) { |
| 1925 | const uint64_t value = Uint64ConstantFrom(constant); |
| 1926 | |
| 1927 | ret = IsUint<8>(Low32Bits(value)) && IsUint<8>(High32Bits(value)); |
| 1928 | } else { |
| 1929 | ret = IsUint<8>(Int32ConstantFrom(constant)); |
| 1930 | } |
| 1931 | |
| 1932 | return ret; |
| 1933 | } |
| 1934 | |
| 1935 | static Location Arm8BitEncodableConstantOrRegister(HInstruction* constant) { |
| 1936 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 1937 | |
| 1938 | if (constant->IsConstant() && CanEncodeConstantAs8BitImmediate(constant->AsConstant())) { |
| 1939 | return Location::ConstantLocation(constant->AsConstant()); |
| 1940 | } |
| 1941 | |
| 1942 | return Location::RequiresRegister(); |
| 1943 | } |
| 1944 | |
| 1945 | static bool CanGenerateConditionalMove(const Location& out, const Location& src) { |
| 1946 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1947 | // we check that we are not dealing with floating-point output (there is no |
| 1948 | // 16-bit VMOV encoding). |
| 1949 | if (!out.IsRegister() && !out.IsRegisterPair()) { |
| 1950 | return false; |
| 1951 | } |
| 1952 | |
| 1953 | // For constants, we also check that the output is in one or two low registers, |
| 1954 | // and that the constants fit in an 8-bit unsigned integer, so that a 16-bit |
| 1955 | // MOV encoding can be used. |
| 1956 | if (src.IsConstant()) { |
| 1957 | if (!CanEncodeConstantAs8BitImmediate(src.GetConstant())) { |
| 1958 | return false; |
| 1959 | } |
| 1960 | |
| 1961 | if (out.IsRegister()) { |
| 1962 | if (!RegisterFrom(out).IsLow()) { |
| 1963 | return false; |
| 1964 | } |
| 1965 | } else { |
| 1966 | DCHECK(out.IsRegisterPair()); |
| 1967 | |
| 1968 | if (!HighRegisterFrom(out).IsLow()) { |
| 1969 | return false; |
| 1970 | } |
| 1971 | } |
| 1972 | } |
| 1973 | |
| 1974 | return true; |
| 1975 | } |
| 1976 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1977 | #undef __ |
| 1978 | |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1979 | vixl32::Label* CodeGeneratorARMVIXL::GetFinalLabel(HInstruction* instruction, |
| 1980 | vixl32::Label* final_label) { |
| 1981 | DCHECK(!instruction->IsControlFlow() && !instruction->IsSuspendCheck()); |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 1982 | DCHECK(!instruction->IsInvoke() || !instruction->GetLocations()->CanCall()); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1983 | |
| 1984 | const HBasicBlock* const block = instruction->GetBlock(); |
| 1985 | const HLoopInformation* const info = block->GetLoopInformation(); |
| 1986 | HInstruction* const next = instruction->GetNext(); |
| 1987 | |
| 1988 | // Avoid a branch to a branch. |
| 1989 | if (next->IsGoto() && (info == nullptr || |
| 1990 | !info->IsBackEdge(*block) || |
| 1991 | !info->HasSuspendCheck())) { |
| 1992 | final_label = GetLabelOf(next->AsGoto()->GetSuccessor()); |
| 1993 | } |
| 1994 | |
| 1995 | return final_label; |
| 1996 | } |
| 1997 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1998 | CodeGeneratorARMVIXL::CodeGeneratorARMVIXL(HGraph* graph, |
| 1999 | const ArmInstructionSetFeatures& isa_features, |
| 2000 | const CompilerOptions& compiler_options, |
| 2001 | OptimizingCompilerStats* stats) |
| 2002 | : CodeGenerator(graph, |
| 2003 | kNumberOfCoreRegisters, |
| 2004 | kNumberOfSRegisters, |
| 2005 | kNumberOfRegisterPairs, |
| 2006 | kCoreCalleeSaves.GetList(), |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2007 | ComputeSRegisterListMask(kFpuCalleeSaves), |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2008 | compiler_options, |
| 2009 | stats), |
| 2010 | block_labels_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2011 | jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2012 | location_builder_(graph, this), |
| 2013 | instruction_visitor_(graph, this), |
| 2014 | move_resolver_(graph->GetArena(), this), |
| 2015 | assembler_(graph->GetArena()), |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2016 | isa_features_(isa_features), |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 2017 | uint32_literals_(std::less<uint32_t>(), |
| 2018 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2019 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 2020 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 2021 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2022 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 2023 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 2024 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 2025 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 2026 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 2027 | jit_string_patches_(StringReferenceValueComparator(), |
| 2028 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 2029 | jit_class_patches_(TypeReferenceValueComparator(), |
| 2030 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2031 | // Always save the LR register to mimic Quick. |
| 2032 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
| Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 2033 | // Give D30 and D31 as scratch register to VIXL. The register allocator only works on |
| 2034 | // S0-S31, which alias to D0-D15. |
| 2035 | GetVIXLAssembler()->GetScratchVRegisterList()->Combine(d31); |
| 2036 | GetVIXLAssembler()->GetScratchVRegisterList()->Combine(d30); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2037 | } |
| 2038 | |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2039 | void JumpTableARMVIXL::EmitTable(CodeGeneratorARMVIXL* codegen) { |
| 2040 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| 2041 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| 2042 | |
| 2043 | // 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] | 2044 | // underlying code buffer and we have generated a jump table of the right size, using |
| 2045 | // codegen->GetVIXLAssembler()->GetBuffer().Align(); |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 2046 | ExactAssemblyScope aas(codegen->GetVIXLAssembler(), |
| 2047 | num_entries * sizeof(int32_t), |
| 2048 | CodeBufferCheckScope::kMaximumSize); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2049 | // TODO(VIXL): Check that using lower case bind is fine here. |
| 2050 | codegen->GetVIXLAssembler()->bind(&table_start_); |
| Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2051 | for (uint32_t i = 0; i < num_entries; i++) { |
| 2052 | codegen->GetVIXLAssembler()->place(bb_addresses_[i].get()); |
| 2053 | } |
| 2054 | } |
| 2055 | |
| 2056 | void JumpTableARMVIXL::FixTable(CodeGeneratorARMVIXL* codegen) { |
| 2057 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| 2058 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| 2059 | |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2060 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 2061 | for (uint32_t i = 0; i < num_entries; i++) { |
| 2062 | vixl32::Label* target_label = codegen->GetLabelOf(successors[i]); |
| 2063 | DCHECK(target_label->IsBound()); |
| 2064 | int32_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
| 2065 | // When doing BX to address we need to have lower bit set to 1 in T32. |
| 2066 | if (codegen->GetVIXLAssembler()->IsUsingT32()) { |
| 2067 | jump_offset++; |
| 2068 | } |
| 2069 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 2070 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2071 | |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 2072 | bb_addresses_[i].get()->UpdateValue(jump_offset, codegen->GetVIXLAssembler()->GetBuffer()); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2073 | } |
| 2074 | } |
| 2075 | |
| Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2076 | void CodeGeneratorARMVIXL::FixJumpTables() { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2077 | for (auto&& jump_table : jump_tables_) { |
| Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2078 | jump_table->FixTable(this); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2079 | } |
| 2080 | } |
| 2081 | |
| Andreas Gampe | ca620d7 | 2016-11-08 08:09:33 -0800 | [diff] [blame] | 2082 | #define __ reinterpret_cast<ArmVIXLAssembler*>(GetAssembler())->GetVIXLAssembler()-> // NOLINT |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2083 | |
| 2084 | void CodeGeneratorARMVIXL::Finalize(CodeAllocator* allocator) { |
| Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2085 | FixJumpTables(); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2086 | GetAssembler()->FinalizeCode(); |
| 2087 | CodeGenerator::Finalize(allocator); |
| 2088 | } |
| 2089 | |
| 2090 | void CodeGeneratorARMVIXL::SetupBlockedRegisters() const { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2091 | // Stack register, LR and PC are always reserved. |
| 2092 | blocked_core_registers_[SP] = true; |
| 2093 | blocked_core_registers_[LR] = true; |
| 2094 | blocked_core_registers_[PC] = true; |
| 2095 | |
| 2096 | // Reserve thread register. |
| 2097 | blocked_core_registers_[TR] = true; |
| 2098 | |
| 2099 | // Reserve temp register. |
| 2100 | blocked_core_registers_[IP] = true; |
| 2101 | |
| 2102 | if (GetGraph()->IsDebuggable()) { |
| 2103 | // Stubs do not save callee-save floating point registers. If the graph |
| 2104 | // is debuggable, we need to deal with these registers differently. For |
| 2105 | // now, just block them. |
| 2106 | for (uint32_t i = kFpuCalleeSaves.GetFirstSRegister().GetCode(); |
| 2107 | i <= kFpuCalleeSaves.GetLastSRegister().GetCode(); |
| 2108 | ++i) { |
| 2109 | blocked_fpu_registers_[i] = true; |
| 2110 | } |
| 2111 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2112 | } |
| 2113 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2114 | InstructionCodeGeneratorARMVIXL::InstructionCodeGeneratorARMVIXL(HGraph* graph, |
| 2115 | CodeGeneratorARMVIXL* codegen) |
| 2116 | : InstructionCodeGenerator(graph, codegen), |
| 2117 | assembler_(codegen->GetAssembler()), |
| 2118 | codegen_(codegen) {} |
| 2119 | |
| 2120 | void CodeGeneratorARMVIXL::ComputeSpillMask() { |
| 2121 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 2122 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
| 2123 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 2124 | // restore another arbitrary register. |
| 2125 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister.GetCode()); |
| 2126 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 2127 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 2128 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 2129 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 2130 | // but in the range. |
| 2131 | if (fpu_spill_mask_ != 0) { |
| 2132 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 2133 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 2134 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 2135 | fpu_spill_mask_ |= (1 << i); |
| 2136 | } |
| 2137 | } |
| 2138 | } |
| 2139 | |
| 2140 | void CodeGeneratorARMVIXL::GenerateFrameEntry() { |
| 2141 | bool skip_overflow_check = |
| 2142 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
| 2143 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
| 2144 | __ Bind(&frame_entry_label_); |
| 2145 | |
| 2146 | if (HasEmptyFrame()) { |
| 2147 | return; |
| 2148 | } |
| 2149 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2150 | if (!skip_overflow_check) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2151 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2152 | vixl32::Register temp = temps.Acquire(); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 2153 | __ Sub(temp, sp, Operand::From(GetStackOverflowReservedBytes(kArm))); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2154 | // The load must immediately precede RecordPcInfo. |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 2155 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2156 | vixl32::kMaxInstructionSizeInBytes, |
| 2157 | CodeBufferCheckScope::kMaximumSize); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2158 | __ ldr(temp, MemOperand(temp)); |
| 2159 | RecordPcInfo(nullptr, 0); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2160 | } |
| 2161 | |
| 2162 | __ Push(RegisterList(core_spill_mask_)); |
| 2163 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 2164 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(kMethodRegister), |
| 2165 | 0, |
| 2166 | core_spill_mask_, |
| 2167 | kArmWordSize); |
| 2168 | if (fpu_spill_mask_ != 0) { |
| 2169 | uint32_t first = LeastSignificantBit(fpu_spill_mask_); |
| 2170 | |
| 2171 | // Check that list is contiguous. |
| 2172 | DCHECK_EQ(fpu_spill_mask_ >> CTZ(fpu_spill_mask_), ~0u >> (32 - POPCOUNT(fpu_spill_mask_))); |
| 2173 | |
| 2174 | __ Vpush(SRegisterList(vixl32::SRegister(first), POPCOUNT(fpu_spill_mask_))); |
| 2175 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2176 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(s0), 0, fpu_spill_mask_, kArmWordSize); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2177 | } |
| Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 2178 | |
| 2179 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 2180 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2181 | vixl32::Register temp = temps.Acquire(); |
| 2182 | // Initialize should_deoptimize flag to 0. |
| 2183 | __ Mov(temp, 0); |
| 2184 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, -kShouldDeoptimizeFlagSize); |
| 2185 | } |
| 2186 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2187 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 2188 | __ Sub(sp, sp, adjust); |
| 2189 | GetAssembler()->cfi().AdjustCFAOffset(adjust); |
| Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 2190 | |
| 2191 | // Save the current method if we need it. Note that we do not |
| 2192 | // do this in HCurrentMethod, as the instruction might have been removed |
| 2193 | // in the SSA graph. |
| 2194 | if (RequiresCurrentMethod()) { |
| 2195 | GetAssembler()->StoreToOffset(kStoreWord, kMethodRegister, sp, 0); |
| 2196 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2197 | } |
| 2198 | |
| 2199 | void CodeGeneratorARMVIXL::GenerateFrameExit() { |
| 2200 | if (HasEmptyFrame()) { |
| 2201 | __ Bx(lr); |
| 2202 | return; |
| 2203 | } |
| 2204 | GetAssembler()->cfi().RememberState(); |
| 2205 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 2206 | __ Add(sp, sp, adjust); |
| 2207 | GetAssembler()->cfi().AdjustCFAOffset(-adjust); |
| 2208 | if (fpu_spill_mask_ != 0) { |
| 2209 | uint32_t first = LeastSignificantBit(fpu_spill_mask_); |
| 2210 | |
| 2211 | // Check that list is contiguous. |
| 2212 | DCHECK_EQ(fpu_spill_mask_ >> CTZ(fpu_spill_mask_), ~0u >> (32 - POPCOUNT(fpu_spill_mask_))); |
| 2213 | |
| 2214 | __ Vpop(SRegisterList(vixl32::SRegister(first), POPCOUNT(fpu_spill_mask_))); |
| 2215 | GetAssembler()->cfi().AdjustCFAOffset( |
| 2216 | -static_cast<int>(kArmWordSize) * POPCOUNT(fpu_spill_mask_)); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2217 | GetAssembler()->cfi().RestoreMany(DWARFReg(vixl32::SRegister(0)), fpu_spill_mask_); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2218 | } |
| 2219 | // Pop LR into PC to return. |
| 2220 | DCHECK_NE(core_spill_mask_ & (1 << kLrCode), 0U); |
| 2221 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << kLrCode))) | 1 << kPcCode; |
| 2222 | __ Pop(RegisterList(pop_mask)); |
| 2223 | GetAssembler()->cfi().RestoreState(); |
| 2224 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
| 2225 | } |
| 2226 | |
| 2227 | void CodeGeneratorARMVIXL::Bind(HBasicBlock* block) { |
| 2228 | __ Bind(GetLabelOf(block)); |
| 2229 | } |
| 2230 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2231 | Location InvokeDexCallingConventionVisitorARMVIXL::GetNextLocation(Primitive::Type type) { |
| 2232 | switch (type) { |
| 2233 | case Primitive::kPrimBoolean: |
| 2234 | case Primitive::kPrimByte: |
| 2235 | case Primitive::kPrimChar: |
| 2236 | case Primitive::kPrimShort: |
| 2237 | case Primitive::kPrimInt: |
| 2238 | case Primitive::kPrimNot: { |
| 2239 | uint32_t index = gp_index_++; |
| 2240 | uint32_t stack_index = stack_index_++; |
| 2241 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2242 | return LocationFrom(calling_convention.GetRegisterAt(index)); |
| 2243 | } else { |
| 2244 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2245 | } |
| 2246 | } |
| 2247 | |
| 2248 | case Primitive::kPrimLong: { |
| 2249 | uint32_t index = gp_index_; |
| 2250 | uint32_t stack_index = stack_index_; |
| 2251 | gp_index_ += 2; |
| 2252 | stack_index_ += 2; |
| 2253 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2254 | if (calling_convention.GetRegisterAt(index).Is(r1)) { |
| 2255 | // Skip R1, and use R2_R3 instead. |
| 2256 | gp_index_++; |
| 2257 | index++; |
| 2258 | } |
| 2259 | } |
| 2260 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2261 | DCHECK_EQ(calling_convention.GetRegisterAt(index).GetCode() + 1, |
| 2262 | calling_convention.GetRegisterAt(index + 1).GetCode()); |
| 2263 | |
| 2264 | return LocationFrom(calling_convention.GetRegisterAt(index), |
| 2265 | calling_convention.GetRegisterAt(index + 1)); |
| 2266 | } else { |
| 2267 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2268 | } |
| 2269 | } |
| 2270 | |
| 2271 | case Primitive::kPrimFloat: { |
| 2272 | uint32_t stack_index = stack_index_++; |
| 2273 | if (float_index_ % 2 == 0) { |
| 2274 | float_index_ = std::max(double_index_, float_index_); |
| 2275 | } |
| 2276 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 2277 | return LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 2278 | } else { |
| 2279 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2280 | } |
| 2281 | } |
| 2282 | |
| 2283 | case Primitive::kPrimDouble: { |
| 2284 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 2285 | uint32_t stack_index = stack_index_; |
| 2286 | stack_index_ += 2; |
| 2287 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 2288 | uint32_t index = double_index_; |
| 2289 | double_index_ += 2; |
| 2290 | Location result = LocationFrom( |
| 2291 | calling_convention.GetFpuRegisterAt(index), |
| 2292 | calling_convention.GetFpuRegisterAt(index + 1)); |
| 2293 | DCHECK(ExpectedPairLayout(result)); |
| 2294 | return result; |
| 2295 | } else { |
| 2296 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2297 | } |
| 2298 | } |
| 2299 | |
| 2300 | case Primitive::kPrimVoid: |
| 2301 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2302 | break; |
| 2303 | } |
| 2304 | return Location::NoLocation(); |
| 2305 | } |
| 2306 | |
| 2307 | Location InvokeDexCallingConventionVisitorARMVIXL::GetReturnLocation(Primitive::Type type) const { |
| 2308 | switch (type) { |
| 2309 | case Primitive::kPrimBoolean: |
| 2310 | case Primitive::kPrimByte: |
| 2311 | case Primitive::kPrimChar: |
| 2312 | case Primitive::kPrimShort: |
| 2313 | case Primitive::kPrimInt: |
| 2314 | case Primitive::kPrimNot: { |
| 2315 | return LocationFrom(r0); |
| 2316 | } |
| 2317 | |
| 2318 | case Primitive::kPrimFloat: { |
| 2319 | return LocationFrom(s0); |
| 2320 | } |
| 2321 | |
| 2322 | case Primitive::kPrimLong: { |
| 2323 | return LocationFrom(r0, r1); |
| 2324 | } |
| 2325 | |
| 2326 | case Primitive::kPrimDouble: { |
| 2327 | return LocationFrom(s0, s1); |
| 2328 | } |
| 2329 | |
| 2330 | case Primitive::kPrimVoid: |
| 2331 | return Location::NoLocation(); |
| 2332 | } |
| 2333 | |
| 2334 | UNREACHABLE(); |
| 2335 | } |
| 2336 | |
| 2337 | Location InvokeDexCallingConventionVisitorARMVIXL::GetMethodLocation() const { |
| 2338 | return LocationFrom(kMethodRegister); |
| 2339 | } |
| 2340 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2341 | void CodeGeneratorARMVIXL::Move32(Location destination, Location source) { |
| 2342 | if (source.Equals(destination)) { |
| 2343 | return; |
| 2344 | } |
| 2345 | if (destination.IsRegister()) { |
| 2346 | if (source.IsRegister()) { |
| 2347 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 2348 | } else if (source.IsFpuRegister()) { |
| 2349 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
| 2350 | } else { |
| 2351 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 2352 | RegisterFrom(destination), |
| 2353 | sp, |
| 2354 | source.GetStackIndex()); |
| 2355 | } |
| 2356 | } else if (destination.IsFpuRegister()) { |
| 2357 | if (source.IsRegister()) { |
| 2358 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
| 2359 | } else if (source.IsFpuRegister()) { |
| 2360 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 2361 | } else { |
| 2362 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 2363 | } |
| 2364 | } else { |
| 2365 | DCHECK(destination.IsStackSlot()) << destination; |
| 2366 | if (source.IsRegister()) { |
| 2367 | GetAssembler()->StoreToOffset(kStoreWord, |
| 2368 | RegisterFrom(source), |
| 2369 | sp, |
| 2370 | destination.GetStackIndex()); |
| 2371 | } else if (source.IsFpuRegister()) { |
| 2372 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 2373 | } else { |
| 2374 | DCHECK(source.IsStackSlot()) << source; |
| 2375 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2376 | vixl32::Register temp = temps.Acquire(); |
| 2377 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 2378 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 2379 | } |
| 2380 | } |
| 2381 | } |
| 2382 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2383 | void CodeGeneratorARMVIXL::MoveConstant(Location location, int32_t value) { |
| 2384 | DCHECK(location.IsRegister()); |
| 2385 | __ Mov(RegisterFrom(location), value); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2386 | } |
| 2387 | |
| 2388 | void CodeGeneratorARMVIXL::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2389 | // TODO(VIXL): Maybe refactor to have the 'move' implementation here and use it in |
| 2390 | // `ParallelMoveResolverARMVIXL::EmitMove`, as is done in the `arm64` backend. |
| 2391 | HParallelMove move(GetGraph()->GetArena()); |
| 2392 | move.AddMove(src, dst, dst_type, nullptr); |
| 2393 | GetMoveResolver()->EmitNativeCode(&move); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2394 | } |
| 2395 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2396 | void CodeGeneratorARMVIXL::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 2397 | if (location.IsRegister()) { |
| 2398 | locations->AddTemp(location); |
| 2399 | } else if (location.IsRegisterPair()) { |
| 2400 | locations->AddTemp(LocationFrom(LowRegisterFrom(location))); |
| 2401 | locations->AddTemp(LocationFrom(HighRegisterFrom(location))); |
| 2402 | } else { |
| 2403 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 2404 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | void CodeGeneratorARMVIXL::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2408 | HInstruction* instruction, |
| 2409 | uint32_t dex_pc, |
| 2410 | SlowPathCode* slow_path) { |
| 2411 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2412 | __ Ldr(lr, MemOperand(tr, GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value())); |
| 2413 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 2414 | // 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] | 2415 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2416 | vixl32::k16BitT32InstructionSizeInBytes, |
| 2417 | CodeBufferCheckScope::kExactSize); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2418 | __ blx(lr); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2419 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2420 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2421 | } |
| 2422 | } |
| 2423 | |
| 2424 | void CodeGeneratorARMVIXL::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2425 | HInstruction* instruction, |
| 2426 | SlowPathCode* slow_path) { |
| 2427 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2428 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2429 | __ Blx(lr); |
| 2430 | } |
| 2431 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2432 | void InstructionCodeGeneratorARMVIXL::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| 2433 | DCHECK(!successor->IsExitBlock()); |
| 2434 | HBasicBlock* block = got->GetBlock(); |
| 2435 | HInstruction* previous = got->GetPrevious(); |
| 2436 | HLoopInformation* info = block->GetLoopInformation(); |
| 2437 | |
| 2438 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| 2439 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 2440 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2441 | return; |
| 2442 | } |
| 2443 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2444 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 2445 | } |
| 2446 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 2447 | __ B(codegen_->GetLabelOf(successor)); |
| 2448 | } |
| 2449 | } |
| 2450 | |
| 2451 | void LocationsBuilderARMVIXL::VisitGoto(HGoto* got) { |
| 2452 | got->SetLocations(nullptr); |
| 2453 | } |
| 2454 | |
| 2455 | void InstructionCodeGeneratorARMVIXL::VisitGoto(HGoto* got) { |
| 2456 | HandleGoto(got, got->GetSuccessor()); |
| 2457 | } |
| 2458 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2459 | void LocationsBuilderARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2460 | try_boundary->SetLocations(nullptr); |
| 2461 | } |
| 2462 | |
| 2463 | void InstructionCodeGeneratorARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2464 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2465 | if (!successor->IsExitBlock()) { |
| 2466 | HandleGoto(try_boundary, successor); |
| 2467 | } |
| 2468 | } |
| 2469 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2470 | void LocationsBuilderARMVIXL::VisitExit(HExit* exit) { |
| 2471 | exit->SetLocations(nullptr); |
| 2472 | } |
| 2473 | |
| 2474 | void InstructionCodeGeneratorARMVIXL::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 2475 | } |
| 2476 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2477 | void InstructionCodeGeneratorARMVIXL::GenerateLongComparesAndJumps(HCondition* cond, |
| 2478 | vixl32::Label* true_label, |
| 2479 | vixl32::Label* false_label) { |
| 2480 | LocationSummary* locations = cond->GetLocations(); |
| 2481 | Location left = locations->InAt(0); |
| 2482 | Location right = locations->InAt(1); |
| 2483 | IfCondition if_cond = cond->GetCondition(); |
| 2484 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2485 | vixl32::Register left_high = HighRegisterFrom(left); |
| 2486 | vixl32::Register left_low = LowRegisterFrom(left); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2487 | IfCondition true_high_cond = if_cond; |
| 2488 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
| 2489 | vixl32::Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
| 2490 | |
| 2491 | // Set the conditions for the test, remembering that == needs to be |
| 2492 | // decided using the low words. |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2493 | switch (if_cond) { |
| 2494 | case kCondEQ: |
| 2495 | case kCondNE: |
| 2496 | // Nothing to do. |
| 2497 | break; |
| 2498 | case kCondLT: |
| 2499 | false_high_cond = kCondGT; |
| 2500 | break; |
| 2501 | case kCondLE: |
| 2502 | true_high_cond = kCondLT; |
| 2503 | break; |
| 2504 | case kCondGT: |
| 2505 | false_high_cond = kCondLT; |
| 2506 | break; |
| 2507 | case kCondGE: |
| 2508 | true_high_cond = kCondGT; |
| 2509 | break; |
| 2510 | case kCondB: |
| 2511 | false_high_cond = kCondA; |
| 2512 | break; |
| 2513 | case kCondBE: |
| 2514 | true_high_cond = kCondB; |
| 2515 | break; |
| 2516 | case kCondA: |
| 2517 | false_high_cond = kCondB; |
| 2518 | break; |
| 2519 | case kCondAE: |
| 2520 | true_high_cond = kCondA; |
| 2521 | break; |
| 2522 | } |
| 2523 | if (right.IsConstant()) { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 2524 | int64_t value = Int64ConstantFrom(right); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2525 | int32_t val_low = Low32Bits(value); |
| 2526 | int32_t val_high = High32Bits(value); |
| 2527 | |
| 2528 | __ Cmp(left_high, val_high); |
| 2529 | if (if_cond == kCondNE) { |
| 2530 | __ B(ARMCondition(true_high_cond), true_label); |
| 2531 | } else if (if_cond == kCondEQ) { |
| 2532 | __ B(ARMCondition(false_high_cond), false_label); |
| 2533 | } else { |
| 2534 | __ B(ARMCondition(true_high_cond), true_label); |
| 2535 | __ B(ARMCondition(false_high_cond), false_label); |
| 2536 | } |
| 2537 | // Must be equal high, so compare the lows. |
| 2538 | __ Cmp(left_low, val_low); |
| 2539 | } else { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2540 | vixl32::Register right_high = HighRegisterFrom(right); |
| 2541 | vixl32::Register right_low = LowRegisterFrom(right); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2542 | |
| 2543 | __ Cmp(left_high, right_high); |
| 2544 | if (if_cond == kCondNE) { |
| 2545 | __ B(ARMCondition(true_high_cond), true_label); |
| 2546 | } else if (if_cond == kCondEQ) { |
| 2547 | __ B(ARMCondition(false_high_cond), false_label); |
| 2548 | } else { |
| 2549 | __ B(ARMCondition(true_high_cond), true_label); |
| 2550 | __ B(ARMCondition(false_high_cond), false_label); |
| 2551 | } |
| 2552 | // Must be equal high, so compare the lows. |
| 2553 | __ Cmp(left_low, right_low); |
| 2554 | } |
| 2555 | // The last comparison might be unsigned. |
| 2556 | // TODO: optimize cases where this is always true/false |
| 2557 | __ B(final_condition, true_label); |
| 2558 | } |
| 2559 | |
| 2560 | void InstructionCodeGeneratorARMVIXL::GenerateCompareTestAndBranch(HCondition* condition, |
| 2561 | vixl32::Label* true_target_in, |
| 2562 | vixl32::Label* false_target_in) { |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2563 | if (CanGenerateTest(condition, codegen_->GetAssembler())) { |
| 2564 | vixl32::Label* non_fallthrough_target; |
| 2565 | bool invert; |
| 2566 | |
| 2567 | if (true_target_in == nullptr) { |
| 2568 | DCHECK(false_target_in != nullptr); |
| 2569 | non_fallthrough_target = false_target_in; |
| 2570 | invert = true; |
| 2571 | } else { |
| 2572 | non_fallthrough_target = true_target_in; |
| 2573 | invert = false; |
| 2574 | } |
| 2575 | |
| 2576 | const auto cond = GenerateTest(condition, invert, codegen_); |
| 2577 | |
| 2578 | __ B(cond.first, non_fallthrough_target); |
| 2579 | |
| 2580 | if (false_target_in != nullptr && false_target_in != non_fallthrough_target) { |
| 2581 | __ B(false_target_in); |
| 2582 | } |
| 2583 | |
| 2584 | return; |
| 2585 | } |
| 2586 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2587 | // Generated branching requires both targets to be explicit. If either of the |
| 2588 | // targets is nullptr (fallthrough) use and bind `fallthrough` instead. |
| 2589 | vixl32::Label fallthrough; |
| 2590 | vixl32::Label* true_target = (true_target_in == nullptr) ? &fallthrough : true_target_in; |
| 2591 | vixl32::Label* false_target = (false_target_in == nullptr) ? &fallthrough : false_target_in; |
| 2592 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2593 | DCHECK_EQ(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
| 2594 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2595 | |
| 2596 | if (false_target != &fallthrough) { |
| 2597 | __ B(false_target); |
| 2598 | } |
| 2599 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2600 | if (fallthrough.IsReferenced()) { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2601 | __ Bind(&fallthrough); |
| 2602 | } |
| 2603 | } |
| 2604 | |
| 2605 | void InstructionCodeGeneratorARMVIXL::GenerateTestAndBranch(HInstruction* instruction, |
| 2606 | size_t condition_input_index, |
| 2607 | vixl32::Label* true_target, |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2608 | vixl32::Label* false_target, |
| 2609 | bool far_target) { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2610 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 2611 | |
| 2612 | if (true_target == nullptr && false_target == nullptr) { |
| 2613 | // Nothing to do. The code always falls through. |
| 2614 | return; |
| 2615 | } else if (cond->IsIntConstant()) { |
| 2616 | // Constant condition, statically compared against "true" (integer value 1). |
| 2617 | if (cond->AsIntConstant()->IsTrue()) { |
| 2618 | if (true_target != nullptr) { |
| 2619 | __ B(true_target); |
| 2620 | } |
| 2621 | } else { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 2622 | DCHECK(cond->AsIntConstant()->IsFalse()) << Int32ConstantFrom(cond); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2623 | if (false_target != nullptr) { |
| 2624 | __ B(false_target); |
| 2625 | } |
| 2626 | } |
| 2627 | return; |
| 2628 | } |
| 2629 | |
| 2630 | // The following code generates these patterns: |
| 2631 | // (1) true_target == nullptr && false_target != nullptr |
| 2632 | // - opposite condition true => branch to false_target |
| 2633 | // (2) true_target != nullptr && false_target == nullptr |
| 2634 | // - condition true => branch to true_target |
| 2635 | // (3) true_target != nullptr && false_target != nullptr |
| 2636 | // - condition true => branch to true_target |
| 2637 | // - branch to false_target |
| 2638 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 2639 | // Condition has been materialized, compare the output to 0. |
| 2640 | if (kIsDebugBuild) { |
| 2641 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 2642 | DCHECK(cond_val.IsRegister()); |
| 2643 | } |
| 2644 | if (true_target == nullptr) { |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2645 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, condition_input_index), |
| 2646 | false_target, |
| 2647 | far_target); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2648 | } else { |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2649 | __ CompareAndBranchIfNonZero(InputRegisterAt(instruction, condition_input_index), |
| 2650 | true_target, |
| 2651 | far_target); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2652 | } |
| 2653 | } else { |
| 2654 | // Condition has not been materialized. Use its inputs as the comparison and |
| 2655 | // its condition as the branch condition. |
| 2656 | HCondition* condition = cond->AsCondition(); |
| 2657 | |
| 2658 | // If this is a long or FP comparison that has been folded into |
| 2659 | // the HCondition, generate the comparison directly. |
| 2660 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 2661 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 2662 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 2663 | return; |
| 2664 | } |
| 2665 | |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2666 | vixl32::Label* non_fallthrough_target; |
| 2667 | vixl32::Condition arm_cond = vixl32::Condition::None(); |
| 2668 | const vixl32::Register left = InputRegisterAt(cond, 0); |
| 2669 | const Operand right = InputOperandAt(cond, 1); |
| 2670 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2671 | if (true_target == nullptr) { |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2672 | arm_cond = ARMCondition(condition->GetOppositeCondition()); |
| 2673 | non_fallthrough_target = false_target; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2674 | } else { |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2675 | arm_cond = ARMCondition(condition->GetCondition()); |
| 2676 | non_fallthrough_target = true_target; |
| 2677 | } |
| 2678 | |
| 2679 | if (right.IsImmediate() && right.GetImmediate() == 0 && (arm_cond.Is(ne) || arm_cond.Is(eq))) { |
| 2680 | if (arm_cond.Is(eq)) { |
| 2681 | __ CompareAndBranchIfZero(left, non_fallthrough_target); |
| 2682 | } else { |
| 2683 | DCHECK(arm_cond.Is(ne)); |
| 2684 | __ CompareAndBranchIfNonZero(left, non_fallthrough_target); |
| 2685 | } |
| 2686 | } else { |
| 2687 | __ Cmp(left, right); |
| 2688 | __ B(arm_cond, non_fallthrough_target); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2689 | } |
| 2690 | } |
| 2691 | |
| 2692 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 2693 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 2694 | if (true_target != nullptr && false_target != nullptr) { |
| 2695 | __ B(false_target); |
| 2696 | } |
| 2697 | } |
| 2698 | |
| 2699 | void LocationsBuilderARMVIXL::VisitIf(HIf* if_instr) { |
| 2700 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 2701 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| 2702 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2703 | } |
| 2704 | } |
| 2705 | |
| 2706 | void InstructionCodeGeneratorARMVIXL::VisitIf(HIf* if_instr) { |
| 2707 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 2708 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2709 | vixl32::Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 2710 | nullptr : codegen_->GetLabelOf(true_successor); |
| 2711 | vixl32::Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 2712 | nullptr : codegen_->GetLabelOf(false_successor); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2713 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
| 2714 | } |
| 2715 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2716 | void LocationsBuilderARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2717 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2718 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 2719 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 2720 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| 2721 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2722 | } |
| 2723 | } |
| 2724 | |
| 2725 | void InstructionCodeGeneratorARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2726 | SlowPathCodeARMVIXL* slow_path = |
| 2727 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARMVIXL>(deoptimize); |
| 2728 | GenerateTestAndBranch(deoptimize, |
| 2729 | /* condition_input_index */ 0, |
| 2730 | slow_path->GetEntryLabel(), |
| 2731 | /* false_target */ nullptr); |
| 2732 | } |
| 2733 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2734 | void LocationsBuilderARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2735 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2736 | LocationSummary(flag, LocationSummary::kNoCall); |
| 2737 | locations->SetOut(Location::RequiresRegister()); |
| 2738 | } |
| 2739 | |
| 2740 | void InstructionCodeGeneratorARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2741 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 2742 | OutputRegister(flag), |
| 2743 | sp, |
| 2744 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 2745 | } |
| 2746 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2747 | void LocationsBuilderARMVIXL::VisitSelect(HSelect* select) { |
| 2748 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2749 | const bool is_floating_point = Primitive::IsFloatingPointType(select->GetType()); |
| 2750 | |
| 2751 | if (is_floating_point) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2752 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2753 | locations->SetInAt(1, Location::FpuRegisterOrConstant(select->GetTrueValue())); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2754 | } else { |
| 2755 | locations->SetInAt(0, Location::RequiresRegister()); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2756 | locations->SetInAt(1, Arm8BitEncodableConstantOrRegister(select->GetTrueValue())); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2757 | } |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2758 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2759 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2760 | locations->SetInAt(2, Location::RegisterOrConstant(select->GetCondition())); |
| 2761 | // The code generator handles overlap with the values, but not with the condition. |
| 2762 | locations->SetOut(Location::SameAsFirstInput()); |
| 2763 | } else if (is_floating_point) { |
| 2764 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2765 | } else { |
| 2766 | if (!locations->InAt(1).IsConstant()) { |
| 2767 | locations->SetInAt(0, Arm8BitEncodableConstantOrRegister(select->GetFalseValue())); |
| 2768 | } |
| 2769 | |
| 2770 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2771 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2772 | } |
| 2773 | |
| 2774 | void InstructionCodeGeneratorARMVIXL::VisitSelect(HSelect* select) { |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2775 | HInstruction* const condition = select->GetCondition(); |
| 2776 | const LocationSummary* const locations = select->GetLocations(); |
| 2777 | const Primitive::Type type = select->GetType(); |
| 2778 | const Location first = locations->InAt(0); |
| 2779 | const Location out = locations->Out(); |
| 2780 | const Location second = locations->InAt(1); |
| 2781 | Location src; |
| 2782 | |
| 2783 | if (condition->IsIntConstant()) { |
| 2784 | if (condition->AsIntConstant()->IsFalse()) { |
| 2785 | src = first; |
| 2786 | } else { |
| 2787 | src = second; |
| 2788 | } |
| 2789 | |
| 2790 | codegen_->MoveLocation(out, src, type); |
| 2791 | return; |
| 2792 | } |
| 2793 | |
| 2794 | if (!Primitive::IsFloatingPointType(type) && |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2795 | (IsBooleanValueOrMaterializedCondition(condition) || |
| 2796 | CanGenerateTest(condition->AsCondition(), codegen_->GetAssembler()))) { |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2797 | bool invert = false; |
| 2798 | |
| 2799 | if (out.Equals(second)) { |
| 2800 | src = first; |
| 2801 | invert = true; |
| 2802 | } else if (out.Equals(first)) { |
| 2803 | src = second; |
| 2804 | } else if (second.IsConstant()) { |
| 2805 | DCHECK(CanEncodeConstantAs8BitImmediate(second.GetConstant())); |
| 2806 | src = second; |
| 2807 | } else if (first.IsConstant()) { |
| 2808 | DCHECK(CanEncodeConstantAs8BitImmediate(first.GetConstant())); |
| 2809 | src = first; |
| 2810 | invert = true; |
| 2811 | } else { |
| 2812 | src = second; |
| 2813 | } |
| 2814 | |
| 2815 | if (CanGenerateConditionalMove(out, src)) { |
| 2816 | if (!out.Equals(first) && !out.Equals(second)) { |
| 2817 | codegen_->MoveLocation(out, src.Equals(first) ? second : first, type); |
| 2818 | } |
| 2819 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2820 | std::pair<vixl32::Condition, vixl32::Condition> cond(eq, ne); |
| 2821 | |
| 2822 | if (IsBooleanValueOrMaterializedCondition(condition)) { |
| 2823 | __ Cmp(InputRegisterAt(select, 2), 0); |
| 2824 | cond = invert ? std::make_pair(eq, ne) : std::make_pair(ne, eq); |
| 2825 | } else { |
| 2826 | cond = GenerateTest(condition->AsCondition(), invert, codegen_); |
| 2827 | } |
| 2828 | |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2829 | const size_t instr_count = out.IsRegisterPair() ? 4 : 2; |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2830 | // We use the scope because of the IT block that follows. |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2831 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 2832 | instr_count * vixl32::k16BitT32InstructionSizeInBytes, |
| 2833 | CodeBufferCheckScope::kExactSize); |
| 2834 | |
| 2835 | if (out.IsRegister()) { |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2836 | __ it(cond.first); |
| 2837 | __ mov(cond.first, RegisterFrom(out), OperandFrom(src, type)); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2838 | } else { |
| 2839 | DCHECK(out.IsRegisterPair()); |
| 2840 | |
| 2841 | Operand operand_high(0); |
| 2842 | Operand operand_low(0); |
| 2843 | |
| 2844 | if (src.IsConstant()) { |
| 2845 | const int64_t value = Int64ConstantFrom(src); |
| 2846 | |
| 2847 | operand_high = High32Bits(value); |
| 2848 | operand_low = Low32Bits(value); |
| 2849 | } else { |
| 2850 | DCHECK(src.IsRegisterPair()); |
| 2851 | operand_high = HighRegisterFrom(src); |
| 2852 | operand_low = LowRegisterFrom(src); |
| 2853 | } |
| 2854 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2855 | __ it(cond.first); |
| 2856 | __ mov(cond.first, LowRegisterFrom(out), operand_low); |
| 2857 | __ it(cond.first); |
| 2858 | __ mov(cond.first, HighRegisterFrom(out), operand_high); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2859 | } |
| 2860 | |
| 2861 | return; |
| 2862 | } |
| 2863 | } |
| 2864 | |
| 2865 | vixl32::Label* false_target = nullptr; |
| 2866 | vixl32::Label* true_target = nullptr; |
| 2867 | vixl32::Label select_end; |
| 2868 | vixl32::Label* const target = codegen_->GetFinalLabel(select, &select_end); |
| 2869 | |
| 2870 | if (out.Equals(second)) { |
| 2871 | true_target = target; |
| 2872 | src = first; |
| 2873 | } else { |
| 2874 | false_target = target; |
| 2875 | src = second; |
| 2876 | |
| 2877 | if (!out.Equals(first)) { |
| 2878 | codegen_->MoveLocation(out, first, type); |
| 2879 | } |
| 2880 | } |
| 2881 | |
| 2882 | GenerateTestAndBranch(select, 2, true_target, false_target, /* far_target */ false); |
| 2883 | codegen_->MoveLocation(out, src, type); |
| 2884 | |
| 2885 | if (select_end.IsReferenced()) { |
| 2886 | __ Bind(&select_end); |
| 2887 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2888 | } |
| 2889 | |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2890 | void LocationsBuilderARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 2891 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 2892 | } |
| 2893 | |
| 2894 | void InstructionCodeGeneratorARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 2895 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| 2896 | } |
| 2897 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2898 | void CodeGeneratorARMVIXL::GenerateNop() { |
| 2899 | __ Nop(); |
| 2900 | } |
| 2901 | |
| 2902 | void LocationsBuilderARMVIXL::HandleCondition(HCondition* cond) { |
| 2903 | LocationSummary* locations = |
| 2904 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
| 2905 | // Handle the long/FP comparisons made in instruction simplification. |
| 2906 | switch (cond->InputAt(0)->GetType()) { |
| 2907 | case Primitive::kPrimLong: |
| 2908 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2909 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 2910 | if (!cond->IsEmittedAtUseSite()) { |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2911 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2912 | } |
| 2913 | break; |
| 2914 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2915 | case Primitive::kPrimFloat: |
| 2916 | case Primitive::kPrimDouble: |
| 2917 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 2918 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2919 | if (!cond->IsEmittedAtUseSite()) { |
| 2920 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2921 | } |
| 2922 | break; |
| 2923 | |
| 2924 | default: |
| 2925 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2926 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 2927 | if (!cond->IsEmittedAtUseSite()) { |
| 2928 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2929 | } |
| 2930 | } |
| 2931 | } |
| 2932 | |
| 2933 | void InstructionCodeGeneratorARMVIXL::HandleCondition(HCondition* cond) { |
| 2934 | if (cond->IsEmittedAtUseSite()) { |
| 2935 | return; |
| 2936 | } |
| 2937 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2938 | const vixl32::Register out = OutputRegister(cond); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2939 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2940 | if (out.IsLow() && CanGenerateTest(cond, codegen_->GetAssembler())) { |
| 2941 | const auto condition = GenerateTest(cond, false, codegen_); |
| 2942 | // We use the scope because of the IT block that follows. |
| 2943 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 2944 | 4 * vixl32::k16BitT32InstructionSizeInBytes, |
| 2945 | CodeBufferCheckScope::kExactSize); |
| 2946 | |
| 2947 | __ it(condition.first); |
| 2948 | __ mov(condition.first, out, 1); |
| 2949 | __ it(condition.second); |
| 2950 | __ mov(condition.second, out, 0); |
| 2951 | return; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2952 | } |
| 2953 | |
| 2954 | // Convert the jumps into the result. |
| 2955 | vixl32::Label done_label; |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2956 | vixl32::Label* const final_label = codegen_->GetFinalLabel(cond, &done_label); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2957 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2958 | if (cond->InputAt(0)->GetType() == Primitive::kPrimLong) { |
| 2959 | vixl32::Label true_label, false_label; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2960 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2961 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 2962 | |
| 2963 | // False case: result = 0. |
| 2964 | __ Bind(&false_label); |
| 2965 | __ Mov(out, 0); |
| 2966 | __ B(final_label); |
| 2967 | |
| 2968 | // True case: result = 1. |
| 2969 | __ Bind(&true_label); |
| 2970 | __ Mov(out, 1); |
| 2971 | } else { |
| 2972 | DCHECK(CanGenerateTest(cond, codegen_->GetAssembler())); |
| 2973 | |
| 2974 | const auto condition = GenerateTest(cond, false, codegen_); |
| 2975 | |
| 2976 | __ Mov(LeaveFlags, out, 0); |
| 2977 | __ B(condition.second, final_label, /* far_target */ false); |
| 2978 | __ Mov(out, 1); |
| 2979 | } |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 2980 | |
| 2981 | if (done_label.IsReferenced()) { |
| 2982 | __ Bind(&done_label); |
| 2983 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2984 | } |
| 2985 | |
| 2986 | void LocationsBuilderARMVIXL::VisitEqual(HEqual* comp) { |
| 2987 | HandleCondition(comp); |
| 2988 | } |
| 2989 | |
| 2990 | void InstructionCodeGeneratorARMVIXL::VisitEqual(HEqual* comp) { |
| 2991 | HandleCondition(comp); |
| 2992 | } |
| 2993 | |
| 2994 | void LocationsBuilderARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 2995 | HandleCondition(comp); |
| 2996 | } |
| 2997 | |
| 2998 | void InstructionCodeGeneratorARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 2999 | HandleCondition(comp); |
| 3000 | } |
| 3001 | |
| 3002 | void LocationsBuilderARMVIXL::VisitLessThan(HLessThan* comp) { |
| 3003 | HandleCondition(comp); |
| 3004 | } |
| 3005 | |
| 3006 | void InstructionCodeGeneratorARMVIXL::VisitLessThan(HLessThan* comp) { |
| 3007 | HandleCondition(comp); |
| 3008 | } |
| 3009 | |
| 3010 | void LocationsBuilderARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 3011 | HandleCondition(comp); |
| 3012 | } |
| 3013 | |
| 3014 | void InstructionCodeGeneratorARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 3015 | HandleCondition(comp); |
| 3016 | } |
| 3017 | |
| 3018 | void LocationsBuilderARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 3019 | HandleCondition(comp); |
| 3020 | } |
| 3021 | |
| 3022 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 3023 | HandleCondition(comp); |
| 3024 | } |
| 3025 | |
| 3026 | void LocationsBuilderARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 3027 | HandleCondition(comp); |
| 3028 | } |
| 3029 | |
| 3030 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 3031 | HandleCondition(comp); |
| 3032 | } |
| 3033 | |
| 3034 | void LocationsBuilderARMVIXL::VisitBelow(HBelow* comp) { |
| 3035 | HandleCondition(comp); |
| 3036 | } |
| 3037 | |
| 3038 | void InstructionCodeGeneratorARMVIXL::VisitBelow(HBelow* comp) { |
| 3039 | HandleCondition(comp); |
| 3040 | } |
| 3041 | |
| 3042 | void LocationsBuilderARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 3043 | HandleCondition(comp); |
| 3044 | } |
| 3045 | |
| 3046 | void InstructionCodeGeneratorARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 3047 | HandleCondition(comp); |
| 3048 | } |
| 3049 | |
| 3050 | void LocationsBuilderARMVIXL::VisitAbove(HAbove* comp) { |
| 3051 | HandleCondition(comp); |
| 3052 | } |
| 3053 | |
| 3054 | void InstructionCodeGeneratorARMVIXL::VisitAbove(HAbove* comp) { |
| 3055 | HandleCondition(comp); |
| 3056 | } |
| 3057 | |
| 3058 | void LocationsBuilderARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 3059 | HandleCondition(comp); |
| 3060 | } |
| 3061 | |
| 3062 | void InstructionCodeGeneratorARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 3063 | HandleCondition(comp); |
| 3064 | } |
| 3065 | |
| 3066 | void LocationsBuilderARMVIXL::VisitIntConstant(HIntConstant* constant) { |
| 3067 | LocationSummary* locations = |
| 3068 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3069 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3070 | } |
| 3071 | |
| 3072 | void InstructionCodeGeneratorARMVIXL::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 3073 | // Will be generated at use site. |
| 3074 | } |
| 3075 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3076 | void LocationsBuilderARMVIXL::VisitNullConstant(HNullConstant* constant) { |
| 3077 | LocationSummary* locations = |
| 3078 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3079 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3080 | } |
| 3081 | |
| 3082 | void InstructionCodeGeneratorARMVIXL::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 3083 | // Will be generated at use site. |
| 3084 | } |
| 3085 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3086 | void LocationsBuilderARMVIXL::VisitLongConstant(HLongConstant* constant) { |
| 3087 | LocationSummary* locations = |
| 3088 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3089 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3090 | } |
| 3091 | |
| 3092 | void InstructionCodeGeneratorARMVIXL::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 3093 | // Will be generated at use site. |
| 3094 | } |
| 3095 | |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3096 | void LocationsBuilderARMVIXL::VisitFloatConstant(HFloatConstant* constant) { |
| 3097 | LocationSummary* locations = |
| 3098 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3099 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3100 | } |
| 3101 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3102 | void InstructionCodeGeneratorARMVIXL::VisitFloatConstant( |
| 3103 | HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3104 | // Will be generated at use site. |
| 3105 | } |
| 3106 | |
| 3107 | void LocationsBuilderARMVIXL::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3108 | LocationSummary* locations = |
| 3109 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3110 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3111 | } |
| 3112 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3113 | void InstructionCodeGeneratorARMVIXL::VisitDoubleConstant( |
| 3114 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3115 | // Will be generated at use site. |
| 3116 | } |
| 3117 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3118 | void LocationsBuilderARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3119 | memory_barrier->SetLocations(nullptr); |
| 3120 | } |
| 3121 | |
| 3122 | void InstructionCodeGeneratorARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3123 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 3124 | } |
| 3125 | |
| 3126 | void LocationsBuilderARMVIXL::VisitReturnVoid(HReturnVoid* ret) { |
| 3127 | ret->SetLocations(nullptr); |
| 3128 | } |
| 3129 | |
| 3130 | void InstructionCodeGeneratorARMVIXL::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 3131 | codegen_->GenerateFrameExit(); |
| 3132 | } |
| 3133 | |
| 3134 | void LocationsBuilderARMVIXL::VisitReturn(HReturn* ret) { |
| 3135 | LocationSummary* locations = |
| 3136 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
| 3137 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
| 3138 | } |
| 3139 | |
| 3140 | void InstructionCodeGeneratorARMVIXL::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 3141 | codegen_->GenerateFrameExit(); |
| 3142 | } |
| 3143 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3144 | void LocationsBuilderARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3145 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3146 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3147 | // the method_idx. |
| 3148 | HandleInvoke(invoke); |
| 3149 | } |
| 3150 | |
| 3151 | void InstructionCodeGeneratorARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3152 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 3153 | } |
| 3154 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3155 | void LocationsBuilderARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3156 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3157 | // art::PrepareForRegisterAllocation. |
| 3158 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 3159 | |
| Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3160 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3161 | if (intrinsic.TryDispatch(invoke)) { |
| 3162 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 3163 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 3164 | } |
| 3165 | return; |
| 3166 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3167 | |
| 3168 | HandleInvoke(invoke); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 3169 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3170 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 3171 | if (invoke->HasPcRelativeDexCache()) { |
| 3172 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 3173 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3174 | } |
| 3175 | |
| Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3176 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARMVIXL* codegen) { |
| 3177 | if (invoke->GetLocations()->Intrinsified()) { |
| 3178 | IntrinsicCodeGeneratorARMVIXL intrinsic(codegen); |
| 3179 | intrinsic.Dispatch(invoke); |
| 3180 | return true; |
| 3181 | } |
| 3182 | return false; |
| 3183 | } |
| 3184 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3185 | void InstructionCodeGeneratorARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3186 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3187 | // art::PrepareForRegisterAllocation. |
| 3188 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 3189 | |
| Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3190 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3191 | return; |
| 3192 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3193 | |
| 3194 | LocationSummary* locations = invoke->GetLocations(); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3195 | codegen_->GenerateStaticOrDirectCall( |
| 3196 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3197 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3198 | } |
| 3199 | |
| 3200 | void LocationsBuilderARMVIXL::HandleInvoke(HInvoke* invoke) { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3201 | InvokeDexCallingConventionVisitorARMVIXL calling_convention_visitor; |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3202 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 3203 | } |
| 3204 | |
| 3205 | void LocationsBuilderARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3206 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3207 | if (intrinsic.TryDispatch(invoke)) { |
| 3208 | return; |
| 3209 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3210 | |
| 3211 | HandleInvoke(invoke); |
| 3212 | } |
| 3213 | |
| 3214 | void InstructionCodeGeneratorARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3215 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3216 | return; |
| 3217 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3218 | |
| 3219 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3220 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3221 | DCHECK(!codegen_->IsLeafMethod()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3222 | } |
| 3223 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3224 | void LocationsBuilderARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3225 | HandleInvoke(invoke); |
| 3226 | // Add the hidden argument. |
| 3227 | invoke->GetLocations()->AddTemp(LocationFrom(r12)); |
| 3228 | } |
| 3229 | |
| 3230 | void InstructionCodeGeneratorARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3231 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 3232 | LocationSummary* locations = invoke->GetLocations(); |
| 3233 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 3234 | vixl32::Register hidden_reg = RegisterFrom(locations->GetTemp(1)); |
| 3235 | Location receiver = locations->InAt(0); |
| 3236 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3237 | |
| 3238 | DCHECK(!receiver.IsStackSlot()); |
| 3239 | |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3240 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
| 3241 | { |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 3242 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 3243 | vixl32::kMaxInstructionSizeInBytes, |
| 3244 | CodeBufferCheckScope::kMaximumSize); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3245 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 3246 | __ ldr(temp, MemOperand(RegisterFrom(receiver), class_offset)); |
| 3247 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 3248 | } |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3249 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3250 | // emit a read barrier for the previous class reference load. |
| 3251 | // However this is not required in practice, as this is an |
| 3252 | // intermediate/temporary reference and because the current |
| 3253 | // concurrent copying collector keeps the from-space memory |
| 3254 | // intact/accessible until the end of the marking phase (the |
| 3255 | // concurrent copying collector may not in the future). |
| 3256 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 3257 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3258 | temp, |
| 3259 | temp, |
| 3260 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 3261 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 3262 | invoke->GetImtIndex(), kArmPointerSize)); |
| 3263 | // temp = temp->GetImtEntryAt(method_offset); |
| 3264 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 3265 | uint32_t entry_point = |
| 3266 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
| 3267 | // LR = temp->GetEntryPoint(); |
| 3268 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
| 3269 | |
| 3270 | // Set the hidden (in r12) argument. It is done here, right before a BLX to prevent other |
| 3271 | // instruction from clobbering it as they might use r12 as a scratch register. |
| 3272 | DCHECK(hidden_reg.Is(r12)); |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3273 | |
| 3274 | { |
| 3275 | // The VIXL macro assembler may clobber any of the scratch registers that are available to it, |
| 3276 | // so it checks if the application is using them (by passing them to the macro assembler |
| 3277 | // methods). The following application of UseScratchRegisterScope corrects VIXL's notion of |
| 3278 | // what is available, and is the opposite of the standard usage: Instead of requesting a |
| 3279 | // temporary location, it imposes an external constraint (i.e. a specific register is reserved |
| 3280 | // for the hidden argument). Note that this works even if VIXL needs a scratch register itself |
| 3281 | // (to materialize the constant), since the destination register becomes available for such use |
| 3282 | // internally for the duration of the macro instruction. |
| 3283 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3284 | temps.Exclude(hidden_reg); |
| 3285 | __ Mov(hidden_reg, invoke->GetDexMethodIndex()); |
| 3286 | } |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3287 | { |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3288 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 3289 | // 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] | 3290 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3291 | vixl32::k16BitT32InstructionSizeInBytes, |
| 3292 | CodeBufferCheckScope::kExactSize); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3293 | // LR(); |
| 3294 | __ blx(lr); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3295 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3296 | DCHECK(!codegen_->IsLeafMethod()); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3297 | } |
| 3298 | } |
| 3299 | |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3300 | void LocationsBuilderARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3301 | HandleInvoke(invoke); |
| 3302 | } |
| 3303 | |
| 3304 | void InstructionCodeGeneratorARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3305 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 3306 | } |
| 3307 | |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3308 | void LocationsBuilderARMVIXL::VisitNeg(HNeg* neg) { |
| 3309 | LocationSummary* locations = |
| 3310 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 3311 | switch (neg->GetResultType()) { |
| 3312 | case Primitive::kPrimInt: { |
| 3313 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3314 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3315 | break; |
| 3316 | } |
| 3317 | case Primitive::kPrimLong: { |
| 3318 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3319 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3320 | break; |
| 3321 | } |
| 3322 | |
| 3323 | case Primitive::kPrimFloat: |
| 3324 | case Primitive::kPrimDouble: |
| 3325 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3326 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3327 | break; |
| 3328 | |
| 3329 | default: |
| 3330 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3331 | } |
| 3332 | } |
| 3333 | |
| 3334 | void InstructionCodeGeneratorARMVIXL::VisitNeg(HNeg* neg) { |
| 3335 | LocationSummary* locations = neg->GetLocations(); |
| 3336 | Location out = locations->Out(); |
| 3337 | Location in = locations->InAt(0); |
| 3338 | switch (neg->GetResultType()) { |
| 3339 | case Primitive::kPrimInt: |
| 3340 | __ Rsb(OutputRegister(neg), InputRegisterAt(neg, 0), 0); |
| 3341 | break; |
| 3342 | |
| 3343 | case Primitive::kPrimLong: |
| 3344 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 3345 | __ Rsbs(LowRegisterFrom(out), LowRegisterFrom(in), 0); |
| 3346 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 3347 | // instruction here, as it does not exist in the Thumb-2 |
| 3348 | // instruction set. We use the following approach |
| 3349 | // using SBC and SUB instead. |
| 3350 | // |
| 3351 | // out.hi = -C |
| 3352 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(out)); |
| 3353 | // out.hi = out.hi - in.hi |
| 3354 | __ Sub(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(in)); |
| 3355 | break; |
| 3356 | |
| 3357 | case Primitive::kPrimFloat: |
| 3358 | case Primitive::kPrimDouble: |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 3359 | __ Vneg(OutputVRegister(neg), InputVRegister(neg)); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3360 | break; |
| 3361 | |
| 3362 | default: |
| 3363 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3364 | } |
| 3365 | } |
| 3366 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3367 | void LocationsBuilderARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
| 3368 | Primitive::Type result_type = conversion->GetResultType(); |
| 3369 | Primitive::Type input_type = conversion->GetInputType(); |
| 3370 | DCHECK_NE(result_type, input_type); |
| 3371 | |
| 3372 | // The float-to-long, double-to-long and long-to-float type conversions |
| 3373 | // rely on a call to the runtime. |
| 3374 | LocationSummary::CallKind call_kind = |
| 3375 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 3376 | && result_type == Primitive::kPrimLong) |
| 3377 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
| 3378 | ? LocationSummary::kCallOnMainOnly |
| 3379 | : LocationSummary::kNoCall; |
| 3380 | LocationSummary* locations = |
| 3381 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 3382 | |
| 3383 | // The Java language does not allow treating boolean as an integral type but |
| 3384 | // our bit representation makes it safe. |
| 3385 | |
| 3386 | switch (result_type) { |
| 3387 | case Primitive::kPrimByte: |
| 3388 | switch (input_type) { |
| 3389 | case Primitive::kPrimLong: |
| 3390 | // Type conversion from long to byte is a result of code transformations. |
| 3391 | case Primitive::kPrimBoolean: |
| 3392 | // Boolean input is a result of code transformations. |
| 3393 | case Primitive::kPrimShort: |
| 3394 | case Primitive::kPrimInt: |
| 3395 | case Primitive::kPrimChar: |
| 3396 | // Processing a Dex `int-to-byte' instruction. |
| 3397 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3398 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3399 | break; |
| 3400 | |
| 3401 | default: |
| 3402 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3403 | << " to " << result_type; |
| 3404 | } |
| 3405 | break; |
| 3406 | |
| 3407 | case Primitive::kPrimShort: |
| 3408 | switch (input_type) { |
| 3409 | case Primitive::kPrimLong: |
| 3410 | // Type conversion from long to short is a result of code transformations. |
| 3411 | case Primitive::kPrimBoolean: |
| 3412 | // Boolean input is a result of code transformations. |
| 3413 | case Primitive::kPrimByte: |
| 3414 | case Primitive::kPrimInt: |
| 3415 | case Primitive::kPrimChar: |
| 3416 | // Processing a Dex `int-to-short' instruction. |
| 3417 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3418 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3419 | break; |
| 3420 | |
| 3421 | default: |
| 3422 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3423 | << " to " << result_type; |
| 3424 | } |
| 3425 | break; |
| 3426 | |
| 3427 | case Primitive::kPrimInt: |
| 3428 | switch (input_type) { |
| 3429 | case Primitive::kPrimLong: |
| 3430 | // Processing a Dex `long-to-int' instruction. |
| 3431 | locations->SetInAt(0, Location::Any()); |
| 3432 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3433 | break; |
| 3434 | |
| 3435 | case Primitive::kPrimFloat: |
| 3436 | // Processing a Dex `float-to-int' instruction. |
| 3437 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3438 | locations->SetOut(Location::RequiresRegister()); |
| 3439 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3440 | break; |
| 3441 | |
| 3442 | case Primitive::kPrimDouble: |
| 3443 | // Processing a Dex `double-to-int' instruction. |
| 3444 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3445 | locations->SetOut(Location::RequiresRegister()); |
| 3446 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3447 | break; |
| 3448 | |
| 3449 | default: |
| 3450 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3451 | << " to " << result_type; |
| 3452 | } |
| 3453 | break; |
| 3454 | |
| 3455 | case Primitive::kPrimLong: |
| 3456 | switch (input_type) { |
| 3457 | case Primitive::kPrimBoolean: |
| 3458 | // Boolean input is a result of code transformations. |
| 3459 | case Primitive::kPrimByte: |
| 3460 | case Primitive::kPrimShort: |
| 3461 | case Primitive::kPrimInt: |
| 3462 | case Primitive::kPrimChar: |
| 3463 | // Processing a Dex `int-to-long' instruction. |
| 3464 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3465 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3466 | break; |
| 3467 | |
| 3468 | case Primitive::kPrimFloat: { |
| 3469 | // Processing a Dex `float-to-long' instruction. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3470 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3471 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 3472 | locations->SetOut(LocationFrom(r0, r1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3473 | break; |
| 3474 | } |
| 3475 | |
| 3476 | case Primitive::kPrimDouble: { |
| 3477 | // Processing a Dex `double-to-long' instruction. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3478 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3479 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0), |
| 3480 | calling_convention.GetFpuRegisterAt(1))); |
| 3481 | locations->SetOut(LocationFrom(r0, r1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3482 | break; |
| 3483 | } |
| 3484 | |
| 3485 | default: |
| 3486 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3487 | << " to " << result_type; |
| 3488 | } |
| 3489 | break; |
| 3490 | |
| 3491 | case Primitive::kPrimChar: |
| 3492 | switch (input_type) { |
| 3493 | case Primitive::kPrimLong: |
| 3494 | // Type conversion from long to char is a result of code transformations. |
| 3495 | case Primitive::kPrimBoolean: |
| 3496 | // Boolean input is a result of code transformations. |
| 3497 | case Primitive::kPrimByte: |
| 3498 | case Primitive::kPrimShort: |
| 3499 | case Primitive::kPrimInt: |
| 3500 | // Processing a Dex `int-to-char' instruction. |
| 3501 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3502 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3503 | break; |
| 3504 | |
| 3505 | default: |
| 3506 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3507 | << " to " << result_type; |
| 3508 | } |
| 3509 | break; |
| 3510 | |
| 3511 | case Primitive::kPrimFloat: |
| 3512 | switch (input_type) { |
| 3513 | case Primitive::kPrimBoolean: |
| 3514 | // Boolean input is a result of code transformations. |
| 3515 | case Primitive::kPrimByte: |
| 3516 | case Primitive::kPrimShort: |
| 3517 | case Primitive::kPrimInt: |
| 3518 | case Primitive::kPrimChar: |
| 3519 | // Processing a Dex `int-to-float' instruction. |
| 3520 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3521 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3522 | break; |
| 3523 | |
| 3524 | case Primitive::kPrimLong: { |
| 3525 | // Processing a Dex `long-to-float' instruction. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3526 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3527 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0), |
| 3528 | calling_convention.GetRegisterAt(1))); |
| 3529 | locations->SetOut(LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3530 | break; |
| 3531 | } |
| 3532 | |
| 3533 | case Primitive::kPrimDouble: |
| 3534 | // Processing a Dex `double-to-float' instruction. |
| 3535 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3536 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3537 | break; |
| 3538 | |
| 3539 | default: |
| 3540 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3541 | << " to " << result_type; |
| 3542 | }; |
| 3543 | break; |
| 3544 | |
| 3545 | case Primitive::kPrimDouble: |
| 3546 | switch (input_type) { |
| 3547 | case Primitive::kPrimBoolean: |
| 3548 | // Boolean input is a result of code transformations. |
| 3549 | case Primitive::kPrimByte: |
| 3550 | case Primitive::kPrimShort: |
| 3551 | case Primitive::kPrimInt: |
| 3552 | case Primitive::kPrimChar: |
| 3553 | // Processing a Dex `int-to-double' instruction. |
| 3554 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3555 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3556 | break; |
| 3557 | |
| 3558 | case Primitive::kPrimLong: |
| 3559 | // Processing a Dex `long-to-double' instruction. |
| 3560 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3561 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3562 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3563 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3564 | break; |
| 3565 | |
| 3566 | case Primitive::kPrimFloat: |
| 3567 | // Processing a Dex `float-to-double' instruction. |
| 3568 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3569 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3570 | break; |
| 3571 | |
| 3572 | default: |
| 3573 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3574 | << " to " << result_type; |
| 3575 | }; |
| 3576 | break; |
| 3577 | |
| 3578 | default: |
| 3579 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3580 | << " to " << result_type; |
| 3581 | } |
| 3582 | } |
| 3583 | |
| 3584 | void InstructionCodeGeneratorARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
| 3585 | LocationSummary* locations = conversion->GetLocations(); |
| 3586 | Location out = locations->Out(); |
| 3587 | Location in = locations->InAt(0); |
| 3588 | Primitive::Type result_type = conversion->GetResultType(); |
| 3589 | Primitive::Type input_type = conversion->GetInputType(); |
| 3590 | DCHECK_NE(result_type, input_type); |
| 3591 | switch (result_type) { |
| 3592 | case Primitive::kPrimByte: |
| 3593 | switch (input_type) { |
| 3594 | case Primitive::kPrimLong: |
| 3595 | // Type conversion from long to byte is a result of code transformations. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3596 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 8); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3597 | break; |
| 3598 | case Primitive::kPrimBoolean: |
| 3599 | // Boolean input is a result of code transformations. |
| 3600 | case Primitive::kPrimShort: |
| 3601 | case Primitive::kPrimInt: |
| 3602 | case Primitive::kPrimChar: |
| 3603 | // Processing a Dex `int-to-byte' instruction. |
| 3604 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 8); |
| 3605 | break; |
| 3606 | |
| 3607 | default: |
| 3608 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3609 | << " to " << result_type; |
| 3610 | } |
| 3611 | break; |
| 3612 | |
| 3613 | case Primitive::kPrimShort: |
| 3614 | switch (input_type) { |
| 3615 | case Primitive::kPrimLong: |
| 3616 | // Type conversion from long to short is a result of code transformations. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3617 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3618 | break; |
| 3619 | case Primitive::kPrimBoolean: |
| 3620 | // Boolean input is a result of code transformations. |
| 3621 | case Primitive::kPrimByte: |
| 3622 | case Primitive::kPrimInt: |
| 3623 | case Primitive::kPrimChar: |
| 3624 | // Processing a Dex `int-to-short' instruction. |
| 3625 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 3626 | break; |
| 3627 | |
| 3628 | default: |
| 3629 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3630 | << " to " << result_type; |
| 3631 | } |
| 3632 | break; |
| 3633 | |
| 3634 | case Primitive::kPrimInt: |
| 3635 | switch (input_type) { |
| 3636 | case Primitive::kPrimLong: |
| 3637 | // Processing a Dex `long-to-int' instruction. |
| 3638 | DCHECK(out.IsRegister()); |
| 3639 | if (in.IsRegisterPair()) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3640 | __ Mov(OutputRegister(conversion), LowRegisterFrom(in)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3641 | } else if (in.IsDoubleStackSlot()) { |
| 3642 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3643 | OutputRegister(conversion), |
| 3644 | sp, |
| 3645 | in.GetStackIndex()); |
| 3646 | } else { |
| 3647 | DCHECK(in.IsConstant()); |
| 3648 | DCHECK(in.GetConstant()->IsLongConstant()); |
| Vladimir Marko | ba1a48e | 2017-04-13 11:50:14 +0100 | [diff] [blame] | 3649 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3650 | __ Mov(OutputRegister(conversion), static_cast<int32_t>(value)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3651 | } |
| 3652 | break; |
| 3653 | |
| 3654 | case Primitive::kPrimFloat: { |
| 3655 | // Processing a Dex `float-to-int' instruction. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3656 | vixl32::SRegister temp = LowSRegisterFrom(locations->GetTemp(0)); |
| Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3657 | __ Vcvt(S32, F32, temp, InputSRegisterAt(conversion, 0)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3658 | __ Vmov(OutputRegister(conversion), temp); |
| 3659 | break; |
| 3660 | } |
| 3661 | |
| 3662 | case Primitive::kPrimDouble: { |
| 3663 | // Processing a Dex `double-to-int' instruction. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3664 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
| Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3665 | __ Vcvt(S32, F64, temp_s, DRegisterFrom(in)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3666 | __ Vmov(OutputRegister(conversion), temp_s); |
| 3667 | break; |
| 3668 | } |
| 3669 | |
| 3670 | default: |
| 3671 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3672 | << " to " << result_type; |
| 3673 | } |
| 3674 | break; |
| 3675 | |
| 3676 | case Primitive::kPrimLong: |
| 3677 | switch (input_type) { |
| 3678 | case Primitive::kPrimBoolean: |
| 3679 | // Boolean input is a result of code transformations. |
| 3680 | case Primitive::kPrimByte: |
| 3681 | case Primitive::kPrimShort: |
| 3682 | case Primitive::kPrimInt: |
| 3683 | case Primitive::kPrimChar: |
| 3684 | // Processing a Dex `int-to-long' instruction. |
| 3685 | DCHECK(out.IsRegisterPair()); |
| 3686 | DCHECK(in.IsRegister()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3687 | __ Mov(LowRegisterFrom(out), InputRegisterAt(conversion, 0)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3688 | // Sign extension. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3689 | __ Asr(HighRegisterFrom(out), LowRegisterFrom(out), 31); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3690 | break; |
| 3691 | |
| 3692 | case Primitive::kPrimFloat: |
| 3693 | // Processing a Dex `float-to-long' instruction. |
| 3694 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
| 3695 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 3696 | break; |
| 3697 | |
| 3698 | case Primitive::kPrimDouble: |
| 3699 | // Processing a Dex `double-to-long' instruction. |
| 3700 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
| 3701 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 3702 | break; |
| 3703 | |
| 3704 | default: |
| 3705 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3706 | << " to " << result_type; |
| 3707 | } |
| 3708 | break; |
| 3709 | |
| 3710 | case Primitive::kPrimChar: |
| 3711 | switch (input_type) { |
| 3712 | case Primitive::kPrimLong: |
| 3713 | // Type conversion from long to char is a result of code transformations. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3714 | __ Ubfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3715 | break; |
| 3716 | case Primitive::kPrimBoolean: |
| 3717 | // Boolean input is a result of code transformations. |
| 3718 | case Primitive::kPrimByte: |
| 3719 | case Primitive::kPrimShort: |
| 3720 | case Primitive::kPrimInt: |
| 3721 | // Processing a Dex `int-to-char' instruction. |
| 3722 | __ Ubfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 3723 | break; |
| 3724 | |
| 3725 | default: |
| 3726 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3727 | << " to " << result_type; |
| 3728 | } |
| 3729 | break; |
| 3730 | |
| 3731 | case Primitive::kPrimFloat: |
| 3732 | switch (input_type) { |
| 3733 | case Primitive::kPrimBoolean: |
| 3734 | // Boolean input is a result of code transformations. |
| 3735 | case Primitive::kPrimByte: |
| 3736 | case Primitive::kPrimShort: |
| 3737 | case Primitive::kPrimInt: |
| 3738 | case Primitive::kPrimChar: { |
| 3739 | // Processing a Dex `int-to-float' instruction. |
| 3740 | __ Vmov(OutputSRegister(conversion), InputRegisterAt(conversion, 0)); |
| Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3741 | __ Vcvt(F32, S32, OutputSRegister(conversion), OutputSRegister(conversion)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3742 | break; |
| 3743 | } |
| 3744 | |
| 3745 | case Primitive::kPrimLong: |
| 3746 | // Processing a Dex `long-to-float' instruction. |
| 3747 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
| 3748 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 3749 | break; |
| 3750 | |
| 3751 | case Primitive::kPrimDouble: |
| 3752 | // Processing a Dex `double-to-float' instruction. |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3753 | __ Vcvt(F32, F64, OutputSRegister(conversion), DRegisterFrom(in)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3754 | break; |
| 3755 | |
| 3756 | default: |
| 3757 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3758 | << " to " << result_type; |
| 3759 | }; |
| 3760 | break; |
| 3761 | |
| 3762 | case Primitive::kPrimDouble: |
| 3763 | switch (input_type) { |
| 3764 | case Primitive::kPrimBoolean: |
| 3765 | // Boolean input is a result of code transformations. |
| 3766 | case Primitive::kPrimByte: |
| 3767 | case Primitive::kPrimShort: |
| 3768 | case Primitive::kPrimInt: |
| 3769 | case Primitive::kPrimChar: { |
| 3770 | // Processing a Dex `int-to-double' instruction. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3771 | __ Vmov(LowSRegisterFrom(out), InputRegisterAt(conversion, 0)); |
| Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3772 | __ Vcvt(F64, S32, DRegisterFrom(out), LowSRegisterFrom(out)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3773 | break; |
| 3774 | } |
| 3775 | |
| 3776 | case Primitive::kPrimLong: { |
| 3777 | // Processing a Dex `long-to-double' instruction. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3778 | vixl32::Register low = LowRegisterFrom(in); |
| 3779 | vixl32::Register high = HighRegisterFrom(in); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3780 | vixl32::SRegister out_s = LowSRegisterFrom(out); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3781 | vixl32::DRegister out_d = DRegisterFrom(out); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3782 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3783 | vixl32::DRegister temp_d = DRegisterFrom(locations->GetTemp(0)); |
| Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3784 | vixl32::DRegister constant_d = DRegisterFrom(locations->GetTemp(1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3785 | |
| 3786 | // temp_d = int-to-double(high) |
| 3787 | __ Vmov(temp_s, high); |
| Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3788 | __ Vcvt(F64, S32, temp_d, temp_s); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3789 | // constant_d = k2Pow32EncodingForDouble |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3790 | __ Vmov(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3791 | // out_d = unsigned-to-double(low) |
| 3792 | __ Vmov(out_s, low); |
| 3793 | __ Vcvt(F64, U32, out_d, out_s); |
| 3794 | // out_d += temp_d * constant_d |
| 3795 | __ Vmla(F64, out_d, temp_d, constant_d); |
| 3796 | break; |
| 3797 | } |
| 3798 | |
| 3799 | case Primitive::kPrimFloat: |
| 3800 | // Processing a Dex `float-to-double' instruction. |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3801 | __ Vcvt(F64, F32, DRegisterFrom(out), InputSRegisterAt(conversion, 0)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3802 | break; |
| 3803 | |
| 3804 | default: |
| 3805 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3806 | << " to " << result_type; |
| 3807 | }; |
| 3808 | break; |
| 3809 | |
| 3810 | default: |
| 3811 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3812 | << " to " << result_type; |
| 3813 | } |
| 3814 | } |
| 3815 | |
| 3816 | void LocationsBuilderARMVIXL::VisitAdd(HAdd* add) { |
| 3817 | LocationSummary* locations = |
| 3818 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
| 3819 | switch (add->GetResultType()) { |
| 3820 | case Primitive::kPrimInt: { |
| 3821 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3822 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3823 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3824 | break; |
| 3825 | } |
| 3826 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3827 | case Primitive::kPrimLong: { |
| 3828 | locations->SetInAt(0, Location::RequiresRegister()); |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 3829 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3830 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3831 | break; |
| 3832 | } |
| 3833 | |
| 3834 | case Primitive::kPrimFloat: |
| 3835 | case Primitive::kPrimDouble: { |
| 3836 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3837 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3838 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3839 | break; |
| 3840 | } |
| 3841 | |
| 3842 | default: |
| 3843 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 3844 | } |
| 3845 | } |
| 3846 | |
| 3847 | void InstructionCodeGeneratorARMVIXL::VisitAdd(HAdd* add) { |
| 3848 | LocationSummary* locations = add->GetLocations(); |
| 3849 | Location out = locations->Out(); |
| 3850 | Location first = locations->InAt(0); |
| 3851 | Location second = locations->InAt(1); |
| 3852 | |
| 3853 | switch (add->GetResultType()) { |
| 3854 | case Primitive::kPrimInt: { |
| 3855 | __ Add(OutputRegister(add), InputRegisterAt(add, 0), InputOperandAt(add, 1)); |
| 3856 | } |
| 3857 | break; |
| 3858 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3859 | case Primitive::kPrimLong: { |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 3860 | if (second.IsConstant()) { |
| 3861 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3862 | GenerateAddLongConst(out, first, value); |
| 3863 | } else { |
| 3864 | DCHECK(second.IsRegisterPair()); |
| 3865 | __ Adds(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 3866 | __ Adc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 3867 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3868 | break; |
| 3869 | } |
| 3870 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3871 | case Primitive::kPrimFloat: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3872 | case Primitive::kPrimDouble: |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3873 | __ Vadd(OutputVRegister(add), InputVRegisterAt(add, 0), InputVRegisterAt(add, 1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3874 | break; |
| 3875 | |
| 3876 | default: |
| 3877 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 3878 | } |
| 3879 | } |
| 3880 | |
| 3881 | void LocationsBuilderARMVIXL::VisitSub(HSub* sub) { |
| 3882 | LocationSummary* locations = |
| 3883 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
| 3884 | switch (sub->GetResultType()) { |
| 3885 | case Primitive::kPrimInt: { |
| 3886 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3887 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
| 3888 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3889 | break; |
| 3890 | } |
| 3891 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3892 | case Primitive::kPrimLong: { |
| 3893 | locations->SetInAt(0, Location::RequiresRegister()); |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 3894 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3895 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3896 | break; |
| 3897 | } |
| 3898 | case Primitive::kPrimFloat: |
| 3899 | case Primitive::kPrimDouble: { |
| 3900 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3901 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3902 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3903 | break; |
| 3904 | } |
| 3905 | default: |
| 3906 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 3907 | } |
| 3908 | } |
| 3909 | |
| 3910 | void InstructionCodeGeneratorARMVIXL::VisitSub(HSub* sub) { |
| 3911 | LocationSummary* locations = sub->GetLocations(); |
| 3912 | Location out = locations->Out(); |
| 3913 | Location first = locations->InAt(0); |
| 3914 | Location second = locations->InAt(1); |
| 3915 | switch (sub->GetResultType()) { |
| 3916 | case Primitive::kPrimInt: { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3917 | __ Sub(OutputRegister(sub), InputRegisterAt(sub, 0), InputOperandAt(sub, 1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3918 | break; |
| 3919 | } |
| 3920 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3921 | case Primitive::kPrimLong: { |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 3922 | if (second.IsConstant()) { |
| 3923 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3924 | GenerateAddLongConst(out, first, -value); |
| 3925 | } else { |
| 3926 | DCHECK(second.IsRegisterPair()); |
| 3927 | __ Subs(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 3928 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 3929 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3930 | break; |
| 3931 | } |
| 3932 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3933 | case Primitive::kPrimFloat: |
| 3934 | case Primitive::kPrimDouble: |
| 3935 | __ Vsub(OutputVRegister(sub), InputVRegisterAt(sub, 0), InputVRegisterAt(sub, 1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3936 | break; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3937 | |
| 3938 | default: |
| 3939 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 3940 | } |
| 3941 | } |
| 3942 | |
| 3943 | void LocationsBuilderARMVIXL::VisitMul(HMul* mul) { |
| 3944 | LocationSummary* locations = |
| 3945 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3946 | switch (mul->GetResultType()) { |
| 3947 | case Primitive::kPrimInt: |
| 3948 | case Primitive::kPrimLong: { |
| 3949 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3950 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3951 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3952 | break; |
| 3953 | } |
| 3954 | |
| 3955 | case Primitive::kPrimFloat: |
| 3956 | case Primitive::kPrimDouble: { |
| 3957 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3958 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3959 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3960 | break; |
| 3961 | } |
| 3962 | |
| 3963 | default: |
| 3964 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 3965 | } |
| 3966 | } |
| 3967 | |
| 3968 | void InstructionCodeGeneratorARMVIXL::VisitMul(HMul* mul) { |
| 3969 | LocationSummary* locations = mul->GetLocations(); |
| 3970 | Location out = locations->Out(); |
| 3971 | Location first = locations->InAt(0); |
| 3972 | Location second = locations->InAt(1); |
| 3973 | switch (mul->GetResultType()) { |
| 3974 | case Primitive::kPrimInt: { |
| 3975 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 3976 | break; |
| 3977 | } |
| 3978 | case Primitive::kPrimLong: { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3979 | vixl32::Register out_hi = HighRegisterFrom(out); |
| 3980 | vixl32::Register out_lo = LowRegisterFrom(out); |
| 3981 | vixl32::Register in1_hi = HighRegisterFrom(first); |
| 3982 | vixl32::Register in1_lo = LowRegisterFrom(first); |
| 3983 | vixl32::Register in2_hi = HighRegisterFrom(second); |
| 3984 | vixl32::Register in2_lo = LowRegisterFrom(second); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3985 | |
| 3986 | // Extra checks to protect caused by the existence of R1_R2. |
| 3987 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 3988 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 3989 | DCHECK(!out_hi.Is(in1_lo)); |
| 3990 | DCHECK(!out_hi.Is(in2_lo)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3991 | |
| 3992 | // input: in1 - 64 bits, in2 - 64 bits |
| 3993 | // output: out |
| 3994 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3995 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3996 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 3997 | |
| 3998 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3999 | vixl32::Register temp = temps.Acquire(); |
| 4000 | // temp <- in1.lo * in2.hi |
| 4001 | __ Mul(temp, in1_lo, in2_hi); |
| 4002 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 4003 | __ Mla(out_hi, in1_hi, in2_lo, temp); |
| 4004 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 4005 | __ Umull(out_lo, temp, in1_lo, in2_lo); |
| 4006 | // 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] | 4007 | __ Add(out_hi, out_hi, temp); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4008 | break; |
| 4009 | } |
| 4010 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4011 | case Primitive::kPrimFloat: |
| 4012 | case Primitive::kPrimDouble: |
| 4013 | __ Vmul(OutputVRegister(mul), InputVRegisterAt(mul, 0), InputVRegisterAt(mul, 1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4014 | break; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4015 | |
| 4016 | default: |
| 4017 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4018 | } |
| 4019 | } |
| 4020 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4021 | void InstructionCodeGeneratorARMVIXL::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 4022 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4023 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4024 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4025 | Location second = instruction->GetLocations()->InAt(1); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4026 | DCHECK(second.IsConstant()); |
| 4027 | |
| 4028 | vixl32::Register out = OutputRegister(instruction); |
| 4029 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4030 | int32_t imm = Int32ConstantFrom(second); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4031 | DCHECK(imm == 1 || imm == -1); |
| 4032 | |
| 4033 | if (instruction->IsRem()) { |
| 4034 | __ Mov(out, 0); |
| 4035 | } else { |
| 4036 | if (imm == 1) { |
| 4037 | __ Mov(out, dividend); |
| 4038 | } else { |
| 4039 | __ Rsb(out, dividend, 0); |
| 4040 | } |
| 4041 | } |
| 4042 | } |
| 4043 | |
| 4044 | void InstructionCodeGeneratorARMVIXL::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 4045 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4046 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4047 | |
| 4048 | LocationSummary* locations = instruction->GetLocations(); |
| 4049 | Location second = locations->InAt(1); |
| 4050 | DCHECK(second.IsConstant()); |
| 4051 | |
| 4052 | vixl32::Register out = OutputRegister(instruction); |
| 4053 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4054 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4055 | int32_t imm = Int32ConstantFrom(second); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4056 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 4057 | int ctz_imm = CTZ(abs_imm); |
| 4058 | |
| 4059 | if (ctz_imm == 1) { |
| 4060 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 4061 | } else { |
| 4062 | __ Asr(temp, dividend, 31); |
| 4063 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 4064 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4065 | __ Add(out, temp, dividend); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4066 | |
| 4067 | if (instruction->IsDiv()) { |
| 4068 | __ Asr(out, out, ctz_imm); |
| 4069 | if (imm < 0) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4070 | __ Rsb(out, out, 0); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4071 | } |
| 4072 | } else { |
| 4073 | __ Ubfx(out, out, 0, ctz_imm); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4074 | __ Sub(out, out, temp); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4075 | } |
| 4076 | } |
| 4077 | |
| 4078 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 4079 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4080 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4081 | |
| 4082 | LocationSummary* locations = instruction->GetLocations(); |
| 4083 | Location second = locations->InAt(1); |
| 4084 | DCHECK(second.IsConstant()); |
| 4085 | |
| 4086 | vixl32::Register out = OutputRegister(instruction); |
| 4087 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4088 | vixl32::Register temp1 = RegisterFrom(locations->GetTemp(0)); |
| 4089 | vixl32::Register temp2 = RegisterFrom(locations->GetTemp(1)); |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4090 | int32_t imm = Int32ConstantFrom(second); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4091 | |
| 4092 | int64_t magic; |
| 4093 | int shift; |
| 4094 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 4095 | |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4096 | // TODO(VIXL): Change the static cast to Operand::From() after VIXL is fixed. |
| 4097 | __ Mov(temp1, static_cast<int32_t>(magic)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4098 | __ Smull(temp2, temp1, dividend, temp1); |
| 4099 | |
| 4100 | if (imm > 0 && magic < 0) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4101 | __ Add(temp1, temp1, dividend); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4102 | } else if (imm < 0 && magic > 0) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4103 | __ Sub(temp1, temp1, dividend); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4104 | } |
| 4105 | |
| 4106 | if (shift != 0) { |
| 4107 | __ Asr(temp1, temp1, shift); |
| 4108 | } |
| 4109 | |
| 4110 | if (instruction->IsDiv()) { |
| 4111 | __ Sub(out, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 4112 | } else { |
| 4113 | __ Sub(temp1, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 4114 | // TODO: Strength reduction for mls. |
| 4115 | __ Mov(temp2, imm); |
| 4116 | __ Mls(out, temp1, temp2, dividend); |
| 4117 | } |
| 4118 | } |
| 4119 | |
| 4120 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemConstantIntegral( |
| 4121 | HBinaryOperation* instruction) { |
| 4122 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4123 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4124 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4125 | Location second = instruction->GetLocations()->InAt(1); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4126 | DCHECK(second.IsConstant()); |
| 4127 | |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4128 | int32_t imm = Int32ConstantFrom(second); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4129 | if (imm == 0) { |
| 4130 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4131 | } else if (imm == 1 || imm == -1) { |
| 4132 | DivRemOneOrMinusOne(instruction); |
| 4133 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 4134 | DivRemByPowerOfTwo(instruction); |
| 4135 | } else { |
| 4136 | DCHECK(imm <= -2 || imm >= 2); |
| 4137 | GenerateDivRemWithAnyConstant(instruction); |
| 4138 | } |
| 4139 | } |
| 4140 | |
| 4141 | void LocationsBuilderARMVIXL::VisitDiv(HDiv* div) { |
| 4142 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4143 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 4144 | // pLdiv runtime call. |
| 4145 | call_kind = LocationSummary::kCallOnMainOnly; |
| 4146 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 4147 | // sdiv will be replaced by other instruction sequence. |
| 4148 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 4149 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4150 | // pIdivmod runtime call. |
| 4151 | call_kind = LocationSummary::kCallOnMainOnly; |
| 4152 | } |
| 4153 | |
| 4154 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 4155 | |
| 4156 | switch (div->GetResultType()) { |
| 4157 | case Primitive::kPrimInt: { |
| 4158 | if (div->InputAt(1)->IsConstant()) { |
| 4159 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4160 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
| 4161 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4162 | int32_t value = Int32ConstantFrom(div->InputAt(1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4163 | if (value == 1 || value == 0 || value == -1) { |
| 4164 | // No temp register required. |
| 4165 | } else { |
| 4166 | locations->AddTemp(Location::RequiresRegister()); |
| 4167 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
| 4168 | locations->AddTemp(Location::RequiresRegister()); |
| 4169 | } |
| 4170 | } |
| 4171 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4172 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4173 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4174 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4175 | } else { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4176 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4177 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4178 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4179 | // 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] | 4180 | // we only need the former. |
| 4181 | locations->SetOut(LocationFrom(r0)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4182 | } |
| 4183 | break; |
| 4184 | } |
| 4185 | case Primitive::kPrimLong: { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4186 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4187 | locations->SetInAt(0, LocationFrom( |
| 4188 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4189 | locations->SetInAt(1, LocationFrom( |
| 4190 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4191 | locations->SetOut(LocationFrom(r0, r1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4192 | break; |
| 4193 | } |
| 4194 | case Primitive::kPrimFloat: |
| 4195 | case Primitive::kPrimDouble: { |
| 4196 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4197 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4198 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4199 | break; |
| 4200 | } |
| 4201 | |
| 4202 | default: |
| 4203 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4204 | } |
| 4205 | } |
| 4206 | |
| 4207 | void InstructionCodeGeneratorARMVIXL::VisitDiv(HDiv* div) { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4208 | Location lhs = div->GetLocations()->InAt(0); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4209 | Location rhs = div->GetLocations()->InAt(1); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4210 | |
| 4211 | switch (div->GetResultType()) { |
| 4212 | case Primitive::kPrimInt: { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4213 | if (rhs.IsConstant()) { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4214 | GenerateDivRemConstantIntegral(div); |
| 4215 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4216 | __ Sdiv(OutputRegister(div), InputRegisterAt(div, 0), InputRegisterAt(div, 1)); |
| 4217 | } else { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4218 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4219 | DCHECK(calling_convention.GetRegisterAt(0).Is(RegisterFrom(lhs))); |
| 4220 | DCHECK(calling_convention.GetRegisterAt(1).Is(RegisterFrom(rhs))); |
| 4221 | DCHECK(r0.Is(OutputRegister(div))); |
| 4222 | |
| 4223 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
| 4224 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4225 | } |
| 4226 | break; |
| 4227 | } |
| 4228 | |
| 4229 | case Primitive::kPrimLong: { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4230 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4231 | DCHECK(calling_convention.GetRegisterAt(0).Is(LowRegisterFrom(lhs))); |
| 4232 | DCHECK(calling_convention.GetRegisterAt(1).Is(HighRegisterFrom(lhs))); |
| 4233 | DCHECK(calling_convention.GetRegisterAt(2).Is(LowRegisterFrom(rhs))); |
| 4234 | DCHECK(calling_convention.GetRegisterAt(3).Is(HighRegisterFrom(rhs))); |
| 4235 | DCHECK(LowRegisterFrom(div->GetLocations()->Out()).Is(r0)); |
| 4236 | DCHECK(HighRegisterFrom(div->GetLocations()->Out()).Is(r1)); |
| 4237 | |
| 4238 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
| 4239 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4240 | break; |
| 4241 | } |
| 4242 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4243 | case Primitive::kPrimFloat: |
| 4244 | case Primitive::kPrimDouble: |
| 4245 | __ Vdiv(OutputVRegister(div), InputVRegisterAt(div, 0), InputVRegisterAt(div, 1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4246 | break; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4247 | |
| 4248 | default: |
| 4249 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4250 | } |
| 4251 | } |
| 4252 | |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4253 | void LocationsBuilderARMVIXL::VisitRem(HRem* rem) { |
| 4254 | Primitive::Type type = rem->GetResultType(); |
| 4255 | |
| 4256 | // Most remainders are implemented in the runtime. |
| 4257 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
| 4258 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 4259 | // sdiv will be replaced by other instruction sequence. |
| 4260 | call_kind = LocationSummary::kNoCall; |
| 4261 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 4262 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4263 | // Have hardware divide instruction for int, do it with three instructions. |
| 4264 | call_kind = LocationSummary::kNoCall; |
| 4265 | } |
| 4266 | |
| 4267 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 4268 | |
| 4269 | switch (type) { |
| 4270 | case Primitive::kPrimInt: { |
| 4271 | if (rem->InputAt(1)->IsConstant()) { |
| 4272 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4273 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
| 4274 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4275 | int32_t value = Int32ConstantFrom(rem->InputAt(1)); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4276 | if (value == 1 || value == 0 || value == -1) { |
| 4277 | // No temp register required. |
| 4278 | } else { |
| 4279 | locations->AddTemp(Location::RequiresRegister()); |
| 4280 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
| 4281 | locations->AddTemp(Location::RequiresRegister()); |
| 4282 | } |
| 4283 | } |
| 4284 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4285 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4286 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4287 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4288 | locations->AddTemp(Location::RequiresRegister()); |
| 4289 | } else { |
| 4290 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4291 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4292 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4293 | // 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] | 4294 | // we only need the latter. |
| 4295 | locations->SetOut(LocationFrom(r1)); |
| 4296 | } |
| 4297 | break; |
| 4298 | } |
| 4299 | case Primitive::kPrimLong: { |
| 4300 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4301 | locations->SetInAt(0, LocationFrom( |
| 4302 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4303 | locations->SetInAt(1, LocationFrom( |
| 4304 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4305 | // The runtime helper puts the output in R2,R3. |
| 4306 | locations->SetOut(LocationFrom(r2, r3)); |
| 4307 | break; |
| 4308 | } |
| 4309 | case Primitive::kPrimFloat: { |
| 4310 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4311 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 4312 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 4313 | locations->SetOut(LocationFrom(s0)); |
| 4314 | break; |
| 4315 | } |
| 4316 | |
| 4317 | case Primitive::kPrimDouble: { |
| 4318 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4319 | locations->SetInAt(0, LocationFrom( |
| 4320 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 4321 | locations->SetInAt(1, LocationFrom( |
| 4322 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 4323 | locations->SetOut(LocationFrom(s0, s1)); |
| 4324 | break; |
| 4325 | } |
| 4326 | |
| 4327 | default: |
| 4328 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4329 | } |
| 4330 | } |
| 4331 | |
| 4332 | void InstructionCodeGeneratorARMVIXL::VisitRem(HRem* rem) { |
| 4333 | LocationSummary* locations = rem->GetLocations(); |
| 4334 | Location second = locations->InAt(1); |
| 4335 | |
| 4336 | Primitive::Type type = rem->GetResultType(); |
| 4337 | switch (type) { |
| 4338 | case Primitive::kPrimInt: { |
| 4339 | vixl32::Register reg1 = InputRegisterAt(rem, 0); |
| 4340 | vixl32::Register out_reg = OutputRegister(rem); |
| 4341 | if (second.IsConstant()) { |
| 4342 | GenerateDivRemConstantIntegral(rem); |
| 4343 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4344 | vixl32::Register reg2 = RegisterFrom(second); |
| 4345 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 4346 | |
| 4347 | // temp = reg1 / reg2 (integer division) |
| 4348 | // dest = reg1 - temp * reg2 |
| 4349 | __ Sdiv(temp, reg1, reg2); |
| 4350 | __ Mls(out_reg, temp, reg2, reg1); |
| 4351 | } else { |
| 4352 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4353 | DCHECK(reg1.Is(calling_convention.GetRegisterAt(0))); |
| 4354 | DCHECK(RegisterFrom(second).Is(calling_convention.GetRegisterAt(1))); |
| 4355 | DCHECK(out_reg.Is(r1)); |
| 4356 | |
| 4357 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
| 4358 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
| 4359 | } |
| 4360 | break; |
| 4361 | } |
| 4362 | |
| 4363 | case Primitive::kPrimLong: { |
| 4364 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
| 4365 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 4366 | break; |
| 4367 | } |
| 4368 | |
| 4369 | case Primitive::kPrimFloat: { |
| 4370 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
| 4371 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 4372 | break; |
| 4373 | } |
| 4374 | |
| 4375 | case Primitive::kPrimDouble: { |
| 4376 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
| 4377 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 4378 | break; |
| 4379 | } |
| 4380 | |
| 4381 | default: |
| 4382 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4383 | } |
| 4384 | } |
| 4385 | |
| 4386 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4387 | void LocationsBuilderARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 4388 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4389 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4390 | } |
| 4391 | |
| 4392 | void InstructionCodeGeneratorARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 4393 | DivZeroCheckSlowPathARMVIXL* slow_path = |
| 4394 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARMVIXL(instruction); |
| 4395 | codegen_->AddSlowPath(slow_path); |
| 4396 | |
| 4397 | LocationSummary* locations = instruction->GetLocations(); |
| 4398 | Location value = locations->InAt(0); |
| 4399 | |
| 4400 | switch (instruction->GetType()) { |
| 4401 | case Primitive::kPrimBoolean: |
| 4402 | case Primitive::kPrimByte: |
| 4403 | case Primitive::kPrimChar: |
| 4404 | case Primitive::kPrimShort: |
| 4405 | case Primitive::kPrimInt: { |
| 4406 | if (value.IsRegister()) { |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 4407 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4408 | } else { |
| 4409 | DCHECK(value.IsConstant()) << value; |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4410 | if (Int32ConstantFrom(value) == 0) { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4411 | __ B(slow_path->GetEntryLabel()); |
| 4412 | } |
| 4413 | } |
| 4414 | break; |
| 4415 | } |
| 4416 | case Primitive::kPrimLong: { |
| 4417 | if (value.IsRegisterPair()) { |
| 4418 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4419 | vixl32::Register temp = temps.Acquire(); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4420 | __ Orrs(temp, LowRegisterFrom(value), HighRegisterFrom(value)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4421 | __ B(eq, slow_path->GetEntryLabel()); |
| 4422 | } else { |
| 4423 | DCHECK(value.IsConstant()) << value; |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4424 | if (Int64ConstantFrom(value) == 0) { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4425 | __ B(slow_path->GetEntryLabel()); |
| 4426 | } |
| 4427 | } |
| 4428 | break; |
| 4429 | } |
| 4430 | default: |
| 4431 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4432 | } |
| 4433 | } |
| 4434 | |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4435 | void InstructionCodeGeneratorARMVIXL::HandleIntegerRotate(HRor* ror) { |
| 4436 | LocationSummary* locations = ror->GetLocations(); |
| 4437 | vixl32::Register in = InputRegisterAt(ror, 0); |
| 4438 | Location rhs = locations->InAt(1); |
| 4439 | vixl32::Register out = OutputRegister(ror); |
| 4440 | |
| 4441 | if (rhs.IsConstant()) { |
| 4442 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 4443 | // so map all rotations to a +ve. equivalent in that range. |
| 4444 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 4445 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 4446 | if (rot) { |
| 4447 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 4448 | // (e.g. left by 2 bits == right by 30.) |
| 4449 | __ Ror(out, in, rot); |
| 4450 | } else if (!out.Is(in)) { |
| 4451 | __ Mov(out, in); |
| 4452 | } |
| 4453 | } else { |
| 4454 | __ Ror(out, in, RegisterFrom(rhs)); |
| 4455 | } |
| 4456 | } |
| 4457 | |
| 4458 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 4459 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 4460 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 4461 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 4462 | void InstructionCodeGeneratorARMVIXL::HandleLongRotate(HRor* ror) { |
| 4463 | LocationSummary* locations = ror->GetLocations(); |
| 4464 | vixl32::Register in_reg_lo = LowRegisterFrom(locations->InAt(0)); |
| 4465 | vixl32::Register in_reg_hi = HighRegisterFrom(locations->InAt(0)); |
| 4466 | Location rhs = locations->InAt(1); |
| 4467 | vixl32::Register out_reg_lo = LowRegisterFrom(locations->Out()); |
| 4468 | vixl32::Register out_reg_hi = HighRegisterFrom(locations->Out()); |
| 4469 | |
| 4470 | if (rhs.IsConstant()) { |
| 4471 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 4472 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
| 4473 | rot &= kMaxLongShiftDistance; |
| 4474 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 4475 | // logic below to a simple pair of binary orr. |
| 4476 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 4477 | if (rot >= kArmBitsPerWord) { |
| 4478 | rot -= kArmBitsPerWord; |
| 4479 | std::swap(in_reg_hi, in_reg_lo); |
| 4480 | } |
| 4481 | // Rotate, or mov to out for zero or word size rotations. |
| 4482 | if (rot != 0u) { |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4483 | __ Lsr(out_reg_hi, in_reg_hi, Operand::From(rot)); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4484 | __ 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] | 4485 | __ Lsr(out_reg_lo, in_reg_lo, Operand::From(rot)); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4486 | __ Orr(out_reg_lo, out_reg_lo, Operand(in_reg_hi, ShiftType::LSL, kArmBitsPerWord - rot)); |
| 4487 | } else { |
| 4488 | __ Mov(out_reg_lo, in_reg_lo); |
| 4489 | __ Mov(out_reg_hi, in_reg_hi); |
| 4490 | } |
| 4491 | } else { |
| 4492 | vixl32::Register shift_right = RegisterFrom(locations->GetTemp(0)); |
| 4493 | vixl32::Register shift_left = RegisterFrom(locations->GetTemp(1)); |
| 4494 | vixl32::Label end; |
| 4495 | vixl32::Label shift_by_32_plus_shift_right; |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4496 | vixl32::Label* final_label = codegen_->GetFinalLabel(ror, &end); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4497 | |
| 4498 | __ And(shift_right, RegisterFrom(rhs), 0x1F); |
| 4499 | __ Lsrs(shift_left, RegisterFrom(rhs), 6); |
| Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 4500 | __ Rsb(LeaveFlags, shift_left, shift_right, Operand::From(kArmBitsPerWord)); |
| Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 4501 | __ B(cc, &shift_by_32_plus_shift_right, /* far_target */ false); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4502 | |
| 4503 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 4504 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 4505 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 4506 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4507 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 4508 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4509 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 4510 | __ Add(out_reg_lo, out_reg_lo, shift_left); |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4511 | __ B(final_label); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4512 | |
| 4513 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 4514 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 4515 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 4516 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 4517 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4518 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 4519 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4520 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 4521 | __ Add(out_reg_lo, out_reg_lo, shift_right); |
| 4522 | |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4523 | if (end.IsReferenced()) { |
| 4524 | __ Bind(&end); |
| 4525 | } |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4526 | } |
| 4527 | } |
| 4528 | |
| 4529 | void LocationsBuilderARMVIXL::VisitRor(HRor* ror) { |
| 4530 | LocationSummary* locations = |
| 4531 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 4532 | switch (ror->GetResultType()) { |
| 4533 | case Primitive::kPrimInt: { |
| 4534 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4535 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 4536 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4537 | break; |
| 4538 | } |
| 4539 | case Primitive::kPrimLong: { |
| 4540 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4541 | if (ror->InputAt(1)->IsConstant()) { |
| 4542 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 4543 | } else { |
| 4544 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4545 | locations->AddTemp(Location::RequiresRegister()); |
| 4546 | locations->AddTemp(Location::RequiresRegister()); |
| 4547 | } |
| 4548 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4549 | break; |
| 4550 | } |
| 4551 | default: |
| 4552 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4553 | } |
| 4554 | } |
| 4555 | |
| 4556 | void InstructionCodeGeneratorARMVIXL::VisitRor(HRor* ror) { |
| 4557 | Primitive::Type type = ror->GetResultType(); |
| 4558 | switch (type) { |
| 4559 | case Primitive::kPrimInt: { |
| 4560 | HandleIntegerRotate(ror); |
| 4561 | break; |
| 4562 | } |
| 4563 | case Primitive::kPrimLong: { |
| 4564 | HandleLongRotate(ror); |
| 4565 | break; |
| 4566 | } |
| 4567 | default: |
| 4568 | LOG(FATAL) << "Unexpected operation type " << type; |
| 4569 | UNREACHABLE(); |
| 4570 | } |
| 4571 | } |
| 4572 | |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4573 | void LocationsBuilderARMVIXL::HandleShift(HBinaryOperation* op) { |
| 4574 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4575 | |
| 4576 | LocationSummary* locations = |
| 4577 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 4578 | |
| 4579 | switch (op->GetResultType()) { |
| 4580 | case Primitive::kPrimInt: { |
| 4581 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4582 | if (op->InputAt(1)->IsConstant()) { |
| 4583 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 4584 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4585 | } else { |
| 4586 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4587 | // Make the output overlap, as it will be used to hold the masked |
| 4588 | // second input. |
| 4589 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4590 | } |
| 4591 | break; |
| 4592 | } |
| 4593 | case Primitive::kPrimLong: { |
| 4594 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4595 | if (op->InputAt(1)->IsConstant()) { |
| 4596 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 4597 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 4598 | // don't clash with high registers which the register allocator currently guarantees. |
| 4599 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4600 | } else { |
| 4601 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4602 | locations->AddTemp(Location::RequiresRegister()); |
| 4603 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4604 | } |
| 4605 | break; |
| 4606 | } |
| 4607 | default: |
| 4608 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 4609 | } |
| 4610 | } |
| 4611 | |
| 4612 | void InstructionCodeGeneratorARMVIXL::HandleShift(HBinaryOperation* op) { |
| 4613 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4614 | |
| 4615 | LocationSummary* locations = op->GetLocations(); |
| 4616 | Location out = locations->Out(); |
| 4617 | Location first = locations->InAt(0); |
| 4618 | Location second = locations->InAt(1); |
| 4619 | |
| 4620 | Primitive::Type type = op->GetResultType(); |
| 4621 | switch (type) { |
| 4622 | case Primitive::kPrimInt: { |
| 4623 | vixl32::Register out_reg = OutputRegister(op); |
| 4624 | vixl32::Register first_reg = InputRegisterAt(op, 0); |
| 4625 | if (second.IsRegister()) { |
| 4626 | vixl32::Register second_reg = RegisterFrom(second); |
| 4627 | // ARM doesn't mask the shift count so we need to do it ourselves. |
| 4628 | __ And(out_reg, second_reg, kMaxIntShiftDistance); |
| 4629 | if (op->IsShl()) { |
| 4630 | __ Lsl(out_reg, first_reg, out_reg); |
| 4631 | } else if (op->IsShr()) { |
| 4632 | __ Asr(out_reg, first_reg, out_reg); |
| 4633 | } else { |
| 4634 | __ Lsr(out_reg, first_reg, out_reg); |
| 4635 | } |
| 4636 | } else { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4637 | int32_t cst = Int32ConstantFrom(second); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4638 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
| 4639 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
| 4640 | __ Mov(out_reg, first_reg); |
| 4641 | } else if (op->IsShl()) { |
| 4642 | __ Lsl(out_reg, first_reg, shift_value); |
| 4643 | } else if (op->IsShr()) { |
| 4644 | __ Asr(out_reg, first_reg, shift_value); |
| 4645 | } else { |
| 4646 | __ Lsr(out_reg, first_reg, shift_value); |
| 4647 | } |
| 4648 | } |
| 4649 | break; |
| 4650 | } |
| 4651 | case Primitive::kPrimLong: { |
| 4652 | vixl32::Register o_h = HighRegisterFrom(out); |
| 4653 | vixl32::Register o_l = LowRegisterFrom(out); |
| 4654 | |
| 4655 | vixl32::Register high = HighRegisterFrom(first); |
| 4656 | vixl32::Register low = LowRegisterFrom(first); |
| 4657 | |
| 4658 | if (second.IsRegister()) { |
| 4659 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 4660 | |
| 4661 | vixl32::Register second_reg = RegisterFrom(second); |
| 4662 | |
| 4663 | if (op->IsShl()) { |
| 4664 | __ And(o_l, second_reg, kMaxLongShiftDistance); |
| 4665 | // Shift the high part |
| 4666 | __ Lsl(o_h, high, o_l); |
| 4667 | // Shift the low part and `or` what overflew on the high part |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4668 | __ Rsb(temp, o_l, Operand::From(kArmBitsPerWord)); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4669 | __ Lsr(temp, low, temp); |
| 4670 | __ Orr(o_h, o_h, temp); |
| 4671 | // If the shift is > 32 bits, override the high part |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4672 | __ Subs(temp, o_l, Operand::From(kArmBitsPerWord)); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4673 | { |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 4674 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 4675 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 4676 | CodeBufferCheckScope::kMaximumSize); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4677 | __ it(pl); |
| 4678 | __ lsl(pl, o_h, low, temp); |
| 4679 | } |
| 4680 | // Shift the low part |
| 4681 | __ Lsl(o_l, low, o_l); |
| 4682 | } else if (op->IsShr()) { |
| 4683 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 4684 | // Shift the low part |
| 4685 | __ Lsr(o_l, low, o_h); |
| 4686 | // Shift the high part and `or` what underflew on the low part |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4687 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4688 | __ Lsl(temp, high, temp); |
| 4689 | __ Orr(o_l, o_l, temp); |
| 4690 | // If the shift is > 32 bits, override the low part |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4691 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4692 | { |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 4693 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 4694 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 4695 | CodeBufferCheckScope::kMaximumSize); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4696 | __ it(pl); |
| 4697 | __ asr(pl, o_l, high, temp); |
| 4698 | } |
| 4699 | // Shift the high part |
| 4700 | __ Asr(o_h, high, o_h); |
| 4701 | } else { |
| 4702 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 4703 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 4704 | __ Lsr(o_l, low, o_h); |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4705 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4706 | __ Lsl(temp, high, temp); |
| 4707 | __ Orr(o_l, o_l, temp); |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4708 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4709 | { |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 4710 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 4711 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 4712 | CodeBufferCheckScope::kMaximumSize); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4713 | __ it(pl); |
| 4714 | __ lsr(pl, o_l, high, temp); |
| 4715 | } |
| 4716 | __ Lsr(o_h, high, o_h); |
| 4717 | } |
| 4718 | } else { |
| 4719 | // Register allocator doesn't create partial overlap. |
| 4720 | DCHECK(!o_l.Is(high)); |
| 4721 | DCHECK(!o_h.Is(low)); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4722 | int32_t cst = Int32ConstantFrom(second); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4723 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
| 4724 | if (shift_value > 32) { |
| 4725 | if (op->IsShl()) { |
| 4726 | __ Lsl(o_h, low, shift_value - 32); |
| 4727 | __ Mov(o_l, 0); |
| 4728 | } else if (op->IsShr()) { |
| 4729 | __ Asr(o_l, high, shift_value - 32); |
| 4730 | __ Asr(o_h, high, 31); |
| 4731 | } else { |
| 4732 | __ Lsr(o_l, high, shift_value - 32); |
| 4733 | __ Mov(o_h, 0); |
| 4734 | } |
| 4735 | } else if (shift_value == 32) { |
| 4736 | if (op->IsShl()) { |
| 4737 | __ Mov(o_h, low); |
| 4738 | __ Mov(o_l, 0); |
| 4739 | } else if (op->IsShr()) { |
| 4740 | __ Mov(o_l, high); |
| 4741 | __ Asr(o_h, high, 31); |
| 4742 | } else { |
| 4743 | __ Mov(o_l, high); |
| 4744 | __ Mov(o_h, 0); |
| 4745 | } |
| 4746 | } else if (shift_value == 1) { |
| 4747 | if (op->IsShl()) { |
| 4748 | __ Lsls(o_l, low, 1); |
| 4749 | __ Adc(o_h, high, high); |
| 4750 | } else if (op->IsShr()) { |
| 4751 | __ Asrs(o_h, high, 1); |
| 4752 | __ Rrx(o_l, low); |
| 4753 | } else { |
| 4754 | __ Lsrs(o_h, high, 1); |
| 4755 | __ Rrx(o_l, low); |
| 4756 | } |
| 4757 | } else { |
| 4758 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
| 4759 | if (op->IsShl()) { |
| 4760 | __ Lsl(o_h, high, shift_value); |
| 4761 | __ Orr(o_h, o_h, Operand(low, ShiftType::LSR, 32 - shift_value)); |
| 4762 | __ Lsl(o_l, low, shift_value); |
| 4763 | } else if (op->IsShr()) { |
| 4764 | __ Lsr(o_l, low, shift_value); |
| 4765 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 4766 | __ Asr(o_h, high, shift_value); |
| 4767 | } else { |
| 4768 | __ Lsr(o_l, low, shift_value); |
| 4769 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 4770 | __ Lsr(o_h, high, shift_value); |
| 4771 | } |
| 4772 | } |
| 4773 | } |
| 4774 | break; |
| 4775 | } |
| 4776 | default: |
| 4777 | LOG(FATAL) << "Unexpected operation type " << type; |
| 4778 | UNREACHABLE(); |
| 4779 | } |
| 4780 | } |
| 4781 | |
| 4782 | void LocationsBuilderARMVIXL::VisitShl(HShl* shl) { |
| 4783 | HandleShift(shl); |
| 4784 | } |
| 4785 | |
| 4786 | void InstructionCodeGeneratorARMVIXL::VisitShl(HShl* shl) { |
| 4787 | HandleShift(shl); |
| 4788 | } |
| 4789 | |
| 4790 | void LocationsBuilderARMVIXL::VisitShr(HShr* shr) { |
| 4791 | HandleShift(shr); |
| 4792 | } |
| 4793 | |
| 4794 | void InstructionCodeGeneratorARMVIXL::VisitShr(HShr* shr) { |
| 4795 | HandleShift(shr); |
| 4796 | } |
| 4797 | |
| 4798 | void LocationsBuilderARMVIXL::VisitUShr(HUShr* ushr) { |
| 4799 | HandleShift(ushr); |
| 4800 | } |
| 4801 | |
| 4802 | void InstructionCodeGeneratorARMVIXL::VisitUShr(HUShr* ushr) { |
| 4803 | HandleShift(ushr); |
| 4804 | } |
| 4805 | |
| 4806 | void LocationsBuilderARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
| 4807 | LocationSummary* locations = |
| 4808 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| 4809 | if (instruction->IsStringAlloc()) { |
| 4810 | locations->AddTemp(LocationFrom(kMethodRegister)); |
| 4811 | } else { |
| 4812 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4813 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4814 | } |
| 4815 | locations->SetOut(LocationFrom(r0)); |
| 4816 | } |
| 4817 | |
| 4818 | void InstructionCodeGeneratorARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
| 4819 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4820 | // of poisoning the reference. |
| 4821 | if (instruction->IsStringAlloc()) { |
| 4822 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4823 | vixl32::Register temp = RegisterFrom(instruction->GetLocations()->GetTemp(0)); |
| 4824 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
| 4825 | GetAssembler()->LoadFromOffset(kLoadWord, temp, tr, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 4826 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, code_offset.Int32Value()); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 4827 | // 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] | 4828 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 4829 | vixl32::k16BitT32InstructionSizeInBytes, |
| 4830 | CodeBufferCheckScope::kExactSize); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4831 | __ blx(lr); |
| 4832 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4833 | } else { |
| 4834 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4835 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4836 | } |
| 4837 | } |
| 4838 | |
| 4839 | void LocationsBuilderARMVIXL::VisitNewArray(HNewArray* instruction) { |
| 4840 | LocationSummary* locations = |
| 4841 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| 4842 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4843 | locations->SetOut(LocationFrom(r0)); |
| Nicolas Geoffray | 8c7c4f1 | 2017-01-26 10:13:11 +0000 | [diff] [blame] | 4844 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4845 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4846 | } |
| 4847 | |
| 4848 | void InstructionCodeGeneratorARMVIXL::VisitNewArray(HNewArray* instruction) { |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4849 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4850 | // of poisoning the reference. |
| Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 4851 | QuickEntrypointEnum entrypoint = |
| 4852 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4853 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4854 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
| Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 4855 | DCHECK(!codegen_->IsLeafMethod()); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4856 | } |
| 4857 | |
| 4858 | void LocationsBuilderARMVIXL::VisitParameterValue(HParameterValue* instruction) { |
| 4859 | LocationSummary* locations = |
| 4860 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4861 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4862 | if (location.IsStackSlot()) { |
| 4863 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4864 | } else if (location.IsDoubleStackSlot()) { |
| 4865 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4866 | } |
| 4867 | locations->SetOut(location); |
| 4868 | } |
| 4869 | |
| 4870 | void InstructionCodeGeneratorARMVIXL::VisitParameterValue( |
| 4871 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4872 | // Nothing to do, the parameter is already at its location. |
| 4873 | } |
| 4874 | |
| 4875 | void LocationsBuilderARMVIXL::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4876 | LocationSummary* locations = |
| 4877 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4878 | locations->SetOut(LocationFrom(kMethodRegister)); |
| 4879 | } |
| 4880 | |
| 4881 | void InstructionCodeGeneratorARMVIXL::VisitCurrentMethod( |
| 4882 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4883 | // Nothing to do, the method is already at its location. |
| 4884 | } |
| 4885 | |
| 4886 | void LocationsBuilderARMVIXL::VisitNot(HNot* not_) { |
| 4887 | LocationSummary* locations = |
| 4888 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
| 4889 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4890 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4891 | } |
| 4892 | |
| 4893 | void InstructionCodeGeneratorARMVIXL::VisitNot(HNot* not_) { |
| 4894 | LocationSummary* locations = not_->GetLocations(); |
| 4895 | Location out = locations->Out(); |
| 4896 | Location in = locations->InAt(0); |
| 4897 | switch (not_->GetResultType()) { |
| 4898 | case Primitive::kPrimInt: |
| 4899 | __ Mvn(OutputRegister(not_), InputRegisterAt(not_, 0)); |
| 4900 | break; |
| 4901 | |
| 4902 | case Primitive::kPrimLong: |
| 4903 | __ Mvn(LowRegisterFrom(out), LowRegisterFrom(in)); |
| 4904 | __ Mvn(HighRegisterFrom(out), HighRegisterFrom(in)); |
| 4905 | break; |
| 4906 | |
| 4907 | default: |
| 4908 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4909 | } |
| 4910 | } |
| 4911 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4912 | void LocationsBuilderARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4913 | LocationSummary* locations = |
| 4914 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4915 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4916 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4917 | } |
| 4918 | |
| 4919 | void InstructionCodeGeneratorARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4920 | __ Eor(OutputRegister(bool_not), InputRegister(bool_not), 1); |
| 4921 | } |
| 4922 | |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4923 | void LocationsBuilderARMVIXL::VisitCompare(HCompare* compare) { |
| 4924 | LocationSummary* locations = |
| 4925 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| 4926 | switch (compare->InputAt(0)->GetType()) { |
| 4927 | case Primitive::kPrimBoolean: |
| 4928 | case Primitive::kPrimByte: |
| 4929 | case Primitive::kPrimShort: |
| 4930 | case Primitive::kPrimChar: |
| 4931 | case Primitive::kPrimInt: |
| 4932 | case Primitive::kPrimLong: { |
| 4933 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4934 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4935 | // Output overlaps because it is written before doing the low comparison. |
| 4936 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4937 | break; |
| 4938 | } |
| 4939 | case Primitive::kPrimFloat: |
| 4940 | case Primitive::kPrimDouble: { |
| 4941 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4942 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
| 4943 | locations->SetOut(Location::RequiresRegister()); |
| 4944 | break; |
| 4945 | } |
| 4946 | default: |
| 4947 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4948 | } |
| 4949 | } |
| 4950 | |
| 4951 | void InstructionCodeGeneratorARMVIXL::VisitCompare(HCompare* compare) { |
| 4952 | LocationSummary* locations = compare->GetLocations(); |
| 4953 | vixl32::Register out = OutputRegister(compare); |
| 4954 | Location left = locations->InAt(0); |
| 4955 | Location right = locations->InAt(1); |
| 4956 | |
| 4957 | vixl32::Label less, greater, done; |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4958 | vixl32::Label* final_label = codegen_->GetFinalLabel(compare, &done); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4959 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| 4960 | vixl32::Condition less_cond = vixl32::Condition(kNone); |
| 4961 | switch (type) { |
| 4962 | case Primitive::kPrimBoolean: |
| 4963 | case Primitive::kPrimByte: |
| 4964 | case Primitive::kPrimShort: |
| 4965 | case Primitive::kPrimChar: |
| 4966 | case Primitive::kPrimInt: { |
| 4967 | // Emit move to `out` before the `Cmp`, as `Mov` might affect the status flags. |
| 4968 | __ Mov(out, 0); |
| 4969 | __ Cmp(RegisterFrom(left), RegisterFrom(right)); // Signed compare. |
| 4970 | less_cond = lt; |
| 4971 | break; |
| 4972 | } |
| 4973 | case Primitive::kPrimLong: { |
| 4974 | __ Cmp(HighRegisterFrom(left), HighRegisterFrom(right)); // Signed compare. |
| Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 4975 | __ B(lt, &less, /* far_target */ false); |
| 4976 | __ B(gt, &greater, /* far_target */ false); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4977 | // Emit move to `out` before the last `Cmp`, as `Mov` might affect the status flags. |
| 4978 | __ Mov(out, 0); |
| 4979 | __ Cmp(LowRegisterFrom(left), LowRegisterFrom(right)); // Unsigned compare. |
| 4980 | less_cond = lo; |
| 4981 | break; |
| 4982 | } |
| 4983 | case Primitive::kPrimFloat: |
| 4984 | case Primitive::kPrimDouble: { |
| 4985 | __ Mov(out, 0); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 4986 | GenerateVcmp(compare, codegen_); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4987 | // To branch on the FP compare result we transfer FPSCR to APSR (encoded as PC in VMRS). |
| 4988 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 4989 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
| 4990 | break; |
| 4991 | } |
| 4992 | default: |
| 4993 | LOG(FATAL) << "Unexpected compare type " << type; |
| 4994 | UNREACHABLE(); |
| 4995 | } |
| 4996 | |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4997 | __ B(eq, final_label, /* far_target */ false); |
| Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 4998 | __ B(less_cond, &less, /* far_target */ false); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4999 | |
| 5000 | __ Bind(&greater); |
| 5001 | __ Mov(out, 1); |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5002 | __ B(final_label); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5003 | |
| 5004 | __ Bind(&less); |
| 5005 | __ Mov(out, -1); |
| 5006 | |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5007 | if (done.IsReferenced()) { |
| 5008 | __ Bind(&done); |
| 5009 | } |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5010 | } |
| 5011 | |
| 5012 | void LocationsBuilderARMVIXL::VisitPhi(HPhi* instruction) { |
| 5013 | LocationSummary* locations = |
| 5014 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5015 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| 5016 | locations->SetInAt(i, Location::Any()); |
| 5017 | } |
| 5018 | locations->SetOut(Location::Any()); |
| 5019 | } |
| 5020 | |
| 5021 | void InstructionCodeGeneratorARMVIXL::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 5022 | LOG(FATAL) << "Unreachable"; |
| 5023 | } |
| 5024 | |
| 5025 | void CodeGeneratorARMVIXL::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 5026 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 5027 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
| 5028 | switch (kind) { |
| 5029 | case MemBarrierKind::kAnyStore: |
| 5030 | case MemBarrierKind::kLoadAny: |
| 5031 | case MemBarrierKind::kAnyAny: { |
| 5032 | flavor = DmbOptions::ISH; |
| 5033 | break; |
| 5034 | } |
| 5035 | case MemBarrierKind::kStoreStore: { |
| 5036 | flavor = DmbOptions::ISHST; |
| 5037 | break; |
| 5038 | } |
| 5039 | default: |
| 5040 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 5041 | } |
| 5042 | __ Dmb(flavor); |
| 5043 | } |
| 5044 | |
| 5045 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicLoad(vixl32::Register addr, |
| 5046 | uint32_t offset, |
| 5047 | vixl32::Register out_lo, |
| 5048 | vixl32::Register out_hi) { |
| 5049 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5050 | if (offset != 0) { |
| 5051 | vixl32::Register temp = temps.Acquire(); |
| 5052 | __ Add(temp, addr, offset); |
| 5053 | addr = temp; |
| 5054 | } |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5055 | __ Ldrexd(out_lo, out_hi, MemOperand(addr)); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5056 | } |
| 5057 | |
| 5058 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicStore(vixl32::Register addr, |
| 5059 | uint32_t offset, |
| 5060 | vixl32::Register value_lo, |
| 5061 | vixl32::Register value_hi, |
| 5062 | vixl32::Register temp1, |
| 5063 | vixl32::Register temp2, |
| 5064 | HInstruction* instruction) { |
| 5065 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5066 | vixl32::Label fail; |
| 5067 | if (offset != 0) { |
| 5068 | vixl32::Register temp = temps.Acquire(); |
| 5069 | __ Add(temp, addr, offset); |
| 5070 | addr = temp; |
| 5071 | } |
| 5072 | __ Bind(&fail); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5073 | { |
| 5074 | // Ensure the pc position is recorded immediately after the `ldrexd` instruction. |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5075 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5076 | vixl32::kMaxInstructionSizeInBytes, |
| 5077 | CodeBufferCheckScope::kMaximumSize); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5078 | // We need a load followed by store. (The address used in a STREX instruction must |
| 5079 | // be the same as the address in the most recently executed LDREX instruction.) |
| 5080 | __ ldrexd(temp1, temp2, MemOperand(addr)); |
| 5081 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5082 | } |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5083 | __ Strexd(temp1, value_lo, value_hi, MemOperand(addr)); |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5084 | __ CompareAndBranchIfNonZero(temp1, &fail); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5085 | } |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5086 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5087 | void LocationsBuilderARMVIXL::HandleFieldSet( |
| 5088 | HInstruction* instruction, const FieldInfo& field_info) { |
| 5089 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5090 | |
| 5091 | LocationSummary* locations = |
| 5092 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5093 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5094 | |
| 5095 | Primitive::Type field_type = field_info.GetFieldType(); |
| 5096 | if (Primitive::IsFloatingPointType(field_type)) { |
| 5097 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5098 | } else { |
| 5099 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5100 | } |
| 5101 | |
| 5102 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
| 5103 | bool generate_volatile = field_info.IsVolatile() |
| 5104 | && is_wide |
| 5105 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5106 | bool needs_write_barrier = |
| 5107 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 5108 | // Temporary registers for the write barrier. |
| 5109 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
| 5110 | if (needs_write_barrier) { |
| 5111 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
| 5112 | locations->AddTemp(Location::RequiresRegister()); |
| 5113 | } else if (generate_volatile) { |
| 5114 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 5115 | // - registers need to be consecutive |
| 5116 | // - the first register should be even but not R14. |
| 5117 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5118 | // revisit this if we ever enable ARM encoding. |
| 5119 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5120 | |
| 5121 | locations->AddTemp(Location::RequiresRegister()); |
| 5122 | locations->AddTemp(Location::RequiresRegister()); |
| 5123 | if (field_type == Primitive::kPrimDouble) { |
| 5124 | // For doubles we need two more registers to copy the value. |
| 5125 | locations->AddTemp(LocationFrom(r2)); |
| 5126 | locations->AddTemp(LocationFrom(r3)); |
| 5127 | } |
| 5128 | } |
| 5129 | } |
| 5130 | |
| 5131 | void InstructionCodeGeneratorARMVIXL::HandleFieldSet(HInstruction* instruction, |
| 5132 | const FieldInfo& field_info, |
| 5133 | bool value_can_be_null) { |
| 5134 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5135 | |
| 5136 | LocationSummary* locations = instruction->GetLocations(); |
| 5137 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 5138 | Location value = locations->InAt(1); |
| 5139 | |
| 5140 | bool is_volatile = field_info.IsVolatile(); |
| 5141 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5142 | Primitive::Type field_type = field_info.GetFieldType(); |
| 5143 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5144 | bool needs_write_barrier = |
| 5145 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 5146 | |
| 5147 | if (is_volatile) { |
| 5148 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 5149 | } |
| 5150 | |
| 5151 | switch (field_type) { |
| 5152 | case Primitive::kPrimBoolean: |
| 5153 | case Primitive::kPrimByte: { |
| 5154 | GetAssembler()->StoreToOffset(kStoreByte, RegisterFrom(value), base, offset); |
| 5155 | break; |
| 5156 | } |
| 5157 | |
| 5158 | case Primitive::kPrimShort: |
| 5159 | case Primitive::kPrimChar: { |
| 5160 | GetAssembler()->StoreToOffset(kStoreHalfword, RegisterFrom(value), base, offset); |
| 5161 | break; |
| 5162 | } |
| 5163 | |
| 5164 | case Primitive::kPrimInt: |
| 5165 | case Primitive::kPrimNot: { |
| 5166 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5167 | // Note that in the case where `value` is a null reference, |
| 5168 | // we do not enter this block, as a null reference does not |
| 5169 | // need poisoning. |
| 5170 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 5171 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5172 | __ Mov(temp, RegisterFrom(value)); |
| 5173 | GetAssembler()->PoisonHeapReference(temp); |
| 5174 | GetAssembler()->StoreToOffset(kStoreWord, temp, base, offset); |
| 5175 | } else { |
| 5176 | GetAssembler()->StoreToOffset(kStoreWord, RegisterFrom(value), base, offset); |
| 5177 | } |
| 5178 | break; |
| 5179 | } |
| 5180 | |
| 5181 | case Primitive::kPrimLong: { |
| 5182 | if (is_volatile && !atomic_ldrd_strd) { |
| 5183 | GenerateWideAtomicStore(base, |
| 5184 | offset, |
| 5185 | LowRegisterFrom(value), |
| 5186 | HighRegisterFrom(value), |
| 5187 | RegisterFrom(locations->GetTemp(0)), |
| 5188 | RegisterFrom(locations->GetTemp(1)), |
| 5189 | instruction); |
| 5190 | } else { |
| 5191 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), base, offset); |
| 5192 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5193 | } |
| 5194 | break; |
| 5195 | } |
| 5196 | |
| 5197 | case Primitive::kPrimFloat: { |
| 5198 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), base, offset); |
| 5199 | break; |
| 5200 | } |
| 5201 | |
| 5202 | case Primitive::kPrimDouble: { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5203 | vixl32::DRegister value_reg = DRegisterFrom(value); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5204 | if (is_volatile && !atomic_ldrd_strd) { |
| 5205 | vixl32::Register value_reg_lo = RegisterFrom(locations->GetTemp(0)); |
| 5206 | vixl32::Register value_reg_hi = RegisterFrom(locations->GetTemp(1)); |
| 5207 | |
| 5208 | __ Vmov(value_reg_lo, value_reg_hi, value_reg); |
| 5209 | |
| 5210 | GenerateWideAtomicStore(base, |
| 5211 | offset, |
| 5212 | value_reg_lo, |
| 5213 | value_reg_hi, |
| 5214 | RegisterFrom(locations->GetTemp(2)), |
| 5215 | RegisterFrom(locations->GetTemp(3)), |
| 5216 | instruction); |
| 5217 | } else { |
| 5218 | GetAssembler()->StoreDToOffset(value_reg, base, offset); |
| 5219 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5220 | } |
| 5221 | break; |
| 5222 | } |
| 5223 | |
| 5224 | case Primitive::kPrimVoid: |
| 5225 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5226 | UNREACHABLE(); |
| 5227 | } |
| 5228 | |
| 5229 | // Longs and doubles are handled in the switch. |
| 5230 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5231 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, we |
| 5232 | // should use a scope and the assembler to emit the store instruction to guarantee that we |
| 5233 | // record the pc at the correct position. But the `Assembler` does not automatically handle |
| 5234 | // unencodable offsets. Practically, everything is fine because the helper and VIXL, at the time |
| 5235 | // of writing, do generate the store instruction last. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5236 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5237 | } |
| 5238 | |
| 5239 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5240 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5241 | vixl32::Register card = RegisterFrom(locations->GetTemp(1)); |
| 5242 | codegen_->MarkGCCard(temp, card, base, RegisterFrom(value), value_can_be_null); |
| 5243 | } |
| 5244 | |
| 5245 | if (is_volatile) { |
| 5246 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 5247 | } |
| 5248 | } |
| 5249 | |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5250 | void LocationsBuilderARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 5251 | const FieldInfo& field_info) { |
| 5252 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 5253 | |
| 5254 | bool object_field_get_with_read_barrier = |
| 5255 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
| 5256 | LocationSummary* locations = |
| 5257 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5258 | object_field_get_with_read_barrier ? |
| 5259 | LocationSummary::kCallOnSlowPath : |
| 5260 | LocationSummary::kNoCall); |
| 5261 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5262 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 5263 | } |
| 5264 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5265 | |
| 5266 | bool volatile_for_double = field_info.IsVolatile() |
| 5267 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
| 5268 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5269 | // The output overlaps in case of volatile long: we don't want the |
| 5270 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 5271 | // object's location. Likewise, in the case of an object field get |
| 5272 | // with read barriers enabled, we do not want the load to overwrite |
| 5273 | // the object's location, as we need it to emit the read barrier. |
| 5274 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 5275 | object_field_get_with_read_barrier; |
| 5276 | |
| 5277 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5278 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5279 | } else { |
| 5280 | locations->SetOut(Location::RequiresRegister(), |
| 5281 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 5282 | } |
| 5283 | if (volatile_for_double) { |
| 5284 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 5285 | // - registers need to be consecutive |
| 5286 | // - the first register should be even but not R14. |
| 5287 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5288 | // revisit this if we ever enable ARM encoding. |
| 5289 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5290 | locations->AddTemp(Location::RequiresRegister()); |
| 5291 | locations->AddTemp(Location::RequiresRegister()); |
| 5292 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5293 | // We need a temporary register for the read barrier marking slow |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 5294 | // path in CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier. |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5295 | locations->AddTemp(Location::RequiresRegister()); |
| 5296 | } |
| 5297 | } |
| 5298 | |
| 5299 | Location LocationsBuilderARMVIXL::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| 5300 | DCHECK(Primitive::IsFloatingPointType(input->GetType())) << input->GetType(); |
| 5301 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 5302 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 5303 | return Location::ConstantLocation(input->AsConstant()); |
| 5304 | } else { |
| 5305 | return Location::RequiresFpuRegister(); |
| 5306 | } |
| 5307 | } |
| 5308 | |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5309 | Location LocationsBuilderARMVIXL::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 5310 | Opcode opcode) { |
| 5311 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 5312 | if (constant->IsConstant() && |
| 5313 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 5314 | return Location::ConstantLocation(constant->AsConstant()); |
| 5315 | } |
| 5316 | return Location::RequiresRegister(); |
| 5317 | } |
| 5318 | |
| 5319 | bool LocationsBuilderARMVIXL::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 5320 | Opcode opcode) { |
| 5321 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 5322 | if (Primitive::Is64BitType(input_cst->GetType())) { |
| 5323 | Opcode high_opcode = opcode; |
| 5324 | SetCc low_set_cc = kCcDontCare; |
| 5325 | switch (opcode) { |
| 5326 | case SUB: |
| 5327 | // Flip the operation to an ADD. |
| 5328 | value = -value; |
| 5329 | opcode = ADD; |
| 5330 | FALLTHROUGH_INTENDED; |
| 5331 | case ADD: |
| 5332 | if (Low32Bits(value) == 0u) { |
| 5333 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 5334 | } |
| 5335 | high_opcode = ADC; |
| 5336 | low_set_cc = kCcSet; |
| 5337 | break; |
| 5338 | default: |
| 5339 | break; |
| 5340 | } |
| 5341 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 5342 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
| 5343 | } else { |
| 5344 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 5345 | } |
| 5346 | } |
| 5347 | |
| 5348 | // TODO(VIXL): Replace art::arm::SetCc` with `vixl32::FlagsUpdate after flags set optimization |
| 5349 | // enabled. |
| 5350 | bool LocationsBuilderARMVIXL::CanEncodeConstantAsImmediate(uint32_t value, |
| 5351 | Opcode opcode, |
| 5352 | SetCc set_cc) { |
| 5353 | ArmVIXLAssembler* assembler = codegen_->GetAssembler(); |
| 5354 | if (assembler->ShifterOperandCanHold(opcode, value, set_cc)) { |
| 5355 | return true; |
| 5356 | } |
| 5357 | Opcode neg_opcode = kNoOperand; |
| Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5358 | uint32_t neg_value = 0; |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5359 | switch (opcode) { |
| Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5360 | case AND: neg_opcode = BIC; neg_value = ~value; break; |
| 5361 | case ORR: neg_opcode = ORN; neg_value = ~value; break; |
| 5362 | case ADD: neg_opcode = SUB; neg_value = -value; break; |
| 5363 | case ADC: neg_opcode = SBC; neg_value = ~value; break; |
| 5364 | case SUB: neg_opcode = ADD; neg_value = -value; break; |
| 5365 | case SBC: neg_opcode = ADC; neg_value = ~value; break; |
| 5366 | case MOV: neg_opcode = MVN; neg_value = ~value; break; |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5367 | default: |
| 5368 | return false; |
| 5369 | } |
| Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5370 | |
| 5371 | if (assembler->ShifterOperandCanHold(neg_opcode, neg_value, set_cc)) { |
| 5372 | return true; |
| 5373 | } |
| 5374 | |
| 5375 | return opcode == AND && IsPowerOfTwo(value + 1); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5376 | } |
| 5377 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5378 | void InstructionCodeGeneratorARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 5379 | const FieldInfo& field_info) { |
| 5380 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 5381 | |
| 5382 | LocationSummary* locations = instruction->GetLocations(); |
| 5383 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 5384 | Location out = locations->Out(); |
| 5385 | bool is_volatile = field_info.IsVolatile(); |
| 5386 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5387 | Primitive::Type field_type = field_info.GetFieldType(); |
| 5388 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5389 | |
| 5390 | switch (field_type) { |
| 5391 | case Primitive::kPrimBoolean: |
| 5392 | GetAssembler()->LoadFromOffset(kLoadUnsignedByte, RegisterFrom(out), base, offset); |
| 5393 | break; |
| 5394 | |
| 5395 | case Primitive::kPrimByte: |
| 5396 | GetAssembler()->LoadFromOffset(kLoadSignedByte, RegisterFrom(out), base, offset); |
| 5397 | break; |
| 5398 | |
| 5399 | case Primitive::kPrimShort: |
| 5400 | GetAssembler()->LoadFromOffset(kLoadSignedHalfword, RegisterFrom(out), base, offset); |
| 5401 | break; |
| 5402 | |
| 5403 | case Primitive::kPrimChar: |
| 5404 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, RegisterFrom(out), base, offset); |
| 5405 | break; |
| 5406 | |
| 5407 | case Primitive::kPrimInt: |
| 5408 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(out), base, offset); |
| 5409 | break; |
| 5410 | |
| 5411 | case Primitive::kPrimNot: { |
| 5412 | // /* HeapReference<Object> */ out = *(base + offset) |
| 5413 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5414 | Location temp_loc = locations->GetTemp(0); |
| 5415 | // Note that a potential implicit null check is handled in this |
| 5416 | // CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier call. |
| 5417 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 5418 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 5419 | if (is_volatile) { |
| 5420 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5421 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5422 | } else { |
| 5423 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(out), base, offset); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5424 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5425 | if (is_volatile) { |
| 5426 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5427 | } |
| 5428 | // If read barriers are enabled, emit read barriers other than |
| 5429 | // Baker's using a slow path (and also unpoison the loaded |
| 5430 | // reference, if heap poisoning is enabled). |
| 5431 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, locations->InAt(0), offset); |
| 5432 | } |
| 5433 | break; |
| 5434 | } |
| 5435 | |
| 5436 | case Primitive::kPrimLong: |
| 5437 | if (is_volatile && !atomic_ldrd_strd) { |
| 5438 | GenerateWideAtomicLoad(base, offset, LowRegisterFrom(out), HighRegisterFrom(out)); |
| 5439 | } else { |
| 5440 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out), base, offset); |
| 5441 | } |
| 5442 | break; |
| 5443 | |
| 5444 | case Primitive::kPrimFloat: |
| 5445 | GetAssembler()->LoadSFromOffset(SRegisterFrom(out), base, offset); |
| 5446 | break; |
| 5447 | |
| 5448 | case Primitive::kPrimDouble: { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5449 | vixl32::DRegister out_dreg = DRegisterFrom(out); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5450 | if (is_volatile && !atomic_ldrd_strd) { |
| 5451 | vixl32::Register lo = RegisterFrom(locations->GetTemp(0)); |
| 5452 | vixl32::Register hi = RegisterFrom(locations->GetTemp(1)); |
| 5453 | GenerateWideAtomicLoad(base, offset, lo, hi); |
| 5454 | // TODO(VIXL): Do we need to be immediately after the ldrexd instruction? If so we need a |
| 5455 | // scope. |
| 5456 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5457 | __ Vmov(out_dreg, lo, hi); |
| 5458 | } else { |
| 5459 | GetAssembler()->LoadDFromOffset(out_dreg, base, offset); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5460 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5461 | } |
| 5462 | break; |
| 5463 | } |
| 5464 | |
| 5465 | case Primitive::kPrimVoid: |
| 5466 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5467 | UNREACHABLE(); |
| 5468 | } |
| 5469 | |
| 5470 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 5471 | // Potential implicit null checks, in the case of reference or |
| 5472 | // double fields, are handled in the previous switch statement. |
| 5473 | } else { |
| 5474 | // 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] | 5475 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, we |
| 5476 | // should use a scope and the assembler to emit the load instruction to guarantee that we |
| 5477 | // record the pc at the correct position. But the `Assembler` does not automatically handle |
| 5478 | // unencodable offsets. Practically, everything is fine because the helper and VIXL, at the time |
| 5479 | // of writing, do generate the store instruction last. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5480 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5481 | } |
| 5482 | |
| 5483 | if (is_volatile) { |
| 5484 | if (field_type == Primitive::kPrimNot) { |
| 5485 | // Memory barriers, in the case of references, are also handled |
| 5486 | // in the previous switch statement. |
| 5487 | } else { |
| 5488 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5489 | } |
| 5490 | } |
| 5491 | } |
| 5492 | |
| 5493 | void LocationsBuilderARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5494 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5495 | } |
| 5496 | |
| 5497 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5498 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 5499 | } |
| 5500 | |
| 5501 | void LocationsBuilderARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5502 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5503 | } |
| 5504 | |
| 5505 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5506 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5507 | } |
| 5508 | |
| 5509 | void LocationsBuilderARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5510 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5511 | } |
| 5512 | |
| 5513 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5514 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5515 | } |
| 5516 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5517 | void LocationsBuilderARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5518 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5519 | } |
| 5520 | |
| 5521 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5522 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 5523 | } |
| 5524 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 5525 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 5526 | HUnresolvedInstanceFieldGet* instruction) { |
| 5527 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5528 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5529 | instruction, instruction->GetFieldType(), calling_convention); |
| 5530 | } |
| 5531 | |
| 5532 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 5533 | HUnresolvedInstanceFieldGet* instruction) { |
| 5534 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5535 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5536 | instruction->GetFieldType(), |
| 5537 | instruction->GetFieldIndex(), |
| 5538 | instruction->GetDexPc(), |
| 5539 | calling_convention); |
| 5540 | } |
| 5541 | |
| 5542 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 5543 | HUnresolvedInstanceFieldSet* instruction) { |
| 5544 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5545 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5546 | instruction, instruction->GetFieldType(), calling_convention); |
| 5547 | } |
| 5548 | |
| 5549 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 5550 | HUnresolvedInstanceFieldSet* instruction) { |
| 5551 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5552 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5553 | instruction->GetFieldType(), |
| 5554 | instruction->GetFieldIndex(), |
| 5555 | instruction->GetDexPc(), |
| 5556 | calling_convention); |
| 5557 | } |
| 5558 | |
| 5559 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldGet( |
| 5560 | HUnresolvedStaticFieldGet* instruction) { |
| 5561 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5562 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5563 | instruction, instruction->GetFieldType(), calling_convention); |
| 5564 | } |
| 5565 | |
| 5566 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldGet( |
| 5567 | HUnresolvedStaticFieldGet* instruction) { |
| 5568 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5569 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5570 | instruction->GetFieldType(), |
| 5571 | instruction->GetFieldIndex(), |
| 5572 | instruction->GetDexPc(), |
| 5573 | calling_convention); |
| 5574 | } |
| 5575 | |
| 5576 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldSet( |
| 5577 | HUnresolvedStaticFieldSet* instruction) { |
| 5578 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5579 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5580 | instruction, instruction->GetFieldType(), calling_convention); |
| 5581 | } |
| 5582 | |
| 5583 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldSet( |
| 5584 | HUnresolvedStaticFieldSet* instruction) { |
| 5585 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5586 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5587 | instruction->GetFieldType(), |
| 5588 | instruction->GetFieldIndex(), |
| 5589 | instruction->GetDexPc(), |
| 5590 | calling_convention); |
| 5591 | } |
| 5592 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5593 | void LocationsBuilderARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 5594 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5595 | locations->SetInAt(0, Location::RequiresRegister()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5596 | } |
| 5597 | |
| 5598 | void CodeGeneratorARMVIXL::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5599 | if (CanMoveNullCheckToUser(instruction)) { |
| 5600 | return; |
| 5601 | } |
| 5602 | |
| 5603 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5604 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5605 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5606 | vixl32::kMaxInstructionSizeInBytes, |
| 5607 | CodeBufferCheckScope::kMaximumSize); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5608 | __ ldr(temps.Acquire(), MemOperand(InputRegisterAt(instruction, 0))); |
| 5609 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5610 | } |
| 5611 | |
| 5612 | void CodeGeneratorARMVIXL::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| 5613 | NullCheckSlowPathARMVIXL* slow_path = |
| 5614 | new (GetGraph()->GetArena()) NullCheckSlowPathARMVIXL(instruction); |
| 5615 | AddSlowPath(slow_path); |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5616 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5617 | } |
| 5618 | |
| 5619 | void InstructionCodeGeneratorARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
| 5620 | codegen_->GenerateNullCheck(instruction); |
| 5621 | } |
| 5622 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5623 | static LoadOperandType GetLoadOperandType(Primitive::Type type) { |
| 5624 | switch (type) { |
| 5625 | case Primitive::kPrimNot: |
| 5626 | return kLoadWord; |
| 5627 | case Primitive::kPrimBoolean: |
| 5628 | return kLoadUnsignedByte; |
| 5629 | case Primitive::kPrimByte: |
| 5630 | return kLoadSignedByte; |
| 5631 | case Primitive::kPrimChar: |
| 5632 | return kLoadUnsignedHalfword; |
| 5633 | case Primitive::kPrimShort: |
| 5634 | return kLoadSignedHalfword; |
| 5635 | case Primitive::kPrimInt: |
| 5636 | return kLoadWord; |
| 5637 | case Primitive::kPrimLong: |
| 5638 | return kLoadWordPair; |
| 5639 | case Primitive::kPrimFloat: |
| 5640 | return kLoadSWord; |
| 5641 | case Primitive::kPrimDouble: |
| 5642 | return kLoadDWord; |
| 5643 | default: |
| 5644 | LOG(FATAL) << "Unreachable type " << type; |
| 5645 | UNREACHABLE(); |
| 5646 | } |
| 5647 | } |
| 5648 | |
| 5649 | static StoreOperandType GetStoreOperandType(Primitive::Type type) { |
| 5650 | switch (type) { |
| 5651 | case Primitive::kPrimNot: |
| 5652 | return kStoreWord; |
| 5653 | case Primitive::kPrimBoolean: |
| 5654 | case Primitive::kPrimByte: |
| 5655 | return kStoreByte; |
| 5656 | case Primitive::kPrimChar: |
| 5657 | case Primitive::kPrimShort: |
| 5658 | return kStoreHalfword; |
| 5659 | case Primitive::kPrimInt: |
| 5660 | return kStoreWord; |
| 5661 | case Primitive::kPrimLong: |
| 5662 | return kStoreWordPair; |
| 5663 | case Primitive::kPrimFloat: |
| 5664 | return kStoreSWord; |
| 5665 | case Primitive::kPrimDouble: |
| 5666 | return kStoreDWord; |
| 5667 | default: |
| 5668 | LOG(FATAL) << "Unreachable type " << type; |
| 5669 | UNREACHABLE(); |
| 5670 | } |
| 5671 | } |
| 5672 | |
| 5673 | void CodeGeneratorARMVIXL::LoadFromShiftedRegOffset(Primitive::Type type, |
| 5674 | Location out_loc, |
| 5675 | vixl32::Register base, |
| 5676 | vixl32::Register reg_index, |
| 5677 | vixl32::Condition cond) { |
| 5678 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 5679 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 5680 | |
| 5681 | switch (type) { |
| 5682 | case Primitive::kPrimByte: |
| 5683 | __ Ldrsb(cond, RegisterFrom(out_loc), mem_address); |
| 5684 | break; |
| 5685 | case Primitive::kPrimBoolean: |
| 5686 | __ Ldrb(cond, RegisterFrom(out_loc), mem_address); |
| 5687 | break; |
| 5688 | case Primitive::kPrimShort: |
| 5689 | __ Ldrsh(cond, RegisterFrom(out_loc), mem_address); |
| 5690 | break; |
| 5691 | case Primitive::kPrimChar: |
| 5692 | __ Ldrh(cond, RegisterFrom(out_loc), mem_address); |
| 5693 | break; |
| 5694 | case Primitive::kPrimNot: |
| 5695 | case Primitive::kPrimInt: |
| 5696 | __ Ldr(cond, RegisterFrom(out_loc), mem_address); |
| 5697 | break; |
| 5698 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
| 5699 | case Primitive::kPrimLong: |
| 5700 | case Primitive::kPrimFloat: |
| 5701 | case Primitive::kPrimDouble: |
| 5702 | default: |
| 5703 | LOG(FATAL) << "Unreachable type " << type; |
| 5704 | UNREACHABLE(); |
| 5705 | } |
| 5706 | } |
| 5707 | |
| 5708 | void CodeGeneratorARMVIXL::StoreToShiftedRegOffset(Primitive::Type type, |
| 5709 | Location loc, |
| 5710 | vixl32::Register base, |
| 5711 | vixl32::Register reg_index, |
| 5712 | vixl32::Condition cond) { |
| 5713 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 5714 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 5715 | |
| 5716 | switch (type) { |
| 5717 | case Primitive::kPrimByte: |
| 5718 | case Primitive::kPrimBoolean: |
| 5719 | __ Strb(cond, RegisterFrom(loc), mem_address); |
| 5720 | break; |
| 5721 | case Primitive::kPrimShort: |
| 5722 | case Primitive::kPrimChar: |
| 5723 | __ Strh(cond, RegisterFrom(loc), mem_address); |
| 5724 | break; |
| 5725 | case Primitive::kPrimNot: |
| 5726 | case Primitive::kPrimInt: |
| 5727 | __ Str(cond, RegisterFrom(loc), mem_address); |
| 5728 | break; |
| 5729 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
| 5730 | case Primitive::kPrimLong: |
| 5731 | case Primitive::kPrimFloat: |
| 5732 | case Primitive::kPrimDouble: |
| 5733 | default: |
| 5734 | LOG(FATAL) << "Unreachable type " << type; |
| 5735 | UNREACHABLE(); |
| 5736 | } |
| 5737 | } |
| 5738 | |
| 5739 | void LocationsBuilderARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
| 5740 | bool object_array_get_with_read_barrier = |
| 5741 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
| 5742 | LocationSummary* locations = |
| 5743 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5744 | object_array_get_with_read_barrier ? |
| 5745 | LocationSummary::kCallOnSlowPath : |
| 5746 | LocationSummary::kNoCall); |
| 5747 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5748 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5749 | } |
| 5750 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5751 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5752 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5753 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5754 | } else { |
| 5755 | // The output overlaps in the case of an object array get with |
| 5756 | // read barriers enabled: we do not want the move to overwrite the |
| 5757 | // array's location, as we need it to emit the read barrier. |
| 5758 | locations->SetOut( |
| 5759 | Location::RequiresRegister(), |
| 5760 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 5761 | } |
| 5762 | // We need a temporary register for the read barrier marking slow |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 5763 | // path in CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier. |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5764 | // Also need for String compression feature. |
| 5765 | if ((object_array_get_with_read_barrier && kUseBakerReadBarrier) |
| 5766 | || (mirror::kUseStringCompression && instruction->IsStringCharAt())) { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 5767 | locations->AddTemp(Location::RequiresRegister()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5768 | } |
| 5769 | } |
| 5770 | |
| 5771 | void InstructionCodeGeneratorARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5772 | LocationSummary* locations = instruction->GetLocations(); |
| 5773 | Location obj_loc = locations->InAt(0); |
| 5774 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 5775 | Location index = locations->InAt(1); |
| 5776 | Location out_loc = locations->Out(); |
| 5777 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 5778 | Primitive::Type type = instruction->GetType(); |
| 5779 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 5780 | instruction->IsStringCharAt(); |
| 5781 | HInstruction* array_instr = instruction->GetArray(); |
| 5782 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5783 | |
| 5784 | switch (type) { |
| 5785 | case Primitive::kPrimBoolean: |
| 5786 | case Primitive::kPrimByte: |
| 5787 | case Primitive::kPrimShort: |
| 5788 | case Primitive::kPrimChar: |
| 5789 | case Primitive::kPrimInt: { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5790 | vixl32::Register length; |
| 5791 | if (maybe_compressed_char_at) { |
| 5792 | length = RegisterFrom(locations->GetTemp(0)); |
| 5793 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5794 | GetAssembler()->LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 5795 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5796 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5797 | if (index.IsConstant()) { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5798 | int32_t const_index = Int32ConstantFrom(index); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5799 | if (maybe_compressed_char_at) { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 5800 | vixl32::Label uncompressed_load, done; |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5801 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5802 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 5803 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5804 | "Expecting 0=compressed, 1=uncompressed"); |
| Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 5805 | __ B(cs, &uncompressed_load, /* far_target */ false); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 5806 | GetAssembler()->LoadFromOffset(kLoadUnsignedByte, |
| 5807 | RegisterFrom(out_loc), |
| 5808 | obj, |
| 5809 | data_offset + const_index); |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5810 | __ B(final_label); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 5811 | __ Bind(&uncompressed_load); |
| 5812 | GetAssembler()->LoadFromOffset(GetLoadOperandType(Primitive::kPrimChar), |
| 5813 | RegisterFrom(out_loc), |
| 5814 | obj, |
| 5815 | data_offset + (const_index << 1)); |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5816 | if (done.IsReferenced()) { |
| 5817 | __ Bind(&done); |
| 5818 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5819 | } else { |
| 5820 | uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type)); |
| 5821 | |
| 5822 | LoadOperandType load_type = GetLoadOperandType(type); |
| 5823 | GetAssembler()->LoadFromOffset(load_type, RegisterFrom(out_loc), obj, full_offset); |
| 5824 | } |
| 5825 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5826 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5827 | vixl32::Register temp = temps.Acquire(); |
| 5828 | |
| 5829 | if (has_intermediate_address) { |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 5830 | // We do not need to compute the intermediate address from the array: the |
| 5831 | // input instruction has done it already. See the comment in |
| 5832 | // `TryExtractArrayAccessAddress()`. |
| 5833 | if (kIsDebugBuild) { |
| 5834 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5835 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 5836 | } |
| 5837 | temp = obj; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5838 | } else { |
| 5839 | __ Add(temp, obj, data_offset); |
| 5840 | } |
| 5841 | if (maybe_compressed_char_at) { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 5842 | vixl32::Label uncompressed_load, done; |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5843 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5844 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 5845 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5846 | "Expecting 0=compressed, 1=uncompressed"); |
| Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 5847 | __ B(cs, &uncompressed_load, /* far_target */ false); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 5848 | __ Ldrb(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 0)); |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5849 | __ B(final_label); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 5850 | __ Bind(&uncompressed_load); |
| 5851 | __ Ldrh(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 1)); |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5852 | if (done.IsReferenced()) { |
| 5853 | __ Bind(&done); |
| 5854 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5855 | } else { |
| 5856 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
| 5857 | } |
| 5858 | } |
| 5859 | break; |
| 5860 | } |
| 5861 | |
| 5862 | case Primitive::kPrimNot: { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5863 | // The read barrier instrumentation of object ArrayGet |
| 5864 | // instructions does not support the HIntermediateAddress |
| 5865 | // instruction. |
| 5866 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 5867 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5868 | static_assert( |
| 5869 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5870 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 5871 | // /* HeapReference<Object> */ out = |
| 5872 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5873 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5874 | Location temp = locations->GetTemp(0); |
| 5875 | // Note that a potential implicit null check is handled in this |
| 5876 | // CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier call. |
| 5877 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 5878 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5879 | } else { |
| 5880 | vixl32::Register out = OutputRegister(instruction); |
| 5881 | if (index.IsConstant()) { |
| 5882 | size_t offset = |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5883 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5884 | GetAssembler()->LoadFromOffset(kLoadWord, out, obj, offset); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5885 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, |
| 5886 | // we should use a scope and the assembler to emit the load instruction to guarantee that |
| 5887 | // we record the pc at the correct position. But the `Assembler` does not automatically |
| 5888 | // handle unencodable offsets. Practically, everything is fine because the helper and |
| 5889 | // VIXL, at the time of writing, do generate the store instruction last. |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5890 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5891 | // If read barriers are enabled, emit read barriers other than |
| 5892 | // Baker's using a slow path (and also unpoison the loaded |
| 5893 | // reference, if heap poisoning is enabled). |
| 5894 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5895 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5896 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5897 | vixl32::Register temp = temps.Acquire(); |
| 5898 | |
| 5899 | if (has_intermediate_address) { |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 5900 | // We do not need to compute the intermediate address from the array: the |
| 5901 | // input instruction has done it already. See the comment in |
| 5902 | // `TryExtractArrayAccessAddress()`. |
| 5903 | if (kIsDebugBuild) { |
| 5904 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5905 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 5906 | } |
| 5907 | temp = obj; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5908 | } else { |
| 5909 | __ Add(temp, obj, data_offset); |
| 5910 | } |
| 5911 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5912 | temps.Close(); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5913 | // TODO(VIXL): Use a scope to ensure that we record the pc position immediately after the |
| 5914 | // load instruction. Practically, everything is fine because the helper and VIXL, at the |
| 5915 | // time of writing, do generate the store instruction last. |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5916 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5917 | // If read barriers are enabled, emit read barriers other than |
| 5918 | // Baker's using a slow path (and also unpoison the loaded |
| 5919 | // reference, if heap poisoning is enabled). |
| 5920 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5921 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5922 | } |
| 5923 | } |
| 5924 | break; |
| 5925 | } |
| 5926 | |
| 5927 | case Primitive::kPrimLong: { |
| 5928 | if (index.IsConstant()) { |
| 5929 | size_t offset = |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5930 | (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5931 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), obj, offset); |
| 5932 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5933 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5934 | vixl32::Register temp = temps.Acquire(); |
| 5935 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 5936 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), temp, data_offset); |
| 5937 | } |
| 5938 | break; |
| 5939 | } |
| 5940 | |
| 5941 | case Primitive::kPrimFloat: { |
| 5942 | vixl32::SRegister out = SRegisterFrom(out_loc); |
| 5943 | if (index.IsConstant()) { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5944 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5945 | GetAssembler()->LoadSFromOffset(out, obj, offset); |
| 5946 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5947 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5948 | vixl32::Register temp = temps.Acquire(); |
| 5949 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 5950 | GetAssembler()->LoadSFromOffset(out, temp, data_offset); |
| 5951 | } |
| 5952 | break; |
| 5953 | } |
| 5954 | |
| 5955 | case Primitive::kPrimDouble: { |
| 5956 | if (index.IsConstant()) { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5957 | size_t offset = (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5958 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), obj, offset); |
| 5959 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5960 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5961 | vixl32::Register temp = temps.Acquire(); |
| 5962 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 5963 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), temp, data_offset); |
| 5964 | } |
| 5965 | break; |
| 5966 | } |
| 5967 | |
| 5968 | case Primitive::kPrimVoid: |
| 5969 | LOG(FATAL) << "Unreachable type " << type; |
| 5970 | UNREACHABLE(); |
| 5971 | } |
| 5972 | |
| 5973 | if (type == Primitive::kPrimNot) { |
| 5974 | // Potential implicit null checks, in the case of reference |
| 5975 | // arrays, are handled in the previous switch statement. |
| 5976 | } else if (!maybe_compressed_char_at) { |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5977 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after |
| 5978 | // the preceding load instruction. |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5979 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5980 | } |
| 5981 | } |
| 5982 | |
| 5983 | void LocationsBuilderARMVIXL::VisitArraySet(HArraySet* instruction) { |
| 5984 | Primitive::Type value_type = instruction->GetComponentType(); |
| 5985 | |
| 5986 | bool needs_write_barrier = |
| 5987 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 5988 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 5989 | |
| 5990 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5991 | instruction, |
| 5992 | may_need_runtime_call_for_type_check ? |
| 5993 | LocationSummary::kCallOnSlowPath : |
| 5994 | LocationSummary::kNoCall); |
| 5995 | |
| 5996 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5997 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5998 | if (Primitive::IsFloatingPointType(value_type)) { |
| 5999 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 6000 | } else { |
| 6001 | locations->SetInAt(2, Location::RequiresRegister()); |
| 6002 | } |
| 6003 | if (needs_write_barrier) { |
| 6004 | // Temporary registers for the write barrier. |
| 6005 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 6006 | locations->AddTemp(Location::RequiresRegister()); |
| 6007 | } |
| 6008 | } |
| 6009 | |
| 6010 | void InstructionCodeGeneratorARMVIXL::VisitArraySet(HArraySet* instruction) { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6011 | LocationSummary* locations = instruction->GetLocations(); |
| 6012 | vixl32::Register array = InputRegisterAt(instruction, 0); |
| 6013 | Location index = locations->InAt(1); |
| 6014 | Primitive::Type value_type = instruction->GetComponentType(); |
| 6015 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 6016 | bool needs_write_barrier = |
| 6017 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 6018 | uint32_t data_offset = |
| 6019 | mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 6020 | Location value_loc = locations->InAt(2); |
| 6021 | HInstruction* array_instr = instruction->GetArray(); |
| 6022 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6023 | |
| 6024 | switch (value_type) { |
| 6025 | case Primitive::kPrimBoolean: |
| 6026 | case Primitive::kPrimByte: |
| 6027 | case Primitive::kPrimShort: |
| 6028 | case Primitive::kPrimChar: |
| 6029 | case Primitive::kPrimInt: { |
| 6030 | if (index.IsConstant()) { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6031 | int32_t const_index = Int32ConstantFrom(index); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6032 | uint32_t full_offset = |
| 6033 | data_offset + (const_index << Primitive::ComponentSizeShift(value_type)); |
| 6034 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 6035 | GetAssembler()->StoreToOffset(store_type, RegisterFrom(value_loc), array, full_offset); |
| 6036 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6037 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6038 | vixl32::Register temp = temps.Acquire(); |
| 6039 | |
| 6040 | if (has_intermediate_address) { |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6041 | // We do not need to compute the intermediate address from the array: the |
| 6042 | // input instruction has done it already. See the comment in |
| 6043 | // `TryExtractArrayAccessAddress()`. |
| 6044 | if (kIsDebugBuild) { |
| 6045 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6046 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6047 | } |
| 6048 | temp = array; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6049 | } else { |
| 6050 | __ Add(temp, array, data_offset); |
| 6051 | } |
| 6052 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 6053 | } |
| 6054 | break; |
| 6055 | } |
| 6056 | |
| 6057 | case Primitive::kPrimNot: { |
| 6058 | vixl32::Register value = RegisterFrom(value_loc); |
| 6059 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 6060 | // See the comment in instruction_simplifier_shared.cc. |
| 6061 | DCHECK(!has_intermediate_address); |
| 6062 | |
| 6063 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 6064 | // Just setting null. |
| 6065 | if (index.IsConstant()) { |
| 6066 | size_t offset = |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6067 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6068 | GetAssembler()->StoreToOffset(kStoreWord, value, array, offset); |
| 6069 | } else { |
| 6070 | DCHECK(index.IsRegister()) << index; |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6071 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6072 | vixl32::Register temp = temps.Acquire(); |
| 6073 | __ Add(temp, array, data_offset); |
| 6074 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 6075 | } |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6076 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after the preceding |
| 6077 | // store instruction. |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6078 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6079 | DCHECK(!needs_write_barrier); |
| 6080 | DCHECK(!may_need_runtime_call_for_type_check); |
| 6081 | break; |
| 6082 | } |
| 6083 | |
| 6084 | DCHECK(needs_write_barrier); |
| 6085 | Location temp1_loc = locations->GetTemp(0); |
| 6086 | vixl32::Register temp1 = RegisterFrom(temp1_loc); |
| 6087 | Location temp2_loc = locations->GetTemp(1); |
| 6088 | vixl32::Register temp2 = RegisterFrom(temp2_loc); |
| 6089 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6090 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6091 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6092 | vixl32::Label done; |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6093 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6094 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 6095 | |
| 6096 | if (may_need_runtime_call_for_type_check) { |
| 6097 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARMVIXL(instruction); |
| 6098 | codegen_->AddSlowPath(slow_path); |
| 6099 | if (instruction->GetValueCanBeNull()) { |
| 6100 | vixl32::Label non_zero; |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6101 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6102 | if (index.IsConstant()) { |
| 6103 | size_t offset = |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6104 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6105 | GetAssembler()->StoreToOffset(kStoreWord, value, array, offset); |
| 6106 | } else { |
| 6107 | DCHECK(index.IsRegister()) << index; |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6108 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6109 | vixl32::Register temp = temps.Acquire(); |
| 6110 | __ Add(temp, array, data_offset); |
| 6111 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 6112 | } |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6113 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after the preceding |
| 6114 | // store instruction. |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6115 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6116 | __ B(final_label); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6117 | __ Bind(&non_zero); |
| 6118 | } |
| 6119 | |
| 6120 | // Note that when read barriers are enabled, the type checks |
| 6121 | // are performed without read barriers. This is fine, even in |
| 6122 | // the case where a class object is in the from-space after |
| 6123 | // the flip, as a comparison involving such a type would not |
| 6124 | // produce a false positive; it may of course produce a false |
| 6125 | // negative, in which case we would take the ArraySet slow |
| 6126 | // path. |
| 6127 | |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6128 | { |
| 6129 | // Ensure we record the pc position immediately after the `ldr` instruction. |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6130 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6131 | vixl32::kMaxInstructionSizeInBytes, |
| 6132 | CodeBufferCheckScope::kMaximumSize); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6133 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 6134 | __ ldr(temp1, MemOperand(array, class_offset)); |
| 6135 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6136 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6137 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 6138 | |
| 6139 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 6140 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 6141 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 6142 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 6143 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 6144 | // nor `temp2`, as we are comparing two poisoned references. |
| 6145 | __ Cmp(temp1, temp2); |
| 6146 | |
| 6147 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 6148 | vixl32::Label do_put; |
| Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 6149 | __ B(eq, &do_put, /* far_target */ false); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6150 | // If heap poisoning is enabled, the `temp1` reference has |
| 6151 | // not been unpoisoned yet; unpoison it now. |
| 6152 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 6153 | |
| 6154 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 6155 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 6156 | // If heap poisoning is enabled, no need to unpoison |
| 6157 | // `temp1`, as we are comparing against null below. |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6158 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6159 | __ Bind(&do_put); |
| 6160 | } else { |
| 6161 | __ B(ne, slow_path->GetEntryLabel()); |
| 6162 | } |
| 6163 | } |
| 6164 | |
| 6165 | vixl32::Register source = value; |
| 6166 | if (kPoisonHeapReferences) { |
| 6167 | // Note that in the case where `value` is a null reference, |
| 6168 | // we do not enter this block, as a null reference does not |
| 6169 | // need poisoning. |
| 6170 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 6171 | __ Mov(temp1, value); |
| 6172 | GetAssembler()->PoisonHeapReference(temp1); |
| 6173 | source = temp1; |
| 6174 | } |
| 6175 | |
| 6176 | if (index.IsConstant()) { |
| 6177 | size_t offset = |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6178 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6179 | GetAssembler()->StoreToOffset(kStoreWord, source, array, offset); |
| 6180 | } else { |
| 6181 | DCHECK(index.IsRegister()) << index; |
| 6182 | |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6183 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6184 | vixl32::Register temp = temps.Acquire(); |
| 6185 | __ Add(temp, array, data_offset); |
| 6186 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6187 | LocationFrom(source), |
| 6188 | temp, |
| 6189 | RegisterFrom(index)); |
| 6190 | } |
| 6191 | |
| 6192 | if (!may_need_runtime_call_for_type_check) { |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6193 | // TODO(VIXL): Ensure we record the pc position immediately after the preceding store |
| 6194 | // instruction. |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6195 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6196 | } |
| 6197 | |
| 6198 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 6199 | |
| 6200 | if (done.IsReferenced()) { |
| 6201 | __ Bind(&done); |
| 6202 | } |
| 6203 | |
| 6204 | if (slow_path != nullptr) { |
| 6205 | __ Bind(slow_path->GetExitLabel()); |
| 6206 | } |
| 6207 | |
| 6208 | break; |
| 6209 | } |
| 6210 | |
| 6211 | case Primitive::kPrimLong: { |
| 6212 | Location value = locations->InAt(2); |
| 6213 | if (index.IsConstant()) { |
| 6214 | size_t offset = |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6215 | (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6216 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), array, offset); |
| 6217 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6218 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6219 | vixl32::Register temp = temps.Acquire(); |
| 6220 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6221 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), temp, data_offset); |
| 6222 | } |
| 6223 | break; |
| 6224 | } |
| 6225 | |
| 6226 | case Primitive::kPrimFloat: { |
| 6227 | Location value = locations->InAt(2); |
| 6228 | DCHECK(value.IsFpuRegister()); |
| 6229 | if (index.IsConstant()) { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6230 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6231 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), array, offset); |
| 6232 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6233 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6234 | vixl32::Register temp = temps.Acquire(); |
| 6235 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 6236 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), temp, data_offset); |
| 6237 | } |
| 6238 | break; |
| 6239 | } |
| 6240 | |
| 6241 | case Primitive::kPrimDouble: { |
| 6242 | Location value = locations->InAt(2); |
| 6243 | DCHECK(value.IsFpuRegisterPair()); |
| 6244 | if (index.IsConstant()) { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6245 | size_t offset = (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6246 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), array, offset); |
| 6247 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6248 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6249 | vixl32::Register temp = temps.Acquire(); |
| 6250 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6251 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), temp, data_offset); |
| 6252 | } |
| 6253 | break; |
| 6254 | } |
| 6255 | |
| 6256 | case Primitive::kPrimVoid: |
| 6257 | LOG(FATAL) << "Unreachable type " << value_type; |
| 6258 | UNREACHABLE(); |
| 6259 | } |
| 6260 | |
| 6261 | // Objects are handled in the switch. |
| 6262 | if (value_type != Primitive::kPrimNot) { |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6263 | // TODO(VIXL): Ensure we record the pc position immediately after the preceding store |
| 6264 | // instruction. |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6265 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6266 | } |
| 6267 | } |
| 6268 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6269 | void LocationsBuilderARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 6270 | LocationSummary* locations = |
| 6271 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6272 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6273 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6274 | } |
| 6275 | |
| 6276 | void InstructionCodeGeneratorARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 6277 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| 6278 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 6279 | vixl32::Register out = OutputRegister(instruction); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6280 | { |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6281 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6282 | vixl32::kMaxInstructionSizeInBytes, |
| 6283 | CodeBufferCheckScope::kMaximumSize); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6284 | __ ldr(out, MemOperand(obj, offset)); |
| 6285 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6286 | } |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6287 | // Mask out compression flag from String's array length. |
| 6288 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6289 | __ Lsr(out, out, 1u); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6290 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6291 | } |
| 6292 | |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6293 | void LocationsBuilderARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6294 | LocationSummary* locations = |
| 6295 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6296 | |
| 6297 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6298 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 6299 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6300 | } |
| 6301 | |
| 6302 | void InstructionCodeGeneratorARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 6303 | vixl32::Register out = OutputRegister(instruction); |
| 6304 | vixl32::Register first = InputRegisterAt(instruction, 0); |
| 6305 | Location second = instruction->GetLocations()->InAt(1); |
| 6306 | |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6307 | if (second.IsRegister()) { |
| 6308 | __ Add(out, first, RegisterFrom(second)); |
| 6309 | } else { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6310 | __ Add(out, first, Int32ConstantFrom(second)); |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6311 | } |
| 6312 | } |
| 6313 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6314 | void LocationsBuilderARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 6315 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6316 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 6317 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 6318 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(1))); |
| 6319 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
| Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6320 | |
| 6321 | HInstruction* index = instruction->InputAt(0); |
| 6322 | HInstruction* length = instruction->InputAt(1); |
| 6323 | // If both index and length are constants we can statically check the bounds. But if at least one |
| 6324 | // of them is not encodable ArmEncodableConstantOrRegister will create |
| 6325 | // Location::RequiresRegister() which is not desired to happen. Instead we create constant |
| 6326 | // locations. |
| 6327 | bool both_const = index->IsConstant() && length->IsConstant(); |
| 6328 | locations->SetInAt(0, both_const |
| 6329 | ? Location::ConstantLocation(index->AsConstant()) |
| 6330 | : ArmEncodableConstantOrRegister(index, CMP)); |
| 6331 | locations->SetInAt(1, both_const |
| 6332 | ? Location::ConstantLocation(length->AsConstant()) |
| 6333 | : ArmEncodableConstantOrRegister(length, CMP)); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6334 | } |
| 6335 | |
| 6336 | void InstructionCodeGeneratorARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
| Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6337 | LocationSummary* locations = instruction->GetLocations(); |
| 6338 | Location index_loc = locations->InAt(0); |
| 6339 | Location length_loc = locations->InAt(1); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6340 | |
| Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6341 | if (length_loc.IsConstant()) { |
| 6342 | int32_t length = Int32ConstantFrom(length_loc); |
| 6343 | if (index_loc.IsConstant()) { |
| 6344 | // BCE will remove the bounds check if we are guaranteed to pass. |
| 6345 | int32_t index = Int32ConstantFrom(index_loc); |
| 6346 | if (index < 0 || index >= length) { |
| 6347 | SlowPathCodeARMVIXL* slow_path = |
| 6348 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARMVIXL(instruction); |
| 6349 | codegen_->AddSlowPath(slow_path); |
| 6350 | __ B(slow_path->GetEntryLabel()); |
| 6351 | } else { |
| 6352 | // Some optimization after BCE may have generated this, and we should not |
| 6353 | // generate a bounds check if it is a valid range. |
| 6354 | } |
| 6355 | return; |
| 6356 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6357 | |
| Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6358 | SlowPathCodeARMVIXL* slow_path = |
| 6359 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARMVIXL(instruction); |
| 6360 | __ Cmp(RegisterFrom(index_loc), length); |
| 6361 | codegen_->AddSlowPath(slow_path); |
| 6362 | __ B(hs, slow_path->GetEntryLabel()); |
| 6363 | } else { |
| 6364 | SlowPathCodeARMVIXL* slow_path = |
| 6365 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARMVIXL(instruction); |
| 6366 | __ Cmp(RegisterFrom(length_loc), InputOperandAt(instruction, 0)); |
| 6367 | codegen_->AddSlowPath(slow_path); |
| 6368 | __ B(ls, slow_path->GetEntryLabel()); |
| 6369 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6370 | } |
| 6371 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6372 | void CodeGeneratorARMVIXL::MarkGCCard(vixl32::Register temp, |
| 6373 | vixl32::Register card, |
| 6374 | vixl32::Register object, |
| 6375 | vixl32::Register value, |
| 6376 | bool can_be_null) { |
| 6377 | vixl32::Label is_null; |
| 6378 | if (can_be_null) { |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6379 | __ CompareAndBranchIfZero(value, &is_null); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6380 | } |
| 6381 | GetAssembler()->LoadFromOffset( |
| 6382 | kLoadWord, card, tr, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 6383 | __ Lsr(temp, object, Operand::From(gc::accounting::CardTable::kCardShift)); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6384 | __ Strb(card, MemOperand(card, temp)); |
| 6385 | if (can_be_null) { |
| 6386 | __ Bind(&is_null); |
| 6387 | } |
| 6388 | } |
| 6389 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6390 | void LocationsBuilderARMVIXL::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 6391 | LOG(FATAL) << "Unreachable"; |
| 6392 | } |
| 6393 | |
| 6394 | void InstructionCodeGeneratorARMVIXL::VisitParallelMove(HParallelMove* instruction) { |
| 6395 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6396 | } |
| 6397 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6398 | void LocationsBuilderARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6399 | LocationSummary* locations = |
| 6400 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 6401 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6402 | } |
| 6403 | |
| 6404 | void InstructionCodeGeneratorARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 6405 | HBasicBlock* block = instruction->GetBlock(); |
| 6406 | if (block->GetLoopInformation() != nullptr) { |
| 6407 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6408 | // The back edge will generate the suspend check. |
| 6409 | return; |
| 6410 | } |
| 6411 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6412 | // The goto will generate the suspend check. |
| 6413 | return; |
| 6414 | } |
| 6415 | GenerateSuspendCheck(instruction, nullptr); |
| 6416 | } |
| 6417 | |
| 6418 | void InstructionCodeGeneratorARMVIXL::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 6419 | HBasicBlock* successor) { |
| 6420 | SuspendCheckSlowPathARMVIXL* slow_path = |
| 6421 | down_cast<SuspendCheckSlowPathARMVIXL*>(instruction->GetSlowPath()); |
| 6422 | if (slow_path == nullptr) { |
| 6423 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARMVIXL(instruction, successor); |
| 6424 | instruction->SetSlowPath(slow_path); |
| 6425 | codegen_->AddSlowPath(slow_path); |
| 6426 | if (successor != nullptr) { |
| 6427 | DCHECK(successor->IsLoopHeader()); |
| 6428 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 6429 | } |
| 6430 | } else { |
| 6431 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 6432 | } |
| 6433 | |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6434 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6435 | vixl32::Register temp = temps.Acquire(); |
| 6436 | GetAssembler()->LoadFromOffset( |
| 6437 | kLoadUnsignedHalfword, temp, tr, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
| 6438 | if (successor == nullptr) { |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6439 | __ CompareAndBranchIfNonZero(temp, slow_path->GetEntryLabel()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6440 | __ Bind(slow_path->GetReturnLabel()); |
| 6441 | } else { |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6442 | __ CompareAndBranchIfZero(temp, codegen_->GetLabelOf(successor)); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6443 | __ B(slow_path->GetEntryLabel()); |
| 6444 | } |
| 6445 | } |
| 6446 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6447 | ArmVIXLAssembler* ParallelMoveResolverARMVIXL::GetAssembler() const { |
| 6448 | return codegen_->GetAssembler(); |
| 6449 | } |
| 6450 | |
| 6451 | void ParallelMoveResolverARMVIXL::EmitMove(size_t index) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6452 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6453 | MoveOperands* move = moves_[index]; |
| 6454 | Location source = move->GetSource(); |
| 6455 | Location destination = move->GetDestination(); |
| 6456 | |
| 6457 | if (source.IsRegister()) { |
| 6458 | if (destination.IsRegister()) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6459 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6460 | } else if (destination.IsFpuRegister()) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6461 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6462 | } else { |
| 6463 | DCHECK(destination.IsStackSlot()); |
| 6464 | GetAssembler()->StoreToOffset(kStoreWord, |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6465 | RegisterFrom(source), |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6466 | sp, |
| 6467 | destination.GetStackIndex()); |
| 6468 | } |
| 6469 | } else if (source.IsStackSlot()) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6470 | if (destination.IsRegister()) { |
| 6471 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 6472 | RegisterFrom(destination), |
| 6473 | sp, |
| 6474 | source.GetStackIndex()); |
| 6475 | } else if (destination.IsFpuRegister()) { |
| 6476 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 6477 | } else { |
| 6478 | DCHECK(destination.IsStackSlot()); |
| 6479 | vixl32::Register temp = temps.Acquire(); |
| 6480 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 6481 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6482 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6483 | } else if (source.IsFpuRegister()) { |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6484 | if (destination.IsRegister()) { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6485 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6486 | } else if (destination.IsFpuRegister()) { |
| 6487 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 6488 | } else { |
| 6489 | DCHECK(destination.IsStackSlot()); |
| 6490 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 6491 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6492 | } else if (source.IsDoubleStackSlot()) { |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6493 | if (destination.IsDoubleStackSlot()) { |
| 6494 | vixl32::DRegister temp = temps.AcquireD(); |
| 6495 | GetAssembler()->LoadDFromOffset(temp, sp, source.GetStackIndex()); |
| 6496 | GetAssembler()->StoreDToOffset(temp, sp, destination.GetStackIndex()); |
| 6497 | } else if (destination.IsRegisterPair()) { |
| 6498 | DCHECK(ExpectedPairLayout(destination)); |
| 6499 | GetAssembler()->LoadFromOffset( |
| 6500 | kLoadWordPair, LowRegisterFrom(destination), sp, source.GetStackIndex()); |
| 6501 | } else { |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6502 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 6503 | GetAssembler()->LoadDFromOffset(DRegisterFrom(destination), sp, source.GetStackIndex()); |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6504 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6505 | } else if (source.IsRegisterPair()) { |
| 6506 | if (destination.IsRegisterPair()) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6507 | __ Mov(LowRegisterFrom(destination), LowRegisterFrom(source)); |
| 6508 | __ Mov(HighRegisterFrom(destination), HighRegisterFrom(source)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6509 | } else if (destination.IsFpuRegisterPair()) { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6510 | __ Vmov(DRegisterFrom(destination), LowRegisterFrom(source), HighRegisterFrom(source)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6511 | } else { |
| 6512 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6513 | DCHECK(ExpectedPairLayout(source)); |
| 6514 | GetAssembler()->StoreToOffset(kStoreWordPair, |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6515 | LowRegisterFrom(source), |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6516 | sp, |
| 6517 | destination.GetStackIndex()); |
| 6518 | } |
| 6519 | } else if (source.IsFpuRegisterPair()) { |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6520 | if (destination.IsRegisterPair()) { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6521 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), DRegisterFrom(source)); |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6522 | } else if (destination.IsFpuRegisterPair()) { |
| 6523 | __ Vmov(DRegisterFrom(destination), DRegisterFrom(source)); |
| 6524 | } else { |
| 6525 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6526 | GetAssembler()->StoreDToOffset(DRegisterFrom(source), sp, destination.GetStackIndex()); |
| 6527 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6528 | } else { |
| 6529 | DCHECK(source.IsConstant()) << source; |
| 6530 | HConstant* constant = source.GetConstant(); |
| 6531 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 6532 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
| 6533 | if (destination.IsRegister()) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6534 | __ Mov(RegisterFrom(destination), value); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6535 | } else { |
| 6536 | DCHECK(destination.IsStackSlot()); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6537 | vixl32::Register temp = temps.Acquire(); |
| 6538 | __ Mov(temp, value); |
| 6539 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6540 | } |
| 6541 | } else if (constant->IsLongConstant()) { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6542 | int64_t value = Int64ConstantFrom(source); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6543 | if (destination.IsRegisterPair()) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6544 | __ Mov(LowRegisterFrom(destination), Low32Bits(value)); |
| 6545 | __ Mov(HighRegisterFrom(destination), High32Bits(value)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6546 | } else { |
| 6547 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6548 | vixl32::Register temp = temps.Acquire(); |
| 6549 | __ Mov(temp, Low32Bits(value)); |
| 6550 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6551 | __ Mov(temp, High32Bits(value)); |
| 6552 | GetAssembler()->StoreToOffset(kStoreWord, |
| 6553 | temp, |
| 6554 | sp, |
| 6555 | destination.GetHighStackIndex(kArmWordSize)); |
| 6556 | } |
| 6557 | } else if (constant->IsDoubleConstant()) { |
| 6558 | double value = constant->AsDoubleConstant()->GetValue(); |
| 6559 | if (destination.IsFpuRegisterPair()) { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6560 | __ Vmov(DRegisterFrom(destination), value); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6561 | } else { |
| 6562 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6563 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6564 | vixl32::Register temp = temps.Acquire(); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6565 | __ Mov(temp, Low32Bits(int_value)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6566 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6567 | __ Mov(temp, High32Bits(int_value)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6568 | GetAssembler()->StoreToOffset(kStoreWord, |
| 6569 | temp, |
| 6570 | sp, |
| 6571 | destination.GetHighStackIndex(kArmWordSize)); |
| 6572 | } |
| 6573 | } else { |
| 6574 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
| 6575 | float value = constant->AsFloatConstant()->GetValue(); |
| 6576 | if (destination.IsFpuRegister()) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6577 | __ Vmov(SRegisterFrom(destination), value); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6578 | } else { |
| 6579 | DCHECK(destination.IsStackSlot()); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6580 | vixl32::Register temp = temps.Acquire(); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6581 | __ Mov(temp, bit_cast<int32_t, float>(value)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6582 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6583 | } |
| 6584 | } |
| 6585 | } |
| 6586 | } |
| 6587 | |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6588 | void ParallelMoveResolverARMVIXL::Exchange(vixl32::Register reg, int mem) { |
| 6589 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 6590 | vixl32::Register temp = temps.Acquire(); |
| 6591 | __ Mov(temp, reg); |
| 6592 | GetAssembler()->LoadFromOffset(kLoadWord, reg, sp, mem); |
| 6593 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6594 | } |
| 6595 | |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6596 | void ParallelMoveResolverARMVIXL::Exchange(int mem1, int mem2) { |
| 6597 | // TODO(VIXL32): Double check the performance of this implementation. |
| 6598 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6599 | vixl32::Register temp1 = temps.Acquire(); |
| 6600 | ScratchRegisterScope ensure_scratch( |
| 6601 | this, temp1.GetCode(), r0.GetCode(), codegen_->GetNumberOfCoreRegisters()); |
| 6602 | vixl32::Register temp2(ensure_scratch.GetRegister()); |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6603 | |
| Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6604 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 6605 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, sp, mem1 + stack_offset); |
| 6606 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, sp, mem2 + stack_offset); |
| 6607 | GetAssembler()->StoreToOffset(kStoreWord, temp1, sp, mem2 + stack_offset); |
| 6608 | GetAssembler()->StoreToOffset(kStoreWord, temp2, sp, mem1 + stack_offset); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6609 | } |
| 6610 | |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6611 | void ParallelMoveResolverARMVIXL::EmitSwap(size_t index) { |
| 6612 | MoveOperands* move = moves_[index]; |
| 6613 | Location source = move->GetSource(); |
| 6614 | Location destination = move->GetDestination(); |
| 6615 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 6616 | |
| 6617 | if (source.IsRegister() && destination.IsRegister()) { |
| 6618 | vixl32::Register temp = temps.Acquire(); |
| 6619 | DCHECK(!RegisterFrom(source).Is(temp)); |
| 6620 | DCHECK(!RegisterFrom(destination).Is(temp)); |
| 6621 | __ Mov(temp, RegisterFrom(destination)); |
| 6622 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 6623 | __ Mov(RegisterFrom(source), temp); |
| 6624 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| 6625 | Exchange(RegisterFrom(source), destination.GetStackIndex()); |
| 6626 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| 6627 | Exchange(RegisterFrom(destination), source.GetStackIndex()); |
| 6628 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 6629 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6630 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6631 | vixl32::Register temp = temps.Acquire(); |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 6632 | __ Vmov(temp, SRegisterFrom(source)); |
| 6633 | __ Vmov(SRegisterFrom(source), SRegisterFrom(destination)); |
| 6634 | __ Vmov(SRegisterFrom(destination), temp); |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6635 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
| 6636 | vixl32::DRegister temp = temps.AcquireD(); |
| 6637 | __ Vmov(temp, LowRegisterFrom(source), HighRegisterFrom(source)); |
| 6638 | __ Mov(LowRegisterFrom(source), LowRegisterFrom(destination)); |
| 6639 | __ Mov(HighRegisterFrom(source), HighRegisterFrom(destination)); |
| 6640 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), temp); |
| 6641 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
| 6642 | vixl32::Register low_reg = LowRegisterFrom(source.IsRegisterPair() ? source : destination); |
| 6643 | int mem = source.IsRegisterPair() ? destination.GetStackIndex() : source.GetStackIndex(); |
| 6644 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
| 6645 | vixl32::DRegister temp = temps.AcquireD(); |
| 6646 | __ Vmov(temp, low_reg, vixl32::Register(low_reg.GetCode() + 1)); |
| 6647 | GetAssembler()->LoadFromOffset(kLoadWordPair, low_reg, sp, mem); |
| 6648 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
| 6649 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6650 | vixl32::DRegister first = DRegisterFrom(source); |
| 6651 | vixl32::DRegister second = DRegisterFrom(destination); |
| 6652 | vixl32::DRegister temp = temps.AcquireD(); |
| 6653 | __ Vmov(temp, first); |
| 6654 | __ Vmov(first, second); |
| 6655 | __ Vmov(second, temp); |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6656 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 6657 | vixl32::DRegister reg = source.IsFpuRegisterPair() |
| 6658 | ? DRegisterFrom(source) |
| 6659 | : DRegisterFrom(destination); |
| 6660 | int mem = source.IsFpuRegisterPair() |
| 6661 | ? destination.GetStackIndex() |
| 6662 | : source.GetStackIndex(); |
| 6663 | vixl32::DRegister temp = temps.AcquireD(); |
| 6664 | __ Vmov(temp, reg); |
| 6665 | GetAssembler()->LoadDFromOffset(reg, sp, mem); |
| 6666 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6667 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 6668 | vixl32::SRegister reg = source.IsFpuRegister() |
| 6669 | ? SRegisterFrom(source) |
| 6670 | : SRegisterFrom(destination); |
| 6671 | int mem = source.IsFpuRegister() |
| 6672 | ? destination.GetStackIndex() |
| 6673 | : source.GetStackIndex(); |
| 6674 | vixl32::Register temp = temps.Acquire(); |
| 6675 | __ Vmov(temp, reg); |
| 6676 | GetAssembler()->LoadSFromOffset(reg, sp, mem); |
| 6677 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6678 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 6679 | vixl32::DRegister temp1 = temps.AcquireD(); |
| 6680 | vixl32::DRegister temp2 = temps.AcquireD(); |
| 6681 | __ Vldr(temp1, MemOperand(sp, source.GetStackIndex())); |
| 6682 | __ Vldr(temp2, MemOperand(sp, destination.GetStackIndex())); |
| 6683 | __ Vstr(temp1, MemOperand(sp, destination.GetStackIndex())); |
| 6684 | __ Vstr(temp2, MemOperand(sp, source.GetStackIndex())); |
| 6685 | } else { |
| 6686 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
| 6687 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6688 | } |
| 6689 | |
| Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6690 | void ParallelMoveResolverARMVIXL::SpillScratch(int reg) { |
| 6691 | __ Push(vixl32::Register(reg)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6692 | } |
| 6693 | |
| Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6694 | void ParallelMoveResolverARMVIXL::RestoreScratch(int reg) { |
| 6695 | __ Pop(vixl32::Register(reg)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6696 | } |
| 6697 | |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6698 | HLoadClass::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadClassKind( |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6699 | HLoadClass::LoadKind desired_class_load_kind) { |
| 6700 | switch (desired_class_load_kind) { |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6701 | case HLoadClass::LoadKind::kInvalid: |
| 6702 | LOG(FATAL) << "UNREACHABLE"; |
| 6703 | UNREACHABLE(); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6704 | case HLoadClass::LoadKind::kReferrersClass: |
| 6705 | break; |
| 6706 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6707 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6708 | break; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6709 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 6710 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6711 | break; |
| 6712 | case HLoadClass::LoadKind::kBootImageAddress: |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6713 | break; |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6714 | case HLoadClass::LoadKind::kBssEntry: |
| 6715 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 6716 | break; |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6717 | case HLoadClass::LoadKind::kJitTableAddress: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6718 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6719 | break; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6720 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 6721 | break; |
| 6722 | } |
| 6723 | return desired_class_load_kind; |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6724 | } |
| 6725 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6726 | void LocationsBuilderARMVIXL::VisitLoadClass(HLoadClass* cls) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6727 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6728 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6729 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6730 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6731 | cls, |
| 6732 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6733 | LocationFrom(r0)); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6734 | DCHECK(calling_convention.GetRegisterAt(0).Is(r0)); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6735 | return; |
| 6736 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6737 | DCHECK(!cls->NeedsAccessCheck()); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6738 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6739 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6740 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6741 | ? LocationSummary::kCallOnSlowPath |
| 6742 | : LocationSummary::kNoCall; |
| 6743 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6744 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6745 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6746 | } |
| 6747 | |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6748 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6749 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6750 | } |
| 6751 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6752 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6753 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6754 | // Rely on the type resolution or initialization and marking to save everything we need. |
| 6755 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 6756 | // to the custom calling convention) or by marking, so we request a different temp. |
| 6757 | locations->AddTemp(Location::RequiresRegister()); |
| 6758 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6759 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 6760 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 6761 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 6762 | // that the the kPrimNot result register is the same as the first argument register. |
| 6763 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6764 | } else { |
| 6765 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6766 | } |
| 6767 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6768 | } |
| 6769 | |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6770 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6771 | // move. |
| 6772 | void InstructionCodeGeneratorARMVIXL::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6773 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6774 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 6775 | codegen_->GenerateLoadClassRuntimeCall(cls); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6776 | return; |
| 6777 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6778 | DCHECK(!cls->NeedsAccessCheck()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6779 | |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6780 | LocationSummary* locations = cls->GetLocations(); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6781 | Location out_loc = locations->Out(); |
| 6782 | vixl32::Register out = OutputRegister(cls); |
| 6783 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6784 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6785 | ? kWithoutReadBarrier |
| 6786 | : kCompilerReadBarrierOption; |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6787 | bool generate_null_check = false; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6788 | switch (load_kind) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6789 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6790 | DCHECK(!cls->CanCallRuntime()); |
| 6791 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6792 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6793 | vixl32::Register current_method = InputRegisterAt(cls, 0); |
| 6794 | GenerateGcRootFieldLoad(cls, |
| 6795 | out_loc, |
| 6796 | current_method, |
| Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6797 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6798 | read_barrier_option); |
| 6799 | break; |
| 6800 | } |
| 6801 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6802 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6803 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 6804 | __ Ldr(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 6805 | cls->GetTypeIndex())); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6806 | break; |
| 6807 | } |
| 6808 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6809 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6810 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 6811 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 6812 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 6813 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 6814 | break; |
| 6815 | } |
| 6816 | case HLoadClass::LoadKind::kBootImageAddress: { |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6817 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6818 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6819 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 6820 | DCHECK_NE(address, 0u); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6821 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6822 | break; |
| 6823 | } |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6824 | case HLoadClass::LoadKind::kBssEntry: { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6825 | vixl32::Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 6826 | ? RegisterFrom(locations->GetTemp(0)) |
| 6827 | : out; |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6828 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 6829 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6830 | codegen_->EmitMovwMovtPlaceholder(labels, temp); |
| 6831 | GenerateGcRootFieldLoad(cls, out_loc, temp, /* offset */ 0, read_barrier_option); |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6832 | generate_null_check = true; |
| 6833 | break; |
| 6834 | } |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6835 | case HLoadClass::LoadKind::kJitTableAddress: { |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6836 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 6837 | cls->GetTypeIndex(), |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6838 | cls->GetClass())); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6839 | // /* GcRoot<mirror::Class> */ out = *out |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6840 | GenerateGcRootFieldLoad(cls, out_loc, out, /* offset */ 0, read_barrier_option); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6841 | break; |
| 6842 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6843 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6844 | case HLoadClass::LoadKind::kInvalid: |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6845 | LOG(FATAL) << "UNREACHABLE"; |
| 6846 | UNREACHABLE(); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6847 | } |
| 6848 | |
| 6849 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6850 | DCHECK(cls->CanCallRuntime()); |
| 6851 | LoadClassSlowPathARMVIXL* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARMVIXL( |
| 6852 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6853 | codegen_->AddSlowPath(slow_path); |
| 6854 | if (generate_null_check) { |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6855 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6856 | } |
| 6857 | if (cls->MustGenerateClinitCheck()) { |
| 6858 | GenerateClassInitializationCheck(slow_path, out); |
| 6859 | } else { |
| 6860 | __ Bind(slow_path->GetExitLabel()); |
| 6861 | } |
| 6862 | } |
| 6863 | } |
| 6864 | |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6865 | void LocationsBuilderARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 6866 | LocationSummary* locations = |
| 6867 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 6868 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6869 | if (check->HasUses()) { |
| 6870 | locations->SetOut(Location::SameAsFirstInput()); |
| 6871 | } |
| 6872 | } |
| 6873 | |
| 6874 | void InstructionCodeGeneratorARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 6875 | // We assume the class is not null. |
| 6876 | LoadClassSlowPathARMVIXL* slow_path = |
| 6877 | new (GetGraph()->GetArena()) LoadClassSlowPathARMVIXL(check->GetLoadClass(), |
| 6878 | check, |
| 6879 | check->GetDexPc(), |
| 6880 | /* do_clinit */ true); |
| 6881 | codegen_->AddSlowPath(slow_path); |
| 6882 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 6883 | } |
| 6884 | |
| 6885 | void InstructionCodeGeneratorARMVIXL::GenerateClassInitializationCheck( |
| 6886 | LoadClassSlowPathARMVIXL* slow_path, vixl32::Register class_reg) { |
| 6887 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6888 | vixl32::Register temp = temps.Acquire(); |
| 6889 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 6890 | temp, |
| 6891 | class_reg, |
| 6892 | mirror::Class::StatusOffset().Int32Value()); |
| 6893 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 6894 | __ B(lt, slow_path->GetEntryLabel()); |
| 6895 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 6896 | // properly. Therefore, we do a memory fence. |
| 6897 | __ Dmb(ISH); |
| 6898 | __ Bind(slow_path->GetExitLabel()); |
| 6899 | } |
| 6900 | |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6901 | HLoadString::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadStringKind( |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6902 | HLoadString::LoadKind desired_string_load_kind) { |
| 6903 | switch (desired_string_load_kind) { |
| 6904 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6905 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6906 | break; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6907 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 6908 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6909 | break; |
| 6910 | case HLoadString::LoadKind::kBootImageAddress: |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6911 | break; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6912 | case HLoadString::LoadKind::kBssEntry: |
| 6913 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 6914 | break; |
| 6915 | case HLoadString::LoadKind::kJitTableAddress: |
| 6916 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6917 | break; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6918 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 6919 | break; |
| 6920 | } |
| 6921 | return desired_string_load_kind; |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6922 | } |
| 6923 | |
| 6924 | void LocationsBuilderARMVIXL::VisitLoadString(HLoadString* load) { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6925 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6926 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6927 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 6928 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6929 | locations->SetOut(LocationFrom(r0)); |
| 6930 | } else { |
| 6931 | locations->SetOut(Location::RequiresRegister()); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6932 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6933 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6934 | // Rely on the pResolveString and marking to save everything we need, including temps. |
| 6935 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 6936 | // 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] | 6937 | locations->AddTemp(Location::RequiresRegister()); |
| 6938 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6939 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 6940 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 6941 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 6942 | // that the the kPrimNot result register is the same as the first argument register. |
| 6943 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6944 | } else { |
| 6945 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6946 | } |
| 6947 | } |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6948 | } |
| 6949 | } |
| 6950 | |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6951 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6952 | // move. |
| 6953 | void InstructionCodeGeneratorARMVIXL::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6954 | LocationSummary* locations = load->GetLocations(); |
| 6955 | Location out_loc = locations->Out(); |
| 6956 | vixl32::Register out = OutputRegister(load); |
| 6957 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 6958 | |
| 6959 | switch (load_kind) { |
| 6960 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6961 | __ Ldr(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 6962 | load->GetStringIndex())); |
| 6963 | return; // No dex cache slow path. |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6964 | } |
| 6965 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 6966 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| 6967 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6968 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6969 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 6970 | return; // No dex cache slow path. |
| 6971 | } |
| 6972 | case HLoadString::LoadKind::kBootImageAddress: { |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6973 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6974 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6975 | DCHECK_NE(address, 0u); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6976 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 6977 | return; // No dex cache slow path. |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6978 | } |
| 6979 | case HLoadString::LoadKind::kBssEntry: { |
| 6980 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6981 | vixl32::Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 6982 | ? RegisterFrom(locations->GetTemp(0)) |
| 6983 | : out; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6984 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6985 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6986 | codegen_->EmitMovwMovtPlaceholder(labels, temp); |
| 6987 | GenerateGcRootFieldLoad(load, out_loc, temp, /* offset */ 0, kCompilerReadBarrierOption); |
| 6988 | LoadStringSlowPathARMVIXL* slow_path = |
| 6989 | new (GetGraph()->GetArena()) LoadStringSlowPathARMVIXL(load); |
| 6990 | codegen_->AddSlowPath(slow_path); |
| 6991 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 6992 | __ Bind(slow_path->GetExitLabel()); |
| 6993 | return; |
| 6994 | } |
| 6995 | case HLoadString::LoadKind::kJitTableAddress: { |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6996 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6997 | load->GetStringIndex(), |
| 6998 | load->GetString())); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6999 | // /* GcRoot<mirror::String> */ out = *out |
| 7000 | GenerateGcRootFieldLoad(load, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
| 7001 | return; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7002 | } |
| 7003 | default: |
| 7004 | break; |
| 7005 | } |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7006 | |
| 7007 | // TODO: Re-add the compiler code to do string dex cache lookup again. |
| 7008 | DCHECK_EQ(load->GetLoadKind(), HLoadString::LoadKind::kDexCacheViaMethod); |
| 7009 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7010 | __ Mov(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7011 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 7012 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 7013 | } |
| 7014 | |
| 7015 | static int32_t GetExceptionTlsOffset() { |
| 7016 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
| 7017 | } |
| 7018 | |
| 7019 | void LocationsBuilderARMVIXL::VisitLoadException(HLoadException* load) { |
| 7020 | LocationSummary* locations = |
| 7021 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 7022 | locations->SetOut(Location::RequiresRegister()); |
| 7023 | } |
| 7024 | |
| 7025 | void InstructionCodeGeneratorARMVIXL::VisitLoadException(HLoadException* load) { |
| 7026 | vixl32::Register out = OutputRegister(load); |
| 7027 | GetAssembler()->LoadFromOffset(kLoadWord, out, tr, GetExceptionTlsOffset()); |
| 7028 | } |
| 7029 | |
| 7030 | |
| 7031 | void LocationsBuilderARMVIXL::VisitClearException(HClearException* clear) { |
| 7032 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 7033 | } |
| 7034 | |
| 7035 | void InstructionCodeGeneratorARMVIXL::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 7036 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 7037 | vixl32::Register temp = temps.Acquire(); |
| 7038 | __ Mov(temp, 0); |
| 7039 | GetAssembler()->StoreToOffset(kStoreWord, temp, tr, GetExceptionTlsOffset()); |
| 7040 | } |
| 7041 | |
| 7042 | void LocationsBuilderARMVIXL::VisitThrow(HThrow* instruction) { |
| 7043 | LocationSummary* locations = |
| 7044 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| 7045 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7046 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7047 | } |
| 7048 | |
| 7049 | void InstructionCodeGeneratorARMVIXL::VisitThrow(HThrow* instruction) { |
| 7050 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| 7051 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 7052 | } |
| 7053 | |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7054 | // Temp is used for read barrier. |
| 7055 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 7056 | if (kEmitCompilerReadBarrier && |
| 7057 | (kUseBakerReadBarrier || |
| 7058 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7059 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7060 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 7061 | return 1; |
| 7062 | } |
| 7063 | return 0; |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7064 | } |
| 7065 | |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7066 | // Interface case has 3 temps, one for holding the number of interfaces, one for the current |
| 7067 | // interface pointer, one for loading the current interface. |
| 7068 | // The other checks have one temp for loading the object's class. |
| 7069 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 7070 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7071 | return 3; |
| 7072 | } |
| 7073 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 7074 | } |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7075 | |
| 7076 | void LocationsBuilderARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 7077 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7078 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7079 | bool baker_read_barrier_slow_path = false; |
| 7080 | switch (type_check_kind) { |
| 7081 | case TypeCheckKind::kExactCheck: |
| 7082 | case TypeCheckKind::kAbstractClassCheck: |
| 7083 | case TypeCheckKind::kClassHierarchyCheck: |
| 7084 | case TypeCheckKind::kArrayObjectCheck: |
| 7085 | call_kind = |
| 7086 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 7087 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
| 7088 | break; |
| 7089 | case TypeCheckKind::kArrayCheck: |
| 7090 | case TypeCheckKind::kUnresolvedCheck: |
| 7091 | case TypeCheckKind::kInterfaceCheck: |
| 7092 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7093 | break; |
| 7094 | } |
| 7095 | |
| 7096 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 7097 | if (baker_read_barrier_slow_path) { |
| 7098 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 7099 | } |
| 7100 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7101 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7102 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 7103 | // Note that TypeCheckSlowPathARM uses this register too. |
| 7104 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7105 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7106 | } |
| 7107 | |
| 7108 | void InstructionCodeGeneratorARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 7109 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7110 | LocationSummary* locations = instruction->GetLocations(); |
| 7111 | Location obj_loc = locations->InAt(0); |
| 7112 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 7113 | vixl32::Register cls = InputRegisterAt(instruction, 1); |
| 7114 | Location out_loc = locations->Out(); |
| 7115 | vixl32::Register out = OutputRegister(instruction); |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7116 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7117 | DCHECK_LE(num_temps, 1u); |
| 7118 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7119 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7120 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7121 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7122 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7123 | vixl32::Label done; |
| 7124 | vixl32::Label* const final_label = codegen_->GetFinalLabel(instruction, &done); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7125 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 7126 | |
| 7127 | // Return 0 if `obj` is null. |
| 7128 | // avoid null check if we know obj is not null. |
| 7129 | if (instruction->MustDoNullCheck()) { |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7130 | DCHECK(!out.Is(obj)); |
| 7131 | __ Mov(out, 0); |
| 7132 | __ CompareAndBranchIfZero(obj, final_label, /* far_target */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7133 | } |
| 7134 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7135 | switch (type_check_kind) { |
| 7136 | case TypeCheckKind::kExactCheck: { |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7137 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7138 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7139 | out_loc, |
| 7140 | obj_loc, |
| 7141 | class_offset, |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7142 | maybe_temp_loc, |
| 7143 | kCompilerReadBarrierOption); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7144 | // Classes must be equal for the instanceof to succeed. |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7145 | __ Cmp(out, cls); |
| 7146 | // We speculatively set the result to false without changing the condition |
| 7147 | // flags, which allows us to avoid some branching later. |
| 7148 | __ Mov(LeaveFlags, out, 0); |
| 7149 | |
| 7150 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7151 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7152 | // encoding can be used. |
| 7153 | if (out.IsLow()) { |
| 7154 | // We use the scope because of the IT block that follows. |
| 7155 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7156 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7157 | CodeBufferCheckScope::kExactSize); |
| 7158 | |
| 7159 | __ it(eq); |
| 7160 | __ mov(eq, out, 1); |
| 7161 | } else { |
| 7162 | __ B(ne, final_label, /* far_target */ false); |
| 7163 | __ Mov(out, 1); |
| 7164 | } |
| 7165 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7166 | break; |
| 7167 | } |
| 7168 | |
| 7169 | case TypeCheckKind::kAbstractClassCheck: { |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7170 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7171 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7172 | out_loc, |
| 7173 | obj_loc, |
| 7174 | class_offset, |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7175 | maybe_temp_loc, |
| 7176 | kCompilerReadBarrierOption); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7177 | // If the class is abstract, we eagerly fetch the super class of the |
| 7178 | // object to avoid doing a comparison we know will fail. |
| 7179 | vixl32::Label loop; |
| 7180 | __ Bind(&loop); |
| 7181 | // /* HeapReference<Class> */ out = out->super_class_ |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7182 | GenerateReferenceLoadOneRegister(instruction, |
| 7183 | out_loc, |
| 7184 | super_offset, |
| 7185 | maybe_temp_loc, |
| 7186 | kCompilerReadBarrierOption); |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7187 | // 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] | 7188 | __ CompareAndBranchIfZero(out, final_label, /* far_target */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7189 | __ Cmp(out, cls); |
| Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7190 | __ B(ne, &loop, /* far_target */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7191 | __ Mov(out, 1); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7192 | break; |
| 7193 | } |
| 7194 | |
| 7195 | case TypeCheckKind::kClassHierarchyCheck: { |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7196 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7197 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7198 | out_loc, |
| 7199 | obj_loc, |
| 7200 | class_offset, |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7201 | maybe_temp_loc, |
| 7202 | kCompilerReadBarrierOption); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7203 | // Walk over the class hierarchy to find a match. |
| 7204 | vixl32::Label loop, success; |
| 7205 | __ Bind(&loop); |
| 7206 | __ Cmp(out, cls); |
| Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7207 | __ B(eq, &success, /* far_target */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7208 | // /* HeapReference<Class> */ out = out->super_class_ |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7209 | GenerateReferenceLoadOneRegister(instruction, |
| 7210 | out_loc, |
| 7211 | super_offset, |
| 7212 | maybe_temp_loc, |
| 7213 | kCompilerReadBarrierOption); |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7214 | // This is essentially a null check, but it sets the condition flags to the |
| 7215 | // proper value for the code that follows the loop, i.e. not `eq`. |
| 7216 | __ Cmp(out, 1); |
| 7217 | __ B(hs, &loop, /* far_target */ false); |
| 7218 | |
| 7219 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7220 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7221 | // encoding can be used. |
| 7222 | if (out.IsLow()) { |
| 7223 | // If `out` is null, we use it for the result, and the condition flags |
| 7224 | // have already been set to `ne`, so the IT block that comes afterwards |
| 7225 | // (and which handles the successful case) turns into a NOP (instead of |
| 7226 | // overwriting `out`). |
| 7227 | __ Bind(&success); |
| 7228 | |
| 7229 | // We use the scope because of the IT block that follows. |
| 7230 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7231 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7232 | CodeBufferCheckScope::kExactSize); |
| 7233 | |
| 7234 | // There is only one branch to the `success` label (which is bound to this |
| 7235 | // IT block), and it has the same condition, `eq`, so in that case the MOV |
| 7236 | // is executed. |
| 7237 | __ it(eq); |
| 7238 | __ mov(eq, out, 1); |
| 7239 | } else { |
| 7240 | // 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] | 7241 | __ B(final_label); |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7242 | __ Bind(&success); |
| 7243 | __ Mov(out, 1); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7244 | } |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7245 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7246 | break; |
| 7247 | } |
| 7248 | |
| 7249 | case TypeCheckKind::kArrayObjectCheck: { |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7250 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7251 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7252 | out_loc, |
| 7253 | obj_loc, |
| 7254 | class_offset, |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7255 | maybe_temp_loc, |
| 7256 | kCompilerReadBarrierOption); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7257 | // Do an exact check. |
| 7258 | vixl32::Label exact_check; |
| 7259 | __ Cmp(out, cls); |
| Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7260 | __ B(eq, &exact_check, /* far_target */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7261 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 7262 | // /* HeapReference<Class> */ out = out->component_type_ |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7263 | GenerateReferenceLoadOneRegister(instruction, |
| 7264 | out_loc, |
| 7265 | component_offset, |
| 7266 | maybe_temp_loc, |
| 7267 | kCompilerReadBarrierOption); |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7268 | // 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] | 7269 | __ CompareAndBranchIfZero(out, final_label, /* far_target */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7270 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 7271 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7272 | __ Cmp(out, 0); |
| 7273 | // We speculatively set the result to false without changing the condition |
| 7274 | // flags, which allows us to avoid some branching later. |
| 7275 | __ Mov(LeaveFlags, out, 0); |
| 7276 | |
| 7277 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7278 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7279 | // encoding can be used. |
| 7280 | if (out.IsLow()) { |
| 7281 | __ Bind(&exact_check); |
| 7282 | |
| 7283 | // We use the scope because of the IT block that follows. |
| 7284 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7285 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7286 | CodeBufferCheckScope::kExactSize); |
| 7287 | |
| 7288 | __ it(eq); |
| 7289 | __ mov(eq, out, 1); |
| 7290 | } else { |
| 7291 | __ B(ne, final_label, /* far_target */ false); |
| 7292 | __ Bind(&exact_check); |
| 7293 | __ Mov(out, 1); |
| 7294 | } |
| 7295 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7296 | break; |
| 7297 | } |
| 7298 | |
| 7299 | case TypeCheckKind::kArrayCheck: { |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7300 | // No read barrier since the slow path will retry upon failure. |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7301 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7302 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7303 | out_loc, |
| 7304 | obj_loc, |
| 7305 | class_offset, |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7306 | maybe_temp_loc, |
| 7307 | kWithoutReadBarrier); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7308 | __ Cmp(out, cls); |
| 7309 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 7310 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARMVIXL(instruction, |
| 7311 | /* is_fatal */ false); |
| 7312 | codegen_->AddSlowPath(slow_path); |
| 7313 | __ B(ne, slow_path->GetEntryLabel()); |
| 7314 | __ Mov(out, 1); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7315 | break; |
| 7316 | } |
| 7317 | |
| 7318 | case TypeCheckKind::kUnresolvedCheck: |
| 7319 | case TypeCheckKind::kInterfaceCheck: { |
| 7320 | // Note that we indeed only call on slow path, but we always go |
| 7321 | // into the slow path for the unresolved and interface check |
| 7322 | // cases. |
| 7323 | // |
| 7324 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7325 | // entry point without resorting to a type checking slow path |
| 7326 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7327 | // require to assign fixed registers for the inputs of this |
| 7328 | // HInstanceOf instruction (following the runtime calling |
| 7329 | // convention), which might be cluttered by the potential first |
| 7330 | // read barrier emission at the beginning of this method. |
| 7331 | // |
| 7332 | // TODO: Introduce a new runtime entry point taking the object |
| 7333 | // to test (instead of its class) as argument, and let it deal |
| 7334 | // with the read barrier issues. This will let us refactor this |
| 7335 | // case of the `switch` code as it was previously (with a direct |
| 7336 | // call to the runtime not using a type checking slow path). |
| 7337 | // This should also be beneficial for the other cases above. |
| 7338 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 7339 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARMVIXL(instruction, |
| 7340 | /* is_fatal */ false); |
| 7341 | codegen_->AddSlowPath(slow_path); |
| 7342 | __ B(slow_path->GetEntryLabel()); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7343 | break; |
| 7344 | } |
| 7345 | } |
| 7346 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7347 | if (done.IsReferenced()) { |
| 7348 | __ Bind(&done); |
| 7349 | } |
| 7350 | |
| 7351 | if (slow_path != nullptr) { |
| 7352 | __ Bind(slow_path->GetExitLabel()); |
| 7353 | } |
| 7354 | } |
| 7355 | |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7356 | void LocationsBuilderARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
| 7357 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7358 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 7359 | |
| 7360 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7361 | switch (type_check_kind) { |
| 7362 | case TypeCheckKind::kExactCheck: |
| 7363 | case TypeCheckKind::kAbstractClassCheck: |
| 7364 | case TypeCheckKind::kClassHierarchyCheck: |
| 7365 | case TypeCheckKind::kArrayObjectCheck: |
| 7366 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 7367 | LocationSummary::kCallOnSlowPath : |
| 7368 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
| 7369 | break; |
| 7370 | case TypeCheckKind::kArrayCheck: |
| 7371 | case TypeCheckKind::kUnresolvedCheck: |
| 7372 | case TypeCheckKind::kInterfaceCheck: |
| 7373 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7374 | break; |
| 7375 | } |
| 7376 | |
| 7377 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 7378 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7379 | locations->SetInAt(1, Location::RequiresRegister()); |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7380 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7381 | } |
| 7382 | |
| 7383 | void InstructionCodeGeneratorARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
| 7384 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7385 | LocationSummary* locations = instruction->GetLocations(); |
| 7386 | Location obj_loc = locations->InAt(0); |
| 7387 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 7388 | vixl32::Register cls = InputRegisterAt(instruction, 1); |
| 7389 | Location temp_loc = locations->GetTemp(0); |
| 7390 | vixl32::Register temp = RegisterFrom(temp_loc); |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7391 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 7392 | DCHECK_LE(num_temps, 3u); |
| 7393 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 7394 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 7395 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7396 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7397 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7398 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 7399 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 7400 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 7401 | const uint32_t object_array_data_offset = |
| 7402 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7403 | |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7404 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 7405 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 7406 | // read barriers is done for performance and code size reasons. |
| 7407 | bool is_type_check_slow_path_fatal = false; |
| 7408 | if (!kEmitCompilerReadBarrier) { |
| 7409 | is_type_check_slow_path_fatal = |
| 7410 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 7411 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7412 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7413 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 7414 | !instruction->CanThrowIntoCatchBlock(); |
| 7415 | } |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7416 | SlowPathCodeARMVIXL* type_check_slow_path = |
| 7417 | new (GetGraph()->GetArena()) TypeCheckSlowPathARMVIXL(instruction, |
| 7418 | is_type_check_slow_path_fatal); |
| 7419 | codegen_->AddSlowPath(type_check_slow_path); |
| 7420 | |
| 7421 | vixl32::Label done; |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7422 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7423 | // Avoid null check if we know obj is not null. |
| 7424 | if (instruction->MustDoNullCheck()) { |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7425 | __ CompareAndBranchIfZero(obj, final_label, /* far_target */ false); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7426 | } |
| 7427 | |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7428 | switch (type_check_kind) { |
| 7429 | case TypeCheckKind::kExactCheck: |
| 7430 | case TypeCheckKind::kArrayCheck: { |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7431 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7432 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7433 | temp_loc, |
| 7434 | obj_loc, |
| 7435 | class_offset, |
| 7436 | maybe_temp2_loc, |
| 7437 | kWithoutReadBarrier); |
| 7438 | |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7439 | __ Cmp(temp, cls); |
| 7440 | // Jump to slow path for throwing the exception or doing a |
| 7441 | // more involved array check. |
| 7442 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 7443 | break; |
| 7444 | } |
| 7445 | |
| 7446 | case TypeCheckKind::kAbstractClassCheck: { |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7447 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7448 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7449 | temp_loc, |
| 7450 | obj_loc, |
| 7451 | class_offset, |
| 7452 | maybe_temp2_loc, |
| 7453 | kWithoutReadBarrier); |
| 7454 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7455 | // If the class is abstract, we eagerly fetch the super class of the |
| 7456 | // object to avoid doing a comparison we know will fail. |
| 7457 | vixl32::Label loop; |
| 7458 | __ Bind(&loop); |
| 7459 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7460 | GenerateReferenceLoadOneRegister(instruction, |
| 7461 | temp_loc, |
| 7462 | super_offset, |
| 7463 | maybe_temp2_loc, |
| 7464 | kWithoutReadBarrier); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7465 | |
| 7466 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7467 | // exception. |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7468 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7469 | |
| 7470 | // Otherwise, compare the classes. |
| 7471 | __ Cmp(temp, cls); |
| Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7472 | __ B(ne, &loop, /* far_target */ false); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7473 | break; |
| 7474 | } |
| 7475 | |
| 7476 | case TypeCheckKind::kClassHierarchyCheck: { |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7477 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7478 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7479 | temp_loc, |
| 7480 | obj_loc, |
| 7481 | class_offset, |
| 7482 | maybe_temp2_loc, |
| 7483 | kWithoutReadBarrier); |
| 7484 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7485 | // Walk over the class hierarchy to find a match. |
| 7486 | vixl32::Label loop; |
| 7487 | __ Bind(&loop); |
| 7488 | __ Cmp(temp, cls); |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7489 | __ B(eq, final_label, /* far_target */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7490 | |
| 7491 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7492 | GenerateReferenceLoadOneRegister(instruction, |
| 7493 | temp_loc, |
| 7494 | super_offset, |
| 7495 | maybe_temp2_loc, |
| 7496 | kWithoutReadBarrier); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7497 | |
| 7498 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7499 | // exception. |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7500 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7501 | // Otherwise, jump to the beginning of the loop. |
| 7502 | __ B(&loop); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7503 | break; |
| 7504 | } |
| 7505 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7506 | case TypeCheckKind::kArrayObjectCheck: { |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7507 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7508 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7509 | temp_loc, |
| 7510 | obj_loc, |
| 7511 | class_offset, |
| 7512 | maybe_temp2_loc, |
| 7513 | kWithoutReadBarrier); |
| 7514 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7515 | // Do an exact check. |
| 7516 | __ Cmp(temp, cls); |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7517 | __ B(eq, final_label, /* far_target */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7518 | |
| 7519 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 7520 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7521 | GenerateReferenceLoadOneRegister(instruction, |
| 7522 | temp_loc, |
| 7523 | component_offset, |
| 7524 | maybe_temp2_loc, |
| 7525 | kWithoutReadBarrier); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7526 | // 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] | 7527 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7528 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 7529 | // to further check that this component type is not a primitive type. |
| 7530 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| 7531 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7532 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7533 | break; |
| 7534 | } |
| 7535 | |
| 7536 | case TypeCheckKind::kUnresolvedCheck: |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7537 | // 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] | 7538 | // We cannot directly call the CheckCast runtime entry point |
| 7539 | // without resorting to a type checking slow path here (i.e. by |
| 7540 | // calling InvokeRuntime directly), as it would require to |
| 7541 | // assign fixed registers for the inputs of this HInstanceOf |
| 7542 | // instruction (following the runtime calling convention), which |
| 7543 | // might be cluttered by the potential first read barrier |
| 7544 | // emission at the beginning of this method. |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7545 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7546 | __ B(type_check_slow_path->GetEntryLabel()); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7547 | break; |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7548 | |
| 7549 | case TypeCheckKind::kInterfaceCheck: { |
| 7550 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 7551 | // positives by doing this. |
| 7552 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7553 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7554 | temp_loc, |
| 7555 | obj_loc, |
| 7556 | class_offset, |
| 7557 | maybe_temp2_loc, |
| 7558 | kWithoutReadBarrier); |
| 7559 | |
| 7560 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 7561 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7562 | temp_loc, |
| 7563 | temp_loc, |
| 7564 | iftable_offset, |
| 7565 | maybe_temp2_loc, |
| 7566 | kWithoutReadBarrier); |
| 7567 | // Iftable is never null. |
| 7568 | __ Ldr(RegisterFrom(maybe_temp2_loc), MemOperand(temp, array_length_offset)); |
| 7569 | // Loop through the iftable and check if any class matches. |
| 7570 | vixl32::Label start_loop; |
| 7571 | __ Bind(&start_loop); |
| 7572 | __ CompareAndBranchIfZero(RegisterFrom(maybe_temp2_loc), |
| 7573 | type_check_slow_path->GetEntryLabel()); |
| 7574 | __ Ldr(RegisterFrom(maybe_temp3_loc), MemOperand(temp, object_array_data_offset)); |
| 7575 | GetAssembler()->MaybeUnpoisonHeapReference(RegisterFrom(maybe_temp3_loc)); |
| 7576 | // Go to next interface. |
| 7577 | __ Add(temp, temp, Operand::From(2 * kHeapReferenceSize)); |
| 7578 | __ Sub(RegisterFrom(maybe_temp2_loc), RegisterFrom(maybe_temp2_loc), 2); |
| 7579 | // Compare the classes and continue the loop if they do not match. |
| 7580 | __ Cmp(cls, RegisterFrom(maybe_temp3_loc)); |
| Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7581 | __ B(ne, &start_loop, /* far_target */ false); |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7582 | break; |
| 7583 | } |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7584 | } |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7585 | if (done.IsReferenced()) { |
| 7586 | __ Bind(&done); |
| 7587 | } |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7588 | |
| 7589 | __ Bind(type_check_slow_path->GetExitLabel()); |
| 7590 | } |
| 7591 | |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 7592 | void LocationsBuilderARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 7593 | LocationSummary* locations = |
| 7594 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| 7595 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7596 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7597 | } |
| 7598 | |
| 7599 | void InstructionCodeGeneratorARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 7600 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 7601 | instruction, |
| 7602 | instruction->GetDexPc()); |
| 7603 | if (instruction->IsEnter()) { |
| 7604 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 7605 | } else { |
| 7606 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 7607 | } |
| 7608 | } |
| 7609 | |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 7610 | void LocationsBuilderARMVIXL::VisitAnd(HAnd* instruction) { |
| 7611 | HandleBitwiseOperation(instruction, AND); |
| 7612 | } |
| 7613 | |
| 7614 | void LocationsBuilderARMVIXL::VisitOr(HOr* instruction) { |
| 7615 | HandleBitwiseOperation(instruction, ORR); |
| 7616 | } |
| 7617 | |
| 7618 | void LocationsBuilderARMVIXL::VisitXor(HXor* instruction) { |
| 7619 | HandleBitwiseOperation(instruction, EOR); |
| 7620 | } |
| 7621 | |
| 7622 | void LocationsBuilderARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
| 7623 | LocationSummary* locations = |
| 7624 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7625 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 7626 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 7627 | // Note: GVN reorders commutative operations to have the constant on the right hand side. |
| 7628 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7629 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
| 7630 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7631 | } |
| 7632 | |
| 7633 | void InstructionCodeGeneratorARMVIXL::VisitAnd(HAnd* instruction) { |
| 7634 | HandleBitwiseOperation(instruction); |
| 7635 | } |
| 7636 | |
| 7637 | void InstructionCodeGeneratorARMVIXL::VisitOr(HOr* instruction) { |
| 7638 | HandleBitwiseOperation(instruction); |
| 7639 | } |
| 7640 | |
| 7641 | void InstructionCodeGeneratorARMVIXL::VisitXor(HXor* instruction) { |
| 7642 | HandleBitwiseOperation(instruction); |
| 7643 | } |
| 7644 | |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 7645 | void LocationsBuilderARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 7646 | LocationSummary* locations = |
| 7647 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7648 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 7649 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 7650 | |
| 7651 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7652 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7653 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7654 | } |
| 7655 | |
| 7656 | void InstructionCodeGeneratorARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 7657 | LocationSummary* locations = instruction->GetLocations(); |
| 7658 | Location first = locations->InAt(0); |
| 7659 | Location second = locations->InAt(1); |
| 7660 | Location out = locations->Out(); |
| 7661 | |
| 7662 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 7663 | vixl32::Register first_reg = RegisterFrom(first); |
| 7664 | vixl32::Register second_reg = RegisterFrom(second); |
| 7665 | vixl32::Register out_reg = RegisterFrom(out); |
| 7666 | |
| 7667 | switch (instruction->GetOpKind()) { |
| 7668 | case HInstruction::kAnd: |
| 7669 | __ Bic(out_reg, first_reg, second_reg); |
| 7670 | break; |
| 7671 | case HInstruction::kOr: |
| 7672 | __ Orn(out_reg, first_reg, second_reg); |
| 7673 | break; |
| 7674 | // There is no EON on arm. |
| 7675 | case HInstruction::kXor: |
| 7676 | default: |
| 7677 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 7678 | UNREACHABLE(); |
| 7679 | } |
| 7680 | return; |
| 7681 | |
| 7682 | } else { |
| 7683 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 7684 | vixl32::Register first_low = LowRegisterFrom(first); |
| 7685 | vixl32::Register first_high = HighRegisterFrom(first); |
| 7686 | vixl32::Register second_low = LowRegisterFrom(second); |
| 7687 | vixl32::Register second_high = HighRegisterFrom(second); |
| 7688 | vixl32::Register out_low = LowRegisterFrom(out); |
| 7689 | vixl32::Register out_high = HighRegisterFrom(out); |
| 7690 | |
| 7691 | switch (instruction->GetOpKind()) { |
| 7692 | case HInstruction::kAnd: |
| 7693 | __ Bic(out_low, first_low, second_low); |
| 7694 | __ Bic(out_high, first_high, second_high); |
| 7695 | break; |
| 7696 | case HInstruction::kOr: |
| 7697 | __ Orn(out_low, first_low, second_low); |
| 7698 | __ Orn(out_high, first_high, second_high); |
| 7699 | break; |
| 7700 | // There is no EON on arm. |
| 7701 | case HInstruction::kXor: |
| 7702 | default: |
| 7703 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 7704 | UNREACHABLE(); |
| 7705 | } |
| 7706 | } |
| 7707 | } |
| 7708 | |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 7709 | void LocationsBuilderARMVIXL::VisitDataProcWithShifterOp( |
| 7710 | HDataProcWithShifterOp* instruction) { |
| 7711 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 7712 | instruction->GetType() == Primitive::kPrimLong); |
| 7713 | LocationSummary* locations = |
| 7714 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7715 | const bool overlap = instruction->GetType() == Primitive::kPrimLong && |
| 7716 | HDataProcWithShifterOp::IsExtensionOp(instruction->GetOpKind()); |
| 7717 | |
| 7718 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7719 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7720 | locations->SetOut(Location::RequiresRegister(), |
| 7721 | overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 7722 | } |
| 7723 | |
| 7724 | void InstructionCodeGeneratorARMVIXL::VisitDataProcWithShifterOp( |
| 7725 | HDataProcWithShifterOp* instruction) { |
| 7726 | const LocationSummary* const locations = instruction->GetLocations(); |
| 7727 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 7728 | const HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 7729 | |
| 7730 | if (instruction->GetType() == Primitive::kPrimInt) { |
| 7731 | DCHECK(!HDataProcWithShifterOp::IsExtensionOp(op_kind)); |
| 7732 | |
| 7733 | const vixl32::Register second = instruction->InputAt(1)->GetType() == Primitive::kPrimLong |
| 7734 | ? LowRegisterFrom(locations->InAt(1)) |
| 7735 | : InputRegisterAt(instruction, 1); |
| 7736 | |
| 7737 | GenerateDataProcInstruction(kind, |
| 7738 | OutputRegister(instruction), |
| 7739 | InputRegisterAt(instruction, 0), |
| 7740 | Operand(second, |
| 7741 | ShiftFromOpKind(op_kind), |
| 7742 | instruction->GetShiftAmount()), |
| 7743 | codegen_); |
| 7744 | } else { |
| 7745 | DCHECK_EQ(instruction->GetType(), Primitive::kPrimLong); |
| 7746 | |
| 7747 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 7748 | const vixl32::Register second = InputRegisterAt(instruction, 1); |
| 7749 | |
| 7750 | DCHECK(!LowRegisterFrom(locations->Out()).Is(second)); |
| 7751 | GenerateDataProc(kind, |
| 7752 | locations->Out(), |
| 7753 | locations->InAt(0), |
| 7754 | second, |
| 7755 | Operand(second, ShiftType::ASR, 31), |
| 7756 | codegen_); |
| 7757 | } else { |
| 7758 | GenerateLongDataProc(instruction, codegen_); |
| 7759 | } |
| 7760 | } |
| 7761 | } |
| 7762 | |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 7763 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 7764 | void InstructionCodeGeneratorARMVIXL::GenerateAndConst(vixl32::Register out, |
| 7765 | vixl32::Register first, |
| 7766 | uint32_t value) { |
| 7767 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 7768 | if (value == 0xffffffffu) { |
| 7769 | if (!out.Is(first)) { |
| 7770 | __ Mov(out, first); |
| 7771 | } |
| 7772 | return; |
| 7773 | } |
| 7774 | if (value == 0u) { |
| 7775 | __ Mov(out, 0); |
| 7776 | return; |
| 7777 | } |
| 7778 | if (GetAssembler()->ShifterOperandCanHold(AND, value)) { |
| Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 7779 | __ And(out, first, value); |
| 7780 | } else if (GetAssembler()->ShifterOperandCanHold(BIC, ~value)) { |
| 7781 | __ Bic(out, first, ~value); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 7782 | } else { |
| Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 7783 | DCHECK(IsPowerOfTwo(value + 1)); |
| 7784 | __ Ubfx(out, first, 0, WhichPowerOf2(value + 1)); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 7785 | } |
| 7786 | } |
| 7787 | |
| 7788 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 7789 | void InstructionCodeGeneratorARMVIXL::GenerateOrrConst(vixl32::Register out, |
| 7790 | vixl32::Register first, |
| 7791 | uint32_t value) { |
| 7792 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 7793 | if (value == 0u) { |
| 7794 | if (!out.Is(first)) { |
| 7795 | __ Mov(out, first); |
| 7796 | } |
| 7797 | return; |
| 7798 | } |
| 7799 | if (value == 0xffffffffu) { |
| 7800 | __ Mvn(out, 0); |
| 7801 | return; |
| 7802 | } |
| 7803 | if (GetAssembler()->ShifterOperandCanHold(ORR, value)) { |
| 7804 | __ Orr(out, first, value); |
| 7805 | } else { |
| 7806 | DCHECK(GetAssembler()->ShifterOperandCanHold(ORN, ~value)); |
| 7807 | __ Orn(out, first, ~value); |
| 7808 | } |
| 7809 | } |
| 7810 | |
| 7811 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 7812 | void InstructionCodeGeneratorARMVIXL::GenerateEorConst(vixl32::Register out, |
| 7813 | vixl32::Register first, |
| 7814 | uint32_t value) { |
| 7815 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 7816 | if (value == 0u) { |
| 7817 | if (!out.Is(first)) { |
| 7818 | __ Mov(out, first); |
| 7819 | } |
| 7820 | return; |
| 7821 | } |
| 7822 | __ Eor(out, first, value); |
| 7823 | } |
| 7824 | |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7825 | void InstructionCodeGeneratorARMVIXL::GenerateAddLongConst(Location out, |
| 7826 | Location first, |
| 7827 | uint64_t value) { |
| 7828 | vixl32::Register out_low = LowRegisterFrom(out); |
| 7829 | vixl32::Register out_high = HighRegisterFrom(out); |
| 7830 | vixl32::Register first_low = LowRegisterFrom(first); |
| 7831 | vixl32::Register first_high = HighRegisterFrom(first); |
| 7832 | uint32_t value_low = Low32Bits(value); |
| 7833 | uint32_t value_high = High32Bits(value); |
| 7834 | if (value_low == 0u) { |
| 7835 | if (!out_low.Is(first_low)) { |
| 7836 | __ Mov(out_low, first_low); |
| 7837 | } |
| 7838 | __ Add(out_high, first_high, value_high); |
| 7839 | return; |
| 7840 | } |
| 7841 | __ Adds(out_low, first_low, value_low); |
| Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 7842 | if (GetAssembler()->ShifterOperandCanHold(ADC, value_high, kCcDontCare)) { |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7843 | __ Adc(out_high, first_high, value_high); |
| Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 7844 | } else if (GetAssembler()->ShifterOperandCanHold(SBC, ~value_high, kCcDontCare)) { |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7845 | __ Sbc(out_high, first_high, ~value_high); |
| 7846 | } else { |
| 7847 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 7848 | UNREACHABLE(); |
| 7849 | } |
| 7850 | } |
| 7851 | |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 7852 | void InstructionCodeGeneratorARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7853 | LocationSummary* locations = instruction->GetLocations(); |
| 7854 | Location first = locations->InAt(0); |
| 7855 | Location second = locations->InAt(1); |
| 7856 | Location out = locations->Out(); |
| 7857 | |
| 7858 | if (second.IsConstant()) { |
| 7859 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 7860 | uint32_t value_low = Low32Bits(value); |
| 7861 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 7862 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 7863 | vixl32::Register out_reg = OutputRegister(instruction); |
| 7864 | if (instruction->IsAnd()) { |
| 7865 | GenerateAndConst(out_reg, first_reg, value_low); |
| 7866 | } else if (instruction->IsOr()) { |
| 7867 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 7868 | } else { |
| 7869 | DCHECK(instruction->IsXor()); |
| 7870 | GenerateEorConst(out_reg, first_reg, value_low); |
| 7871 | } |
| 7872 | } else { |
| 7873 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 7874 | uint32_t value_high = High32Bits(value); |
| 7875 | vixl32::Register first_low = LowRegisterFrom(first); |
| 7876 | vixl32::Register first_high = HighRegisterFrom(first); |
| 7877 | vixl32::Register out_low = LowRegisterFrom(out); |
| 7878 | vixl32::Register out_high = HighRegisterFrom(out); |
| 7879 | if (instruction->IsAnd()) { |
| 7880 | GenerateAndConst(out_low, first_low, value_low); |
| 7881 | GenerateAndConst(out_high, first_high, value_high); |
| 7882 | } else if (instruction->IsOr()) { |
| 7883 | GenerateOrrConst(out_low, first_low, value_low); |
| 7884 | GenerateOrrConst(out_high, first_high, value_high); |
| 7885 | } else { |
| 7886 | DCHECK(instruction->IsXor()); |
| 7887 | GenerateEorConst(out_low, first_low, value_low); |
| 7888 | GenerateEorConst(out_high, first_high, value_high); |
| 7889 | } |
| 7890 | } |
| 7891 | return; |
| 7892 | } |
| 7893 | |
| 7894 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 7895 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 7896 | vixl32::Register second_reg = InputRegisterAt(instruction, 1); |
| 7897 | vixl32::Register out_reg = OutputRegister(instruction); |
| 7898 | if (instruction->IsAnd()) { |
| 7899 | __ And(out_reg, first_reg, second_reg); |
| 7900 | } else if (instruction->IsOr()) { |
| 7901 | __ Orr(out_reg, first_reg, second_reg); |
| 7902 | } else { |
| 7903 | DCHECK(instruction->IsXor()); |
| 7904 | __ Eor(out_reg, first_reg, second_reg); |
| 7905 | } |
| 7906 | } else { |
| 7907 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 7908 | vixl32::Register first_low = LowRegisterFrom(first); |
| 7909 | vixl32::Register first_high = HighRegisterFrom(first); |
| 7910 | vixl32::Register second_low = LowRegisterFrom(second); |
| 7911 | vixl32::Register second_high = HighRegisterFrom(second); |
| 7912 | vixl32::Register out_low = LowRegisterFrom(out); |
| 7913 | vixl32::Register out_high = HighRegisterFrom(out); |
| 7914 | if (instruction->IsAnd()) { |
| 7915 | __ And(out_low, first_low, second_low); |
| 7916 | __ And(out_high, first_high, second_high); |
| 7917 | } else if (instruction->IsOr()) { |
| 7918 | __ Orr(out_low, first_low, second_low); |
| 7919 | __ Orr(out_high, first_high, second_high); |
| 7920 | } else { |
| 7921 | DCHECK(instruction->IsXor()); |
| 7922 | __ Eor(out_low, first_low, second_low); |
| 7923 | __ Eor(out_high, first_high, second_high); |
| 7924 | } |
| 7925 | } |
| 7926 | } |
| 7927 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7928 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadOneRegister( |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7929 | HInstruction* instruction, |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7930 | Location out, |
| 7931 | uint32_t offset, |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7932 | Location maybe_temp, |
| 7933 | ReadBarrierOption read_barrier_option) { |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7934 | vixl32::Register out_reg = RegisterFrom(out); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7935 | if (read_barrier_option == kWithReadBarrier) { |
| 7936 | CHECK(kEmitCompilerReadBarrier); |
| 7937 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 7938 | if (kUseBakerReadBarrier) { |
| 7939 | // Load with fast path based Baker's read barrier. |
| 7940 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7941 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 7942 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
| 7943 | } else { |
| 7944 | // Load with slow path based read barrier. |
| 7945 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 7946 | // in the following move operation, as we will need it for the |
| 7947 | // read barrier below. |
| 7948 | __ Mov(RegisterFrom(maybe_temp), out_reg); |
| 7949 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7950 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 7951 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 7952 | } |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7953 | } else { |
| 7954 | // Plain load with no read barrier. |
| 7955 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7956 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 7957 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 7958 | } |
| 7959 | } |
| 7960 | |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7961 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadTwoRegisters( |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7962 | HInstruction* instruction, |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7963 | Location out, |
| 7964 | Location obj, |
| 7965 | uint32_t offset, |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7966 | Location maybe_temp, |
| 7967 | ReadBarrierOption read_barrier_option) { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7968 | vixl32::Register out_reg = RegisterFrom(out); |
| 7969 | vixl32::Register obj_reg = RegisterFrom(obj); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7970 | if (read_barrier_option == kWithReadBarrier) { |
| 7971 | CHECK(kEmitCompilerReadBarrier); |
| 7972 | if (kUseBakerReadBarrier) { |
| 7973 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 7974 | // Load with fast path based Baker's read barrier. |
| 7975 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7976 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 7977 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
| 7978 | } else { |
| 7979 | // Load with slow path based read barrier. |
| 7980 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7981 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 7982 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7983 | } |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7984 | } else { |
| 7985 | // Plain load with no read barrier. |
| 7986 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7987 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 7988 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 7989 | } |
| 7990 | } |
| 7991 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7992 | void InstructionCodeGeneratorARMVIXL::GenerateGcRootFieldLoad( |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7993 | HInstruction* instruction, |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7994 | Location root, |
| 7995 | vixl32::Register obj, |
| 7996 | uint32_t offset, |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7997 | ReadBarrierOption read_barrier_option) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7998 | vixl32::Register root_reg = RegisterFrom(root); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7999 | if (read_barrier_option == kWithReadBarrier) { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8000 | DCHECK(kEmitCompilerReadBarrier); |
| 8001 | if (kUseBakerReadBarrier) { |
| 8002 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8003 | // Baker's read barrier are used. |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8004 | // |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8005 | // Note that we do not actually check the value of |
| 8006 | // `GetIsGcMarking()` to decide whether to mark the loaded GC |
| 8007 | // root or not. Instead, we load into `temp` the read barrier |
| 8008 | // mark entry point corresponding to register `root`. If `temp` |
| 8009 | // is null, it means that `GetIsGcMarking()` is false, and vice |
| 8010 | // versa. |
| 8011 | // |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8012 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8013 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 8014 | // if (temp != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 8015 | // // Slow path. |
| 8016 | // root = temp(root); // root = ReadBarrier::Mark(root); // Runtime entry point call. |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8017 | // } |
| 8018 | |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8019 | // Slow path marking the GC root `root`. The entrypoint will already be loaded in `temp`. |
| 8020 | Location temp = LocationFrom(lr); |
| 8021 | SlowPathCodeARMVIXL* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARMVIXL( |
| 8022 | instruction, root, /* entrypoint */ temp); |
| 8023 | codegen_->AddSlowPath(slow_path); |
| 8024 | |
| 8025 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8026 | const int32_t entry_point_offset = |
| 8027 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(root.reg()); |
| 8028 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 8029 | // threads are suspended or running a checkpoint. |
| 8030 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp), tr, entry_point_offset); |
| 8031 | |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8032 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8033 | GetAssembler()->LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8034 | static_assert( |
| 8035 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 8036 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 8037 | "have different sizes."); |
| 8038 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 8039 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 8040 | "have different sizes."); |
| 8041 | |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8042 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 8043 | // checking GetIsGcMarking. |
| 8044 | __ CompareAndBranchIfNonZero(RegisterFrom(temp), slow_path->GetEntryLabel()); |
| 8045 | __ Bind(slow_path->GetExitLabel()); |
| 8046 | } else { |
| 8047 | // GC root loaded through a slow path for read barriers other |
| 8048 | // than Baker's. |
| 8049 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 8050 | __ Add(root_reg, obj, offset); |
| 8051 | // /* mirror::Object* */ root = root->Read() |
| 8052 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 8053 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8054 | } else { |
| 8055 | // Plain GC root load with no read barrier. |
| 8056 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8057 | GetAssembler()->LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8058 | // Note that GC roots are not affected by heap poisoning, thus we |
| 8059 | // do not have to unpoison `root_reg` here. |
| 8060 | } |
| 8061 | } |
| 8062 | |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8063 | void CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8064 | Location ref, |
| 8065 | vixl32::Register obj, |
| 8066 | uint32_t offset, |
| 8067 | Location temp, |
| 8068 | bool needs_null_check) { |
| 8069 | DCHECK(kEmitCompilerReadBarrier); |
| 8070 | DCHECK(kUseBakerReadBarrier); |
| 8071 | |
| 8072 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 8073 | Location no_index = Location::NoLocation(); |
| 8074 | ScaleFactor no_scale_factor = TIMES_1; |
| 8075 | GenerateReferenceLoadWithBakerReadBarrier( |
| 8076 | 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] | 8077 | } |
| 8078 | |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8079 | void CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8080 | Location ref, |
| 8081 | vixl32::Register obj, |
| 8082 | uint32_t data_offset, |
| 8083 | Location index, |
| 8084 | Location temp, |
| 8085 | bool needs_null_check) { |
| 8086 | DCHECK(kEmitCompilerReadBarrier); |
| 8087 | DCHECK(kUseBakerReadBarrier); |
| 8088 | |
| 8089 | static_assert( |
| 8090 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 8091 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 8092 | // /* HeapReference<Object> */ ref = |
| 8093 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 8094 | ScaleFactor scale_factor = TIMES_4; |
| 8095 | GenerateReferenceLoadWithBakerReadBarrier( |
| 8096 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
| Roland Levillain | 6070e88 | 2016-11-03 17:51:58 +0000 | [diff] [blame] | 8097 | } |
| 8098 | |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8099 | void CodeGeneratorARMVIXL::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8100 | Location ref, |
| 8101 | vixl32::Register obj, |
| 8102 | uint32_t offset, |
| 8103 | Location index, |
| 8104 | ScaleFactor scale_factor, |
| 8105 | Location temp, |
| Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame^] | 8106 | bool needs_null_check) { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8107 | DCHECK(kEmitCompilerReadBarrier); |
| 8108 | DCHECK(kUseBakerReadBarrier); |
| 8109 | |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8110 | // Query `art::Thread::Current()->GetIsGcMarking()` to decide |
| 8111 | // whether we need to enter the slow path to mark the reference. |
| 8112 | // Then, in the slow path, check the gray bit in the lock word of |
| 8113 | // the reference's holder (`obj`) to decide whether to mark `ref` or |
| 8114 | // not. |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8115 | // |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8116 | // Note that we do not actually check the value of `GetIsGcMarking()`; |
| Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame^] | 8117 | // instead, we load into `temp2` the read barrier mark entry point |
| 8118 | // corresponding to register `ref`. If `temp2` is null, it means |
| 8119 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8120 | // |
| 8121 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8122 | // if (temp2 != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 8123 | // // Slow path. |
| 8124 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8125 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 8126 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 8127 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 8128 | // if (is_gray) { |
| 8129 | // ref = temp2(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 8130 | // } |
| 8131 | // } else { |
| 8132 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 8133 | // } |
| 8134 | |
| 8135 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 8136 | |
| 8137 | // Slow path marking the object `ref` when the GC is marking. The |
| 8138 | // entrypoint will already be loaded in `temp2`. |
| 8139 | Location temp2 = LocationFrom(lr); |
| 8140 | SlowPathCodeARMVIXL* slow_path = |
| 8141 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierSlowPathARMVIXL( |
| 8142 | instruction, |
| 8143 | ref, |
| 8144 | obj, |
| 8145 | offset, |
| 8146 | index, |
| 8147 | scale_factor, |
| 8148 | needs_null_check, |
| 8149 | temp_reg, |
| 8150 | /* entrypoint */ temp2); |
| 8151 | AddSlowPath(slow_path); |
| 8152 | |
| 8153 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## ref.reg() |
| 8154 | const int32_t entry_point_offset = |
| 8155 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref.reg()); |
| 8156 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 8157 | // threads are suspended or running a checkpoint. |
| 8158 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp2), tr, entry_point_offset); |
| 8159 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 8160 | // checking GetIsGcMarking. |
| 8161 | __ CompareAndBranchIfNonZero(RegisterFrom(temp2), slow_path->GetEntryLabel()); |
| 8162 | // Fast path: the GC is not marking: just load the reference. |
| 8163 | GenerateRawReferenceLoad(instruction, ref, obj, offset, index, scale_factor, needs_null_check); |
| 8164 | __ Bind(slow_path->GetExitLabel()); |
| 8165 | } |
| 8166 | |
| 8167 | void CodeGeneratorARMVIXL::UpdateReferenceFieldWithBakerReadBarrier(HInstruction* instruction, |
| 8168 | Location ref, |
| 8169 | vixl32::Register obj, |
| 8170 | Location field_offset, |
| 8171 | Location temp, |
| 8172 | bool needs_null_check, |
| 8173 | vixl32::Register temp2) { |
| 8174 | DCHECK(kEmitCompilerReadBarrier); |
| 8175 | DCHECK(kUseBakerReadBarrier); |
| 8176 | |
| 8177 | // Query `art::Thread::Current()->GetIsGcMarking()` to decide |
| 8178 | // whether we need to enter the slow path to update the reference |
| 8179 | // field within `obj`. Then, in the slow path, check the gray bit |
| 8180 | // in the lock word of the reference's holder (`obj`) to decide |
| 8181 | // whether to mark `ref` and update the field or not. |
| 8182 | // |
| 8183 | // Note that we do not actually check the value of `GetIsGcMarking()`; |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8184 | // instead, we load into `temp3` the read barrier mark entry point |
| 8185 | // corresponding to register `ref`. If `temp3` is null, it means |
| 8186 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8187 | // |
| 8188 | // temp3 = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8189 | // if (temp3 != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 8190 | // // Slow path. |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8191 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8192 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame^] | 8193 | // HeapReference<mirror::Object> ref = *(obj + field_offset); // Reference load. |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8194 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 8195 | // if (is_gray) { |
| Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame^] | 8196 | // old_ref = ref; |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8197 | // ref = temp3(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame^] | 8198 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8199 | // } |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8200 | // } |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8201 | |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8202 | vixl32::Register temp_reg = RegisterFrom(temp); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8203 | |
| Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame^] | 8204 | // Slow path updating the object reference at address `obj + field_offset` |
| 8205 | // 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] | 8206 | Location temp3 = LocationFrom(lr); |
| Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame^] | 8207 | SlowPathCodeARMVIXL* slow_path = |
| 8208 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL( |
| 8209 | instruction, |
| 8210 | ref, |
| 8211 | obj, |
| 8212 | /* offset */ 0u, |
| 8213 | /* index */ field_offset, |
| 8214 | /* scale_factor */ ScaleFactor::TIMES_1, |
| 8215 | needs_null_check, |
| 8216 | temp_reg, |
| 8217 | temp2, |
| 8218 | /* entrypoint */ temp3); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8219 | AddSlowPath(slow_path); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8220 | |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8221 | // temp3 = Thread::Current()->pReadBarrierMarkReg ## ref.reg() |
| 8222 | const int32_t entry_point_offset = |
| 8223 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref.reg()); |
| 8224 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 8225 | // threads are suspended or running a checkpoint. |
| 8226 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp3), tr, entry_point_offset); |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8227 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 8228 | // checking GetIsGcMarking. |
| 8229 | __ CompareAndBranchIfNonZero(RegisterFrom(temp3), slow_path->GetEntryLabel()); |
| Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame^] | 8230 | // Fast path: the GC is not marking: nothing to do (the field is |
| 8231 | // up-to-date, and we don't need to load the reference). |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8232 | __ Bind(slow_path->GetExitLabel()); |
| Roland Levillain | 844e653 | 2016-11-03 16:09:47 +0000 | [diff] [blame] | 8233 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8234 | |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8235 | void CodeGeneratorARMVIXL::GenerateRawReferenceLoad(HInstruction* instruction, |
| 8236 | Location ref, |
| 8237 | vixl::aarch32::Register obj, |
| 8238 | uint32_t offset, |
| 8239 | Location index, |
| 8240 | ScaleFactor scale_factor, |
| 8241 | bool needs_null_check) { |
| 8242 | Primitive::Type type = Primitive::kPrimNot; |
| 8243 | vixl32::Register ref_reg = RegisterFrom(ref, type); |
| 8244 | |
| 8245 | // If needed, vixl::EmissionCheckScope guards are used to ensure |
| 8246 | // that no pools are emitted between the load (macro) instruction |
| 8247 | // and MaybeRecordImplicitNullCheck. |
| 8248 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8249 | if (index.IsValid()) { |
| 8250 | // Load types involving an "index": ArrayGet, |
| 8251 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 8252 | // intrinsics. |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8253 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8254 | if (index.IsConstant()) { |
| 8255 | size_t computed_offset = |
| 8256 | (Int32ConstantFrom(index) << scale_factor) + offset; |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8257 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8258 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8259 | if (needs_null_check) { |
| 8260 | MaybeRecordImplicitNullCheck(instruction); |
| 8261 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8262 | } else { |
| 8263 | // Handle the special case of the |
| 8264 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 8265 | // intrinsics, which use a register pair as index ("long |
| 8266 | // offset"), of which only the low part contains data. |
| 8267 | vixl32::Register index_reg = index.IsRegisterPair() |
| 8268 | ? LowRegisterFrom(index) |
| 8269 | : RegisterFrom(index); |
| 8270 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8271 | vixl32::Register temp = temps.Acquire(); |
| 8272 | __ Add(temp, obj, Operand(index_reg, ShiftType::LSL, scale_factor)); |
| 8273 | { |
| 8274 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 8275 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, temp, offset); |
| 8276 | if (needs_null_check) { |
| 8277 | MaybeRecordImplicitNullCheck(instruction); |
| 8278 | } |
| 8279 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8280 | } |
| 8281 | } else { |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8282 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
| 8283 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8284 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8285 | if (needs_null_check) { |
| 8286 | MaybeRecordImplicitNullCheck(instruction); |
| 8287 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8288 | } |
| 8289 | |
| Roland Levillain | 844e653 | 2016-11-03 16:09:47 +0000 | [diff] [blame] | 8290 | // Object* ref = ref_addr->AsMirrorPtr() |
| 8291 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| Roland Levillain | 844e653 | 2016-11-03 16:09:47 +0000 | [diff] [blame] | 8292 | } |
| 8293 | |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8294 | void CodeGeneratorARMVIXL::GenerateReadBarrierSlow(HInstruction* instruction, |
| 8295 | Location out, |
| 8296 | Location ref, |
| 8297 | Location obj, |
| 8298 | uint32_t offset, |
| 8299 | Location index) { |
| 8300 | DCHECK(kEmitCompilerReadBarrier); |
| 8301 | |
| 8302 | // Insert a slow path based read barrier *after* the reference load. |
| 8303 | // |
| 8304 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 8305 | // reference will be carried out by the runtime within the slow |
| 8306 | // path. |
| 8307 | // |
| 8308 | // Note that `ref` currently does not get unpoisoned (when heap |
| 8309 | // poisoning is enabled), which is alright as the `ref` argument is |
| 8310 | // not used by the artReadBarrierSlow entry point. |
| 8311 | // |
| 8312 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 8313 | SlowPathCodeARMVIXL* slow_path = new (GetGraph()->GetArena()) |
| 8314 | ReadBarrierForHeapReferenceSlowPathARMVIXL(instruction, out, ref, obj, offset, index); |
| 8315 | AddSlowPath(slow_path); |
| 8316 | |
| 8317 | __ B(slow_path->GetEntryLabel()); |
| 8318 | __ Bind(slow_path->GetExitLabel()); |
| 8319 | } |
| 8320 | |
| 8321 | void CodeGeneratorARMVIXL::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8322 | Location out, |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8323 | Location ref, |
| 8324 | Location obj, |
| 8325 | uint32_t offset, |
| 8326 | Location index) { |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8327 | if (kEmitCompilerReadBarrier) { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8328 | // Baker's read barriers shall be handled by the fast path |
| 8329 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8330 | DCHECK(!kUseBakerReadBarrier); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8331 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 8332 | // by the runtime within the slow path. |
| 8333 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8334 | } else if (kPoisonHeapReferences) { |
| 8335 | GetAssembler()->UnpoisonHeapReference(RegisterFrom(out)); |
| 8336 | } |
| 8337 | } |
| 8338 | |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8339 | void CodeGeneratorARMVIXL::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 8340 | Location out, |
| 8341 | Location root) { |
| 8342 | DCHECK(kEmitCompilerReadBarrier); |
| 8343 | |
| 8344 | // Insert a slow path based read barrier *after* the GC root load. |
| 8345 | // |
| 8346 | // Note that GC roots are not affected by heap poisoning, so we do |
| 8347 | // not need to do anything special for this here. |
| 8348 | SlowPathCodeARMVIXL* slow_path = |
| 8349 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARMVIXL(instruction, out, root); |
| 8350 | AddSlowPath(slow_path); |
| 8351 | |
| 8352 | __ B(slow_path->GetEntryLabel()); |
| 8353 | __ Bind(slow_path->GetExitLabel()); |
| 8354 | } |
| 8355 | |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8356 | // Check if the desired_dispatch_info is supported. If it is, return it, |
| 8357 | // otherwise return a fall-back info that should be used instead. |
| 8358 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARMVIXL::GetSupportedInvokeStaticOrDirectDispatch( |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8359 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 8360 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | e807ff7 | 2017-01-23 09:03:12 +0000 | [diff] [blame] | 8361 | return desired_dispatch_info; |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8362 | } |
| 8363 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8364 | vixl32::Register CodeGeneratorARMVIXL::GetInvokeStaticOrDirectExtraParameter( |
| 8365 | HInvokeStaticOrDirect* invoke, vixl32::Register temp) { |
| 8366 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 8367 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 8368 | if (!invoke->GetLocations()->Intrinsified()) { |
| 8369 | return RegisterFrom(location); |
| 8370 | } |
| 8371 | // For intrinsics we allow any location, so it may be on the stack. |
| 8372 | if (!location.IsRegister()) { |
| 8373 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, location.GetStackIndex()); |
| 8374 | return temp; |
| 8375 | } |
| 8376 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 8377 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 8378 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 8379 | // simple and more robust approach rather that trying to determine if that's the case. |
| 8380 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| Scott Wakeling | d5cd497 | 2017-02-03 11:38:35 +0000 | [diff] [blame] | 8381 | if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(RegisterFrom(location).GetCode())) { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8382 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(RegisterFrom(location).GetCode()); |
| 8383 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, stack_offset); |
| 8384 | return temp; |
| 8385 | } |
| 8386 | return RegisterFrom(location); |
| 8387 | } |
| 8388 | |
| TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 8389 | Location CodeGeneratorARMVIXL::GenerateCalleeMethodStaticOrDirectCall( |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8390 | HInvokeStaticOrDirect* invoke, Location temp) { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8391 | 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] | 8392 | switch (invoke->GetMethodLoadKind()) { |
| 8393 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 8394 | uint32_t offset = |
| 8395 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 8396 | // temp = thread->string_init_entrypoint |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8397 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp), tr, offset); |
| 8398 | break; |
| 8399 | } |
| 8400 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 8401 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 8402 | break; |
| 8403 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 8404 | __ Mov(RegisterFrom(temp), Operand::From(invoke->GetMethodAddress())); |
| 8405 | break; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8406 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 8407 | HArmDexCacheArraysBase* base = |
| 8408 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 8409 | vixl32::Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, RegisterFrom(temp)); |
| 8410 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 8411 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp), base_reg, offset); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8412 | break; |
| 8413 | } |
| 8414 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
| 8415 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 8416 | vixl32::Register method_reg; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8417 | vixl32::Register reg = RegisterFrom(temp); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8418 | if (current_method.IsRegister()) { |
| 8419 | method_reg = RegisterFrom(current_method); |
| 8420 | } else { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8421 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 8422 | DCHECK(!current_method.IsValid()); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8423 | method_reg = reg; |
| 8424 | GetAssembler()->LoadFromOffset(kLoadWord, reg, sp, kCurrentMethodStackOffset); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8425 | } |
| 8426 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 8427 | GetAssembler()->LoadFromOffset( |
| 8428 | kLoadWord, |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8429 | reg, |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8430 | method_reg, |
| 8431 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
| 8432 | // temp = temp[index_in_cache]; |
| 8433 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 8434 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
| 8435 | GetAssembler()->LoadFromOffset( |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8436 | kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8437 | break; |
| 8438 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8439 | } |
| TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 8440 | return callee_method; |
| 8441 | } |
| 8442 | |
| 8443 | void CodeGeneratorARMVIXL::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 8444 | Location temp) { |
| 8445 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8446 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8447 | switch (invoke->GetCodePtrLocation()) { |
| 8448 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 8449 | __ Bl(GetFrameEntryLabel()); |
| 8450 | break; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8451 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 8452 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 8453 | GetAssembler()->LoadFromOffset( |
| 8454 | kLoadWord, |
| 8455 | lr, |
| 8456 | RegisterFrom(callee_method), |
| 8457 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8458 | { |
| 8459 | // 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] | 8460 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 8461 | vixl32::k16BitT32InstructionSizeInBytes, |
| 8462 | CodeBufferCheckScope::kExactSize); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8463 | // LR() |
| 8464 | __ blx(lr); |
| 8465 | } |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8466 | break; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8467 | } |
| 8468 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8469 | DCHECK(!IsLeafMethod()); |
| 8470 | } |
| 8471 | |
| 8472 | void CodeGeneratorARMVIXL::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 8473 | vixl32::Register temp = RegisterFrom(temp_location); |
| 8474 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 8475 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
| 8476 | |
| 8477 | // Use the calling convention instead of the location of the receiver, as |
| 8478 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 8479 | // slow path, the arguments have been moved to the right place, so here we are |
| 8480 | // guaranteed that the receiver is the first register of the calling convention. |
| 8481 | InvokeDexCallingConventionARMVIXL calling_convention; |
| 8482 | vixl32::Register receiver = calling_convention.GetRegisterAt(0); |
| 8483 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8484 | { |
| 8485 | // Make sure the pc is recorded immediately after the `ldr` instruction. |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 8486 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 8487 | vixl32::kMaxInstructionSizeInBytes, |
| 8488 | CodeBufferCheckScope::kMaximumSize); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8489 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 8490 | __ ldr(temp, MemOperand(receiver, class_offset)); |
| 8491 | MaybeRecordImplicitNullCheck(invoke); |
| 8492 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8493 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 8494 | // emit a read barrier for the previous class reference load. |
| 8495 | // However this is not required in practice, as this is an |
| 8496 | // intermediate/temporary reference and because the current |
| 8497 | // concurrent copying collector keeps the from-space memory |
| 8498 | // intact/accessible until the end of the marking phase (the |
| 8499 | // concurrent copying collector may not in the future). |
| 8500 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 8501 | |
| 8502 | // temp = temp->GetMethodAt(method_offset); |
| 8503 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 8504 | kArmPointerSize).Int32Value(); |
| 8505 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 8506 | // LR = temp->GetEntryPoint(); |
| 8507 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
| 8508 | // LR(); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8509 | // This `blx` *must* be the *last* instruction generated by this stub, so that calls to |
| 8510 | // `RecordPcInfo()` immediately following record the correct pc. Use a scope to help guarantee |
| 8511 | // that. |
| 8512 | // 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] | 8513 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 8514 | vixl32::k16BitT32InstructionSizeInBytes, |
| 8515 | CodeBufferCheckScope::kExactSize); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8516 | __ blx(lr); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8517 | } |
| 8518 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8519 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeStringPatch( |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8520 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 8521 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8522 | } |
| 8523 | |
| 8524 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeTypePatch( |
| 8525 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 8526 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
| 8527 | } |
| 8528 | |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8529 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewTypeBssEntryPatch( |
| 8530 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 8531 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 8532 | } |
| 8533 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8534 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeDexCacheArrayPatch( |
| 8535 | const DexFile& dex_file, uint32_t element_offset) { |
| 8536 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 8537 | } |
| 8538 | |
| 8539 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativePatch( |
| 8540 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 8541 | patches->emplace_back(dex_file, offset_or_index); |
| 8542 | return &patches->back(); |
| 8543 | } |
| 8544 | |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 8545 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateBootImageStringLiteral( |
| 8546 | const DexFile& dex_file, |
| 8547 | dex::StringIndex string_index) { |
| 8548 | return boot_image_string_patches_.GetOrCreate( |
| 8549 | StringReference(&dex_file, string_index), |
| 8550 | [this]() { |
| 8551 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 8552 | }); |
| 8553 | } |
| 8554 | |
| 8555 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateBootImageTypeLiteral( |
| 8556 | const DexFile& dex_file, |
| 8557 | dex::TypeIndex type_index) { |
| 8558 | return boot_image_type_patches_.GetOrCreate( |
| 8559 | TypeReference(&dex_file, type_index), |
| 8560 | [this]() { |
| 8561 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 8562 | }); |
| 8563 | } |
| 8564 | |
| 8565 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateBootImageAddressLiteral(uint32_t address) { |
| Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 8566 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 8567 | } |
| 8568 | |
| 8569 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateDexCacheAddressLiteral(uint32_t address) { |
| 8570 | return DeduplicateUint32Literal(address, &uint32_literals_); |
| 8571 | } |
| 8572 | |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 8573 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitStringLiteral( |
| 8574 | const DexFile& dex_file, |
| 8575 | dex::StringIndex string_index, |
| 8576 | Handle<mirror::String> handle) { |
| 8577 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 8578 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 8579 | return jit_string_patches_.GetOrCreate( |
| 8580 | StringReference(&dex_file, string_index), |
| 8581 | [this]() { |
| 8582 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 8583 | }); |
| 8584 | } |
| 8585 | |
| 8586 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 8587 | dex::TypeIndex type_index, |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 8588 | Handle<mirror::Class> handle) { |
| 8589 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 8590 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 8591 | return jit_class_patches_.GetOrCreate( |
| 8592 | TypeReference(&dex_file, type_index), |
| 8593 | [this]() { |
| 8594 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 8595 | }); |
| 8596 | } |
| 8597 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8598 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 8599 | inline void CodeGeneratorARMVIXL::EmitPcRelativeLinkerPatches( |
| 8600 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 8601 | ArenaVector<LinkerPatch>* linker_patches) { |
| 8602 | for (const PcRelativePatchInfo& info : infos) { |
| 8603 | const DexFile& dex_file = info.target_dex_file; |
| 8604 | size_t offset_or_index = info.offset_or_index; |
| 8605 | DCHECK(info.add_pc_label.IsBound()); |
| 8606 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.GetLocation()); |
| 8607 | // Add MOVW patch. |
| 8608 | DCHECK(info.movw_label.IsBound()); |
| 8609 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.GetLocation()); |
| 8610 | linker_patches->push_back(Factory(movw_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 8611 | // Add MOVT patch. |
| 8612 | DCHECK(info.movt_label.IsBound()); |
| 8613 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.GetLocation()); |
| 8614 | linker_patches->push_back(Factory(movt_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 8615 | } |
| 8616 | } |
| 8617 | |
| 8618 | void CodeGeneratorARMVIXL::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 8619 | DCHECK(linker_patches->empty()); |
| 8620 | size_t size = |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8621 | /* MOVW+MOVT for each entry */ 2u * pc_relative_dex_cache_patches_.size() + |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 8622 | boot_image_string_patches_.size() + |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8623 | /* MOVW+MOVT for each entry */ 2u * pc_relative_string_patches_.size() + |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 8624 | boot_image_type_patches_.size() + |
| 8625 | /* MOVW+MOVT for each entry */ 2u * pc_relative_type_patches_.size() + |
| Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 8626 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size(); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8627 | linker_patches->reserve(size); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8628 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 8629 | linker_patches); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 8630 | for (const auto& entry : boot_image_string_patches_) { |
| 8631 | const StringReference& target_string = entry.first; |
| 8632 | VIXLUInt32Literal* literal = entry.second; |
| 8633 | DCHECK(literal->IsBound()); |
| 8634 | uint32_t literal_offset = literal->GetLocation(); |
| 8635 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 8636 | target_string.dex_file, |
| 8637 | target_string.string_index.index_)); |
| 8638 | } |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8639 | if (!GetCompilerOptions().IsBootImage()) { |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8640 | DCHECK(pc_relative_type_patches_.empty()); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8641 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 8642 | linker_patches); |
| 8643 | } else { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8644 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 8645 | linker_patches); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8646 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 8647 | linker_patches); |
| 8648 | } |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8649 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 8650 | linker_patches); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 8651 | for (const auto& entry : boot_image_type_patches_) { |
| 8652 | const TypeReference& target_type = entry.first; |
| 8653 | VIXLUInt32Literal* literal = entry.second; |
| 8654 | DCHECK(literal->IsBound()); |
| 8655 | uint32_t literal_offset = literal->GetLocation(); |
| 8656 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 8657 | target_type.dex_file, |
| 8658 | target_type.type_index.index_)); |
| 8659 | } |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8660 | DCHECK_EQ(size, linker_patches->size()); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 8661 | } |
| 8662 | |
| 8663 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateUint32Literal( |
| 8664 | uint32_t value, |
| 8665 | Uint32ToLiteralMap* map) { |
| 8666 | return map->GetOrCreate( |
| 8667 | value, |
| 8668 | [this, value]() { |
| 8669 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ value); |
| 8670 | }); |
| 8671 | } |
| 8672 | |
| 8673 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateMethodLiteral( |
| 8674 | MethodReference target_method, |
| 8675 | MethodToLiteralMap* map) { |
| 8676 | return map->GetOrCreate( |
| 8677 | target_method, |
| 8678 | [this]() { |
| 8679 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 8680 | }); |
| 8681 | } |
| 8682 | |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8683 | void LocationsBuilderARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 8684 | LocationSummary* locations = |
| 8685 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 8686 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 8687 | Location::RequiresRegister()); |
| 8688 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 8689 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 8690 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8691 | } |
| 8692 | |
| 8693 | void InstructionCodeGeneratorARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 8694 | vixl32::Register res = OutputRegister(instr); |
| 8695 | vixl32::Register accumulator = |
| 8696 | InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 8697 | vixl32::Register mul_left = |
| 8698 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 8699 | vixl32::Register mul_right = |
| 8700 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
| 8701 | |
| 8702 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 8703 | __ Mla(res, mul_left, mul_right, accumulator); |
| 8704 | } else { |
| 8705 | __ Mls(res, mul_left, mul_right, accumulator); |
| 8706 | } |
| 8707 | } |
| 8708 | |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8709 | void LocationsBuilderARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 8710 | // Nothing to do, this should be removed during prepare for register allocator. |
| 8711 | LOG(FATAL) << "Unreachable"; |
| 8712 | } |
| 8713 | |
| 8714 | void InstructionCodeGeneratorARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 8715 | // Nothing to do, this should be removed during prepare for register allocator. |
| 8716 | LOG(FATAL) << "Unreachable"; |
| 8717 | } |
| 8718 | |
| 8719 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 8720 | void LocationsBuilderARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8721 | LocationSummary* locations = |
| 8722 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 8723 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8724 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
| 8725 | codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 8726 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 8727 | if (switch_instr->GetStartValue() != 0) { |
| 8728 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 8729 | } |
| 8730 | } |
| 8731 | } |
| 8732 | |
| 8733 | // TODO(VIXL): Investigate and reach the parity with old arm codegen. |
| 8734 | void InstructionCodeGeneratorARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8735 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 8736 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 8737 | LocationSummary* locations = switch_instr->GetLocations(); |
| 8738 | vixl32::Register value_reg = InputRegisterAt(switch_instr, 0); |
| 8739 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 8740 | |
| 8741 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
| 8742 | !codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 8743 | // Create a series of compare/jumps. |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8744 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8745 | vixl32::Register temp_reg = temps.Acquire(); |
| 8746 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 8747 | // the immediate, because IP is used as the destination register. For the other |
| 8748 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 8749 | // and they can be encoded in the instruction without making use of IP register. |
| 8750 | __ Adds(temp_reg, value_reg, -lower_bound); |
| 8751 | |
| 8752 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 8753 | // Jump to successors[0] if value == lower_bound. |
| 8754 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 8755 | int32_t last_index = 0; |
| 8756 | for (; num_entries - last_index > 2; last_index += 2) { |
| 8757 | __ Adds(temp_reg, temp_reg, -2); |
| 8758 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 8759 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 8760 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 8761 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 8762 | } |
| 8763 | if (num_entries - last_index == 2) { |
| 8764 | // The last missing case_value. |
| 8765 | __ Cmp(temp_reg, 1); |
| 8766 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
| 8767 | } |
| 8768 | |
| 8769 | // And the default for any other value. |
| 8770 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 8771 | __ B(codegen_->GetLabelOf(default_block)); |
| 8772 | } |
| 8773 | } else { |
| 8774 | // Create a table lookup. |
| 8775 | vixl32::Register table_base = RegisterFrom(locations->GetTemp(0)); |
| 8776 | |
| 8777 | JumpTableARMVIXL* jump_table = codegen_->CreateJumpTable(switch_instr); |
| 8778 | |
| 8779 | // Remove the bias. |
| 8780 | vixl32::Register key_reg; |
| 8781 | if (lower_bound != 0) { |
| 8782 | key_reg = RegisterFrom(locations->GetTemp(1)); |
| 8783 | __ Sub(key_reg, value_reg, lower_bound); |
| 8784 | } else { |
| 8785 | key_reg = value_reg; |
| 8786 | } |
| 8787 | |
| 8788 | // Check whether the value is in the table, jump to default block if not. |
| 8789 | __ Cmp(key_reg, num_entries - 1); |
| 8790 | __ B(hi, codegen_->GetLabelOf(default_block)); |
| 8791 | |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8792 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8793 | vixl32::Register jump_offset = temps.Acquire(); |
| 8794 | |
| 8795 | // Load jump offset from the table. |
| Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 8796 | { |
| 8797 | const size_t jump_size = switch_instr->GetNumEntries() * sizeof(int32_t); |
| 8798 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 8799 | (vixl32::kMaxInstructionSizeInBytes * 4) + jump_size, |
| 8800 | CodeBufferCheckScope::kMaximumSize); |
| 8801 | __ adr(table_base, jump_table->GetTableStartLabel()); |
| 8802 | __ ldr(jump_offset, MemOperand(table_base, key_reg, vixl32::LSL, 2)); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8803 | |
| Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 8804 | // Jump to target block by branching to table_base(pc related) + offset. |
| 8805 | vixl32::Register target_address = table_base; |
| 8806 | __ add(target_address, table_base, jump_offset); |
| 8807 | __ bx(target_address); |
| Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 8808 | |
| Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 8809 | jump_table->EmitTable(codegen_); |
| 8810 | } |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8811 | } |
| 8812 | } |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8813 | void LocationsBuilderARMVIXL::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 8814 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 8815 | locations->SetOut(Location::RequiresRegister()); |
| 8816 | } |
| 8817 | |
| 8818 | void InstructionCodeGeneratorARMVIXL::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 8819 | vixl32::Register base_reg = OutputRegister(base); |
| 8820 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 8821 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
| 8822 | codegen_->EmitMovwMovtPlaceholder(labels, base_reg); |
| 8823 | } |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8824 | |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8825 | // Copy the result of a call into the given target. |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8826 | void CodeGeneratorARMVIXL::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 8827 | if (!trg.IsValid()) { |
| 8828 | DCHECK_EQ(type, Primitive::kPrimVoid); |
| 8829 | return; |
| 8830 | } |
| 8831 | |
| 8832 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 8833 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8834 | Location return_loc = InvokeDexCallingConventionVisitorARMVIXL().GetReturnLocation(type); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8835 | if (return_loc.Equals(trg)) { |
| 8836 | return; |
| 8837 | } |
| 8838 | |
| 8839 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 8840 | // with the last branch. |
| 8841 | if (type == Primitive::kPrimLong) { |
| 8842 | TODO_VIXL32(FATAL); |
| 8843 | } else if (type == Primitive::kPrimDouble) { |
| 8844 | TODO_VIXL32(FATAL); |
| 8845 | } else { |
| 8846 | // Let the parallel move resolver take care of all of this. |
| 8847 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 8848 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 8849 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8850 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8851 | } |
| 8852 | |
| xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 8853 | void LocationsBuilderARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 8854 | LocationSummary* locations = |
| 8855 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 8856 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8857 | locations->SetOut(Location::RequiresRegister()); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8858 | } |
| 8859 | |
| xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 8860 | void InstructionCodeGeneratorARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 8861 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| 8862 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 8863 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
| 8864 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 8865 | OutputRegister(instruction), |
| 8866 | InputRegisterAt(instruction, 0), |
| 8867 | method_offset); |
| 8868 | } else { |
| 8869 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 8870 | instruction->GetIndex(), kArmPointerSize)); |
| 8871 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 8872 | OutputRegister(instruction), |
| 8873 | InputRegisterAt(instruction, 0), |
| 8874 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 8875 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 8876 | OutputRegister(instruction), |
| 8877 | OutputRegister(instruction), |
| 8878 | method_offset); |
| 8879 | } |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8880 | } |
| 8881 | |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 8882 | static void PatchJitRootUse(uint8_t* code, |
| 8883 | const uint8_t* roots_data, |
| 8884 | VIXLUInt32Literal* literal, |
| 8885 | uint64_t index_in_table) { |
| 8886 | DCHECK(literal->IsBound()); |
| 8887 | uint32_t literal_offset = literal->GetLocation(); |
| 8888 | uintptr_t address = |
| 8889 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 8890 | uint8_t* data = code + literal_offset; |
| 8891 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 8892 | } |
| 8893 | |
| 8894 | void CodeGeneratorARMVIXL::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 8895 | for (const auto& entry : jit_string_patches_) { |
| 8896 | const auto& it = jit_string_roots_.find(entry.first); |
| 8897 | DCHECK(it != jit_string_roots_.end()); |
| 8898 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
| 8899 | } |
| 8900 | for (const auto& entry : jit_class_patches_) { |
| 8901 | const auto& it = jit_class_roots_.find(entry.first); |
| 8902 | DCHECK(it != jit_class_roots_.end()); |
| 8903 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
| 8904 | } |
| 8905 | } |
| 8906 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8907 | void CodeGeneratorARMVIXL::EmitMovwMovtPlaceholder( |
| 8908 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels, |
| 8909 | vixl32::Register out) { |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 8910 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 8911 | 3 * vixl32::kMaxInstructionSizeInBytes, |
| 8912 | CodeBufferCheckScope::kMaximumSize); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8913 | // TODO(VIXL): Think about using mov instead of movw. |
| 8914 | __ bind(&labels->movw_label); |
| 8915 | __ movw(out, /* placeholder */ 0u); |
| 8916 | __ bind(&labels->movt_label); |
| 8917 | __ movt(out, /* placeholder */ 0u); |
| 8918 | __ bind(&labels->add_pc_label); |
| 8919 | __ add(out, out, pc); |
| 8920 | } |
| 8921 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8922 | #undef __ |
| 8923 | #undef QUICK_ENTRY_POINT |
| 8924 | #undef TODO_VIXL32 |
| 8925 | |
| 8926 | } // namespace arm |
| 8927 | } // namespace art |